3 * Copyright 1986, 1987, 1988
4 * by MIT Student Information Processing Board.
6 * For copyright info, see "mit-sipb-cr.h".
11 #include <afsconfig.h>
12 #include <afs/param.h>
21 #include <sys/param.h>
29 #include "mit-sipb-cr.h"
33 static const char copyright[] =
34 "Copyright 1987,1988 by MIT Student Information Processing Board";
37 extern char *gensym();
38 extern char *current_token;
39 extern int table_number, current;
41 char *table_name = (char *)NULL;
42 FILE *hfile, *cfile, *msfile;
51 char * xmalloc (size) unsigned int size; {
52 char * p = malloc (size);
60 static int check_arg (str_list, arg) char const *const *str_list, *arg; {
62 if (!strcmp(arg, *str_list++))
67 static const char *const debug_args[] = {
73 static const char *const lang_args[] = {
79 static const char *const language_names[] = {
86 static const char * const c_src_prolog[] = {
87 "#include <afs/param.h>\n",
88 "#include <afs/error_table.h>\n",
89 "static const char * const text[] = {\n",
93 static const char * const krc_src_prolog[] = {
95 "#define NOARGS void\n",
100 "#include <afs/param.h>\n",
101 "#include <afs/error_table.h>\n",
102 "static const char * const text[] = {\n",
106 static const char warning[] =
107 "/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n";
109 static const char msf_warning[] =
110 "$ \n$ %s:\n$ This file is automatically generated; please do not edit it.\n$ \n$set 1\n";
113 char c_file[MAXPATHLEN]; /* output file */
114 char h_file[MAXPATHLEN]; /* output */
115 char msf_file[MAXPATHLEN];
117 static void usage () {
118 fprintf (stderr, "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-v version]\n",
123 static void dup_err (type, one, two) char const *type, *one, *two; {
124 fprintf (stderr, "%s: multiple %s specified: `%s' and `%s'\n",
125 whoami, type, one, two);
129 #include "AFS_component_version_number.c"
131 int main (argc, argv) int argc; char **argv; {
133 char const * const *cpp;
134 int got_language = 0;
135 char *got_include = 0;
140 * The following signal action for AIX is necessary so that in case of a
141 * crash (i.e. core is generated) we can include the user's data section
142 * in the core dump. Unfortunately, by default, only a partial core is
143 * generated which, in many cases, isn't too useful.
145 struct sigaction nsa;
147 sigemptyset(&nsa.sa_mask);
148 nsa.sa_handler = SIG_DFL;
149 nsa.sa_flags = SA_FULLDUMP;
150 sigaction(SIGSEGV, &nsa, NULL);
152 /* argument parsing */
156 p = strrchr (whoami, '/');
159 while (argv++, --argc) {
163 dup_err ("filenames", filename, arg);
168 if (check_arg (debug_args, arg))
170 else if (check_arg (lang_args, arg)) {
172 arg = *++argv, argc--;
176 dup_err ("languanges", language_names[(int)language], arg);
177 #define check_lang(x,v) else if (!strcasecmp(arg,x)) language = v
178 check_lang ("c", lang_C);
179 check_lang ("ansi_c", lang_C);
180 check_lang ("ansi-c", lang_C);
181 check_lang ("krc", lang_KRC);
182 check_lang ("kr_c", lang_KRC);
183 check_lang ("kr-c", lang_KRC);
184 check_lang ("k&r-c", lang_KRC);
185 check_lang ("k&r_c", lang_KRC);
186 check_lang ("c++", lang_CPP);
187 check_lang ("cplusplus", lang_CPP);
188 check_lang ("c-plus-plus", lang_CPP);
191 fprintf (stderr, "%s: unknown language name `%s'\n",
193 fprintf (stderr, "\tpick one of: C K&R-C\n");
197 else if (strcmp (arg, "h") == 0) {
198 arg = *++argv, argc--;
202 else if (strcmp (arg, "v") == 0) {
203 arg = *++argv, argc--;
205 if (version != 1 && version != 2) {
206 fprintf (stderr, "%s: unknown control argument -`%s'\n",
211 if (version == 2) use_msf = 1;
214 fprintf (stderr, "%s: unknown control argument -`%s'\n",
224 else if (language == lang_CPP) {
225 fprintf (stderr, "%s: Sorry, C++ support is not yet finished.\n",
231 p = strrchr(filename, '/');
232 if (p == (char *)NULL)
236 ename = xmalloc (strlen(p) + 5);
239 /* Now, flush .et suffix if it exists. */
240 p = strrchr(ename, '.');
242 if (strcmp (p, ".et") == 0)
247 sprintf(msf_file, "%s.msf", ename);
249 sprintf(c_file, "%s.c", ename);
252 sprintf(h_file, "%s.h", got_include);
254 sprintf(h_file, "%s.h", ename);
256 p = strrchr(filename, '.');
259 p = xmalloc (strlen(filename) + 4);
260 sprintf(p, "%s.et", filename);
264 yyin = fopen(filename, "r");
270 /* on NT, yyout is not initialized to stdout */
275 hfile = fopen(h_file, "w");
276 if (hfile == (FILE *)NULL) {
280 fprintf (hfile, warning, h_file);
283 char prolog_h_file[MAXPATHLEN];
287 strcpy (prolog_h_file, got_include);
288 strcat (prolog_h_file, ".p.h");
289 prolog_hfile = fopen(prolog_h_file, "r");
291 fprintf (stderr, "Including %s at beginning of %s file.\n", prolog_h_file, h_file);
292 fprintf (hfile, "/* Including %s at beginning of %s file. */\n\n",
293 prolog_h_file, h_file);
295 count = fread (buffer, sizeof(char), sizeof(buffer), prolog_hfile);
297 perror(prolog_h_file);
300 written = fwrite (buffer, sizeof(char), count, hfile);
301 if (count != written) {
302 perror(prolog_h_file);
306 fprintf (hfile, "\n/* End of prolog file %s. */\n\n", prolog_h_file);
311 msfile = fopen(msf_file, "w");
312 if (msfile == (FILE *)NULL) {
316 fprintf(msfile, msf_warning, msf_file);
318 cfile = fopen(c_file, "w");
319 if (cfile == (FILE *)NULL) {
323 fprintf (cfile, warning, c_file);
326 if (language == lang_C)
328 else if (language == lang_KRC)
329 cpp = krc_src_prolog;
333 fputs (*cpp++, cfile);
338 fclose(yyin); /* bye bye input file */
341 fputs (" 0\n};\n\n", cfile);
343 "static const struct error_table et = { text, %ldL, %d };\n\n",
344 (long int) table_number, current);
345 fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
346 fprintf(cfile, "void initialize_%s_error_table (%s) {\n",
347 table_name, (language == lang_C) ? "void" : "NOARGS");
348 fputs(" add_to_error_table(&etlink);\n", cfile);
353 fprintf (hfile, "extern void initialize_%s_error_table ();\n",
356 fprintf (hfile, "#define initialize_%s_error_table()\n",
360 fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n",
361 table_name, (long int) table_number);
362 /* compatibility... */
363 fprintf (hfile, "\n/* for compatibility with older versions... */\n");
364 fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
365 table_name, table_name);
366 fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
368 fprintf (hfile, "\n/* for compatibility with other users... */\n");
369 lcstring (lcname, table_name, sizeof(lcname));
370 fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n",
371 lcname, (long int) table_number);
372 fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
374 fprintf (hfile, "#define initialize_%s_error_table initialize_%s_error_table\n",
376 fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
378 fclose(hfile); /* bye bye include file */
384 void yyerror(const char *s) {
386 fprintf(stderr, "\nLine number %d; last token was '%s'\n",
387 yylineno, current_token);