106bfebdeSXin LI /****************************************************************************
2*21817992SBaptiste Daroussin * Copyright 2018-2020,2024 Thomas E. Dickey *
3e1865124SBaptiste Daroussin * Copyright 2009-2013,2017 Free Software Foundation, Inc. *
406bfebdeSXin LI * *
506bfebdeSXin LI * Permission is hereby granted, free of charge, to any person obtaining a *
606bfebdeSXin LI * copy of this software and associated documentation files (the *
706bfebdeSXin LI * "Software"), to deal in the Software without restriction, including *
806bfebdeSXin LI * without limitation the rights to use, copy, modify, merge, publish, *
906bfebdeSXin LI * distribute, distribute with modifications, sublicense, and/or sell *
1006bfebdeSXin LI * copies of the Software, and to permit persons to whom the Software is *
1106bfebdeSXin LI * furnished to do so, subject to the following conditions: *
1206bfebdeSXin LI * *
1306bfebdeSXin LI * The above copyright notice and this permission notice shall be included *
1406bfebdeSXin LI * in all copies or substantial portions of the Software. *
1506bfebdeSXin LI * *
1606bfebdeSXin LI * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
1706bfebdeSXin LI * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
1806bfebdeSXin LI * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
1906bfebdeSXin LI * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
2006bfebdeSXin LI * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
2106bfebdeSXin LI * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
2206bfebdeSXin LI * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
2306bfebdeSXin LI * *
2406bfebdeSXin LI * Except as contained in this notice, the name(s) of the above copyright *
2506bfebdeSXin LI * holders shall not be used in advertising or otherwise to promote the *
2606bfebdeSXin LI * sale, use or other dealings in this Software without prior written *
2706bfebdeSXin LI * authorization. *
2806bfebdeSXin LI ****************************************************************************/
2906bfebdeSXin LI
3006bfebdeSXin LI /****************************************************************************
3106bfebdeSXin LI * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
3206bfebdeSXin LI * and: Eric S. Raymond <esr@snark.thyrsus.com> *
3306bfebdeSXin LI * and: Thomas E. Dickey 1996-on *
3406bfebdeSXin LI ****************************************************************************/
3506bfebdeSXin LI
3606bfebdeSXin LI /*
3706bfebdeSXin LI * make_hash.c --- build-time program for constructing comp_captab.c
3806bfebdeSXin LI */
3906bfebdeSXin LI
4006bfebdeSXin LI #include <build.priv.h>
4106bfebdeSXin LI
4206bfebdeSXin LI #include <tic.h>
4306bfebdeSXin LI #include <hashsize.h>
4406bfebdeSXin LI
4506bfebdeSXin LI #include <ctype.h>
4606bfebdeSXin LI
47*21817992SBaptiste Daroussin MODULE_ID("$Id: make_hash.c,v 1.34 2024/03/02 19:35:40 tom Exp $")
4806bfebdeSXin LI
4906bfebdeSXin LI /*
5006bfebdeSXin LI * _nc_make_hash_table()
5106bfebdeSXin LI *
5206bfebdeSXin LI * Takes the entries in table[] and hashes them into hash_table[]
53aae38d10SBaptiste Daroussin * by name. There are CAPTABSIZE entries in the predefined table[]
54aae38d10SBaptiste Daroussin * and HASHTABSIZE slots in hash_table[].
5506bfebdeSXin LI *
5606bfebdeSXin LI */
5706bfebdeSXin LI
5806bfebdeSXin LI #undef MODULE_ID
5906bfebdeSXin LI #define MODULE_ID(id) /*nothing */
6006bfebdeSXin LI #include <tinfo/doalloc.c>
6106bfebdeSXin LI
62aae38d10SBaptiste Daroussin #define L_PAREN "("
63aae38d10SBaptiste Daroussin #define R_PAREN ")"
64aae38d10SBaptiste Daroussin #define L_BRACE "{"
65aae38d10SBaptiste Daroussin #define R_BRACE "}"
66aae38d10SBaptiste Daroussin
67aae38d10SBaptiste Daroussin static const char *typenames[] =
68aae38d10SBaptiste Daroussin {"BOOLEAN", "NUMBER", "STRING"};
69aae38d10SBaptiste Daroussin
7073f0a83dSXin LI static void
failed(const char * s)7173f0a83dSXin LI failed(const char *s)
7273f0a83dSXin LI {
7373f0a83dSXin LI perror(s);
7473f0a83dSXin LI exit(EXIT_FAILURE);
7573f0a83dSXin LI }
7673f0a83dSXin LI
7773f0a83dSXin LI static char *
strmalloc(char * s)7873f0a83dSXin LI strmalloc(char *s)
7973f0a83dSXin LI {
8073f0a83dSXin LI size_t need = strlen(s) + 1;
8173f0a83dSXin LI char *result = malloc(need);
8273f0a83dSXin LI if (result == 0)
8373f0a83dSXin LI failed("strmalloc");
8473f0a83dSXin LI _nc_STRCPY(result, s, need);
8573f0a83dSXin LI return result;
8673f0a83dSXin LI }
8773f0a83dSXin LI
8806bfebdeSXin LI /*
8906bfebdeSXin LI * int hash_function(string)
9006bfebdeSXin LI *
9106bfebdeSXin LI * Computes the hashing function on the given string.
9206bfebdeSXin LI *
93aae38d10SBaptiste Daroussin * The current hash function is the sum of each consecutive pair
9406bfebdeSXin LI * of characters, taken as two-byte integers, mod HASHTABSIZE.
9506bfebdeSXin LI *
9606bfebdeSXin LI */
9706bfebdeSXin LI
9806bfebdeSXin LI static int
hash_function(const char * string)9906bfebdeSXin LI hash_function(const char *string)
10006bfebdeSXin LI {
10106bfebdeSXin LI long sum = 0;
10206bfebdeSXin LI
10306bfebdeSXin LI while (*string) {
104e1865124SBaptiste Daroussin sum += (long) (UChar(*string) + (UChar(*(string + 1)) << 8));
10506bfebdeSXin LI string++;
10606bfebdeSXin LI }
10706bfebdeSXin LI
10806bfebdeSXin LI return (int) (sum % HASHTABSIZE);
10906bfebdeSXin LI }
11006bfebdeSXin LI
111e1865124SBaptiste Daroussin #define UNUSED -1
112e1865124SBaptiste Daroussin
11306bfebdeSXin LI static void
_nc_make_hash_table(struct user_table_entry * table,HashValue * hash_table,unsigned tablesize)114aae38d10SBaptiste Daroussin _nc_make_hash_table(struct user_table_entry *table,
115aae38d10SBaptiste Daroussin HashValue * hash_table,
116aae38d10SBaptiste Daroussin unsigned tablesize)
11706bfebdeSXin LI {
118aae38d10SBaptiste Daroussin unsigned i;
11906bfebdeSXin LI int hashvalue;
12006bfebdeSXin LI int collisions = 0;
12106bfebdeSXin LI
12206bfebdeSXin LI for (i = 0; i < HASHTABSIZE; i++) {
123e1865124SBaptiste Daroussin hash_table[i] = UNUSED;
12406bfebdeSXin LI }
125aae38d10SBaptiste Daroussin for (i = 0; i < tablesize; i++) {
126aae38d10SBaptiste Daroussin hashvalue = hash_function(table[i].ute_name);
12706bfebdeSXin LI
12806bfebdeSXin LI if (hash_table[hashvalue] >= 0)
12906bfebdeSXin LI collisions++;
13006bfebdeSXin LI
131e1865124SBaptiste Daroussin if (hash_table[hashvalue] != UNUSED) {
132aae38d10SBaptiste Daroussin table[i].ute_link = hash_table[hashvalue];
133e1865124SBaptiste Daroussin }
134aae38d10SBaptiste Daroussin hash_table[hashvalue] = (HashValue) i;
13506bfebdeSXin LI }
13606bfebdeSXin LI
137aae38d10SBaptiste Daroussin printf("/* %d collisions out of %d entries */\n", collisions, tablesize);
13806bfebdeSXin LI }
13906bfebdeSXin LI
14006bfebdeSXin LI /*
14106bfebdeSXin LI * This filter reads from standard input a list of tab-delimited columns,
14206bfebdeSXin LI * (e.g., from Caps.filtered) computes the hash-value of a specified column and
14306bfebdeSXin LI * writes the hashed tables to standard output.
14406bfebdeSXin LI *
14506bfebdeSXin LI * By compiling the hash table at build time, we're able to make the entire
14606bfebdeSXin LI * set of terminfo and termcap tables readonly (and also provide some runtime
14706bfebdeSXin LI * performance enhancement).
14806bfebdeSXin LI */
14906bfebdeSXin LI
15006bfebdeSXin LI #define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */
15106bfebdeSXin LI
15273f0a83dSXin LI static int
count_columns(char ** list)15373f0a83dSXin LI count_columns(char **list)
15473f0a83dSXin LI {
15573f0a83dSXin LI int result = 0;
15673f0a83dSXin LI if (list != 0) {
15773f0a83dSXin LI while (*list++) {
15873f0a83dSXin LI ++result;
15973f0a83dSXin LI }
16073f0a83dSXin LI }
16173f0a83dSXin LI return result;
16273f0a83dSXin LI }
16373f0a83dSXin LI
16406bfebdeSXin LI static char **
parse_columns(char * buffer)16506bfebdeSXin LI parse_columns(char *buffer)
16606bfebdeSXin LI {
16706bfebdeSXin LI static char **list;
16806bfebdeSXin LI
16906bfebdeSXin LI int col = 0;
17006bfebdeSXin LI
171aae38d10SBaptiste Daroussin if (buffer == 0) {
172aae38d10SBaptiste Daroussin free(list);
173aae38d10SBaptiste Daroussin list = 0;
174aae38d10SBaptiste Daroussin return 0;
175aae38d10SBaptiste Daroussin }
17606bfebdeSXin LI
17706bfebdeSXin LI if (*buffer != '#') {
178aae38d10SBaptiste Daroussin if (list == 0) {
179aae38d10SBaptiste Daroussin list = typeCalloc(char *, (MAX_COLUMNS + 1));
180aae38d10SBaptiste Daroussin if (list == 0)
181aae38d10SBaptiste Daroussin return (0);
182aae38d10SBaptiste Daroussin }
18306bfebdeSXin LI while (*buffer != '\0') {
18406bfebdeSXin LI char *s;
18506bfebdeSXin LI for (s = buffer; (*s != '\0') && !isspace(UChar(*s)); s++)
18606bfebdeSXin LI /*EMPTY */ ;
18706bfebdeSXin LI if (s != buffer) {
18806bfebdeSXin LI char mark = *s;
18906bfebdeSXin LI *s = '\0';
19006bfebdeSXin LI if ((s - buffer) > 1
19106bfebdeSXin LI && (*buffer == '"')
19206bfebdeSXin LI && (s[-1] == '"')) { /* strip the quotes */
19306bfebdeSXin LI assert(s > buffer + 1);
19406bfebdeSXin LI s[-1] = '\0';
19506bfebdeSXin LI buffer++;
19606bfebdeSXin LI }
19706bfebdeSXin LI list[col] = buffer;
19806bfebdeSXin LI col++;
19906bfebdeSXin LI if (mark == '\0')
20006bfebdeSXin LI break;
20106bfebdeSXin LI while (*++s && isspace(UChar(*s)))
20206bfebdeSXin LI /*EMPTY */ ;
20306bfebdeSXin LI buffer = s;
20406bfebdeSXin LI } else
20506bfebdeSXin LI break;
20606bfebdeSXin LI }
20706bfebdeSXin LI }
20806bfebdeSXin LI return col ? list : 0;
20906bfebdeSXin LI }
21006bfebdeSXin LI
211aae38d10SBaptiste Daroussin #define SetType(n,t) \
212aae38d10SBaptiste Daroussin if (is_user) \
213aae38d10SBaptiste Daroussin name_table[n].ute_type |= (int)(1 << (t)); \
214aae38d10SBaptiste Daroussin else \
215aae38d10SBaptiste Daroussin name_table[n].ute_type = (t)
216aae38d10SBaptiste Daroussin
217aae38d10SBaptiste Daroussin #define GetType(n) \
218aae38d10SBaptiste Daroussin (is_user \
219aae38d10SBaptiste Daroussin ? get_type(name_table[n].ute_type) \
220aae38d10SBaptiste Daroussin : typenames[name_table[n].ute_type])
221aae38d10SBaptiste Daroussin
222aae38d10SBaptiste Daroussin static char *
get_type(int type_mask)223aae38d10SBaptiste Daroussin get_type(int type_mask)
224aae38d10SBaptiste Daroussin {
225aae38d10SBaptiste Daroussin static char result[80];
226aae38d10SBaptiste Daroussin unsigned n;
227aae38d10SBaptiste Daroussin _nc_STRCPY(result, L_PAREN, sizeof(result));
228aae38d10SBaptiste Daroussin for (n = 0; n < 3; ++n) {
229aae38d10SBaptiste Daroussin if ((1 << n) & type_mask) {
230aae38d10SBaptiste Daroussin size_t want = 5 + strlen(typenames[n]);
231aae38d10SBaptiste Daroussin if (want > sizeof(result)) {
232aae38d10SBaptiste Daroussin fprintf(stderr, "Buffer is not large enough for %s + %s\n",
233aae38d10SBaptiste Daroussin result, typenames[n]);
234aae38d10SBaptiste Daroussin exit(EXIT_FAILURE);
235aae38d10SBaptiste Daroussin }
236aae38d10SBaptiste Daroussin if (result[1])
237aae38d10SBaptiste Daroussin _nc_STRCAT(result, "|", sizeof(result));
238aae38d10SBaptiste Daroussin _nc_STRCAT(result, "1<<", sizeof(result));
239aae38d10SBaptiste Daroussin _nc_STRCAT(result, typenames[n], sizeof(result));
240aae38d10SBaptiste Daroussin }
241aae38d10SBaptiste Daroussin }
242aae38d10SBaptiste Daroussin _nc_STRCAT(result, R_PAREN, sizeof(result));
243aae38d10SBaptiste Daroussin return result;
244aae38d10SBaptiste Daroussin }
245aae38d10SBaptiste Daroussin
24606bfebdeSXin LI int
main(int argc,char ** argv)24706bfebdeSXin LI main(int argc, char **argv)
24806bfebdeSXin LI {
249aae38d10SBaptiste Daroussin unsigned tablesize = CAPTABSIZE;
250aae38d10SBaptiste Daroussin struct user_table_entry *name_table = typeCalloc(struct
251aae38d10SBaptiste Daroussin user_table_entry, tablesize);
25206bfebdeSXin LI HashValue *hash_table = typeCalloc(HashValue, HASHTABSIZE);
253*21817992SBaptiste Daroussin const char *root_name;
25406bfebdeSXin LI int column = 0;
25506bfebdeSXin LI int bigstring = 0;
256aae38d10SBaptiste Daroussin unsigned n;
257aae38d10SBaptiste Daroussin unsigned nn;
258aae38d10SBaptiste Daroussin unsigned tableused = 0;
259aae38d10SBaptiste Daroussin bool is_user;
260aae38d10SBaptiste Daroussin const char *table_name;
26106bfebdeSXin LI char buffer[BUFSIZ];
26206bfebdeSXin LI
26306bfebdeSXin LI short BoolCount = 0;
26406bfebdeSXin LI short NumCount = 0;
26506bfebdeSXin LI short StrCount = 0;
26606bfebdeSXin LI
26706bfebdeSXin LI /* The first argument is the column-number (starting with 0).
26806bfebdeSXin LI * The second is the root name of the tables to generate.
26906bfebdeSXin LI */
27006bfebdeSXin LI if (argc <= 3
27106bfebdeSXin LI || (column = atoi(argv[1])) <= 0
27206bfebdeSXin LI || (column >= MAX_COLUMNS)
27306bfebdeSXin LI || *(root_name = argv[2]) == 0
27406bfebdeSXin LI || (bigstring = atoi(argv[3])) < 0
27506bfebdeSXin LI || name_table == 0
27606bfebdeSXin LI || hash_table == 0) {
27706bfebdeSXin LI fprintf(stderr, "usage: make_hash column root_name bigstring\n");
27806bfebdeSXin LI exit(EXIT_FAILURE);
27906bfebdeSXin LI }
280aae38d10SBaptiste Daroussin is_user = (*root_name == 'u');
281aae38d10SBaptiste Daroussin table_name = (is_user ? "user" : "name");
28206bfebdeSXin LI
28306bfebdeSXin LI /*
28406bfebdeSXin LI * Read the table into our arrays.
28506bfebdeSXin LI */
286aae38d10SBaptiste Daroussin for (n = 0; (n < tablesize) && fgets(buffer, BUFSIZ, stdin);) {
287aae38d10SBaptiste Daroussin char **list;
288aae38d10SBaptiste Daroussin char *nlp = strchr(buffer, '\n');
28906bfebdeSXin LI if (nlp)
29006bfebdeSXin LI *nlp = '\0';
291aae38d10SBaptiste Daroussin else
292aae38d10SBaptiste Daroussin buffer[sizeof(buffer) - 2] = '\0';
29306bfebdeSXin LI list = parse_columns(buffer);
29406bfebdeSXin LI if (list == 0) /* blank or comment */
29506bfebdeSXin LI continue;
296aae38d10SBaptiste Daroussin if (is_user) {
297aae38d10SBaptiste Daroussin if (strcmp(list[0], "userdef"))
298aae38d10SBaptiste Daroussin continue;
299aae38d10SBaptiste Daroussin } else if (!strcmp(list[0], "userdef")) {
300aae38d10SBaptiste Daroussin continue;
301aae38d10SBaptiste Daroussin }
302aae38d10SBaptiste Daroussin if (column < 0 || column > count_columns(list)) {
30373f0a83dSXin LI fprintf(stderr, "expected %d columns, have %d:\n%s\n",
30473f0a83dSXin LI column,
30573f0a83dSXin LI count_columns(list),
30673f0a83dSXin LI buffer);
30773f0a83dSXin LI exit(EXIT_FAILURE);
30873f0a83dSXin LI }
309aae38d10SBaptiste Daroussin nn = tableused;
310aae38d10SBaptiste Daroussin if (is_user) {
311aae38d10SBaptiste Daroussin unsigned j;
312aae38d10SBaptiste Daroussin for (j = 0; j < tableused; ++j) {
313aae38d10SBaptiste Daroussin if (!strcmp(list[column], name_table[j].ute_name)) {
314aae38d10SBaptiste Daroussin nn = j;
315aae38d10SBaptiste Daroussin break;
316aae38d10SBaptiste Daroussin }
317aae38d10SBaptiste Daroussin }
318aae38d10SBaptiste Daroussin }
319aae38d10SBaptiste Daroussin if (nn == tableused) {
320aae38d10SBaptiste Daroussin name_table[nn].ute_link = -1; /* end-of-hash */
321aae38d10SBaptiste Daroussin name_table[nn].ute_name = strmalloc(list[column]);
322aae38d10SBaptiste Daroussin ++tableused;
323aae38d10SBaptiste Daroussin }
324aae38d10SBaptiste Daroussin
32506bfebdeSXin LI if (!strcmp(list[2], "bool")) {
326aae38d10SBaptiste Daroussin SetType(nn, BOOLEAN);
327aae38d10SBaptiste Daroussin name_table[nn].ute_index = BoolCount++;
32806bfebdeSXin LI } else if (!strcmp(list[2], "num")) {
329aae38d10SBaptiste Daroussin SetType(nn, NUMBER);
330aae38d10SBaptiste Daroussin name_table[nn].ute_index = NumCount++;
33106bfebdeSXin LI } else if (!strcmp(list[2], "str")) {
332aae38d10SBaptiste Daroussin SetType(nn, STRING);
333aae38d10SBaptiste Daroussin name_table[nn].ute_index = StrCount++;
334aae38d10SBaptiste Daroussin if (is_user) {
335aae38d10SBaptiste Daroussin if (*list[3] != '-') {
336aae38d10SBaptiste Daroussin unsigned j;
337aae38d10SBaptiste Daroussin name_table[nn].ute_argc = (unsigned) strlen(list[3]);
338aae38d10SBaptiste Daroussin for (j = 0; j < name_table[nn].ute_argc; ++j) {
339aae38d10SBaptiste Daroussin if (list[3][j] == 's') {
340aae38d10SBaptiste Daroussin name_table[nn].ute_args |= (1U << j);
341aae38d10SBaptiste Daroussin }
342aae38d10SBaptiste Daroussin }
343aae38d10SBaptiste Daroussin }
344aae38d10SBaptiste Daroussin }
34506bfebdeSXin LI } else {
34606bfebdeSXin LI fprintf(stderr, "Unknown type: %s\n", list[2]);
34706bfebdeSXin LI exit(EXIT_FAILURE);
34806bfebdeSXin LI }
34906bfebdeSXin LI n++;
35006bfebdeSXin LI }
351aae38d10SBaptiste Daroussin if (tablesize > tableused)
352aae38d10SBaptiste Daroussin tablesize = tableused;
353aae38d10SBaptiste Daroussin _nc_make_hash_table(name_table, hash_table, tablesize);
35406bfebdeSXin LI
35506bfebdeSXin LI /*
35606bfebdeSXin LI * Write the compiled tables to standard output
35706bfebdeSXin LI */
35806bfebdeSXin LI if (bigstring) {
35906bfebdeSXin LI int len = 0;
36006bfebdeSXin LI int nxt;
36106bfebdeSXin LI
36206bfebdeSXin LI printf("static const char %s_names_text[] = \\\n", root_name);
363aae38d10SBaptiste Daroussin for (n = 0; n < tablesize; n++) {
364aae38d10SBaptiste Daroussin nxt = (int) strlen(name_table[n].ute_name) + 5;
36506bfebdeSXin LI if (nxt + len > 72) {
36606bfebdeSXin LI printf("\\\n");
36706bfebdeSXin LI len = 0;
36806bfebdeSXin LI }
369aae38d10SBaptiste Daroussin printf("\"%s\\0\" ", name_table[n].ute_name);
37006bfebdeSXin LI len += nxt;
37106bfebdeSXin LI }
37206bfebdeSXin LI printf(";\n\n");
37306bfebdeSXin LI
37406bfebdeSXin LI len = 0;
375aae38d10SBaptiste Daroussin printf("static %s_table_data const %s_names_data[] =\n",
376aae38d10SBaptiste Daroussin table_name,
37706bfebdeSXin LI root_name);
378aae38d10SBaptiste Daroussin printf("%s\n", L_BRACE);
379aae38d10SBaptiste Daroussin for (n = 0; n < tablesize; n++) {
380aae38d10SBaptiste Daroussin printf("\t%s %15d,\t%10s,", L_BRACE, len, GetType(n));
381aae38d10SBaptiste Daroussin if (is_user)
382aae38d10SBaptiste Daroussin printf("\t%d,%d,",
383aae38d10SBaptiste Daroussin name_table[n].ute_argc,
384aae38d10SBaptiste Daroussin name_table[n].ute_args);
385aae38d10SBaptiste Daroussin printf("\t%3d, %3d %s%c\n",
386aae38d10SBaptiste Daroussin name_table[n].ute_index,
387aae38d10SBaptiste Daroussin name_table[n].ute_link,
388aae38d10SBaptiste Daroussin R_BRACE,
389aae38d10SBaptiste Daroussin n < tablesize - 1 ? ',' : ' ');
390aae38d10SBaptiste Daroussin len += (int) strlen(name_table[n].ute_name) + 1;
39106bfebdeSXin LI }
392aae38d10SBaptiste Daroussin printf("%s;\n\n", R_BRACE);
393aae38d10SBaptiste Daroussin printf("static struct %s_table_entry *_nc_%s_table = 0;\n\n",
394aae38d10SBaptiste Daroussin table_name,
395aae38d10SBaptiste Daroussin root_name);
39606bfebdeSXin LI } else {
39706bfebdeSXin LI
398aae38d10SBaptiste Daroussin printf("static struct %s_table_entry const _nc_%s_table[] =\n",
399aae38d10SBaptiste Daroussin table_name,
40006bfebdeSXin LI root_name);
401aae38d10SBaptiste Daroussin printf("%s\n", L_BRACE);
402aae38d10SBaptiste Daroussin for (n = 0; n < tablesize; n++) {
40373f0a83dSXin LI _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "\"%s\"",
404aae38d10SBaptiste Daroussin name_table[n].ute_name);
405aae38d10SBaptiste Daroussin printf("\t%s %15s,\t%10s,", L_BRACE, buffer, GetType(n));
406aae38d10SBaptiste Daroussin if (is_user)
407aae38d10SBaptiste Daroussin printf("\t%d,%d,",
408aae38d10SBaptiste Daroussin name_table[n].ute_argc,
409aae38d10SBaptiste Daroussin name_table[n].ute_args);
410aae38d10SBaptiste Daroussin printf("\t%3d, %3d %s%c\n",
411aae38d10SBaptiste Daroussin name_table[n].ute_index,
412aae38d10SBaptiste Daroussin name_table[n].ute_link,
413aae38d10SBaptiste Daroussin R_BRACE,
414aae38d10SBaptiste Daroussin n < tablesize - 1 ? ',' : ' ');
41506bfebdeSXin LI }
416aae38d10SBaptiste Daroussin printf("%s;\n\n", R_BRACE);
41706bfebdeSXin LI }
41806bfebdeSXin LI
41906bfebdeSXin LI printf("static const HashValue _nc_%s_hash_table[%d] =\n",
42006bfebdeSXin LI root_name,
42106bfebdeSXin LI HASHTABSIZE + 1);
422aae38d10SBaptiste Daroussin printf("%s\n", L_BRACE);
42306bfebdeSXin LI for (n = 0; n < HASHTABSIZE; n++) {
42406bfebdeSXin LI printf("\t%3d,\n", hash_table[n]);
42506bfebdeSXin LI }
42606bfebdeSXin LI printf("\t0\t/* base-of-table */\n");
427aae38d10SBaptiste Daroussin printf("%s;\n\n", R_BRACE);
42806bfebdeSXin LI
429aae38d10SBaptiste Daroussin if (!is_user) {
43006bfebdeSXin LI printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n",
43106bfebdeSXin LI BoolCount, NumCount, StrCount);
43206bfebdeSXin LI printf("#error\t--> term.h and comp_captab.c disagree about the <--\n");
43306bfebdeSXin LI printf("#error\t--> numbers of booleans, numbers and/or strings <--\n");
43406bfebdeSXin LI printf("#endif\n\n");
435aae38d10SBaptiste Daroussin }
43606bfebdeSXin LI
43706bfebdeSXin LI free(hash_table);
438aae38d10SBaptiste Daroussin for (n = 0; (n < tablesize); ++n) {
439aae38d10SBaptiste Daroussin free((void *) name_table[n].ute_name);
440aae38d10SBaptiste Daroussin }
441aae38d10SBaptiste Daroussin free(name_table);
442aae38d10SBaptiste Daroussin parse_columns(0);
443aae38d10SBaptiste Daroussin
44406bfebdeSXin LI return EXIT_SUCCESS;
44506bfebdeSXin LI }
446