pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp doc/dev/system-file-format.texi src/data/C...


From: Ben Pfaff
Subject: [Pspp-cvs] pspp doc/dev/system-file-format.texi src/data/C...
Date: Fri, 07 Dec 2007 05:22:06 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 07/12/07 05:22:06

Modified files:
        doc/dev        : system-file-format.texi 
        src/data       : ChangeLog sys-file-reader.c 

Log message:
        Handle variable display parameters record with only 2 data items per
        variable.  Reported by Guido Gay <address@hidden>.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/doc/dev/system-file-format.texi?cvsroot=pspp&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.173&r2=1.174
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/sys-file-reader.c?cvsroot=pspp&r1=1.52&r2=1.53

Patches:
Index: doc/dev/system-file-format.texi
===================================================================
RCS file: /cvsroot/pspp/pspp/doc/dev/system-file-format.texi,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- doc/dev/system-file-format.texi     11 Nov 2007 05:51:39 -0000      1.1
+++ doc/dev/system-file-format.texi     7 Dec 2007 05:22:06 -0000       1.2
@@ -606,7 +606,7 @@
 
 /* @r{Repeated @code{count} times}. */
 int32               measure;
-int32               width;
+int32               width;           /* @r{Not always present.} */
 int32               alignment;
 @end example
 
@@ -622,7 +622,7 @@
 
 @item int32 count;
 The number of sets of variable display parameters (ordinarily the
-number of variables in the dictionary), times 3.
+number of variables in the dictionary), times 2 or 3.
 @end table
 
 The remaining members are repeated @code{count} times, in the same
@@ -648,6 +648,10 @@
 @item int32 width;
 The width of the display column for the variable in characters.
 
+This field is present if @var{count} is 3 times the number of
+variables in the dictionary.  It is omitted if @var{count} is 2 times
+the number of variables.
+
 @item int32 alignment;
 The alignment of the variable for display purposes:
 

Index: src/data/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -b -r1.173 -r1.174
--- src/data/ChangeLog  5 Dec 2007 06:15:38 -0000       1.173
+++ src/data/ChangeLog  7 Dec 2007 05:22:06 -0000       1.174
@@ -1,3 +1,11 @@
+2007-12-06  Ben Pfaff  <address@hidden>
+
+       Patch #6303.
+
+       * sys-file-reader.c (read_display_parameters): Handle variable
+       display parameters record with only 2 data items per variable.
+       Reported by Guido Gay <address@hidden>.
+
 2007-12-04  Ben Pfaff  <address@hidden>
 
        * identifier.c (lex_id_match_n): New function.

Index: src/data/sys-file-reader.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/sys-file-reader.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- src/data/sys-file-reader.c  11 Nov 2007 05:51:41 -0000      1.52
+++ src/data/sys-file-reader.c  7 Dec 2007 05:22:06 -0000       1.53
@@ -845,19 +845,36 @@
 read_display_parameters (struct sfm_reader *r, size_t size, size_t count,
                          struct dictionary *dict)
 {
-  const size_t n_vars = count / 3 ;
+  size_t n_vars;
+  bool includes_width;
   bool warned = false;
-  int i;
+  size_t i;
+
+  if (size != 4)
+    {
+      sys_warn (r, _("Bad size %zu on extension 11."), size);
+      skip_bytes (r, size * count);
+      return;
+    }
 
-  if (count % 3 || n_vars != dict_get_var_cnt (dict))
-    sys_error (r, _("Bad size (%zu) or count (%zu) on extension 11."),
-               size, count);
+  n_vars = dict_get_var_cnt (dict);
+  if (count == 3 * n_vars)
+    includes_width = true;
+  else if (count == 2 * n_vars)
+    includes_width = false;
+  else
+    {
+      sys_warn (r, _("Extension 11 has bad count %zu (for %zu variables)."),
+                count, n_vars);
+      skip_bytes (r, size * count);
+      return;
+    }
 
   for (i = 0; i < n_vars; ++i)
     {
       struct variable *v = dict_get_var (dict, i);
       int measure = read_int (r);
-      int width = read_int (r);
+      int width = includes_width ? read_int (r) : 0;
       int align = read_int (r);
 
       /* SPSS 14 sometimes seems to set string variables' measure
@@ -865,16 +882,13 @@
       if (0 == measure && var_is_alpha (v))
         measure = 1;
 
-      /* Older versions (SPSS 9.0) sometimes set the display width
-        to zero.  This causes confusion especially in the GUI */
-      if (0 == width)
-       width = 8;
-
       if (measure < 1 || measure > 3 || align < 0 || align > 2)
         {
           if (!warned)
-            sys_warn (r, _("Invalid variable display parameters.  "
-                           "Default parameters substituted."));
+            sys_warn (r, _("Invalid variable display parameters "
+                           "for variable %zu (%s).  "
+                           "Default parameters substituted."),
+                      i, var_get_name (v));
           warned = true;
           continue;
         }
@@ -882,10 +896,15 @@
       var_set_measure (v, (measure == 1 ? MEASURE_NOMINAL
                            : measure == 2 ? MEASURE_ORDINAL
                            : MEASURE_SCALE));
-      var_set_display_width (v, width);
       var_set_alignment (v, (align == 0 ? ALIGN_LEFT
                              : align == 1 ? ALIGN_RIGHT
                              : ALIGN_CENTRE));
+
+      /* Older versions (SPSS 9.0) sometimes set the display
+        width to zero.  This causes confusion in the GUI, so
+        only set the width if it is nonzero. */
+      if (width > 0)
+        var_set_display_width (v, width);
     }
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]