From 1bfabd49d76fa7d0e62aa2e29966b2f3e71e3cf6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 16 Feb 2014 21:28:26 -0800 Subject: [PATCH] data-out: Avoid excessive spaces in data_out_stretchy() output. By formatting all numbers with width 40, the output almost always began with a long string of spaces. That tended to stretch out table cells. This commit fixes the problem. --- src/data/data-out.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/data/data-out.c b/src/data/data-out.c index 03aa67ff4e..94e555cc82 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, 2013 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 @@ -200,16 +200,24 @@ char * data_out_stretchy (const union value *input, const char *encoding, const struct fmt_spec *format, struct pool *pool) { - struct fmt_spec wide_format; if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM)) { - /* XXX In the common case this wastes memory for 40 bytes of mostly - spaces. */ + 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; - format = &wide_format; + + 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); -- 2.30.2