+ int value;
+ const char *name;
+ const char *label;
+} GEnumValue;
+
+const GEnumValue align[] =
+ {
+ {ALIGN_LEFT, "left", N_("Left")},
+ {ALIGN_RIGHT, "right", N_("Right")},
+ {ALIGN_CENTRE, "center", N_("Center")},
+ {0,0,0}
+ };
+
+const GEnumValue measure[] =
+ {
+ {MEASURE_NOMINAL, "nominal", N_("Nominal")},
+ {MEASURE_ORDINAL, "ordinal", N_("Ordinal")},
+ {MEASURE_SCALE, "scale", N_("Scale")},
+ {0,0,0}
+ };
+
+const GEnumValue role[] =
+ {
+ {ROLE_INPUT, "input", N_("Input")},
+ {ROLE_TARGET, "output", N_("Output")},
+ {ROLE_BOTH, "both", N_("Both")},
+ {ROLE_NONE, "none", N_("None")},
+ {ROLE_PARTITION, "partition", N_("Partition")},
+ {ROLE_SPLIT, "split", N_("Split")},
+ {0,0,0}
+ };
+
+/* A variable. */
+struct variable
+ {
+ /* Dictionary information. */
+ char *name; /* Variable name. Mixed case. */
+ int width; /* 0 for numeric, otherwise string width. */
+ struct missing_values miss; /* Missing values. */
+ struct fmt_spec print; /* Default format for PRINT. */
+ struct fmt_spec write; /* Default format for WRITE. */
+ struct val_labs *val_labs; /* Value labels. */
+ char *label; /* Variable label. */
+ struct string name_and_label; /* The name and label in the same string */
+
+ /* GUI information. */
+ enum measure measure; /* Nominal, ordinal, or continuous. */
+ enum var_role role; /* Intended use. */
+ int display_width; /* Width of data editor column. */
+ enum alignment alignment; /* Alignment of data in GUI. */
+
+ /* Case information. */
+ bool leave; /* Leave value from case to case? */
+
+ /* Data for use by containing dictionary. */
+ struct vardict_info *vardict;
+
+ /* Used only for system and portable file input and output.
+ See short-names.h. */
+ char **short_names;
+ size_t short_name_cnt;
+
+ /* Custom attributes. */
+ struct attrset attributes;
+ };
+\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 void var_set_label_quiet (struct variable *v, const char *label);
+static void var_set_name_quiet (struct variable *v, const char *name);
+
+/* Creates and returns a new variable with the given NAME and
+ WIDTH and other fields initialized to default values. The
+ variable is not added to a dictionary; for that, use
+ dict_create_var instead. */
+struct variable *
+var_create (const char *name, int width)
+{
+ struct variable *v;
+ enum val_type type;
+
+ assert (width >= 0 && width <= MAX_STRING);
+
+ v = xzalloc (sizeof *v);
+ var_set_name_quiet (v, name);
+ v->width = width;
+ mv_init (&v->miss, width);
+ v->leave = var_must_leave (v);
+ type = val_type_from_width (width);
+ v->alignment = var_default_alignment (type);
+ v->measure = var_default_measure (type);
+ v->role = ROLE_INPUT;
+ v->display_width = var_default_display_width (width);
+ v->print = v->write = var_default_formats (width);
+ attrset_init (&v->attributes);
+ ds_init_empty (&v->name_and_label);
+
+ return v;
+}
+
+/* Destroys variable V.
+ V must not belong to a dictionary. If it does, use
+ dict_delete_var instead. */
+void
+var_destroy (struct variable *v)
+{
+ if (v != NULL)
+ {
+ assert (!var_has_vardict (v));
+ mv_destroy (&v->miss);
+ var_clear_short_names (v);
+ val_labs_destroy (v->val_labs);
+ var_set_label_quiet (v, NULL);
+ attrset_destroy (var_get_attributes (v));
+ free (v->name);
+ ds_destroy (&v->name_and_label);
+ free (v);
+ }