/****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 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 *
#include <ctype.h>
-MODULE_ID("$Id: make_hash.c,v 1.3 2010/05/22 18:02:50 tom Exp $")
+MODULE_ID("$Id: make_hash.c,v 1.10 2012/12/16 00:40:14 tom Exp $")
/*
* _nc_make_hash_table()
#define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */
+static int
+count_columns(char **list)
+{
+ int result = 0;
+ if (list != 0) {
+ while (*list++) {
+ ++result;
+ }
+ }
+ return result;
+}
+
static char **
parse_columns(char *buffer)
{
list = parse_columns(buffer);
if (list == 0) /* blank or comment */
continue;
+ if (column > count_columns(list)) {
+ fprintf(stderr, "expected %d columns, have %d:\n%s\n",
+ column,
+ count_columns(list),
+ buffer);
+ exit(EXIT_FAILURE);
+ }
name_table[n].nte_link = -1; /* end-of-hash */
name_table[n].nte_name = strdup(list[column]);
if (!strcmp(list[2], "bool")) {
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++) {
- sprintf(buffer, "\"%s\"",
- name_table[n].nte_name);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "\"%s\"",
+ name_table[n].nte_name);
printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n",
buffer,
typenames[name_table[n].nte_type],