]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/make_hash.c
ncurses 5.9 - patch 20130713
[ncurses.git] / ncurses / tinfo / make_hash.c
index 99e4bd4fbd781eb813760ef975d3616bc7e73bea..31f21005f4187c639084c3edc4e65e1cb66581bf 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -44,7 +44,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: make_hash.c,v 1.9 2012/11/18 01:30:03 tom Exp $")
+MODULE_ID("$Id: make_hash.c,v 1.12 2013/02/16 21:27:50 tom Exp $")
 
 /*
  *     _nc_make_hash_table()
@@ -59,6 +59,23 @@ MODULE_ID("$Id: make_hash.c,v 1.9 2012/11/18 01:30:03 tom Exp $")
 #define MODULE_ID(id)          /*nothing */
 #include <tinfo/doalloc.c>
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    exit(EXIT_FAILURE);
+}
+
+static char *
+strmalloc(char *s)
+{
+    char *result = malloc(strlen(s) + 1);
+    if (result == 0)
+       failed("strmalloc");
+    strcpy(result, s);
+    return result;
+}
+
 /*
  *     int hash_function(string)
  *
@@ -138,7 +155,7 @@ parse_columns(char *buffer)
 
     int col = 0;
 
-    if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0)
+    if (list == 0 && (list = typeCalloc(char *, (MAX_COLUMNS + 1))) == 0)
          return (0);
 
     if (*buffer != '#') {
@@ -221,7 +238,7 @@ main(int argc, char **argv)
            exit(EXIT_FAILURE);
        }
        name_table[n].nte_link = -1;    /* end-of-hash */
-       name_table[n].nte_name = strdup(list[column]);
+       name_table[n].nte_name = strmalloc(list[column]);
        if (!strcmp(list[2], "bool")) {
            name_table[n].nte_type = BOOLEAN;
            name_table[n].nte_index = BoolCount++;
@@ -275,8 +292,7 @@ main(int argc, char **argv)
        printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name);
     } else {
 
-       printf("static struct name_table_entry %s _nc_%s_table[] =\n",
-              bigstring ? "" : "const",
+       printf("static struct name_table_entry const _nc_%s_table[] =\n",
               root_name);
        printf("{\n");
        for (n = 0; n < CAPTABSIZE; n++) {