Avoid letting data fields overflow in output and GUI. 20130527010502/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 26 May 2013 23:43:01 +0000 (16:43 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 26 May 2013 23:43:01 +0000 (16:43 -0700)
When the output for data_out() is too big for the field width, it produces
output that consists of just asterisks: ******.  This is OK when the
output is really going into a fixed-width space, such as the output for
PRINT and WRITE.  But it is obnoxious if the output is going into PSPP
output or the GUI.  This commit introduces a new function that typically
does not do this, and starts using it in output and the GUI.

Bug #35829.
Reported by John Darrington.
Bug #30731.
Reported by lavila <la@jump23.com>.

src/data/data-out.c
src/data/data-out.h
src/output/tab.c
src/ui/gui/helper.c
tests/language/dictionary/weight.at

index d3125955b856da23edf85deeff9d48bf1a7556de..03aa67ff4e58813f12a45273ff3edd3c28fde53c 100644 (file)
@@ -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 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,28 @@ 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)
+{
+  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. */
+      wide_format.type = format->type;
+      wide_format.w = 40;
+      wide_format.d = format->d;
+      format = &wide_format;
+    }
+
+  return data_out_pool (input, encoding, format, pool);
+}
+
 char *
 data_out (const union value *input, const char *encoding, const struct fmt_spec *format)
 {
index 7dff441289c76e6b155719d230f1e776762499e0..b18d067436fbb9b95a3cc5a9043ea20560b26632 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2011, 2013 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
@@ -29,6 +29,8 @@ char * data_out (const union value *, const char *encoding, const struct fmt_spe
 
 char * data_out_pool (const union value *, const char *encoding, const struct fmt_spec *, struct pool *pool);
 
+char *data_out_stretchy (const union value *, const char *encoding, const struct fmt_spec *, struct pool *);
+
 void data_out_recode (const union value *input, const char *input_encoding,
                       const struct fmt_spec *,
                       struct string *output, const char *output_encoding);
index f5f1f1f84b6ba5ea4535213d23f84948e7a1fb43..bc4ac534d0a30bb8d9ece455c79d1c5f414a063c 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2013 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
@@ -379,9 +379,9 @@ tab_value (struct tab_table *table, int c, int r, unsigned char opt,
     }
 #endif
 
-  contents = data_out_pool (v, var_get_encoding (var),
-                            f != NULL ? f : var_get_print_format (var),
-                            table->container);
+  contents = data_out_stretchy (v, var_get_encoding (var),
+                                f != NULL ? f : var_get_print_format (var),
+                                table->container);
 
   table->cc[c + r * table->cf] = contents;
   table->ct[c + r * table->cf] = opt;
@@ -419,7 +419,7 @@ tab_fixed (struct tab_table *table, int c, int r, unsigned char opt,
 #endif
 
   double_value.f = val;
-  s = data_out_pool (&double_value, C_ENCODING, &f, table->container);
+  s = data_out_stretchy (&double_value, C_ENCODING, &f, table->container);
 
   table->cc[c + r * table->cf] = s + strspn (s, " ");
   table->ct[c + r * table->cf] = opt;
@@ -461,7 +461,7 @@ tab_double (struct tab_table *table, int c, int r, unsigned char opt,
 #endif
 
   double_value.f = val;
-  s = data_out_pool (&double_value, C_ENCODING, fmt, table->container);
+  s = data_out_stretchy (&double_value, C_ENCODING, fmt, table->container);
   table->cc[c + r * table->cf] = s + strspn (s, " ");
   table->ct[c + r * table->cf] = opt;
 }
index 84df352fdd48cf47ea671d2bf63c6886f01064f1..7fc951d3cdeff0a7252bc3cb4de5f1a1ae79effe 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009, 2010, 2011, 2012  Free Software Foundation
+   Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013  Free Software Foundation
 
    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
@@ -96,7 +96,7 @@ value_to_text__ (union value v,
 {
   gchar *s;
 
-  s = data_out (&v, encoding, format);
+  s = data_out_stretchy (&v, encoding, format, NULL);
   if (fmt_is_numeric (format->type))
     g_strchug (s);
   else
index 40226924d7f5e78929780e11e5ed5e8083bb312b..a85347e516fff34da067dd0c2326270f00c31356 100644 (file)
@@ -72,7 +72,7 @@ BVAR,1,6- 10,F5.0
 
 Table: Valid cases = 730; cases with missing value(s) = 0.
 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
-AVAR,730,0,31.515,.405,10.937,119.608,2.411,.181,1.345,.090,76.000,18.000,94.000,23006.00
+AVAR,730,0,31.515,.405,10.937,119.608,2.411,.181,1.345,.090,76.000,18.000,94.000,23006.000
 
 Table: AVAR
 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
@@ -145,7 +145,7 @@ S.E. Skew,,.090
 Range,,76.000
 Minimum,,18.000
 Maximum,,94.000
-Sum,,23006.00
+Sum,,23006.000
 Percentiles,50 (Median),28
 ])
 AT_CLEANUP