/* 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
assert (fmt_check_output (format));
if (format->type == FMT_A)
{
- char *in = CHAR_CAST (char *, value_str (input, format->w));
+ char *in = CHAR_CAST (char *, input->s);
char *out = recode_string (output_encoding, input_encoding,
in, format->w);
ds_put_cstr (output, out);
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);
+ char *in = CHAR_CAST (char *, input->s);
+ return recode_string_pool (UTF8, input_encoding, in, format->w, pool);
}
else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
{
}
}
+/* 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 (const union value *input, const char *encoding, const struct fmt_spec *format)
+data_out_stretchy (const union value *input, const char *encoding,
+ const struct fmt_spec *format, struct pool *pool)
{
- return data_out_pool (input, encoding, format, NULL);
+
+ 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 *input_encoding,
+ const struct fmt_spec *format)
+{
+ return data_out_pool (input, input_encoding, format, NULL);
}
\f
{
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;
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))
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 (input->s, format->w / 2, output);
}
\f
/* Decimal and scientific formatting. */
{
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);
}