From: Ben Pfaff Date: Fri, 7 Dec 2007 05:22:06 +0000 (+0000) Subject: Handle variable display parameters record with only 2 data items per X-Git-Tag: v0.6.0~168 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=317ba3232cb1361259bba6aa8444b141068dd0d3;p=pspp-builds.git Handle variable display parameters record with only 2 data items per variable. Reported by Guido Gay . --- diff --git a/doc/dev/system-file-format.texi b/doc/dev/system-file-format.texi index 193c6601..70fa385c 100644 --- a/doc/dev/system-file-format.texi +++ b/doc/dev/system-file-format.texi @@ -606,7 +606,7 @@ int32 count; /* @r{Repeated @code{count} times}. */ int32 measure; -int32 width; +int32 width; /* @r{Not always present.} */ int32 alignment; @end example @@ -622,7 +622,7 @@ The size of @code{int32}. Always set to 4. @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 @@ as nominal scale. @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: diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 6c3b4518..e25c3984 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,11 @@ +2007-12-06 Ben Pfaff + + 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 . + 2007-12-04 Ben Pfaff * identifier.c (lex_id_match_n): New function. diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 1d172ade..18829430 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -845,19 +845,36 @@ static void 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 (count % 3 || n_vars != dict_get_var_cnt (dict)) - sys_error (r, _("Bad size (%zu) or count (%zu) on extension 11."), - size, count); + if (size != 4) + { + sys_warn (r, _("Bad size %zu on extension 11."), size); + skip_bytes (r, size * count); + return; + } + + 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 @@ read_display_parameters (struct sfm_reader *r, size_t size, size_t count, 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 @@ read_display_parameters (struct sfm_reader *r, size_t size, size_t count, 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); } }