/[pspp]/pspp/src/dictionary.c
ViewVC logotype

Diff of /pspp/src/dictionary.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by jmd, Wed Apr 13 10:09:59 2005 UTC revision 1.17 by jmd, Sat Apr 23 07:55:29 2005 UTC
# Line 84  hash_long_name (const void *e_, void *au Line 84  hash_long_name (const void *e_, void *au
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    
# Line 96  dict_create (void) Line 99  dict_create (void)
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;
# Line 232  dict_get_varname_block(const struct dict Line 236  dict_get_varname_block(const struct dict
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,
# Line 248  dict_add_longvar_entry(struct dictionary Line 251  dict_add_longvar_entry(struct dictionary
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 )
# Line 260  dict_add_longvar_entry(struct dictionary Line 262  dict_add_longvar_entry(struct dictionary
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
# Line 409  dict_create_var_x (struct dictionary *d, Line 420  dict_create_var_x (struct dictionary *d,
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;
# Line 751  dict_rename_vars (struct dictionary *d, Line 766  dict_rename_vars (struct dictionary *d,
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;

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26