data-in: Eliminate "implied_decimals" parameter from data_in().
[pspp] / src / language / data-io / data-parser.c
index fe78aeb36ed272f309481870d79ea6669d48d735..0802bba8c5971117b2ebf9db50ca7ed35b9a0d02 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
 #include <language/data-io/data-reader.h>
 #include <libpspp/message.h>
 #include <libpspp/str.h>
-#include <output/table.h>
+#include <output/tab.h>
 
 #include "xalloc.h"
 
@@ -471,7 +471,7 @@ cut_field (const struct data_parser *parser, struct dfm_reader *reader,
             }
           *field = ds_ss (tmp);
         }
-      *last_column = dfm_column_start (reader);
+      *last_column = *first_column + (ss_length (line) - ss_length (p));
 
       /* Skip trailing soft separator and a single hard separator
          if present. */
@@ -484,7 +484,8 @@ cut_field (const struct data_parser *parser, struct dfm_reader *reader,
     {
       /* Regular field. */
       ss_get_chars (&p, ss_cspan (p, ds_ss (&parser->any_sep)), field);
-      *last_column = dfm_column_start (reader);
+      *last_column = *first_column + ss_length (*field);
+
       if (!ss_ltrim (&p, parser->soft_seps) || ss_is_empty (p)
           || ss_find_char (parser->hard_seps, p.string[0]) != SIZE_MAX)
         {
@@ -530,13 +531,18 @@ parse_fixed (const struct data_parser *parser, struct dfm_reader *reader,
       line = dfm_get_record (reader);
 
       for (; f < &parser->fields[parser->field_cnt] && f->record == row; f++)
-        data_in (ss_substr (line, f->first_column - 1,
-                            f->format.w),
-                 encoding, f->format.type, f->format.d,
-                 f->first_column, f->first_column + f->format.w,
-                parser->dict,
-                 case_data_rw_idx (c, f->case_idx),
-                 fmt_var_width (&f->format));
+        {
+          struct substring s = ss_substr (line, f->first_column - 1,
+                                          f->format.w);
+          union value *value = case_data_rw_idx (c, f->case_idx);
+
+          data_in (s, encoding, f->format.type,
+                   f->first_column, f->first_column + f->format.w,
+                   parser->dict, value, fmt_var_width (&f->format));
+
+          data_in_imply_decimals (s, encoding, f->format.type, f->format.d,
+                                  value);
+        }
 
       dfm_forward_record (reader);
     }
@@ -576,8 +582,7 @@ parse_delimited_span (const struct data_parser *parser,
            }
        }
 
-      data_in (s, encoding, f->format.type, 0,
-               first_column, last_column,
+      data_in (s, encoding, f->format.type, first_column, last_column,
               parser->dict,
                case_data_rw_idx (c, f->case_idx),
                fmt_var_width (&f->format));
@@ -596,29 +601,29 @@ 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;
        }
 
-      data_in (s, encoding, f->format.type, 0,
-               first_column, last_column,
+      data_in (s, encoding, f->format.type, first_column, last_column,
               parser->dict,
                case_data_rw_idx (c, f->case_idx),
                fmt_var_width (&f->format));
@@ -645,7 +650,6 @@ dump_fixed_table (const struct data_parser *parser,
   size_t i;
 
   t = tab_create (4, parser->field_cnt + 1);
-  tab_columns (t, TAB_COL_DOWN);
   tab_headers (t, 0, 0, 1, 0);
   tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Variable"));
   tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Record"));
@@ -653,7 +657,6 @@ dump_fixed_table (const struct data_parser *parser,
   tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Format"));
   tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 3, parser->field_cnt);
   tab_hline (t, TAL_2, 0, 3, 1);
-  tab_dim (t, tab_natural_dimensions, NULL, NULL);
 
   for (i = 0; i < parser->field_cnt; i++)
     {
@@ -686,13 +689,11 @@ dump_delimited_table (const struct data_parser *parser,
   size_t i;
 
   t = tab_create (2, parser->field_cnt + 1);
-  tab_columns (t, TAB_COL_DOWN);
   tab_headers (t, 0, 0, 1, 0);
   tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Variable"));
   tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Format"));
   tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 1, parser->field_cnt);
   tab_hline (t, TAL_2, 0, 1, 1);
-  tab_dim (t, tab_natural_dimensions, NULL, NULL);
 
   for (i = 0; i < parser->field_cnt; i++)
     {