134 |
assert (var != NULL); |
assert (var != NULL); |
135 |
assert (cnt != NULL); |
assert (cnt != NULL); |
136 |
|
|
137 |
|
|
138 |
vs = var_set_create_from_dict (d); |
vs = var_set_create_from_dict (d); |
139 |
success = parse_var_set_vars (vs, var, cnt, opts); |
success = parse_var_set_vars (vs, var, cnt, opts); |
140 |
if ( success == 0 ) |
if ( success == 0 ) |
267 |
else |
else |
268 |
included = NULL; |
included = NULL; |
269 |
|
|
270 |
if (lex_match (T_ALL)) |
if (lex_match (T_ALL)) |
271 |
add_variables (v, nv, &mv, included, pv_opts, |
add_variables (v, nv, &mv, included, pv_opts, |
272 |
vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY); |
vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY); |
273 |
else |
else |
303 |
first_var->name, last_var->name); |
first_var->name, last_var->name); |
304 |
goto fail; |
goto fail; |
305 |
} |
} |
|
|
|
306 |
if (class != last_class) |
if (class != last_class) |
307 |
{ |
{ |
308 |
msg (SE, _("When using the TO keyword to specify several " |
msg (SE, _("When using the TO keyword to specify several " |
409 |
*names = NULL; |
*names = NULL; |
410 |
} |
} |
411 |
|
|
412 |
name1 = xmalloc (36); |
name1 = xmalloc (4 * (SHORT_NAME_LEN + 1)); |
413 |
name2 = &name1[1 * 9]; |
name2 = &name1[1 * SHORT_NAME_LEN + 1]; |
414 |
root1 = &name1[2 * 9]; |
root1 = &name1[2 * SHORT_NAME_LEN + 1]; |
415 |
root2 = &name1[3 * 9]; |
root2 = &name1[3 * SHORT_NAME_LEN + 1]; |
416 |
do |
do |
417 |
{ |
{ |
418 |
if (token != T_ID) |
if (token != T_ID) |
464 |
|
|
465 |
for (n = n1; n <= n2; n++) |
for (n = n1; n <= n2; n++) |
466 |
{ |
{ |
467 |
(*names)[nvar] = xmalloc (9); |
(*names)[nvar] = xmalloc (SHORT_NAME_LEN + 1); |
468 |
sprintf ((*names)[nvar], "%s%0*d", root1, d1, n); |
sprintf ((*names)[nvar], "%s%0*d", root1, d1, n); |
469 |
nvar++; |
nvar++; |
470 |
} |
} |
594 |
{ |
{ |
595 |
assert (vs != NULL); |
assert (vs != NULL); |
596 |
assert (name != NULL); |
assert (name != NULL); |
597 |
assert (strlen (name) < 9); |
assert (strlen (name) <= LONG_NAME_LEN ); |
598 |
|
|
599 |
return vs->lookup_var_idx (vs, name); |
return vs->lookup_var_idx (vs, name); |
600 |
} |
} |
662 |
struct variable *const *var;/* Array of variables. */ |
struct variable *const *var;/* Array of variables. */ |
663 |
size_t var_cnt; /* Number of elements in var. */ |
size_t var_cnt; /* Number of elements in var. */ |
664 |
struct hsh_table *name_tab; /* Hash from variable names to variables. */ |
struct hsh_table *name_tab; /* Hash from variable names to variables. */ |
665 |
|
struct hsh_table *longname_tab; /* Hash of short names indexed by long names */ |
666 |
}; |
}; |
667 |
|
|
668 |
/* Returns the number of variables in VS. */ |
/* Returns the number of variables in VS. */ |
689 |
static int |
static int |
690 |
array_var_set_lookup_var_idx (const struct var_set *vs, const char *name) |
array_var_set_lookup_var_idx (const struct var_set *vs, const char *name) |
691 |
{ |
{ |
692 |
|
char *short_name ; |
693 |
struct array_var_set *avs = vs->aux; |
struct array_var_set *avs = vs->aux; |
694 |
struct variable v, *vp, *const *vpp; |
struct variable v, *vp, *const *vpp; |
695 |
|
|
696 |
strcpy (v.name, name); |
struct name_table_entry key; |
697 |
|
key.longname = name; |
698 |
|
|
699 |
|
struct name_table_entry *nte; |
700 |
|
|
701 |
|
assert (avs->longname_tab); |
702 |
|
|
703 |
|
|
704 |
|
nte = hsh_find (avs->longname_tab, &key); |
705 |
|
|
706 |
|
if (!nte) |
707 |
|
return -1; |
708 |
|
|
709 |
|
short_name = nte->name; |
710 |
|
|
711 |
|
strcpy (v.name, short_name); |
712 |
vp = &v; |
vp = &v; |
713 |
vpp = hsh_find (avs->name_tab, &vp); |
vpp = hsh_find (avs->name_tab, &vp); |
714 |
return vpp != NULL ? vpp - avs->var : -1; |
return vpp != NULL ? vpp - avs->var : -1; |
721 |
struct array_var_set *avs = vs->aux; |
struct array_var_set *avs = vs->aux; |
722 |
|
|
723 |
hsh_destroy (avs->name_tab); |
hsh_destroy (avs->name_tab); |
724 |
|
hsh_destroy (avs->longname_tab); |
725 |
free (avs); |
free (avs); |
726 |
free (vs); |
free (vs); |
727 |
} |
} |
744 |
avs->var = var; |
avs->var = var; |
745 |
avs->var_cnt = var_cnt; |
avs->var_cnt = var_cnt; |
746 |
avs->name_tab = hsh_create (2 * var_cnt, |
avs->name_tab = hsh_create (2 * var_cnt, |
747 |
compare_var_ptr_names, hash_var_ptr_name, NULL, |
compare_var_ptr_names, hash_var_ptr_name, |
748 |
NULL); |
NULL, NULL); |
749 |
for (i = 0; i < var_cnt; i++) |
|
750 |
if (hsh_insert (avs->name_tab, (void *) &var[i]) != NULL) |
avs->longname_tab = hsh_create (2 * var_cnt, |
751 |
{ |
compare_long_names, hash_long_name, |
752 |
var_set_destroy (vs); |
NULL, NULL); |
|
return NULL; |
|
|
} |
|
753 |
|
|
754 |
|
for (i = 0; i < var_cnt; i++) |
755 |
|
{ |
756 |
|
struct name_table_entry *nte ; |
757 |
|
|
758 |
|
if (hsh_insert (avs->name_tab, &var[i]) != NULL) |
759 |
|
{ |
760 |
|
var_set_destroy (vs); |
761 |
|
return NULL; |
762 |
|
} |
763 |
|
|
764 |
|
nte = xmalloc (sizeof (*nte)); |
765 |
|
nte->name = strdup(var[i]->name); |
766 |
|
nte->longname = strdup(var[i]->longname); |
767 |
|
|
768 |
|
if (hsh_insert (avs->longname_tab, nte) != NULL) |
769 |
|
{ |
770 |
|
var_set_destroy (vs); |
771 |
|
free (nte); |
772 |
|
return NULL; |
773 |
|
} |
774 |
|
|
775 |
|
} |
776 |
|
|
777 |
return vs; |
return vs; |
778 |
} |
} |