X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdata-in.c;h=480d335a9c086b007f01b0a9efcde1b516e2bf0e;hb=638a86001fe7a237bd6c19a181d796305290d72a;hp=7e7d087d51dcfa1ab9811715ff7354f106081bae;hpb=8830c95bb9e8d72621787866141a27fc22e8c786;p=pspp diff --git a/src/data/data-in.c b/src/data/data-in.c index 7e7d087d51..480d335a9c 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -34,6 +34,7 @@ #include "settings.h" #include "value.h" #include "format.h" +#include "dictionary.h" #include #include @@ -54,7 +55,7 @@ /* Information about parsing one data field. */ struct data_in { - const char *encoding; /* Encoding of source. */ + const char *src_enc; /* Encoding of source. */ struct substring input; /* Source. */ enum fmt_type format; /* Input format. */ int implied_decimals; /* Number of implied decimal places. */ @@ -89,6 +90,9 @@ static int hexit_value (int c); representation in OUTPUT, which the caller must have initialized with the given WIDTH (0 for a numeric field, otherwise the string width). + Iff FORMAT is a string format, then DICT must be a pointer + to the dictionary associated with OUTPUT. Otherwise, DICT + may be null. If no decimal point is included in a numeric format, then IMPLIED_DECIMALS decimal places are implied. Specify 0 if no @@ -103,7 +107,9 @@ static int hexit_value (int c); bool 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) + int first_column, int last_column, + const struct dictionary *dict, + union value *output, int width) { static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] = { @@ -112,28 +118,12 @@ data_in (struct substring input, const char *encoding, }; struct data_in i; - void *copy = NULL; + + char *s = NULL; bool ok; assert ((width != 0) == fmt_is_string (format)); - if (0 == strcmp (encoding, LEGACY_NATIVE) - || fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING)) - { - i.input = input; - i.encoding = encoding; - } - else - { - char *s; - ss_alloc_uninit (&i.input, ss_length (input)); - - s = recode_string (LEGACY_NATIVE, encoding, ss_data (input), ss_length (input)); - memcpy (ss_data (i.input), s, ss_length (input)); - free (s); - i.encoding = LEGACY_NATIVE; - copy = ss_data (i.input); - } i.format = format; i.implied_decimals = implied_decimals; @@ -142,22 +132,39 @@ data_in (struct substring input, const char *encoding, i.first_column = first_column; i.last_column = last_column; + i.src_enc = encoding; - if (!ss_is_empty (i.input)) + if (ss_is_empty (input)) { - ok = handlers[i.format] (&i); - if (!ok) - default_result (&i); + default_result (&i); + return true; + } + + if (fmt_get_category (format) & ( FMT_CAT_BINARY | FMT_CAT_HEXADECIMAL | FMT_CAT_LEGACY)) + { + i.input = input; } else { - default_result (&i); - ok = true; + const char *dest_encoding; + + if ( dict == NULL) + { + assert (0 == (fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING))); + dest_encoding = LEGACY_NATIVE; + } + else + dest_encoding = dict_get_encoding (dict); + + s = recode_string (dest_encoding, i.src_enc, ss_data (input), ss_length (input)); + i.input = ss_cstr (s); } - if (copy) - free (copy); + ok = handlers[i.format] (&i); + if (!ok) + default_result (&i); + free (s); return ok; } @@ -617,9 +624,8 @@ parse_A (struct data_in *i) const char *src = ss_data (i->input); size_t src_size = ss_length (i->input); - char *s = recode_string (LEGACY_NATIVE, i->encoding, src, MIN (src_size, dst_size)); - memcpy (dst, s, dst_size); - free (s); + memcpy (dst, src, MIN (src_size, dst_size)); + if (dst_size > src_size) memset (&dst[src_size], ' ', dst_size - src_size); @@ -645,10 +651,10 @@ parse_AHEX (struct data_in *i) return false; } - if (0 != strcmp (i->encoding, LEGACY_NATIVE)) + if (0 != strcmp (i->src_enc, LEGACY_NATIVE)) { - hi = legacy_to_native (i->encoding, hi); - lo = legacy_to_native (i->encoding, lo); + hi = legacy_to_native (i->src_enc, hi); + lo = legacy_to_native (i->src_enc, lo); } if (!c_isxdigit (hi) || !c_isxdigit (lo)) { @@ -867,7 +873,7 @@ parse_trailer (struct data_in *i) if (ss_is_empty (i->input)) return true; - data_warning (i, _("Trailing garbage \"%.*s\" following date."), + data_warning (i, _("Trailing garbage `%.*s' following date."), (int) ss_length (i->input), ss_data (i->input)); return false; } @@ -1193,9 +1199,11 @@ vdata_warning (const struct data_in *i, const char *format, va_list args) ds_put_format (&text, _("%s field) "), fmt_name (i->format)); ds_put_vformat (&text, format, args); - m.category = MSG_DATA; - m.severity = MSG_WARNING; + m.category = MSG_C_DATA; + m.severity = MSG_S_WARNING; m.text = ds_cstr (&text); + m.where.file_name = NULL; + m.where.line_number = 0; msg_emit (&m); }