X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdata-in.c;h=eda6d1258f729b8d05352fb71fe1a24a0cdb1ef6;hb=18121006e5416f858633900820c4518dd30479c4;hp=3f2f8074d800321647acad71805e8fab2ec0b856;hpb=9b94efd7513afdb12a6023024e00e50801532fee;p=pspp diff --git a/src/data/data-in.c b/src/data/data-in.c index 3f2f8074d8..eda6d1258f 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009 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 @@ -27,11 +27,13 @@ #include #include #include +#include #include "calendar.h" #include "identifier.h" #include "settings.h" #include "value.h" +#include "format.h" #include #include @@ -83,20 +85,24 @@ static int hexit_value (int c); /* Parses the characters in INPUT, which are encoded in the given ENCODING, according to FORMAT. Stores the parsed - representation in OUTPUT, which has the given WIDTH (0 for - a numeric field, otherwise the string width). + representation in OUTPUT, which the caller must have + initialized with the given WIDTH (0 for a numeric field, + otherwise the string width). If no decimal point is included in a numeric format, then IMPLIED_DECIMALS decimal places are implied. Specify 0 if no decimal places should be implied. - If FIRST_COLUMN is nonzero, then it should be the 1-based - column number of the first character in INPUT, used in error - messages. */ + If FIRST_COLUMN and LAST_COLUMN are nonzero, then they should + be the 1-based column number of the first and + one-past-the-last-character in INPUT, for use in error + messages. (LAST_COLUMN cannot always be calculated from + FIRST_COLUMN plus the length of the input because of the + possibility of escaped quotes in strings, etc.) */ bool data_in (struct substring input, enum legacy_encoding encoding, enum fmt_type format, int implied_decimals, - int first_column, union value *output, int width) + int first_column, int last_column, union value *output, int width) { static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] = { @@ -131,7 +137,7 @@ data_in (struct substring input, enum legacy_encoding encoding, i.width = width; i.first_column = first_column; - i.last_column = first_column + ss_length (input) - 1; + i.last_column = last_column; if (!ss_is_empty (i.input)) { @@ -167,7 +173,10 @@ parse_number (struct data_in *i) int save_errno; char *tail; - assert (fmt_get_category (i->format) != FMT_CAT_CUSTOM); + if (fmt_get_category (i->format) == FMT_CAT_CUSTOM) + { + style = settings_get_style (FMT_F); + } /* Trim spaces and check for missing value representation. */ if (trim_spaces_and_check_missing (i)) @@ -599,7 +608,7 @@ parse_A (struct data_in *i) { /* This is equivalent to buf_copy_rpad, except that we posibly do a character set recoding in the middle. */ - char *dst = i->output->s; + char *dst = value_str_rw (i->output, i->width); size_t dst_size = i->width; const char *src = ss_data (i->input); size_t src_size = ss_length (i->input); @@ -615,6 +624,7 @@ parse_A (struct data_in *i) static bool parse_AHEX (struct data_in *i) { + char *s = value_str_rw (i->output, i->width); size_t j; for (j = 0; ; j++) @@ -641,10 +651,10 @@ parse_AHEX (struct data_in *i) } if (j < i->width) - i->output->s[j] = hexit_value (hi) * 16 + hexit_value (lo); + s[j] = hexit_value (hi) * 16 + hexit_value (lo); } - memset (i->output->s + j, ' ', i->width - j); + memset (&s[j], ' ', i->width - j); return true; } @@ -1167,11 +1177,11 @@ vdata_warning (const struct data_in *i, const char *format, va_list args) ds_put_char (&text, '('); if (i->first_column != 0) { - if (i->first_column == i->last_column) + if (i->first_column == i->last_column - 1) ds_put_format (&text, _("column %d"), i->first_column); else ds_put_format (&text, _("columns %d-%d"), - i->first_column, i->last_column); + i->first_column, i->last_column - 1); ds_put_cstr (&text, ", "); } ds_put_format (&text, _("%s field) "), fmt_name (i->format)); @@ -1212,7 +1222,7 @@ static void default_result (struct data_in *i) { if (fmt_is_string (i->format)) - memset (i->output->s, ' ', i->width); + memset (value_str_rw (i->output, i->width), ' ', i->width); else i->output->f = settings_get_blanks (); }