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>
21 #include <sys/param.h>
29 #include "mit-sipb-cr.h"
34 static const char copyright[] =
35 "Copyright 1987,1988 by MIT Student Information Processing Board";
38 extern char *current_token;
39 extern int table_number, current;
41 char *table_name = (char *)NULL;
42 FILE *hfile, *cfile, *msfile;
56 xmalloc(unsigned int size)
58 char *p = (char *)malloc(size);
67 check_arg(char const *const *str_list, char const *arg)
70 if (!strcmp(arg, *str_list++))
75 static const char *const debug_args[] = {
81 static const char *const lang_args[] = {
87 static const char *const language_names[] = {
94 static const char *const c_src_prolog[] = {
95 "#include <afs/param.h>\n",
96 "#include <afs/error_table.h>\n",
97 "static const char * const text[] = {\n",
101 static const char *const krc_src_prolog[] = {
103 "#define NOARGS void\n",
108 "#include <afs/param.h>\n",
109 "#include <afs/error_table.h>\n",
110 "static const char * const text[] = {\n",
114 static const char warning[] =
115 "/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n";
117 static const char msf_warning[] =
118 "$ \n$ %s:\n$ This file is automatically generated; please do not edit it.\n$ \n$set 1\n";
121 char c_file[MAXPATHLEN]; /* output file */
122 char h_file[MAXPATHLEN]; /* output */
123 char msf_file[MAXPATHLEN];
124 char et_file[MAXPATHLEN]; /* full path to input file */
130 "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-p prefix] [-v version]\n",
136 dup_err(char const *type, char const *one, char const *two)
138 fprintf(stderr, "%s: multiple %s specified: `%s' and `%s'\n", whoami,
143 #include "AFS_component_version_number.c"
146 main(int argc, char **argv)
149 char const *const *cpp;
150 int got_language = 0;
151 char *got_include = 0;
152 char *got_prefix = ".";
157 * The following signal action for AIX is necessary so that in case of a
158 * crash (i.e. core is generated) we can include the user's data section
159 * in the core dump. Unfortunately, by default, only a partial core is
160 * generated which, in many cases, isn't too useful.
162 struct sigaction nsa;
164 sigemptyset(&nsa.sa_mask);
165 nsa.sa_handler = SIG_DFL;
166 nsa.sa_flags = SA_FULLDUMP;
167 sigaction(SIGSEGV, &nsa, NULL);
169 /* argument parsing */
173 p = strrchr(whoami, '/');
176 while (argv++, --argc) {
180 dup_err("filenames", filename, arg);
184 if (check_arg(debug_args, arg))
186 else if (check_arg(lang_args, arg)) {
188 arg = *++argv, argc--;
192 dup_err("languanges", language_names[(int)language], arg);
194 #define check_lang(x,v) if (!strcasecmp(arg,x)) language = v
195 check_lang("c", lang_C);
196 check_lang("ansi_c", lang_C);
197 check_lang("ansi-c", lang_C);
198 check_lang("krc", lang_KRC);
199 check_lang("kr_c", lang_KRC);
200 check_lang("kr-c", lang_KRC);
201 check_lang("k&r-c", lang_KRC);
202 check_lang("k&r_c", lang_KRC);
203 check_lang("c++", lang_CPP);
204 check_lang("cplusplus", lang_CPP);
205 check_lang("c-plus-plus", lang_CPP);
209 fprintf(stderr, "%s: unknown language name `%s'\n",
211 fprintf(stderr, "\tpick one of: C K&R-C\n");
214 } else if (strcmp(arg, "h") == 0) {
215 arg = *++argv, argc--;
219 } else if (strcmp(arg, "p") == 0) {
220 arg = *++argv, argc--;
224 } else if (strcmp(arg, "v") == 0) {
225 arg = *++argv, argc--;
227 if (version != 1 && version != 2) {
228 fprintf(stderr, "%s: unknown control argument -`%s'\n",
236 fprintf(stderr, "%s: unknown control argument -`%s'\n",
246 else if (language == lang_CPP) {
247 fprintf(stderr, "%s: Sorry, C++ support is not yet finished.\n",
253 p = strrchr(filename, '/');
254 if (p == (char *)NULL)
258 ename = xmalloc(strlen(p) + 5);
261 /* Now, flush .et suffix if it exists. */
262 p = strrchr(ename, '.');
264 if (strcmp(p, ".et") == 0)
269 sprintf(msf_file, "%s.msf", ename);
271 sprintf(c_file, "%s.c", ename);
274 sprintf(h_file, "%s.h", got_include);
276 sprintf(h_file, "%s.h", ename);
278 p = strrchr(filename, '.');
280 p = xmalloc(strlen(filename) + 4);
281 sprintf(p, "%s.et", filename);
285 sprintf(et_file, "%s/%s", got_prefix, filename);
287 yyin = fopen(et_file, "r");
293 /* on NT, yyout is not initialized to stdout */
298 hfile = fopen(h_file, "w");
299 if (hfile == (FILE *) NULL) {
303 fprintf(hfile, warning, h_file);
306 char prolog_h_file[MAXPATHLEN];
310 strcpy(prolog_h_file, got_prefix);
311 strcat(prolog_h_file, "/");
312 strcat(prolog_h_file, got_include);
313 strcat(prolog_h_file, ".p.h");
314 prolog_hfile = fopen(prolog_h_file, "r");
316 fprintf(stderr, "Including %s at beginning of %s file.\n",
317 prolog_h_file, h_file);
318 fprintf(hfile, "/* Including %s at beginning of %s file. */\n\n",
319 prolog_h_file, h_file);
322 fread(buffer, sizeof(char), sizeof(buffer), prolog_hfile);
324 perror(prolog_h_file);
327 written = fwrite(buffer, sizeof(char), count, hfile);
328 if (count != written) {
329 perror(prolog_h_file);
333 fprintf(hfile, "\n/* End of prolog file %s. */\n\n",
339 msfile = fopen(msf_file, "w");
340 if (msfile == (FILE *) NULL) {
344 fprintf(msfile, msf_warning, msf_file);
346 cfile = fopen(c_file, "w");
347 if (cfile == (FILE *) NULL) {
351 fprintf(cfile, warning, c_file);
354 if (language == lang_C)
356 else if (language == lang_KRC)
357 cpp = krc_src_prolog;
361 fputs(*cpp++, cfile);
366 fclose(yyin); /* bye bye input file */
369 fputs(" 0\n};\n\n", cfile);
371 "static const struct error_table et = { text, %ldL, %d };\n\n",
372 (long int)table_number, current);
373 fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
374 fprintf(cfile, "void initialize_%s_error_table(void) {\n",
376 fputs(" afs_add_to_error_table(&etlink);\n", cfile);
381 fprintf(hfile, "extern void initialize_%s_error_table(void);\n",
384 fprintf(hfile, "#define initialize_%s_error_table(void)\n",
388 fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", table_name,
389 (long int)table_number);
390 /* compatibility... */
391 fprintf(hfile, "\n/* for compatibility with older versions... */\n");
392 fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
393 table_name, table_name);
394 fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
396 fprintf(hfile, "\n/* for compatibility with other users... */\n");
397 lcstring(lcname, table_name, sizeof(lcname));
398 fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", lcname,
399 (long int)table_number);
400 fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
403 "#define initialize_%s_error_table initialize_%s_error_table\n",
405 fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
407 fclose(hfile); /* bye bye include file */
414 yyerror(const char *s)
417 fprintf(stderr, "\nLine number %d; last token was '%s'\n", yylineno,