1 /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #define HASH_SIZE 2503 /* a prime */
28 hashf (name, len, hashsize)
29 register U_CHAR *name;
36 r = HASHSTEP (r, *name++);
38 return MAKE_POS (r) % hashsize;
41 int hash_tab[HASH_SIZE];
47 /* Avoid error if config defines abort as fancy_abort.
48 It's not worth "really" implementing this because ordinary
49 compiler users never run fix-header. */
68 while (i > 0 && argv[i-1] != '/') --i;
71 fprintf (outf, "struct fn_decl std_protos[] = {\n");
75 int c = skip_spaces (inf, ' ');
76 int param_nesting = 1;
77 char *param_start, *param_end, *decl_start,
78 *name_start, *name_end;
82 linebuf.ptr = linebuf.base;
84 c = read_upto (inf, &linebuf, '\n');
85 if (linebuf.base[0] == '#') /* skip cpp command */
87 if (linebuf.base[0] == '\0') /* skip empty line */
90 ptr = linebuf.ptr - 1;
91 while (*ptr == ' ' || *ptr == '\t') ptr--;
94 fprintf (stderr, "Funny input line: %s\n", linebuf.base);
97 while (*ptr == ' ' || *ptr == '\t') ptr--;
100 fprintf (stderr, "Funny input line: %s\n", linebuf.base);
107 if (c == '(' && --param_nesting == 0)
115 while (*ptr == ' ' || *ptr == '\t') ptr--;
120 fprintf (stderr, "%s: Can't handle this complex prototype: %s\n",
121 argv[0], linebuf.base);
126 while (isalnum (*ptr) || *ptr == '_') --ptr;
128 while (*ptr == ' ' || *ptr == '\t') ptr--;
134 decl_start = linebuf.base;
135 if (strncmp (decl_start, "typedef ", 8) == 0)
137 if (strncmp (decl_start, "extern ", 7) == 0)
141 /* NOTE: If you edit this,
142 also edit lookup_std_proto in fix-header.c !! */
143 i = hashf (name_start, name_end - name_start, HASH_SIZE);
145 if (hash_tab[i] != 0)
149 i = (i+1) % HASH_SIZE;
152 if (hash_tab[i] == 0)
156 hash_tab[i] = next_index;
158 fprintf (outf, " {\"%s\", \"%s\", \"%s\" },\n",
159 name_start, decl_start, param_start);
166 fprintf (outf, "{0, 0, 0}\n};\n");
169 fprintf (outf, "#define HASH_SIZE %d\n", HASH_SIZE);
170 fprintf (outf, "short hash_tab[HASH_SIZE] = {\n");
171 for (i = 0; i < HASH_SIZE; i++)
172 fprintf (outf, " %d,\n", hash_tab[i]);
173 fprintf (outf, "};\n");
182 fprintf (stderr, "%s: %s\n", "gen-protos", s);
183 exit (FATAL_EXIT_CODE);