Unbreak K&R support, and generate code that works in K&R C as well as

ANSI C no matter what language is specified.
This commit is contained in:
Dag-Erling Smørgrav 1998-12-18 14:29:51 +00:00
parent 3a5dbbd324
commit d63c42d19f

View File

@ -26,7 +26,7 @@ static const char copyright[] =
"Copyright 1987,1988 by MIT Student Information Processing Board";
static const char rcsid_compile_et_c[] =
"$Header: /home/ncvs/src/usr.bin/compile_et/compile_et.c,v 1.4 1997/06/30 06:42:41 charnier Exp $";
"$Header: /home/ncvs/src/usr.bin/compile_et/compile_et.c,v 1.5 1998/12/15 12:20:27 des Exp $";
#endif
extern char *gensym();
@ -73,19 +73,13 @@ static const char *const language_names[] = {
0,
};
static const char * const c_src_prolog[] = {
"static const char * const text[] = {\n",
0,
};
static const char * const krc_src_prolog[] = {
static const char * const noargs_def[] = {
"#ifdef __STDC__\n",
"#define NOARGS void\n",
"#else\n",
"#define NOARGS\n",
"#define const\n",
"#endif\n\n",
"static const char * const text[] = {\n",
0,
};
@ -221,14 +215,12 @@ int main (argc, argv) int argc; char **argv; {
fprintf (cfile, warning, c_file);
/* prologue */
if (language == lang_C)
cpp = c_src_prolog;
else if (language == lang_KRC)
cpp = krc_src_prolog;
else
abort ();
while (*cpp)
fputs (*cpp++, cfile);
for (cpp = noargs_def; *cpp; cpp++) {
fputs (*cpp, cfile);
fputs (*cpp, hfile);
}
fputs("static const char * const text[] = {\n", cfile);
/* parse it */
yyparse();
@ -242,8 +234,8 @@ int main (argc, argv) int argc; char **argv; {
table_number, current);
fputs("static struct et_list link = { 0, 0 };\n\n",
cfile);
fprintf(cfile, "void initialize_%s_error_table (%s) {\n",
table_name, (language == lang_C) ? "void" : "NOARGS");
fprintf(cfile, "void initialize_%s_error_table (NOARGS) {\n",
table_name);
fputs(" if (!link.table) {\n", cfile);
fputs(" link.next = _et_list;\n", cfile);
fputs(" link.table = &et;\n", cfile);
@ -252,8 +244,8 @@ int main (argc, argv) int argc; char **argv; {
fputs("}\n", cfile);
fclose(cfile);
fprintf (hfile, "extern void initialize_%s_error_table (%s);\n",
table_name, (language == lang_C) ? "void" : "");
fprintf (hfile, "extern void initialize_%s_error_table (NOARGS);\n",
table_name);
fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%dL)\n",
table_name, table_number);
/* compatibility... */