X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=blobdiff_plain;f=src%2Fdata%2Fdata-in.c;h=e7a83f25b44a5f7a55d2c46e20aed4dc7785e40e;hp=a6544afbbeb7c338b10f4fe9a978c649fb910e37;hb=9254d30d06a0565c89daccedd93a94c4c6086004;hpb=bf6be2aa2a406ee96e4b402734e191b3dbbf956e diff --git a/src/data/data-in.c b/src/data/data-in.c index a6544afb..e7a83f25 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 @@ -53,7 +53,7 @@ /* Information about parsing one data field. */ struct data_in { - enum legacy_encoding encoding;/* Encoding of source. */ + const char *encoding; /* Encoding of source. */ struct substring input; /* Source. */ enum fmt_type format; /* Input format. */ int implied_decimals; /* Number of implied decimal places. */ @@ -85,8 +85,9 @@ 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 @@ -99,7 +100,7 @@ static int hexit_value (int c); 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, +data_in (struct substring input, const char *encoding, enum fmt_type format, int implied_decimals, int first_column, int last_column, union value *output, int width) { @@ -115,7 +116,7 @@ data_in (struct substring input, enum legacy_encoding encoding, assert ((width != 0) == fmt_is_string (format)); - if (encoding == LEGACY_NATIVE + if (0 == strcmp (encoding, LEGACY_NATIVE) || fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING)) { i.input = input; @@ -607,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); @@ -623,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++) @@ -637,7 +639,7 @@ parse_AHEX (struct data_in *i) return false; } - if (i->encoding != LEGACY_NATIVE) + if (0 != strcmp (i->encoding, LEGACY_NATIVE)) { hi = legacy_to_native (i->encoding, hi); lo = legacy_to_native (i->encoding, lo); @@ -649,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; } @@ -1220,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 (); }