Fully implement arbitrary delimiters on DATA LIST, extending the half
[pspp-builds.git] / src / file-type.c
index e5e3d81e9fde266feb938c8637abadcc4b598bb8..2b11a4abd21ce4deb551a893ad6d2e1a6c7efb41 100644 (file)
@@ -18,7 +18,7 @@
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <stdlib.h>
 #include "alloc.h"
 #include "command.h"
@@ -109,7 +109,6 @@ cmd_file_type (void)
   fty->had_rec_type = 0;
   fty->recs_head = fty->recs_tail = NULL;
 
-  lex_match_id ("TYPE");
   if (lex_match_id ("MIXED"))
     fty->type = FTY_MIXED;
   else if (lex_match_id ("GROUPED"))
@@ -270,6 +269,8 @@ cmd_file_type (void)
        }
     }
 
+  if (!dfm_open_for_reading (fty->handle))
+    goto error;
   default_handle = fty->handle;
 
   create_col_var (&fty->record);
@@ -423,9 +424,6 @@ cmd_record_type (void)
        }
     }
 
-  lex_match_id ("RECORD");
-  lex_match_id ("TYPE");
-
   /* Parse record type values. */
   if (lex_match_id ("OTHER"))
     rct->flags |= RCT_OTHER;
@@ -446,7 +444,7 @@ cmd_record_type (void)
              if (!lex_force_string ())
                goto error;
              rct->v[rct->nv].c = xmalloc (fty->record.nc + 1);
-             st_bare_pad_copy (rct->v[rct->nv].c, ds_value (&tokstr),
+             st_bare_pad_copy (rct->v[rct->nv].c, ds_c_str (&tokstr),
                                fty->record.nc + 1);
            }
          else
@@ -582,8 +580,6 @@ cmd_end_file_type (void)
   fty = vfm_source->aux;
   fty->case_size = dict_get_case_size (default_dict);
 
-  lex_match_id ("TYPE");
-
   if (fty->recs_tail)
     {
       fty->recs_tail->lt = n_trns - 1;
@@ -627,9 +623,6 @@ file_type_source_read (struct case_source *source,
                        write_case_data wc_data UNUSED)
 {
   struct file_type_pgm *fty = source->aux;
-  char *line;
-  int len;
-
   struct fmt_spec format;
 
   dfm_push (fty->handle);
@@ -637,19 +630,22 @@ file_type_source_read (struct case_source *source,
   format.type = fty->record.fmt;
   format.w = fty->record.nc;
   format.d = 0;
-  while (NULL != (line = dfm_get_record (fty->handle, &len)))
+  while (!dfm_eof (fty->handle))
     {
+      struct len_string line;
       struct record_type *iter;
       union value v;
       int i;
 
+      dfm_expand_tabs (fty->handle);
+      dfm_get_record (fty->handle, &line);
       if (formats[fty->record.fmt].cat & FCAT_STRING)
        {
          struct data_in di;
          
          v.c = c->data[fty->record.v->fv].s;
 
-         data_in_finite_line (&di, line, len,
+         data_in_finite_line (&di, ls_c_str (&line), ls_length (&line),
                               fty->record.fc, fty->record.fc + fty->record.nc);
          di.v = (union value *) v.c;
          di.flags = 0;
@@ -672,7 +668,7 @@ file_type_source_read (struct case_source *source,
        {
          struct data_in di;
 
-         data_in_finite_line (&di, line, len,
+         data_in_finite_line (&di, ls_c_str (&line), ls_length (&line),
                               fty->record.fc, fty->record.fc + fty->record.nc);
          di.v = &v;
          di.flags = 0;
@@ -692,13 +688,13 @@ file_type_source_read (struct case_source *source,
          if (fty->wild)
            msg (SW, _("Unknown record type %g."), v.f);
        }
-      dfm_fwd_record (fty->handle);
+      dfm_forward_record (fty->handle);
       continue;
 
     found:
       /* Arrive here if there is a matching record_type, which is in
          iter. */
-      dfm_fwd_record (fty->handle);
+      dfm_forward_record (fty->handle);
     }
 
 /*  switch(fty->type)