return hash;
}
+
+
+
static char *make_short_name(struct dictionary *dict, const char *longname) ;
d->var = NULL;
d->var_cnt = d->var_cap = 0;
d->name_tab = hsh_create (8, compare_var_names, hash_var_name, NULL, NULL);
- 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,
+ (hsh_free_func *) free_nte, NULL);
d->next_value_idx = 0;
d->split = NULL;
d->split_cnt = 0;
*size = bufsize;
}
-
/* Add a new entry into the dictionary's long name table, and update the
- corresponding varible with the relevant long name.
+ corresponding variable with the relevant long name.
*/
void
dict_add_longvar_entry(struct dictionary *d,
nte->longname = strdup(longname);
nte->name = strdup(name);
-
/* Look up the name in name_tab */
v = hsh_find ( d->name_tab, name);
if ( !v )
v->longname = nte->longname;
hsh_insert(d->long_name_tab, nte);
-
+}
+/* Destroy and free up an nte */
+void
+free_nte(struct name_table_entry *nte)
+{
+ assert(nte);
+ free(nte->longname);
+ free(nte->name);
+ free(nte);
}
+
/* Destroys the aux data for every variable in D, by calling
var_clear_aux() for each variable. */
void
v->name[SHORT_NAME_LEN] = '\0';
}
else
- strcpy(v->name,make_short_name(d, name));
+ {
+ const char *sn = make_short_name(d, name);
+ strncpy(v->name, sn, SHORT_NAME_LEN);
+ free(sn);
+ }
v->index = d->var_cnt;
for (i = 0; i < count; i++)
{
+ char *sn;
struct name_table_entry key;
struct name_table_entry *nte;
assert (new_names[i] != NULL);
assert (*new_names[i] != '\0');
assert (strlen (new_names[i]) <= LONG_NAME_LEN );
- strcpy (vars[i]->name, make_short_name(d, new_names[i]));
+
+ sn = make_short_name(d, new_names[i]);
+ strncpy(vars[i]->name, sn, SHORT_NAME_LEN);
+ free(sn);
+
key.longname = vars[i]->longname;
int compare_var_names (const void *, const void *, void *);
unsigned hash_var_name (const void *, void *);
+/* Destroy and free up an nte */
+void free_nte(struct name_table_entry *nte);
+
unsigned hash_long_name (const void *e_, void *aux UNUSED) ;
int compare_long_names(const void *a_, const void *b_, void *aux);