* automake.mk: Add new file.
[pspp-builds.git] / src / language / data-io / data-list.c
index 6ca829fc5ab7d75d5459c58d1d828436cc5d5c3c..4fea7a407038364aca731376c6c86d11d9e66caf 100644 (file)
@@ -120,7 +120,7 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds)
   struct dictionary *dict;
   struct data_list_pgm *dls;
   int table = -1;                /* Print table if nonzero, -1=undecided. */
-  struct file_handle *fh = fh_inline_file ();
+  struct file_handle *fh = NULL;
   struct pool *tmp_pool;
   bool ok;
 
@@ -143,6 +143,7 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds)
       if (lex_match_id (lexer, "FILE"))
        {
          lex_match (lexer, '=');
+          fh_unref (fh);
          fh = fh_parse (lexer, FH_REF_FILE | FH_REF_INLINE);
          if (fh == NULL)
            goto error;
@@ -244,6 +245,8 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds)
        }
     }
 
+  if (fh == NULL)
+    fh = fh_inline_file ();
   fh_set_default_handle (fh);
 
   if (dls->type == -1)
@@ -292,10 +295,12 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds)
     }
 
   pool_destroy (tmp_pool);
+  fh_unref (fh);
 
   return CMD_SUCCESS;
 
  error:
+  fh_unref (fh);
   data_list_trns_free (dls);
   return CMD_CASCADING_FAILURE;
 }
@@ -668,6 +673,7 @@ read_from_data_list (const struct data_list_pgm *dls, struct ccase *c)
 static bool
 read_from_data_list_fixed (const struct data_list_pgm *dls, struct ccase *c)
 {
+  enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (dls->reader);
   struct dls_var_spec *spec;
   int row;
 
@@ -693,9 +699,10 @@ read_from_data_list_fixed (const struct data_list_pgm *dls, struct ccase *c)
           if (row < spec->record)
             break;
 
-          data_in (ss_substr (line, spec->first_column - 1, spec->input.w),
-                   spec->input.type, spec->input.d, spec->first_column,
-                   case_data_rw_idx (c, spec->fv),
+          data_in (ss_substr (line, spec->first_column - 1,
+                              spec->input.w),
+                   encoding, spec->input.type, spec->input.d,
+                   spec->first_column, case_data_rw_idx (c, spec->fv),
                    fmt_var_width (&spec->input));
         }
 
@@ -711,6 +718,7 @@ read_from_data_list_fixed (const struct data_list_pgm *dls, struct ccase *c)
 static bool
 read_from_data_list_free (const struct data_list_pgm *dls, struct ccase *c)
 {
+  enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (dls->reader);
   struct dls_var_spec *spec;
 
   ll_for_each (spec, struct dls_var_spec, ll, &dls->specs)
@@ -731,7 +739,7 @@ read_from_data_list_free (const struct data_list_pgm *dls, struct ccase *c)
            }
        }
 
-      data_in (field, spec->input.type, 0,
+      data_in (field, encoding, spec->input.type, 0,
                dfm_get_column (dls->reader, ss_data (field)),
                case_data_rw_idx (c, spec->fv), fmt_var_width (&spec->input));
     }
@@ -744,6 +752,7 @@ read_from_data_list_free (const struct data_list_pgm *dls, struct ccase *c)
 static bool
 read_from_data_list_list (const struct data_list_pgm *dls, struct ccase *c)
 {
+  enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (dls->reader);
   struct dls_var_spec *spec;
 
   if (dfm_eof (dls->reader))
@@ -771,7 +780,7 @@ read_from_data_list_list (const struct data_list_pgm *dls, struct ccase *c)
          break;
        }
 
-      data_in (field, spec->input.type, 0,
+      data_in (field, encoding, spec->input.type, 0,
                dfm_get_column (dls->reader, ss_data (field)),
                case_data_rw_idx (c, spec->fv), fmt_var_width (&spec->input));
     }