X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fdata-parser.c;h=800ae57b50db3e027a82396ce243e4604cf45f5f;hb=38993354cabb6fc37bb882be92f9a49e9aeb4c88;hp=fe78aeb36ed272f309481870d79ea6669d48d735;hpb=8b71948cd57dbd2787cb4c50525b957e9be8a62b;p=pspp diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index fe78aeb36e..800ae57b50 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include "xalloc.h" @@ -471,7 +471,7 @@ cut_field (const struct data_parser *parser, struct dfm_reader *reader, } *field = ds_ss (tmp); } - *last_column = dfm_column_start (reader); + *last_column = *first_column + (ss_length (line) - ss_length (p)); /* Skip trailing soft separator and a single hard separator if present. */ @@ -484,7 +484,8 @@ cut_field (const struct data_parser *parser, struct dfm_reader *reader, { /* Regular field. */ ss_get_chars (&p, ss_cspan (p, ds_ss (&parser->any_sep)), field); - *last_column = dfm_column_start (reader); + *last_column = *first_column + ss_length (*field); + if (!ss_ltrim (&p, parser->soft_seps) || ss_is_empty (p) || ss_find_char (parser->hard_seps, p.string[0]) != SIZE_MAX) { @@ -508,7 +509,8 @@ static bool parse_fixed (const struct data_parser *parser, struct dfm_reader *reader, struct ccase *c) { - const char *encoding = dfm_reader_get_legacy_encoding (reader); + const char *input_encoding = dfm_reader_get_legacy_encoding (reader); + const char *output_encoding = dict_get_encoding (parser->dict); struct field *f; int row; @@ -530,13 +532,18 @@ parse_fixed (const struct data_parser *parser, struct dfm_reader *reader, line = dfm_get_record (reader); for (; f < &parser->fields[parser->field_cnt] && f->record == row; f++) - data_in (ss_substr (line, f->first_column - 1, - f->format.w), - encoding, f->format.type, f->format.d, - f->first_column, f->first_column + f->format.w, - parser->dict, - case_data_rw_idx (c, f->case_idx), - fmt_var_width (&f->format)); + { + struct substring s = ss_substr (line, f->first_column - 1, + f->format.w); + union value *value = case_data_rw_idx (c, f->case_idx); + + data_in (s, input_encoding, f->format.type, + f->first_column, f->first_column + f->format.w, + value, fmt_var_width (&f->format), output_encoding); + + data_in_imply_decimals (s, input_encoding, f->format.type, + f->format.d, value); + } dfm_forward_record (reader); } @@ -551,7 +558,8 @@ static bool parse_delimited_span (const struct data_parser *parser, struct dfm_reader *reader, struct ccase *c) { - const char *encoding = dfm_reader_get_legacy_encoding (reader); + const char *input_encoding = dfm_reader_get_legacy_encoding (reader); + const char *output_encoding = dict_get_encoding (parser->dict); struct string tmp = DS_EMPTY_INITIALIZER; struct field *f; @@ -576,11 +584,9 @@ parse_delimited_span (const struct data_parser *parser, } } - data_in (s, encoding, f->format.type, 0, - first_column, last_column, - parser->dict, + data_in (s, input_encoding, f->format.type, first_column, last_column, case_data_rw_idx (c, f->case_idx), - fmt_var_width (&f->format)); + fmt_var_width (&f->format), output_encoding); } ds_destroy (&tmp); return true; @@ -593,35 +599,35 @@ static bool parse_delimited_no_span (const struct data_parser *parser, struct dfm_reader *reader, struct ccase *c) { - const char *encoding = dfm_reader_get_legacy_encoding (reader); + const char *input_encoding = dfm_reader_get_legacy_encoding (reader); + const char *output_encoding = dict_get_encoding (parser->dict); struct string tmp = DS_EMPTY_INITIALIZER; struct substring s; - struct field *f; + struct field *f, *end; if (dfm_eof (reader)) return false; - for (f = parser->fields; f < &parser->fields[parser->field_cnt]; f++) + end = &parser->fields[parser->field_cnt]; + for (f = parser->fields; f < end; f++) { int first_column, last_column; if (!cut_field (parser, reader, &first_column, &last_column, &tmp, &s)) { - if (settings_get_undefined ()) + if (f < end - 1 && settings_get_undefined ()) msg (SW, _("Missing value(s) for all variables from %s onward. " "These will be filled with the system-missing value " "or blanks, as appropriate."), f->name); - for (; f < &parser->fields[parser->field_cnt]; f++) + for (; f < end; f++) value_set_missing (case_data_rw_idx (c, f->case_idx), fmt_var_width (&f->format)); goto exit; } - data_in (s, encoding, f->format.type, 0, - first_column, last_column, - parser->dict, + data_in (s, input_encoding, f->format.type, first_column, last_column, case_data_rw_idx (c, f->case_idx), - fmt_var_width (&f->format)); + fmt_var_width (&f->format), output_encoding); } s = dfm_get_record (reader); @@ -645,7 +651,6 @@ dump_fixed_table (const struct data_parser *parser, size_t i; t = tab_create (4, parser->field_cnt + 1); - tab_columns (t, TAB_COL_DOWN); tab_headers (t, 0, 0, 1, 0); tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Variable")); tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Record")); @@ -653,7 +658,6 @@ dump_fixed_table (const struct data_parser *parser, tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Format")); tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 3, parser->field_cnt); tab_hline (t, TAL_2, 0, 3, 1); - tab_dim (t, tab_natural_dimensions, NULL, NULL); for (i = 0; i < parser->field_cnt; i++) { @@ -686,13 +690,11 @@ dump_delimited_table (const struct data_parser *parser, size_t i; t = tab_create (2, parser->field_cnt + 1); - tab_columns (t, TAB_COL_DOWN); tab_headers (t, 0, 0, 1, 0); tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Variable")); tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Format")); tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 1, parser->field_cnt); tab_hline (t, TAL_2, 0, 1, 1); - tab_dim (t, tab_natural_dimensions, NULL, NULL); for (i = 0; i < parser->field_cnt; i++) {