X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdata-out.c;h=cb21600a72962bdddcb47eda87dd494db913e7da;hb=e94c7d5a9d2e971e0e3eca623f6bf281d903c24c;hp=3f3611f00da2c032587c53971403e73ff502e35f;hpb=32ea29485bdd610b7d05dd806c5f06f68da0f0fe;p=pspp diff --git a/src/data/data-out.c b/src/data/data-out.c index 3f3611f00d..cb21600a72 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -157,21 +157,21 @@ binary_to_utf8 (const char *in, struct pool *pool) VALUE must be the correct width for FORMAT, that is, its width must be fmt_var_width(FORMAT). - ENCODING must be the encoding of INPUT. Normally this can be obtained by - calling dict_get_encoding() on the dictionary with which INPUT is - associated. ENCODING is only important when FORMAT's type is FMT_A. + INPUT_ENCODING must be the encoding of INPUT. Normally this can be obtained + by calling dict_get_encoding() on the dictionary with which INPUT is + associated. INPUT_ENCODING is only important when FORMAT's type is FMT_A. The return value is dynamically allocated, and must be freed by the caller. If POOL is non-null, then the return value is allocated on that pool. */ char * -data_out_pool (const union value *input, const char *encoding, +data_out_pool (const union value *input, const char *input_encoding, const struct fmt_spec *format, struct pool *pool) { assert (fmt_check_output (format)); if (format->type == FMT_A) { char *in = CHAR_CAST (char *, value_str (input, format->w)); - return recode_string_pool (UTF8, encoding, in, format->w, pool); + return recode_string_pool (UTF8, input_encoding, in, format->w, pool); } else if (fmt_get_category (format->type) == FMT_CAT_BINARY) { @@ -224,9 +224,10 @@ data_out_stretchy (const union value *input, const char *encoding, } char * -data_out (const union value *input, const char *encoding, const struct fmt_spec *format) +data_out (const union value *input, const char *input_encoding, + const struct fmt_spec *format) { - return data_out_pool (input, encoding, format, NULL); + return data_out_pool (input, input_encoding, format, NULL); } @@ -473,7 +474,8 @@ output_date (const union value *input, const struct fmt_spec *format, { if (year <= 9999) p += sprintf (p, "%04d", year); - else if (format->type == FMT_DATETIME) + else if (format->type == FMT_DATETIME + || format->type == FMT_YMDHMS) p = stpcpy (p, "****"); else goto overflow; @@ -508,10 +510,14 @@ output_date (const union value *input, const struct fmt_spec *format, number = fmod (number, 60. * 60.); break; case 'M': + if (number < 0) + *p++ = '-'; + number = fabs (number); p += sprintf (p, "%02d", (int) floor (number / 60.)); number = fmod (number, 60.); excess_width = format->w - (p - tmp); - if (excess_width < 0) + if (excess_width < 0 + || (format->type == FMT_MTIME && excess_width < 3)) goto overflow; if (excess_width == 3 || excess_width == 4 || (excess_width >= 5 && format->d == 0))