1 /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2 Copyright (C) 1993, 1994, 1995, 1996 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. */
28 #define HASH_SIZE 2503 /* a prime */
29 int hash_tab
[HASH_SIZE
];
33 hashf (name
, len
, hashsize
)
34 register U_CHAR
*name
;
41 r
= HASHSTEP (r
, *name
++);
43 return MAKE_POS (r
) % hashsize
;
52 /* NOTE: If you edit this, also edit lookup_std_proto in fix-header.c !! */
53 i
= hashf (fname
, strlen (fname
), HASH_SIZE
);
59 i
= (i
+1) % HASH_SIZE
;
66 hash_tab
[i
] = next_index
;
71 /* Given a function prototype, fill in the fields of FN.
72 The result is a boolean indicating if a function prototype was found.
74 The input string is modified (trailing NULs are inserted).
75 The fields of FN point to the input string. */
78 parse_fn_proto (start
, end
, fn
)
83 int param_nesting
= 1;
84 char *param_start
, *param_end
, *decl_start
, *name_start
, *name_end
;
87 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
90 fprintf (stderr
, "Funny input line: %s\n", start
);
93 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
96 fprintf (stderr
, "Funny input line: %s\n", start
);
103 if (c
== '(' && --param_nesting
== 0)
111 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
116 fprintf (stderr
, "%s: Can't handle this complex prototype: %s\n",
122 while (isalnum (*ptr
) || *ptr
== '_') --ptr
;
124 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
130 if (strncmp (decl_start
, "typedef ", 8) == 0)
132 if (strncmp (decl_start
, "extern ", 7) == 0)
135 fn
->fname
= name_start
;
136 fn
->rtype
= decl_start
;
137 fn
->params
= param_start
;
151 struct fn_decl fn_decl
;
153 i
= strlen (argv
[0]);
154 while (i
> 0 && argv
[0][i
-1] != '/') --i
;
155 progname
= &argv
[0][i
];
157 INIT_SSTRING (&linebuf
);
159 fprintf (outf
, "struct fn_decl std_protos[] = {\n");
161 /* A hash table entry of 0 means "unused" so reserve it. */
162 fprintf (outf
, " {\"\", \"\", \"\"},\n");
167 int c
= skip_spaces (inf
, ' ');
171 linebuf
.ptr
= linebuf
.base
;
173 c
= read_upto (inf
, &linebuf
, '\n');
174 if (linebuf
.base
[0] == '#') /* skip cpp command */
176 if (linebuf
.base
[0] == '\0') /* skip empty line */
179 if (! parse_fn_proto (linebuf
.base
, linebuf
.ptr
, &fn_decl
))
182 add_hash (fn_decl
.fname
);
184 fprintf (outf
, " {\"%s\", \"%s\", \"%s\"},\n",
185 fn_decl
.fname
, fn_decl
.rtype
, fn_decl
.params
);
190 fprintf (outf
, " {0, 0, 0}\n};\n");
193 fprintf (outf
, "#define HASH_SIZE %d\n", HASH_SIZE
);
194 fprintf (outf
, "short hash_tab[HASH_SIZE] = {\n");
195 for (i
= 0; i
< HASH_SIZE
; i
++)
196 fprintf (outf
, " %d,\n", hash_tab
[i
]);
197 fprintf (outf
, "};\n");
202 /* Avoid error if config defines abort as fancy_abort.
203 It's not worth "really" implementing this because ordinary
204 compiler users never run fix-header. */
216 fprintf (stderr
, "%s: %s\n", "gen-protos", s
);
217 exit (FATAL_EXIT_CODE
);