dataset: Before deleting variables, make sure new values are added.
[pspp] / src / data / mdd-writer.c
index 10728e8cbdf988b0181990b0338808465b8a0005..a0387843a235c03b1c0d9db423e0ea001476318d 100644 (file)
@@ -64,20 +64,20 @@ enum val_numeric_type
 static enum val_numeric_type
 var_get_numeric_type_ (const struct variable *var)
 {
-  const struct fmt_spec *print = var_get_print_format (var);
+  const struct fmt_spec print = var_get_print_format (var);
   if (var_get_type (var) == VAL_STRING)
     return VAL_STRING_TYPE;
 
   if (var_has_value_labels (var))
     return VAL_CATEGORICAL_TYPE;
 
-  if (print->d > 0)
+  if (print.d > 0)
     return VAL_DECIMAL_TYPE;
 
-  if (print->type == FMT_DATETIME)
+  if (print.type == FMT_DATETIME)
     return VAL_DATETIME_TYPE;
 
-  if (print->type == FMT_F)
+  if (print.type == FMT_F)
     return VAL_INTEGER_TYPE;
 
   return VAL_CATEGORICAL_TYPE;
@@ -122,7 +122,7 @@ all_variables (struct dictionary *dict);
 struct all_dict_variables
 all_variables (struct dictionary *dict)
 {
-  size_t n_vars = dict_get_var_cnt (dict);
+  size_t n_vars = dict_get_n_vars (dict);
 
   /* Start with a set of all variable names. */
   struct string_set var_names = STRING_SET_INITIALIZER (var_names);
@@ -405,10 +405,9 @@ write_variable_section (xmlTextWriter *writer, const struct variable *var, int i
 
              XXX only checking "user" here because not sure of correct other
              cases. */
-          if (var_is_value_missing (var, value, MV_USER))
-            write_attr (writer, "missing", "user");
-          else if (var_is_value_missing (var, value, MV_SYSTEM))
-            write_attr (writer, "missing", "system");
+          enum mv_class miss = var_is_value_missing (var, value);
+          if (miss)
+            write_attr (writer, "missing", miss == MV_USER ? "user" : "system");
 
           /* <properties/> */
           xmlTextWriterStartElement (writer, _xml ("properties"));
@@ -449,7 +448,7 @@ mdd_write (struct file_handle *fh, struct dictionary *dict,
            const char *sav_name)
 {
   struct mdd_writer *w = XZALLOC (struct mdd_writer);
-  size_t n_vars = dict_get_var_cnt (dict);
+  size_t n_vars = dict_get_n_vars (dict);
 
   /* Open file handle as an exclusive writer. */
   /* TRANSLATORS: this fragment will be interpolated into
@@ -624,7 +623,7 @@ mdd_write (struct file_handle *fh, struct dictionary *dict,
 
   /* We reserve ids 1...N_VARS for variables and then start other ids after
      that. */
-  int id = dict_get_var_cnt (dict) + 1;
+  int id = dict_get_n_vars (dict) + 1;
 
   /* <definition/> */
   xmlTextWriterStartElement (w->writer, _xml ("definition"));