]> gcc.gnu.org Git - gcc.git/blame - gcc/gen-protos.c
Include ctype.h.
[gcc.git] / gcc / gen-protos.c
CommitLineData
7936052f
PB
1/* gen-protos.c - massages a list of prototypes, for use by fixproto.
2 Copyright (C) 1993 Free Software Foundation, Inc.
3
4This program is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the
6Free Software Foundation; either version 2, or (at your option) any
7later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18#include <stdio.h>
794c765c 19#include <ctype.h>
7936052f
PB
20#include "scan.h"
21
22#define HASH_SIZE 2503 /* a prime */
23
24int hash_tab[HASH_SIZE];
cefd15ce 25int verbose = 0;
7936052f
PB
26
27sstring linebuf;
28
29int
30main (argc, argv)
31 int argc;
32 char** argv;
33{
34 FILE *inf = stdin;
35 FILE *outf = stdout;
36 int next_index = 0;
37 int i, i0;
38
39 fprintf (outf, "struct fn_decl std_protos[] = {\n");
40
41 for (;;)
42 {
43 int c = skip_spaces (inf, ' ');
44 int param_nesting = 1;
45 char *param_start, *param_end, *decl_start,
46 *name_start, *name_end;
47 register char *ptr;
48 if (c == EOF)
49 break;
50 linebuf.ptr = linebuf.base;
51 ungetc (c, inf);
52 c = read_upto (inf, &linebuf, '\n');
53 if (linebuf.base[0] == '#') /* skip cpp command */
54 continue;
55 if (linebuf.base[0] == '\0') /* skip empty line */
56 continue;
57
58 ptr = linebuf.ptr - 1;
59 while (*ptr == ' ' || *ptr == '\t') ptr--;
60 if (*ptr-- != ';')
61 {
62 fprintf (stderr, "Funny input line: %s\n", linebuf.base);
63 continue;
64 }
65 while (*ptr == ' ' || *ptr == '\t') ptr--;
66 if (*ptr != ')')
67 {
68 fprintf (stderr, "Funny input line: %s\n", linebuf.base);
69 continue;
70 }
71 param_end = ptr;
72 for (;;)
73 {
74 int c = *--ptr;
75 if (c == '(' && --param_nesting == 0)
76 break;
77 else if (c == ')')
78 param_nesting++;
79 }
80 param_start = ptr+1;
81
82 ptr--;
83 while (*ptr == ' ' || *ptr == '\t') ptr--;
84
85 if (!isalnum (*ptr))
86 {
cefd15ce
PB
87 if (verbose)
88 fprintf (stderr, "%s: Can't handle this complex prototype: %s\n",
89 argv[0], linebuf.base);
7936052f
PB
90 continue;
91 }
92 name_end = ptr+1;
93
94 while (isalnum (*ptr) || *ptr == '_') --ptr;
95 name_start = ptr+1;
96 while (*ptr == ' ' || *ptr == '\t') ptr--;
97 ptr[1] = 0;
98 *name_end = 0;
99 *param_end = 0;
100 *name_end = 0;
101
102 decl_start = linebuf.base;
103 if (strncmp (decl_start, "typedef ", 8) == 0)
104 continue;
105 if (strncmp (decl_start, "extern ", 7) == 0)
106 decl_start += 7;
107
108
109 /* NOTE: If you edit this,
110 also edit lookup_std_proto in patch-header.c !! */
111 i = hash(name_start) % HASH_SIZE;
112 i0 = i;
113 if (hash_tab[i] != 0)
114 {
115 for (;;)
116 {
117 i = (i+1) % HASH_SIZE;
118 if (i == i0)
119 abort();
120 if (hash_tab[i] == 0)
121 break;
122 }
123 }
124 hash_tab[i] = next_index;
125
633b477b 126 fprintf (outf, " {\"%s\", \"%s\", \"%s\" },\n",
7936052f
PB
127 name_start, decl_start, param_start, i, i0);
128
129 next_index++;
130
131 if (c == EOF)
132 break;
133 }
134 fprintf (outf, "{0, 0, 0}\n};\n");
135
136
137 fprintf (outf, "#define HASH_SIZE %d\n", HASH_SIZE);
138 fprintf (outf, "short hash_tab[HASH_SIZE] = {\n");
139 for (i = 0; i < HASH_SIZE; i++)
140 fprintf (outf, " %d,\n", hash_tab[i]);
141 fprintf (outf, "};\n");
142
143 return 0;
144}
This page took 0.069223 seconds and 5 git commands to generate.