variable.c: (var_set_width) traits other than width may also be set
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 23 Jun 2013 08:49:12 +0000 (10:49 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 23 Jun 2013 08:49:12 +0000 (10:49 +0200)
src/data/format.c
src/data/format.h
src/data/variable.c

index 21162a05ae4f4ab21aff8012def2fdcd83d30123..3a380bda45c0d960758739531289436da37f7af9 100644 (file)
@@ -475,8 +475,10 @@ fmt_equal (const struct fmt_spec *a, const struct fmt_spec *b)
   return a->type == b->type && a->w == b->w && a->d == b->d;
 }
 
-/* Adjusts FMT to be valid for a value of the given WIDTH. */
-void
+/* Adjusts FMT to be valid for a value of the given WIDTH if necessary.
+   If nothing needed to be changed the return value is false
+ */
+bool
 fmt_resize (struct fmt_spec *fmt, int width)
 {
   if ((width > 0) != fmt_is_string (fmt->type))
@@ -494,7 +496,9 @@ fmt_resize (struct fmt_spec *fmt, int width)
   else
     {
       /* Still numeric. */
+      return false;
     }
+  return true;
 }
 
 /* Adjusts FMT's width and decimal places to be valid for USE.  */
index def3cdc3f7a02eb3745f75bfe03c4a610d836f94..16ffc4b5213d4ede6a476b26f6daebc5e3fa4743 100644 (file)
@@ -96,7 +96,7 @@ bool fmt_check_width_compat (const struct fmt_spec *, int var_width);
 int fmt_var_width (const struct fmt_spec *);
 char *fmt_to_string (const struct fmt_spec *, char s[FMT_STRING_LEN_MAX + 1]);
 bool fmt_equal (const struct fmt_spec *, const struct fmt_spec *);
-void fmt_resize (struct fmt_spec *, int new_width);
+bool fmt_resize (struct fmt_spec *, int new_width);
 
 void fmt_fix (struct fmt_spec *, enum fmt_use);
 void fmt_fix_input (struct fmt_spec *);
index 8b9b8e24b9be88c58c42d436a891f58f10e2bfc0..e981ba661f66b8eb7a1f8d57e1ac9fcff8c22adb 100644 (file)
@@ -249,18 +249,23 @@ var_set_width (struct variable *v, int new_width)
 {
   struct variable *ov;
   const int old_width = v->width;
+  unsigned int traits = 0;
 
   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
+  if (var_has_missing_values (v))
     {
-      mv_destroy (&v->miss);
-      mv_init (&v->miss, new_width);
+      if (mv_is_resizable (&v->miss, new_width))
+       mv_resize (&v->miss, new_width);
+      else
+       {
+         mv_destroy (&v->miss);
+         mv_init (&v->miss, new_width);
+       }
+      traits |= VAR_TRAIT_MISSING_VALUES;
     }
 
   if (v->val_labs != NULL)
@@ -272,13 +277,18 @@ var_set_width (struct variable *v, int new_width)
           val_labs_destroy (v->val_labs);
           v->val_labs = NULL;
         }
+      traits |= VAR_TRAIT_VALUE_LABELS;
     }
 
-  fmt_resize (&v->print, new_width);
-  fmt_resize (&v->write, new_width);
+  if (fmt_resize (&v->print, new_width))
+    traits |= VAR_TRAIT_PRINT_FORMAT;
+
+  if (fmt_resize (&v->write, new_width))
+    traits |= VAR_TRAIT_WRITE_FORMAT;
 
   v->width = new_width;
-  dict_var_changed (v, VAR_TRAIT_WIDTH, ov);
+  traits |= VAR_TRAIT_WIDTH;
+  dict_var_changed (v, traits, ov);
 }
 
 /* Returns true if variable V is numeric, false otherwise. */