Split VAR_TRAIT_FORMAT into PRINT and WRITE variants
[pspp] / src / data / variable.c
index f4da2c4da09a17e9c3a20a25fddf380eaba45497..8b9b8e24b9be88c58c42d436a891f58f10e2bfc0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013 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
@@ -160,8 +160,9 @@ var_set_name_quiet (struct variable *v, const char *name)
 void
 var_set_name (struct variable *v, const char *name)
 {
+  struct variable *ov = var_clone (v);
   var_set_name_quiet (v, name);
-  dict_var_changed (v, VAR_TRAIT_NAME);
+  dict_var_changed (v, VAR_TRAIT_NAME, ov);
 }
 
 /* Returns VAR's dictionary class. */
@@ -246,11 +247,14 @@ var_get_width (const struct variable *v)
 void
 var_set_width (struct variable *v, int new_width)
 {
+  struct variable *ov;
   const int old_width = v->width;
 
   if (old_width == new_width)
     return;
 
+  ov = var_clone (v);
+
   if (mv_is_resizable (&v->miss, new_width))
     mv_resize (&v->miss, new_width);
   else
@@ -274,8 +278,7 @@ var_set_width (struct variable *v, int new_width)
   fmt_resize (&v->write, new_width);
 
   v->width = new_width;
-  dict_var_resized (v, old_width);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_WIDTH, ov);
 }
 
 /* Returns true if variable V is numeric, false otherwise. */
@@ -325,8 +328,9 @@ var_set_missing_values_quiet (struct variable *v, const struct missing_values *m
 void
 var_set_missing_values (struct variable *v, const struct missing_values *miss)
 {
+  struct variable *ov = var_clone (v);
   var_set_missing_values_quiet (v, miss);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_MISSING_VALUES, ov);
 }
 
 /* Sets variable V to have no user-missing values. */
@@ -413,8 +417,9 @@ var_set_value_labels_quiet (struct variable *v, const struct val_labs *vls)
 void
 var_set_value_labels (struct variable *v, const struct val_labs *vls)
 {
+  struct variable *ov = var_clone (v);
   var_set_value_labels_quiet (v, vls);
-  dict_var_changed (v);  
+  dict_var_changed (v, VAR_TRAIT_LABEL, ov);  
 }
 
 
@@ -548,8 +553,9 @@ var_set_print_format_quiet (struct variable *v, const struct fmt_spec *print)
 void
 var_set_print_format (struct variable *v, const struct fmt_spec *print)
 {
+  struct variable *ov = var_clone (v);
   var_set_print_format_quiet (v, print);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_PRINT_FORMAT, ov);
 }
 
 /* Returns V's write format specification. */
@@ -580,8 +586,9 @@ var_set_write_format_quiet (struct variable *v, const struct fmt_spec *write)
 void
 var_set_write_format (struct variable *v, const struct fmt_spec *write)
 {
+  struct variable *ov = var_clone (v);
   var_set_write_format_quiet (v, write);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_WRITE_FORMAT, ov);
 }
 
 
@@ -592,8 +599,10 @@ var_set_write_format (struct variable *v, const struct fmt_spec *write)
 void
 var_set_both_formats (struct variable *v, const struct fmt_spec *format)
 {
-  var_set_print_format (v, format);
-  var_set_write_format (v, format);
+  struct variable *ov = var_clone (v);
+  var_set_print_format_quiet (v, format);
+  var_set_write_format_quiet (v, format);
+  dict_var_changed (v, VAR_TRAIT_PRINT_FORMAT | VAR_TRAIT_WRITE_FORMAT, ov);
 }
 
 /* Returns the default print and write format for a variable of
@@ -723,9 +732,10 @@ var_set_label_quiet (struct variable *v, const char *label, bool issue_warning)
 bool
 var_set_label (struct variable *v, const char *label, bool issue_warning)
 {
+  struct variable *ov = var_clone (v);
   bool truncated = var_set_label_quiet (v, label, issue_warning);
 
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_LABEL, ov);
 
   return truncated;
 }
@@ -794,8 +804,9 @@ var_set_measure_quiet (struct variable *v, enum measure measure)
 void
 var_set_measure (struct variable *v, enum measure measure)
 {
+  struct variable *ov = var_clone (v);
   var_set_measure_quiet (v, measure);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_MEASURE, ov);
 }
 
 
@@ -823,15 +834,15 @@ var_set_display_width_quiet (struct variable *v, int new_width)
   if (v->display_width != new_width)
     {
       v->display_width = new_width;
-      dict_var_display_width_changed (v);
     }
 }
 
 void
 var_set_display_width (struct variable *v, int new_width)
 {
+  struct variable *ov = var_clone (v);
   var_set_display_width_quiet (v, new_width);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_DISPLAY_WIDTH, ov);
 }
 
 
@@ -891,8 +902,9 @@ var_set_alignment_quiet (struct variable *v, enum alignment alignment)
 void
 var_set_alignment (struct variable *v, enum alignment alignment)
 {
+  struct variable *ov = var_clone (v);
   var_set_alignment_quiet (v, alignment);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_ALIGNMENT, ov);
 }
 
 
@@ -929,8 +941,9 @@ var_set_leave_quiet (struct variable *v, bool leave)
 void
 var_set_leave (struct variable *v, bool leave)
 {
+  struct variable *ov = var_clone (v);
   var_set_leave_quiet (v, leave);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_LEAVE, ov);
 }
 
 
@@ -977,6 +990,8 @@ var_get_short_name (const struct variable *var, size_t idx)
 void
 var_set_short_name (struct variable *var, size_t idx, const char *short_name)
 {
+  struct variable *ov = var_clone (var);
+
   assert (short_name == NULL || id_is_plausible (short_name, false));
 
   /* Clear old short name numbered IDX, if any. */
@@ -1002,7 +1017,7 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name)
       var->short_names[idx] = utf8_to_upper (short_name);
     }
 
-  dict_var_changed (var);
+  dict_var_changed (var, VAR_TRAIT_NAME, ov);
 }
 
 /* Clears V's short names. */
@@ -1063,8 +1078,9 @@ var_set_attributes_quiet (struct variable *v, const struct attrset *attrs)
 void
 var_set_attributes (struct variable *v, const struct attrset *attrs) 
 {
+  struct variable *ov = var_clone (v);
   var_set_attributes_quiet (v, attrs);
-  dict_var_changed (v);
+  dict_var_changed (v, VAR_TRAIT_ATTRIBUTES, ov);
 }