projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
format: Count prefix and suffix width in terms of display columns.
[pspp-builds.git]
/
src
/
data
/
data-out.c
diff --git
a/src/data/data-out.c
b/src/data/data-out.c
index 85e8eaae3a0288b1d32af2798798c527995db63a..bb774374d476cbc7b6c04aa0db60c7ecc452fc04 100644
(file)
--- a/
src/data/data-out.c
+++ b/
src/data/data-out.c
@@
-131,10
+131,13
@@
char *
data_out_pool (const union value *input, const char *encoding,
const struct fmt_spec *format, struct pool *pool)
{
data_out_pool (const union value *input, const char *encoding,
const struct fmt_spec *format, struct pool *pool)
{
- char *output = xmalloc (format->w + 1);
+ const struct fmt_number_style *style = settings_get_style (format->type);
+ char *output;
char *t ;
assert (fmt_check_output (format));
char *t ;
assert (fmt_check_output (format));
+ output = xmalloc (format->w + style->extra_bytes + 1);
+
converters[format->type] (input, format, output);
t = recode_string_pool (UTF8, encoding, output, format->w, pool);
converters[format->type] (input, format, output);
t = recode_string_pool (UTF8, encoding, output, format->w, pool);
@@
-600,9
+603,9
@@
output_decimal (const struct rounder *r, const struct fmt_spec *format,
the negative suffix, plus (if negative) the negative
prefix. */
width = rounder_width (r, decimals, &integer_digits, &add_neg_prefix);
the negative suffix, plus (if negative) the negative
prefix. */
width = rounder_width (r, decimals, &integer_digits, &add_neg_prefix);
- width += s
s_length (style->neg_suffix)
;
+ width += s
tyle->neg_suffix.width
;
if (add_neg_prefix)
if (add_neg_prefix)
- width += s
s_length (style->neg_prefix)
;
+ width += s
tyle->neg_prefix.width
;
if (width > format->w)
continue;
if (width > format->w)
continue;
@@
-632,10
+635,9
@@
output_decimal (const struct rounder *r, const struct fmt_spec *format,
if (format->w > width)
p = mempset (p, ' ', format->w - width);
if (add_neg_prefix)
if (format->w > width)
p = mempset (p, ' ', format->w - width);
if (add_neg_prefix)
- p = mempcpy (p, ss_data (style->neg_prefix),
- ss_length (style->neg_prefix));
+ p = stpcpy (p, style->neg_prefix.s);
if (add_affixes)
if (add_affixes)
- p =
mempcpy (p, ss_data (style->prefix), ss_length (style->prefix)
);
+ p =
stpcpy (p, style->prefix.s
);
if (!add_grouping)
p = mempcpy (p, magnitude, integer_digits);
else
if (!add_grouping)
p = mempcpy (p, magnitude, integer_digits);
else
@@
-654,13
+656,15
@@
output_decimal (const struct rounder *r, const struct fmt_spec *format,
p = mempcpy (p, &magnitude[integer_digits + 1], decimals);
}
if (add_affixes)
p = mempcpy (p, &magnitude[integer_digits + 1], decimals);
}
if (add_affixes)
- p =
mempcpy (p, ss_data (style->suffix), ss_length (style->suffix)
);
+ p =
stpcpy (p, style->suffix.s
);
if (add_neg_prefix)
if (add_neg_prefix)
- p = mempcpy (p, ss_data (style->neg_suffix),
- ss_length (style->neg_suffix));
+ p = stpcpy (p, style->neg_suffix.s);
else
else
- p = mempset (p, ' ', ss_length (style->neg_suffix));
- assert (p == output + format->w);
+ p = mempset (p, ' ', style->neg_suffix.width);
+
+ assert (p >= output + format->w);
+ assert (p <= output + format->w + style->extra_bytes);
+ *p = '\0';
return true;
}
return true;
}
@@
-681,9
+685,9
@@
output_scientific (double number, const struct fmt_spec *format,
char buf[64], *p;
/* Allocate minimum required space. */
char buf[64], *p;
/* Allocate minimum required space. */
- width = 6 + s
s_length (style->neg_suffix)
;
+ width = 6 + s
tyle->neg_suffix.width
;
if (number < 0)
if (number < 0)
- width += s
s_length (style->neg_prefix)
;
+ width += s
tyle->neg_prefix.width
;
if (width > format->w)
return false;
if (width > format->w)
return false;
@@
-706,10
+710,9
@@
output_scientific (double number, const struct fmt_spec *format,
if (width < format->w)
p = mempset (p, ' ', format->w - width);
if (number < 0)
if (width < format->w)
p = mempset (p, ' ', format->w - width);
if (number < 0)
- p = mempcpy (p, ss_data (style->neg_prefix),
- ss_length (style->neg_prefix));
+ p = stpcpy (p, style->neg_prefix.s);
if (add_affixes)
if (add_affixes)
- p =
mempcpy (p, ss_data (style->prefix), ss_length (style->prefix)
);
+ p =
stpcpy (p, style->prefix.s
);
if (fraction_width > 0)
sprintf (p, "%#.*E", fraction_width - 1, fabs (number));
else
if (fraction_width > 0)
sprintf (p, "%#.*E", fraction_width - 1, fabs (number));
else
@@
-736,16
+739,15
@@
output_scientific (double number, const struct fmt_spec *format,
/* Add suffixes. */
p = strchr (p, '\0');
if (add_affixes)
/* Add suffixes. */
p = strchr (p, '\0');
if (add_affixes)
- p =
mempcpy (p, ss_data (style->suffix), ss_length (style->suffix)
);
+ p =
stpcpy (p, style->suffix.s
);
if (number < 0)
if (number < 0)
- p = mempcpy (p, ss_data (style->neg_suffix),
- ss_length (style->neg_suffix));
+ p = stpcpy (p, style->neg_suffix.s);
else
else
- p = mempset (p, ' ', s
s_length (style->neg_suffix)
);
+ p = mempset (p, ' ', s
tyle->neg_suffix.width
);
- assert (p
== buf
+ format->w);
-
memcpy (output, buf, format->w
);
-
output[format->w]
= '\0';
+ assert (p
>= output
+ format->w);
+
assert (p <= output + format->w + style->extra_bytes
);
+
*p
= '\0';
return true;
}
return true;
}