Changed all the licence notices in all the files.
[pspp-builds.git] / src / dictionary.c
index 86076f9cc761fd6e8479fdd290c6d370b735944f..a3185b997129c324808d2411419fe56e8ebb1c8f 100644 (file)
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include "dictionary.h"
@@ -84,6 +84,9 @@ hash_long_name (const void *e_, void *aux UNUSED)
   return hash;
 }
 
+
+
+
 static char *make_short_name(struct dictionary *dict, const char *longname) ;
 
 
@@ -96,7 +99,8 @@ dict_create (void)
   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;
@@ -232,9 +236,8 @@ dict_get_varname_block(const struct dictionary *dict, char **text, int *size)
   *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, 
@@ -248,7 +251,6 @@ 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 ) 
@@ -260,10 +262,19 @@ dict_add_longvar_entry(struct dictionary *d,
   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
@@ -409,7 +420,11 @@ dict_create_var_x (struct dictionary *d, const char *name, int width,
       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 + 1);
+      free(sn);
+    }
   
 
   v->index = d->var_cnt;
@@ -551,6 +566,7 @@ dict_rename_var (struct dictionary *d, struct variable *v,
   strncpy (v->name, new_name, sizeof v->name);
   v->name[SHORT_NAME_LEN] = '\0';
   hsh_force_insert (d->name_tab, v);
+  dict_add_longvar_entry (d, new_name, new_name);
 }
 
 /* Returns the variable named NAME in D, or a null pointer if no
@@ -751,12 +767,17 @@ dict_rename_vars (struct dictionary *d,
   
   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 + 1);
+      free(sn);
+      
 
 
       key.longname = vars[i]->longname;
@@ -1252,6 +1273,7 @@ make_short_name(struct dictionary *dict, const char *longname)
        strcat(d, suffix);
   }
 
+
   return d;
 }