X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fdata%2Fdata-out.c;h=3f3611f00da2c032587c53971403e73ff502e35f;hb=32ea29485bdd610b7d05dd806c5f06f68da0f0fe;hp=d3125955b856da23edf85deeff9d48bf1a7556de;hpb=d97b45134c672a8daf9cede78bd844484dcdaaeb;p=pspp diff --git a/src/data/data-out.c b/src/data/data-out.c index d3125955b8..3f3611f00d 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2012, 2013, 2014 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 @@ -193,6 +193,36 @@ data_out_pool (const union value *input, const char *encoding, } } +/* Like data_out_pool(), except that for basic numeric formats (F, COMMA, DOT, + COLLAR, PCT, E) and custom currency formats are formatted as wide as + necessary to fully display the selected number of decimal places. */ +char * +data_out_stretchy (const union value *input, const char *encoding, + const struct fmt_spec *format, struct pool *pool) +{ + + if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM)) + { + const struct fmt_number_style *style = settings_get_style (format->type); + struct fmt_spec wide_format; + char tmp[128]; + size_t size; + + wide_format.type = format->type; + wide_format.w = 40; + wide_format.d = format->d; + + size = format->w + style->extra_bytes + 1; + if (size <= sizeof tmp) + { + output_number (input, &wide_format, tmp); + return pool_strdup (pool, tmp + strspn (tmp, " ")); + } + } + + return data_out_pool (input, encoding, format, pool); +} + char * data_out (const union value *input, const char *encoding, const struct fmt_spec *format) { @@ -585,7 +615,7 @@ static void output_AHEX (const union value *input, const struct fmt_spec *format, char *output) { - output_hex (value_str (input, format->w), format->w / 2, output); + output_hex (value_str (input, format->w / 2), format->w / 2, output); } /* Decimal and scientific formatting. */ @@ -775,7 +805,7 @@ output_scientific (double number, const struct fmt_spec *format, { char *cp = strchr (p, 'E') + 1; long int exponent = strtol (cp, NULL, 10); - if (abs (exponent) > 999) + if (labs (exponent) > 999) return false; sprintf (cp, "%+04ld", exponent); }