1 /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2 Copyright (C) 1993, 94-96, 1998 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
];
38 /* NOTE: If you edit this, also edit lookup_std_proto in fix-header.c !! */
39 i
= hashf (fname
, strlen (fname
), HASH_SIZE
);
45 i
= (i
+1) % HASH_SIZE
;
52 hash_tab
[i
] = next_index
;
57 /* Given a function prototype, fill in the fields of FN.
58 The result is a boolean indicating if a function prototype was found.
60 The input string is modified (trailing NULs are inserted).
61 The fields of FN point to the input string. */
64 parse_fn_proto (start
, end
, fn
)
69 int param_nesting
= 1;
70 char *param_start
, *param_end
, *decl_start
, *name_start
, *name_end
;
73 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
76 fprintf (stderr
, "Funny input line: %s\n", start
);
79 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
82 fprintf (stderr
, "Funny input line: %s\n", start
);
89 if (c
== '(' && --param_nesting
== 0)
97 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
99 if (!ISALNUM ((unsigned char)*ptr
))
102 fprintf (stderr
, "%s: Can't handle this complex prototype: %s\n",
108 while (ISALNUM ((unsigned char)*ptr
) || *ptr
== '_') --ptr
;
110 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
116 if (strncmp (decl_start
, "typedef ", 8) == 0)
118 if (strncmp (decl_start
, "extern ", 7) == 0)
121 fn
->fname
= name_start
;
122 fn
->rtype
= decl_start
;
123 fn
->params
= param_start
;
129 int argc ATTRIBUTE_UNUSED
;
136 struct fn_decl fn_decl
;
138 i
= strlen (argv
[0]);
139 while (i
> 0 && argv
[0][i
-1] != '/') --i
;
140 progname
= &argv
[0][i
];
142 INIT_SSTRING (&linebuf
);
144 fprintf (outf
, "struct fn_decl std_protos[] = {\n");
146 /* A hash table entry of 0 means "unused" so reserve it. */
147 fprintf (outf
, " {\"\", \"\", \"\", 0},\n");
152 int c
= skip_spaces (inf
, ' ');
156 linebuf
.ptr
= linebuf
.base
;
158 c
= read_upto (inf
, &linebuf
, '\n');
159 if (linebuf
.base
[0] == '#') /* skip cpp command */
161 if (linebuf
.base
[0] == '\0') /* skip empty line */
164 if (! parse_fn_proto (linebuf
.base
, linebuf
.ptr
, &fn_decl
))
167 add_hash (fn_decl
.fname
);
169 fprintf (outf
, " {\"%s\", \"%s\", \"%s\", 0},\n",
170 fn_decl
.fname
, fn_decl
.rtype
, fn_decl
.params
);
175 fprintf (outf
, " {0, 0, 0, 0}\n};\n");
178 fprintf (outf
, "#define HASH_SIZE %d\n", HASH_SIZE
);
179 fprintf (outf
, "short hash_tab[HASH_SIZE] = {\n");
180 for (i
= 0; i
< HASH_SIZE
; i
++)
181 fprintf (outf
, " %d,\n", hash_tab
[i
]);
182 fprintf (outf
, "};\n");