- struct variable *v;
-
- assert (d != NULL);
- assert (name != NULL);
-
- assert (width >= 0 && width <= MAX_STRING);
-
- assert (var_is_plausible_name(name,0));
-
- /* Make sure there's not already a variable by that name. */
- if (dict_lookup_var (d, name) != NULL)
- return NULL;
-
- /* Allocate and initialize variable. */
- v = xmalloc (sizeof *v);
- str_copy_trunc (v->name, sizeof v->name, name);
- v->type = width == 0 ? NUMERIC : ALPHA;
- v->width = width;
- v->fv = d->next_value_idx;
- v->nv = width == 0 ? 1 : DIV_RND_UP (width, MAX_SHORT_STRING);
- v->leave = dict_class_from_id (v->name) == DC_SCRATCH;
- v->index = d->var_cnt;
- mv_init (&v->miss, width);
- if (v->type == NUMERIC)
- {
- v->print = f8_2;
- v->alignment = ALIGN_RIGHT;
- v->display_width = 8;
- v->measure = MEASURE_SCALE;
- }
- else
- {
- v->print = make_output_format (FMT_A, v->width, 0);
- v->alignment = ALIGN_LEFT;
- v->display_width = 8;
- v->measure = MEASURE_NOMINAL;
- }
- v->write = v->print;
- v->val_labs = val_labs_create (v->width);
- v->label = NULL;
- var_clear_short_name (v);
- v->aux = NULL;
- v->aux_dtor = NULL;
- v->obs_vals = NULL;
+ /* Add dictionary info to variable. */
+ struct vardict_info vdi;
+ vdi.case_index = d->next_value_idx;
+ vdi.dict_index = d->var_cnt;
+ vdi.dict = d;
+ var_set_vardict (v, &vdi);