/* 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
};
\f
+static void var_set_print_format_quiet (struct variable *v, const struct fmt_spec *print);
+static void var_set_write_format_quiet (struct variable *v, const struct fmt_spec *write);
static bool var_set_label_quiet (struct variable *v, const char *label, bool issue_warning);
static void var_set_name_quiet (struct variable *v, const char *name);
return v->width;
}
-/* Changes the width of V to NEW_WIDTH.
- This function should be used cautiously. */
void
-var_set_width (struct variable *v, int new_width)
+var_set_width_and_formats (struct variable *v, int new_width,
+ const struct fmt_spec *print, const struct fmt_spec *write)
{
struct variable *ov;
- const int old_width = v->width;
-
- if (old_width == new_width)
- return;
+ unsigned int traits = 0;
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)
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_resized (v, old_width);
- dict_var_changed (v, VAR_TRAIT_WIDTH, ov);
+ traits |= VAR_TRAIT_WIDTH;
+
+ if (print)
+ {
+ var_set_print_format_quiet (v, print);
+ traits |= VAR_TRAIT_PRINT_FORMAT;
+ }
+
+ if (write)
+ {
+ var_set_write_format_quiet (v, write);
+ traits |= VAR_TRAIT_WRITE_FORMAT;
+ }
+
+ dict_var_changed (v, traits, ov);
}
+/* Changes the width of V to NEW_WIDTH.
+ This function should be used cautiously. */
+void
+var_set_width (struct variable *v, int new_width)
+{
+ const int old_width = v->width;
+
+ if (old_width == new_width)
+ return;
+
+ var_set_width_and_formats (v, new_width, NULL, NULL);
+}
+
+
+
+
/* Returns true if variable V is numeric, false otherwise. */
bool
var_is_numeric (const struct variable *v)
{
struct variable *ov = var_clone (v);
var_set_print_format_quiet (v, print);
- dict_var_changed (v, VAR_TRAIT_FORMAT, ov);
+ dict_var_changed (v, VAR_TRAIT_PRINT_FORMAT, ov);
}
/* Returns V's write format specification. */
{
struct variable *ov = var_clone (v);
var_set_write_format_quiet (v, write);
- dict_var_changed (v, VAR_TRAIT_FORMAT, ov);
+ dict_var_changed (v, VAR_TRAIT_WRITE_FORMAT, ov);
}
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_FORMAT, ov);
+ dict_var_changed (v, VAR_TRAIT_PRINT_FORMAT | VAR_TRAIT_WRITE_FORMAT, ov);
}
/* Returns the default print and write format for a variable of
if (v->display_width != new_width)
{
v->display_width = new_width;
- dict_var_display_width_changed (v);
}
}