Fixed a bug causing pspp to crash when computed variables had no format
[pspp-builds.git] / src / matrix-data.c
index 892e716f2031ad4403bbac64dd312dd40340ec01..9502c5755578c7b9b2b9aa2f123f92627f099c0d 100644 (file)
@@ -216,8 +216,7 @@ cmd_matrix_data (void)
                
                if (strcmp (v[i], "ROWTYPE_"))
                  {
-                   new_var = dict_create_var (default_dict, v[i], 0);
-                    assert (new_var != NULL);
+                   new_var = dict_create_var_assert (default_dict, v[i], 0);
                    new_var->p.mxd.vartype = MXD_CONTINUOUS;
                    new_var->p.mxd.subtype = i;
                  }
@@ -229,8 +228,7 @@ cmd_matrix_data (void)
          }
          
          {
-           rowtype_ = dict_create_var (default_dict, "ROWTYPE_", 8);
-            assert (rowtype_ != NULL);
+           rowtype_ = dict_create_var_assert (default_dict, "ROWTYPE_", 8);
            rowtype_->p.mxd.vartype = MXD_ROWTYPE;
            rowtype_->p.mxd.subtype = 0;
          }
@@ -296,8 +294,7 @@ cmd_matrix_data (void)
                  goto lossage;
                }
 
-             single_split = dict_create_var (default_dict, tokid, 0);
-              assert (single_split != NULL);
+             single_split = dict_create_var_assert (default_dict, tokid, 0);
              lex_get ();
 
              single_split->p.mxd.vartype = MXD_CONTINUOUS;
@@ -540,8 +537,7 @@ cmd_matrix_data (void)
       
   /* Create VARNAME_. */
   {
-    varname_ = dict_create_var (default_dict, "VARNAME_", 8);
-    assert (varname_ != NULL);
+    varname_ = dict_create_var_assert (default_dict, "VARNAME_", 8);
     varname_->p.mxd.vartype = MXD_VARNAME;
     varname_->p.mxd.subtype = 0;
   }
@@ -1029,8 +1025,9 @@ static double *split_values;
 
 static int nr_read_splits (int compare);
 static int nr_read_factors (int cell);
-static void nr_output_data (void);
-static int matrix_data_read_without_rowtype (void);
+static void nr_output_data (write_case_func *, write_case_data);
+static void matrix_data_read_without_rowtype (write_case_func *,
+                                              write_case_data);
 
 /* Read from the data file and write it to the active file. */
 static void
@@ -1045,10 +1042,10 @@ read_matrices_without_rowtype (void)
   nr_factor_values = xmalloc (sizeof *nr_factor_values * n_factors * cells);
   max_cell_index = 0;
 
-  matrix_data_source.read = (void (*)(void)) matrix_data_read_without_rowtype;
+  matrix_data_source.read = matrix_data_read_without_rowtype;
   vfm_source = &matrix_data_source;
   
-  procedure (NULL, NULL, NULL);
+  procedure (NULL, NULL, NULL, NULL);
 
   free (split_values);
   free (nr_factor_values);
@@ -1213,8 +1210,9 @@ nr_read_data_lines (int per_factor, int cell, int content, int compare)
 
 /* When ROWTYPE_ does not appear in the data, reads the matrices and
    writes them to the output file.  Returns success. */
-static int
-matrix_data_read_without_rowtype (void)
+static void
+matrix_data_read_without_rowtype (write_case_func *write_case,
+                                  write_case_data wc_data)
 {
   {
     int *cp;
@@ -1257,7 +1255,7 @@ matrix_data_read_without_rowtype (void)
       int *bp, *ep, *np;
       
       if (!nr_read_splits (0))
-       return 0;
+       return;
       
       for (bp = contents; *bp != EOC; bp = np)
        {
@@ -1292,15 +1290,15 @@ matrix_data_read_without_rowtype (void)
 
                for (cp = bp; cp < ep; cp++) 
                  if (!nr_read_data_lines (per_factor, i, *cp, cp != bp))
-                   return 0;
+                   return;
              }
          }
        }
 
-      nr_output_data ();
+      nr_output_data (write_case, wc_data);
 
       if (dict_get_split_cnt (default_dict) == 0 || !another_token ())
-       return 1;
+       return;
     }
 }
 
@@ -1411,7 +1409,8 @@ nr_read_factors (int cell)
 /* Write the contents of a cell having content type CONTENT and data
    CP to the active file. */
 static void
-dump_cell_content (int content, double *cp)
+dump_cell_content (int content, double *cp,
+                   write_case_func *write_case, write_case_data wc_data)
 {
   int type = content_type[content];
 
@@ -1442,14 +1441,14 @@ dump_cell_content (int content, double *cp)
                             dict_get_var (default_dict,
                                           first_continuous + i)->name,
                            8);
-       write_case ();
+       write_case (wc_data);
       }
   }
 }
 
 /* Finally dump out everything from nr_data[] to the output file. */
 static void
-nr_output_data (void)
+nr_output_data (write_case_func *write_case, write_case_data wc_data)
 {
   {
     struct variable *const *split;
@@ -1487,7 +1486,8 @@ nr_output_data (void)
                  assert (nr_data[content] != NULL
                          && nr_data[content][cell] != NULL);
 
-                 dump_cell_content (content, nr_data[content][cell]);
+                 dump_cell_content (content, nr_data[content][cell],
+                                     write_case, wc_data);
                }
          }
        }
@@ -1505,7 +1505,8 @@ nr_output_data (void)
     
     for (content = 0; content <= PROX; content++)
       if (!is_per_factor[content] && nr_data[content] != NULL)
-       dump_cell_content (content, nr_data[content][0]);
+       dump_cell_content (content, nr_data[content][0],
+                           write_case, wc_data);
   }
 }
 \f
@@ -1529,12 +1530,13 @@ struct factor_data *wr_data;
 /* Current factor. */
 struct factor_data *wr_current;
 
-static int wr_read_splits (void);
-static int wr_output_data (void);
+static int wr_read_splits (write_case_func *, write_case_data);
+static int wr_output_data (write_case_func *, write_case_data);
 static int wr_read_rowtype (void);
 static int wr_read_factors (void);
 static int wr_read_indeps (void);
-static int matrix_data_read_with_rowtype (void);
+static void matrix_data_read_with_rowtype (write_case_func *,
+                                           write_case_data);
 
 /* When ROWTYPE_ appears in the data, reads the matrices and writes
    them to the output file. */
@@ -1546,40 +1548,40 @@ read_matrices_with_rowtype (void)
   split_values = NULL;
   cells = 0;
 
-  matrix_data_source.read = (void (*)(void)) matrix_data_read_with_rowtype;
+  matrix_data_source.read = matrix_data_read_with_rowtype;
   vfm_source = &matrix_data_source;
   
-  procedure (NULL, NULL, NULL);
+  procedure (NULL, NULL, NULL, NULL);
 
   free (split_values);
   fh_close_handle (data_file);
 }
 
 /* Read from the data file and write it to the active file. */
-static int
-matrix_data_read_with_rowtype (void)
+static void
+matrix_data_read_with_rowtype (write_case_func *write_case,
+                               write_case_data wc_data)
 {
   do
     {
-      if (!wr_read_splits ())
-       return 0;
+      if (!wr_read_splits (write_case, wc_data))
+       return;
 
       if (!wr_read_factors ())
-       return 0;
+       return;
 
       if (!wr_read_indeps ())
-       return 0;
+       return;
     }
   while (another_token ());
 
-  wr_output_data ();
-  return 1;
+  wr_output_data (write_case, wc_data);
 }
 
 /* Read the split file variables.  If they differ from the previous
    set of split variables then output the data.  Returns success. */
 static int 
-wr_read_splits (void)
+wr_read_splits (write_case_func *write_case, write_case_data wc_data)
 {
   int compare;
   size_t split_cnt;
@@ -1614,7 +1616,7 @@ wr_read_splits (void)
 
        if (compare && split_values[i] != mtokval && !different)
          {
-           if (!wr_output_data ())
+           if (!wr_output_data (write_case, wc_data))
              return 0;
            different = 1;
            cells = 0;
@@ -1628,7 +1630,7 @@ wr_read_splits (void)
 
 /* Compares doubles A and B, treating SYSMIS as greatest. */
 static int
-compare_doubles (const void *a_, const void *b_, void *aux unused)
+compare_doubles (const void *a_, const void *b_, void *aux UNUSED)
 {
   const double *a = a_;
   const double *b = b_;
@@ -1664,7 +1666,7 @@ compare_factors (const void *a_, const void *b_)
 /* Write out the data for the current split file to the active
    file. */
 static int 
-wr_output_data (void)
+wr_output_data (write_case_func *write_case, write_case_data wc_data)
 {
   {
     struct variable *const *split;
@@ -1742,7 +1744,8 @@ wr_output_data (void)
 
              fill_matrix (content, iter->data[content]);
 
-             dump_cell_content (content, iter->data[content]);
+             dump_cell_content (content, iter->data[content],
+                                 write_case, wc_data);
            }
        }
       }