From: John Darrington Date: Sun, 23 Jun 2013 08:49:12 +0000 (+0200) Subject: variable.c: (var_set_width) traits other than width may also be set X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7037d42254bb3c0e1dac2e1bd6ef95c6db8ba27;p=pspp variable.c: (var_set_width) traits other than width may also be set --- diff --git a/src/data/format.c b/src/data/format.c index 21162a05ae..3a380bda45 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -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. */ diff --git a/src/data/format.h b/src/data/format.h index def3cdc3f7..16ffc4b521 100644 --- a/src/data/format.h +++ b/src/data/format.h @@ -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 *); diff --git a/src/data/variable.c b/src/data/variable.c index 8b9b8e24b9..e981ba661f 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -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. */