134 |
assert (var != NULL); |
assert (var != NULL); |
135 |
assert (cnt != NULL); |
assert (cnt != NULL); |
136 |
|
|
|
|
|
137 |
vs = var_set_create_from_dict (d); |
vs = var_set_create_from_dict (d); |
138 |
success = parse_var_set_vars (vs, var, cnt, opts); |
success = parse_var_set_vars (vs, var, cnt, opts); |
139 |
if ( success == 0 ) |
if ( success == 0 ) |
266 |
else |
else |
267 |
included = NULL; |
included = NULL; |
268 |
|
|
269 |
if (lex_match (T_ALL)) |
if (lex_match (T_ALL)) |
270 |
add_variables (v, nv, &mv, included, pv_opts, |
add_variables (v, nv, &mv, included, pv_opts, |
271 |
vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY); |
vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY); |
272 |
else |
else |
302 |
first_var->name, last_var->name); |
first_var->name, last_var->name); |
303 |
goto fail; |
goto fail; |
304 |
} |
} |
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 " |
391 |
int d1, d2; |
int d1, d2; |
392 |
int n; |
int n; |
393 |
int nvar, mvar; |
int nvar, mvar; |
394 |
char *name1, *name2; |
char name1[LONG_NAME_LEN + 1], name2[LONG_NAME_LEN + 1]; |
395 |
char *root1, *root2; |
char root1[LONG_NAME_LEN + 1], root2[LONG_NAME_LEN + 1]; |
396 |
int success = 0; |
int success = 0; |
397 |
|
|
398 |
assert (names != NULL); |
assert (names != NULL); |
409 |
*names = NULL; |
*names = NULL; |
410 |
} |
} |
411 |
|
|
|
name1 = xmalloc (4 * (SHORT_NAME_LEN + 1)); |
|
|
name2 = &name1[1 * SHORT_NAME_LEN + 1]; |
|
|
root1 = &name1[2 * SHORT_NAME_LEN + 1]; |
|
|
root2 = &name1[3 * SHORT_NAME_LEN + 1]; |
|
412 |
do |
do |
413 |
{ |
{ |
414 |
if (token != T_ID) |
if (token != T_ID) |
439 |
|| !extract_num (name2, root2, &n2, &d2)) |
|| !extract_num (name2, root2, &n2, &d2)) |
440 |
goto fail; |
goto fail; |
441 |
|
|
442 |
if (strcmp (root1, root2)) |
if (strcasecmp (root1, root2)) |
443 |
{ |
{ |
444 |
msg (SE, _("Prefixes don't match in use of TO convention.")); |
msg (SE, _("Prefixes don't match in use of TO convention.")); |
445 |
goto fail; |
goto fail; |
460 |
|
|
461 |
for (n = n1; n <= n2; n++) |
for (n = n1; n <= n2; n++) |
462 |
{ |
{ |
463 |
(*names)[nvar] = xmalloc (SHORT_NAME_LEN + 1); |
char name[LONG_NAME_LEN + 1]; |
464 |
sprintf ((*names)[nvar], "%s%0*d", root1, d1, n); |
sprintf (name, "%s%0*d", root1, d1, n); |
465 |
|
(*names)[nvar] = xstrdup (name); |
466 |
nvar++; |
nvar++; |
467 |
} |
} |
468 |
} |
} |
486 |
|
|
487 |
fail: |
fail: |
488 |
*nnames = nvar; |
*nnames = nvar; |
|
free (name1); |
|
489 |
if (!success) |
if (!success) |
490 |
{ |
{ |
491 |
int i; |
int i; |
658 |
struct variable *const *var;/* Array of variables. */ |
struct variable *const *var;/* Array of variables. */ |
659 |
size_t var_cnt; /* Number of elements in var. */ |
size_t var_cnt; /* Number of elements in var. */ |
660 |
struct hsh_table *name_tab; /* Hash from variable names to variables. */ |
struct hsh_table *name_tab; /* Hash from variable names to variables. */ |
|
struct hsh_table *longname_tab; /* Hash of short names indexed by long names */ |
|
661 |
}; |
}; |
662 |
|
|
663 |
/* Returns the number of variables in VS. */ |
/* Returns the number of variables in VS. */ |
684 |
static int |
static int |
685 |
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) |
686 |
{ |
{ |
|
char *short_name ; |
|
687 |
struct array_var_set *avs = vs->aux; |
struct array_var_set *avs = vs->aux; |
688 |
struct variable v, *vp, *const *vpp; |
struct variable v, *vp, *const *vpp; |
689 |
|
|
690 |
struct name_table_entry key; |
strcpy (v.name, name); |
|
key.longname = name; |
|
|
|
|
|
struct name_table_entry *nte; |
|
|
|
|
|
assert (avs->longname_tab); |
|
|
|
|
|
|
|
|
nte = hsh_find (avs->longname_tab, &key); |
|
|
|
|
|
if (!nte) |
|
|
return -1; |
|
|
|
|
|
short_name = nte->name; |
|
|
|
|
|
strcpy (v.name, short_name); |
|
691 |
vp = &v; |
vp = &v; |
692 |
vpp = hsh_find (avs->name_tab, &vp); |
vpp = hsh_find (avs->name_tab, &vp); |
693 |
return vpp != NULL ? vpp - avs->var : -1; |
return vpp != NULL ? vpp - avs->var : -1; |
700 |
struct array_var_set *avs = vs->aux; |
struct array_var_set *avs = vs->aux; |
701 |
|
|
702 |
hsh_destroy (avs->name_tab); |
hsh_destroy (avs->name_tab); |
|
hsh_destroy (avs->longname_tab); |
|
703 |
free (avs); |
free (avs); |
704 |
free (vs); |
free (vs); |
705 |
} |
} |
722 |
avs->var = var; |
avs->var = var; |
723 |
avs->var_cnt = var_cnt; |
avs->var_cnt = var_cnt; |
724 |
avs->name_tab = hsh_create (2 * var_cnt, |
avs->name_tab = hsh_create (2 * var_cnt, |
725 |
compare_var_ptr_names, hash_var_ptr_name, |
compare_var_ptr_names, hash_var_ptr_name, NULL, |
726 |
NULL, NULL); |
NULL); |
|
|
|
|
avs->longname_tab = hsh_create (2 * var_cnt, |
|
|
compare_long_names, hash_long_name, |
|
|
(hsh_free_func *) free_nte, |
|
|
NULL); |
|
|
|
|
727 |
for (i = 0; i < var_cnt; i++) |
for (i = 0; i < var_cnt; i++) |
728 |
{ |
if (hsh_insert (avs->name_tab, (void *) &var[i]) != NULL) |
729 |
struct name_table_entry *nte ; |
{ |
730 |
|
var_set_destroy (vs); |
731 |
if (hsh_insert (avs->name_tab, &var[i]) != NULL) |
return NULL; |
732 |
{ |
} |
733 |
var_set_destroy (vs); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
nte = xmalloc (sizeof (*nte)); |
|
|
nte->name = strdup(var[i]->name); |
|
|
nte->longname = strdup(var[i]->longname); |
|
|
|
|
|
if (hsh_insert (avs->longname_tab, nte) != NULL) |
|
|
{ |
|
|
var_set_destroy (vs); |
|
|
free (nte); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
734 |
return vs; |
return vs; |
735 |
} |
} |