DATA LIST: Don't report an error for an empty final field in LIST format.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 6 Aug 2010 23:32:04 +0000 (16:32 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 9 Aug 2010 17:59:05 +0000 (10:59 -0700)
Also add test to prevent inadvertent regressions.

src/language/data-io/data-parser.c
tests/language/data-io/data-list.at

index 1e68c904c3a4e9f16f7567f1205e70929a343c95..2d7f9f4cd4a0528ba1131cc51daa7a43f9df13aa 100644 (file)
@@ -597,22 +597,23 @@ parse_delimited_no_span (const struct data_parser *parser,
   const char *encoding = dfm_reader_get_legacy_encoding (reader);
   struct string tmp = DS_EMPTY_INITIALIZER;
   struct substring s;
-  struct field *f;
+  struct field *f, *end;
 
   if (dfm_eof (reader))
     return false;
 
-  for (f = parser->fields; f < &parser->fields[parser->field_cnt]; f++)
+  end = &parser->fields[parser->field_cnt];
+  for (f = parser->fields; f < end; f++)
     {
       int first_column, last_column;
       if (!cut_field (parser, reader, &first_column, &last_column, &tmp, &s))
        {
-         if (settings_get_undefined ())
+         if (f < end - 1 && settings_get_undefined ())
            msg (SW, _("Missing value(s) for all variables from %s onward.  "
                        "These will be filled with the system-missing value "
                        "or blanks, as appropriate."),
                 f->name);
-          for (; f < &parser->fields[parser->field_cnt]; f++)
+          for (; f < end; f++)
             value_set_missing (case_data_rw_idx (c, f->case_idx),
                                fmt_var_width (&f->format));
           goto exit;
index 589708842149d780ead52721795a378b583d59d1..7683b9c57ba4e9d33660c71b8286f84b1f4148a9 100644 (file)
@@ -1,5 +1,35 @@
 AT_BANNER([DATA LIST])
 
+AT_SETUP([DATA LIST LIST with empty fields])
+AT_DATA([data-list.pspp], [dnl
+DATA LIST LIST NOTABLE /A B C (F1.0).
+BEGIN DATA.
+,,
+,,3
+,2,
+,2,3
+1,,
+1,,3
+1,2,
+1,2,3
+END DATA.
+
+LIST.
+])
+AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
+Table: Data List
+A,B,C
+.,.,.
+.,.,3
+.,2,.
+.,2,3
+1,.,.
+1,.,3
+1,2,.
+1,2,3
+])
+AT_CLEANUP
+
 AT_SETUP([DATA LIST LIST with explicit delimiters])
 AT_DATA([data-list.pspp], [dnl
 data list list ('|','X') /A B C D.