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>
13 #include <afs/afsutil.h>
22 #include <sys/param.h>
30 #include "mit-sipb-cr.h"
35 static const char copyright[] =
36 "Copyright 1987,1988 by MIT Student Information Processing Board";
39 extern char *current_token;
40 extern int table_number, current;
42 char *table_name = (char *)NULL;
43 FILE *hfile, *cfile, *msfile;
56 char * xmalloc (unsigned int size)
58 char * p = malloc (size);
66 static int check_arg (char const *const *str_list, char const *arg)
69 if (!strcmp(arg, *str_list++))
74 static const char *const debug_args[] = {
80 static const char *const lang_args[] = {
86 static const char *const language_names[] = {
93 static const char * const c_src_prolog[] = {
94 "#include <afs/param.h>\n",
95 "#include <afs/error_table.h>\n",
96 "static const char * const text[] = {\n",
100 static const char * const krc_src_prolog[] = {
102 "#define NOARGS void\n",
107 "#include <afs/param.h>\n",
108 "#include <afs/error_table.h>\n",
109 "static const char * const text[] = {\n",
113 static const char warning[] =
114 "/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n";
116 static const char msf_warning[] =
117 "$ \n$ %s:\n$ This file is automatically generated; please do not edit it.\n$ \n$set 1\n";
120 char c_file[MAXPATHLEN]; /* output file */
121 char h_file[MAXPATHLEN]; /* output */
122 char msf_file[MAXPATHLEN];
123 char et_file[MAXPATHLEN]; /* full path to input file */
125 static void usage (void)
127 fprintf (stderr, "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-p prefix] [-v version]\n",
132 static void dup_err (char const *type,
136 fprintf (stderr, "%s: multiple %s specified: `%s' and `%s'\n",
137 whoami, type, one, two);
141 #include "AFS_component_version_number.c"
143 int main (int argc, char **argv)
146 char const * const *cpp;
147 int got_language = 0;
148 char *got_include = 0;
149 char *got_prefix = ".";
154 * The following signal action for AIX is necessary so that in case of a
155 * crash (i.e. core is generated) we can include the user's data section
156 * in the core dump. Unfortunately, by default, only a partial core is
157 * generated which, in many cases, isn't too useful.
159 struct sigaction nsa;
161 sigemptyset(&nsa.sa_mask);
162 nsa.sa_handler = SIG_DFL;
163 nsa.sa_flags = SA_FULLDUMP;
164 sigaction(SIGSEGV, &nsa, NULL);
166 /* argument parsing */
170 p = strrchr (whoami, '/');
173 while (argv++, --argc) {
177 dup_err ("filenames", filename, arg);
182 if (check_arg (debug_args, arg))
184 else if (check_arg (lang_args, arg)) {
186 arg = *++argv, argc--;
190 dup_err ("languanges", language_names[(int)language], arg);
191 #define check_lang(x,v) else if (!strcasecmp(arg,x)) language = v
192 check_lang ("c", lang_C);
193 check_lang ("ansi_c", lang_C);
194 check_lang ("ansi-c", lang_C);
195 check_lang ("krc", lang_KRC);
196 check_lang ("kr_c", lang_KRC);
197 check_lang ("kr-c", lang_KRC);
198 check_lang ("k&r-c", lang_KRC);
199 check_lang ("k&r_c", lang_KRC);
200 check_lang ("c++", lang_CPP);
201 check_lang ("cplusplus", lang_CPP);
202 check_lang ("c-plus-plus", lang_CPP);
205 fprintf (stderr, "%s: unknown language name `%s'\n",
207 fprintf (stderr, "\tpick one of: C K&R-C\n");
211 else if (strcmp (arg, "h") == 0) {
212 arg = *++argv, argc--;
216 else if (strcmp (arg, "p") == 0) {
217 arg = *++argv, argc--;
221 else if (strcmp (arg, "v") == 0) {
222 arg = *++argv, argc--;
224 if (version != 1 && version != 2) {
225 fprintf (stderr, "%s: unknown control argument -`%s'\n",
230 if (version == 2) use_msf = 1;
233 fprintf (stderr, "%s: unknown control argument -`%s'\n",
243 else if (language == lang_CPP) {
244 fprintf (stderr, "%s: Sorry, C++ support is not yet finished.\n",
250 p = strrchr(filename, '/');
251 if (p == (char *)NULL)
255 ename = xmalloc (strlen(p) + 5);
258 /* Now, flush .et suffix if it exists. */
259 p = strrchr(ename, '.');
261 if (strcmp (p, ".et") == 0)
266 sprintf(msf_file, "%s.msf", ename);
268 sprintf(c_file, "%s.c", ename);
271 sprintf(h_file, "%s.h", got_include);
273 sprintf(h_file, "%s.h", ename);
275 p = strrchr(filename, '.');
278 p = xmalloc (strlen(filename) + 4);
279 sprintf(p, "%s.et", filename);
283 sprintf(et_file, "%s/%s", got_prefix, filename);
285 yyin = fopen(et_file, "r");
291 /* on NT, yyout is not initialized to stdout */
296 hfile = fopen(h_file, "w");
297 if (hfile == (FILE *)NULL) {
301 fprintf (hfile, warning, h_file);
304 char prolog_h_file[MAXPATHLEN];
308 strcpy (prolog_h_file, got_prefix);
309 strcat (prolog_h_file, "/");
310 strcat (prolog_h_file, got_include);
311 strcat (prolog_h_file, ".p.h");
312 prolog_hfile = fopen(prolog_h_file, "r");
314 fprintf (stderr, "Including %s at beginning of %s file.\n", prolog_h_file, h_file);
315 fprintf (hfile, "/* Including %s at beginning of %s file. */\n\n",
316 prolog_h_file, h_file);
318 count = fread (buffer, sizeof(char), sizeof(buffer), prolog_hfile);
320 perror(prolog_h_file);
323 written = fwrite (buffer, sizeof(char), count, hfile);
324 if (count != written) {
325 perror(prolog_h_file);
329 fprintf (hfile, "\n/* End of prolog file %s. */\n\n", prolog_h_file);
334 msfile = fopen(msf_file, "w");
335 if (msfile == (FILE *)NULL) {
339 fprintf(msfile, msf_warning, msf_file);
341 cfile = fopen(c_file, "w");
342 if (cfile == (FILE *)NULL) {
346 fprintf (cfile, warning, c_file);
349 if (language == lang_C)
351 else if (language == lang_KRC)
352 cpp = krc_src_prolog;
356 fputs (*cpp++, cfile);
361 fclose(yyin); /* bye bye input file */
364 fputs (" 0\n};\n\n", cfile);
366 "static const struct error_table et = { text, %ldL, %d };\n\n",
367 (long int) table_number, current);
368 fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
369 fprintf(cfile, "void initialize_%s_error_table(void) {\n", table_name);
370 fputs(" add_to_error_table(&etlink);\n", cfile);
375 fprintf (hfile, "extern void initialize_%s_error_table(void);\n",
378 fprintf (hfile, "#define initialize_%s_error_table(void)\n",
382 fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n",
383 table_name, (long int) table_number);
384 /* compatibility... */
385 fprintf (hfile, "\n/* for compatibility with older versions... */\n");
386 fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
387 table_name, table_name);
388 fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
390 fprintf (hfile, "\n/* for compatibility with other users... */\n");
391 lcstring (lcname, table_name, sizeof(lcname));
392 fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n",
393 lcname, (long int) table_number);
394 fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
396 fprintf (hfile, "#define initialize_%s_error_table initialize_%s_error_table\n",
398 fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
400 fclose(hfile); /* bye bye include file */
406 void yyerror(const char *s)
409 fprintf(stderr, "\nLine number %d; last token was '%s'\n",
410 yylineno, current_token);