|
|
1.1 root 1: /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2: Copyright (C) 1993 Free Software Foundation, Inc.
3:
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
7: later version.
8:
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.
13:
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
17:
18: #include <stdio.h>
19: #include <ctype.h>
20: #include "hconfig.h"
21: #include "scan.h"
22:
23: #define HASH_SIZE 2503 /* a prime */
24:
25: int hash_tab[HASH_SIZE];
26: int verbose = 0;
27:
28: sstring linebuf;
29:
30: /* Avoid error if config defines abort as fancy_abort.
31: It's not worth "really" implementing this because ordinary
32: compiler users never run fix-header. */
33:
34: void
35: fancy_abort ()
36: {
37: abort ();
38: }
39:
40: int
41: main (argc, argv)
42: int argc;
43: char** argv;
44: {
45: FILE *inf = stdin;
46: FILE *outf = stdout;
47: int next_index = 0;
48: int i, i0;
49:
50: fprintf (outf, "struct fn_decl std_protos[] = {\n");
51:
52: for (;;)
53: {
54: int c = skip_spaces (inf, ' ');
55: int param_nesting = 1;
56: char *param_start, *param_end, *decl_start,
57: *name_start, *name_end;
58: register char *ptr;
59: if (c == EOF)
60: break;
61: linebuf.ptr = linebuf.base;
62: ungetc (c, inf);
63: c = read_upto (inf, &linebuf, '\n');
64: if (linebuf.base[0] == '#') /* skip cpp command */
65: continue;
66: if (linebuf.base[0] == '\0') /* skip empty line */
67: continue;
68:
69: ptr = linebuf.ptr - 1;
70: while (*ptr == ' ' || *ptr == '\t') ptr--;
71: if (*ptr-- != ';')
72: {
73: fprintf (stderr, "Funny input line: %s\n", linebuf.base);
74: continue;
75: }
76: while (*ptr == ' ' || *ptr == '\t') ptr--;
77: if (*ptr != ')')
78: {
79: fprintf (stderr, "Funny input line: %s\n", linebuf.base);
80: continue;
81: }
82: param_end = ptr;
83: for (;;)
84: {
85: int c = *--ptr;
86: if (c == '(' && --param_nesting == 0)
87: break;
88: else if (c == ')')
89: param_nesting++;
90: }
91: param_start = ptr+1;
92:
93: ptr--;
94: while (*ptr == ' ' || *ptr == '\t') ptr--;
95:
96: if (!isalnum (*ptr))
97: {
98: if (verbose)
99: fprintf (stderr, "%s: Can't handle this complex prototype: %s\n",
100: argv[0], linebuf.base);
101: continue;
102: }
103: name_end = ptr+1;
104:
105: while (isalnum (*ptr) || *ptr == '_') --ptr;
106: name_start = ptr+1;
107: while (*ptr == ' ' || *ptr == '\t') ptr--;
108: ptr[1] = 0;
109: *name_end = 0;
110: *param_end = 0;
111: *name_end = 0;
112:
113: decl_start = linebuf.base;
114: if (strncmp (decl_start, "typedef ", 8) == 0)
115: continue;
116: if (strncmp (decl_start, "extern ", 7) == 0)
117: decl_start += 7;
118:
119:
120: /* NOTE: If you edit this,
121: also edit lookup_std_proto in fix-header.c !! */
122: i = hash (name_start) % HASH_SIZE;
123: i0 = i;
124: if (hash_tab[i] != 0)
125: {
126: for (;;)
127: {
128: i = (i+1) % HASH_SIZE;
129: if (i == i0)
130: abort ();
131: if (hash_tab[i] == 0)
132: break;
133: }
134: }
135: hash_tab[i] = next_index;
136:
137: fprintf (outf, " {\"%s\", \"%s\", \"%s\" },\n",
138: name_start, decl_start, param_start, i, i0);
139:
140: next_index++;
141:
142: if (c == EOF)
143: break;
144: }
145: fprintf (outf, "{0, 0, 0}\n};\n");
146:
147:
148: fprintf (outf, "#define HASH_SIZE %d\n", HASH_SIZE);
149: fprintf (outf, "short hash_tab[HASH_SIZE] = {\n");
150: for (i = 0; i < HASH_SIZE; i++)
151: fprintf (outf, " %d,\n", hash_tab[i]);
152: fprintf (outf, "};\n");
153:
154: return 0;
155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.