sys-file-reader: Variable attributes record uses long variable names.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 21 May 2010 04:56:48 +0000 (21:56 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 21 May 2010 04:56:48 +0000 (21:56 -0700)
Michel Boaventura provided a system file for which PSPP complained about
bad variable attributes records.  I found out that this was because the
variables were specified using long names, not short names.  This commit
allows PSPP to read these variable attributes properly.

doc/dev/system-file-format.texi
src/data/sys-file-reader.c

index 757867cab230f5a7d6b11936d5b00951120f7332..972b1331b4fb0f0be54ff7b2118f8bb204a71293 100644 (file)
@@ -1087,7 +1087,8 @@ element.
 In record type 18, this field contains a sequence of one or more
 variable attribute sets.  If more than one variable attribute set is
 present, each one after the first is delimited from the previous by
 In record type 18, this field contains a sequence of one or more
 variable attribute sets.  If more than one variable attribute set is
 present, each one after the first is delimited from the previous by
-@code{/}.  Each variable attribute set consists of a variable name,
+@code{/}.  Each variable attribute set consists of a (potentially
+long) variable name,
 followed by @code{:}, followed by an attribute set with the same
 syntax as on record type 17.
 
 followed by @code{:}, followed by an attribute set with the same
 syntax as on record type 17.
 
index 48a5188fb65fe39586804774c6e1f96b09ea0a92..03234c2d66166f60138cd67fa22ca7b7291e581e 100644 (file)
@@ -133,6 +133,10 @@ static void text_warn (struct sfm_reader *r, struct text_record *text,
 static char *text_get_token (struct text_record *,
                              struct substring delimiters, char *delimiter);
 static bool text_match (struct text_record *, char c);
 static char *text_get_token (struct text_record *,
                              struct substring delimiters, char *delimiter);
 static bool text_match (struct text_record *, char c);
+static bool text_read_variable_name (struct sfm_reader *, struct dictionary *,
+                                     struct text_record *,
+                                     struct substring delimiters,
+                                     struct variable **);
 static bool text_read_short_name (struct sfm_reader *, struct dictionary *,
                                   struct text_record *,
                                   struct substring delimiters,
 static bool text_read_short_name (struct sfm_reader *, struct dictionary *,
                                   struct text_record *,
                                   struct substring delimiters,
@@ -1697,7 +1701,7 @@ read_variable_attributes (struct sfm_reader *r,
   for (;;) 
     {
       struct variable *var;
   for (;;) 
     {
       struct variable *var;
-      if (!text_read_short_name (r, dict, text, ss_cstr (":"), &var))
+      if (!text_read_variable_name (r, dict, text, ss_cstr (":"), &var))
         break;
       read_attributes (r, text, var != NULL ? var_get_attributes (var) : NULL);
     }
         break;
       read_attributes (r, text, var != NULL ? var_get_attributes (var) : NULL);
     }
@@ -2131,6 +2135,27 @@ read_variable_to_value_pair (struct sfm_reader *r, struct dictionary *dict,
     }
 }
 
     }
 }
 
+static bool
+text_read_variable_name (struct sfm_reader *r, struct dictionary *dict,
+                         struct text_record *text, struct substring delimiters,
+                         struct variable **var)
+{
+  char *name;
+
+  name = text_get_token (text, delimiters, NULL);
+  if (name == NULL)
+    return false;
+
+  *var = dict_lookup_var (dict, name);
+  if (*var != NULL)
+    return true;
+
+  text_warn (r, text, _("Dictionary record refers to unknown variable %s."),
+             name);
+  return false;
+}
+
+
 static bool
 text_read_short_name (struct sfm_reader *r, struct dictionary *dict,
                       struct text_record *text, struct substring delimiters,
 static bool
 text_read_short_name (struct sfm_reader *r, struct dictionary *dict,
                       struct text_record *text, struct substring delimiters,