84 |
return hash; |
return hash; |
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
static char *make_short_name(struct dictionary *dict, const char *longname) ; |
static char *make_short_name(struct dictionary *dict, const char *longname) ; |
91 |
|
|
92 |
|
|
99 |
d->var = NULL; |
d->var = NULL; |
100 |
d->var_cnt = d->var_cap = 0; |
d->var_cnt = d->var_cap = 0; |
101 |
d->name_tab = hsh_create (8, compare_var_names, hash_var_name, NULL, NULL); |
d->name_tab = hsh_create (8, compare_var_names, hash_var_name, NULL, NULL); |
102 |
d->long_name_tab = hsh_create (8, compare_long_names, hash_long_name, NULL, NULL); |
d->long_name_tab = hsh_create (8, compare_long_names, hash_long_name, |
103 |
|
(hsh_free_func *) free_nte, NULL); |
104 |
d->next_value_idx = 0; |
d->next_value_idx = 0; |
105 |
d->split = NULL; |
d->split = NULL; |
106 |
d->split_cnt = 0; |
d->split_cnt = 0; |
236 |
*size = bufsize; |
*size = bufsize; |
237 |
} |
} |
238 |
|
|
|
|
|
239 |
/* Add a new entry into the dictionary's long name table, and update the |
/* Add a new entry into the dictionary's long name table, and update the |
240 |
corresponding varible with the relevant long name. |
corresponding variable with the relevant long name. |
241 |
*/ |
*/ |
242 |
void |
void |
243 |
dict_add_longvar_entry(struct dictionary *d, |
dict_add_longvar_entry(struct dictionary *d, |
251 |
nte->longname = strdup(longname); |
nte->longname = strdup(longname); |
252 |
nte->name = strdup(name); |
nte->name = strdup(name); |
253 |
|
|
|
|
|
254 |
/* Look up the name in name_tab */ |
/* Look up the name in name_tab */ |
255 |
v = hsh_find ( d->name_tab, name); |
v = hsh_find ( d->name_tab, name); |
256 |
if ( !v ) |
if ( !v ) |
262 |
v->longname = nte->longname; |
v->longname = nte->longname; |
263 |
|
|
264 |
hsh_insert(d->long_name_tab, nte); |
hsh_insert(d->long_name_tab, nte); |
265 |
|
} |
266 |
|
|
267 |
|
/* Destroy and free up an nte */ |
268 |
|
void |
269 |
|
free_nte(struct name_table_entry *nte) |
270 |
|
{ |
271 |
|
assert(nte); |
272 |
|
free(nte->longname); |
273 |
|
free(nte->name); |
274 |
|
free(nte); |
275 |
} |
} |
276 |
|
|
277 |
|
|
278 |
/* Destroys the aux data for every variable in D, by calling |
/* Destroys the aux data for every variable in D, by calling |
279 |
var_clear_aux() for each variable. */ |
var_clear_aux() for each variable. */ |
280 |
void |
void |
420 |
v->name[SHORT_NAME_LEN] = '\0'; |
v->name[SHORT_NAME_LEN] = '\0'; |
421 |
} |
} |
422 |
else |
else |
423 |
strcpy(v->name,make_short_name(d, name)); |
{ |
424 |
|
const char *sn = make_short_name(d, name); |
425 |
|
strncpy(v->name, sn, SHORT_NAME_LEN); |
426 |
|
free(sn); |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
v->index = d->var_cnt; |
v->index = d->var_cnt; |
766 |
|
|
767 |
for (i = 0; i < count; i++) |
for (i = 0; i < count; i++) |
768 |
{ |
{ |
769 |
|
char *sn; |
770 |
struct name_table_entry key; |
struct name_table_entry key; |
771 |
struct name_table_entry *nte; |
struct name_table_entry *nte; |
772 |
assert (new_names[i] != NULL); |
assert (new_names[i] != NULL); |
773 |
assert (*new_names[i] != '\0'); |
assert (*new_names[i] != '\0'); |
774 |
assert (strlen (new_names[i]) <= LONG_NAME_LEN ); |
assert (strlen (new_names[i]) <= LONG_NAME_LEN ); |
775 |
strcpy (vars[i]->name, make_short_name(d, new_names[i])); |
|
776 |
|
sn = make_short_name(d, new_names[i]); |
777 |
|
strncpy(vars[i]->name, sn, SHORT_NAME_LEN); |
778 |
|
free(sn); |
779 |
|
|
780 |
|
|
781 |
|
|
782 |
key.longname = vars[i]->longname; |
key.longname = vars[i]->longname; |