+ return hsh_hash_case_string (var_get_name (*v));
+}
+\f
+/* Returns the type of a variable with the given WIDTH. */
+static enum var_type
+width_to_type (int width)
+{
+ return width == 0 ? NUMERIC : ALPHA;
+}
+
+/* Returns the type of variable V. */
+enum var_type
+var_get_type (const struct variable *v)
+{
+ return width_to_type (v->width);
+}
+
+/* Returns the width of variable V. */
+int
+var_get_width (const struct variable *v)
+{
+ return v->width;
+}
+
+/* Sets the width of V to WIDTH. */
+void
+var_set_width (struct variable *v, int new_width)
+{
+ enum var_type new_type = width_to_type (new_width);
+
+ if (mv_is_resizable (&v->miss, new_width))
+ mv_resize (&v->miss, new_width);
+ else
+ mv_init (&v->miss, new_width);
+
+ if (v->val_labs != NULL)
+ {
+ if (val_labs_can_set_width (v->val_labs, new_width))
+ val_labs_set_width (v->val_labs, new_width);
+ else
+ {
+ val_labs_destroy (v->val_labs);
+ v->val_labs = NULL;
+ }
+ }
+
+ if (var_get_type (v) != new_type)
+ {
+ v->print = (new_type == NUMERIC
+ ? fmt_for_output (FMT_F, 8, 2)
+ : fmt_for_output (FMT_A, new_width, 0));
+ v->write = v->print;
+ }
+ else if (new_type == ALPHA)
+ {
+ v->print.w = v->print.type == FMT_AHEX ? new_width * 2 : new_width;
+ v->write.w = v->write.type == FMT_AHEX ? new_width * 2 : new_width;
+ }
+
+ v->width = new_width;
+}
+
+/* Returns true if variable V is numeric, false otherwise. */
+bool
+var_is_numeric (const struct variable *v)
+{
+ return var_get_type (v) == NUMERIC;
+}
+
+/* Returns true if variable V is a string variable, false
+ otherwise. */
+bool
+var_is_alpha (const struct variable *v)
+{
+ return var_get_type (v) == ALPHA;
+}
+
+/* Returns true if variable V is a short string variable, false
+ otherwise. */
+bool
+var_is_short_string (const struct variable *v)
+{
+ return v->width > 0 && v->width <= MAX_SHORT_STRING;
+}
+
+/* Returns true if variable V is a long string variable, false
+ otherwise. */
+bool
+var_is_long_string (const struct variable *v)
+{
+ return v->width > MAX_SHORT_STRING;
+}
+
+/* Returns true if variable V is a very long string variable,
+ false otherwise. */
+bool
+var_is_very_long_string (const struct variable *v)
+{
+ return v->width > MAX_LONG_STRING;
+}
+
+/* Returns variable V's missing values. */
+const struct missing_values *
+var_get_missing_values (const struct variable *v)
+{
+ return &v->miss;
+}
+
+/* Sets variable V's missing values to MISS, which must be of the
+ correct width. */
+void
+var_set_missing_values (struct variable *v, const struct missing_values *miss)
+{
+ if (miss != NULL)
+ {
+ assert (v->width == mv_get_width (miss));
+ mv_copy (&v->miss, miss);
+ }
+ else
+ mv_init (&v->miss, v->width);
+}
+
+/* Sets variable V to have no user-missing values. */
+void
+var_clear_missing_values (struct variable *v)
+{
+ var_set_missing_values (v, NULL);
+}
+
+/* Returns true if V has any user-missing values,
+ false otherwise. */
+bool
+var_has_missing_values (const struct variable *v)
+{
+ return !mv_is_empty (&v->miss);
+}
+
+/* Returns true if VALUE is system missing or user-missing value
+ for V, false otherwise. */
+bool
+var_is_value_missing (const struct variable *v, const union value *value)
+{
+ return mv_is_value_missing (&v->miss, value);
+}
+
+/* Returns true if D is system missing or a missing value in V,
+ false otherwise.
+ V must be a numeric variable. */
+bool
+var_is_num_missing (const struct variable *v, double d)
+{
+ return mv_is_num_missing (&v->miss, d);
+}
+
+/* Returns true if S[] is a missing value for V, false otherwise.
+ S[] must contain exactly as many characters as V's width.
+ V must be a string variable. */
+bool
+var_is_str_missing (const struct variable *v, const char s[])
+{
+ return mv_is_str_missing (&v->miss, s);
+}
+
+/* Returns true if VALUE is a missing value for V, false
+ otherwise. */
+bool
+var_is_value_user_missing (const struct variable *v, const union value *value)
+{
+ return mv_is_value_user_missing (&v->miss, value);
+}
+
+/* Returns true if D is a user-missing value for V, false
+ otherwise. V must be a numeric variable. */
+bool
+var_is_num_user_missing (const struct variable *v, double d)
+{
+ return mv_is_num_user_missing (&v->miss, d);
+}
+
+/* Returns true if S[] is a missing value for V, false otherwise.
+ V must be a string variable.
+ S[] must contain exactly as many characters as V's width. */
+bool
+var_is_str_user_missing (const struct variable *v, const char s[])
+{
+ return mv_is_str_user_missing (&v->miss, s);
+}
+
+/* Returns true if V is a numeric variable and VALUE is the
+ system missing value. */
+bool
+var_is_value_system_missing (const struct variable *v,
+ const union value *value)
+{
+ return mv_is_value_system_missing (&v->miss, value);
+}
+\f
+/* Print and write formats. */
+
+/* Returns V's print format specification. */
+const struct fmt_spec *
+var_get_print_format (const struct variable *v)
+{
+ return &v->print;
+}
+
+/* Sets V's print format specification to PRINT, which must be a
+ valid format specification for outputting a variable of V's
+ width. */
+void
+var_set_print_format (struct variable *v, const struct fmt_spec *print)
+{
+ assert (fmt_check_width_compat (print, v->width));
+ v->print = *print;
+}
+
+/* Returns V's write format specification. */
+const struct fmt_spec *
+var_get_write_format (const struct variable *v)
+{
+ return &v->write;
+}
+
+/* Sets V's write format specification to WRITE, which must be a
+ valid format specification for outputting a variable of V's
+ width. */
+void
+var_set_write_format (struct variable *v, const struct fmt_spec *write)
+{
+ assert (fmt_check_width_compat (write, v->width));
+ v->write = *write;
+}
+
+/* Sets V's print and write format specifications to FORMAT,
+ which must be a valid format specification for outputting a
+ variable of V's width. */
+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);
+}
+\f
+/* Returns V's variable label, or a null pointer if it has none. */
+const char *
+var_get_label (const struct variable *v)
+{
+ return v->label;
+}
+
+/* Sets V's variable label to LABEL, stripping off leading and
+ trailing white space and truncating to 255 characters.
+ If LABEL is a null pointer or if LABEL is an empty string
+ (after stripping white space), then V's variable label (if
+ any) is removed. */
+void
+var_set_label (struct variable *v, const char *label)
+{
+ free (v->label);
+ v->label = NULL;
+
+ if (label != NULL)
+ {
+ struct substring s = ss_cstr (label);
+ ss_trim (&s, ss_cstr (CC_SPACES));
+ ss_truncate (&s, 255);
+ if (!ss_is_empty (s))
+ v->label = ss_xstrdup (s);
+ }
+}
+
+/* Removes any variable label from V. */
+void
+var_clear_label (struct variable *v)
+{
+ var_set_label (v, NULL);
+}
+
+/* Returns true if V has a variable V,
+ false otherwise. */
+bool
+var_has_label (const struct variable *v)
+{
+ return v->label != NULL;