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>
16 #include <afs/afsutil.h>
17 #include "mit-sipb-cr.h"
22 static const char copyright[] =
23 "Copyright 1987,1988 by MIT Student Information Processing Board";
26 extern char *current_token;
27 extern int table_number, current;
29 char *table_name = (char *)NULL;
30 FILE *hfile, *cfile, *msfile;
44 xmalloc(unsigned int size)
46 char *p = (char *)malloc(size);
55 check_arg(char const *const *str_list, char const *arg)
58 if (!strcmp(arg, *str_list++))
63 static const char *const debug_args[] = {
69 static const char *const lang_args[] = {
75 static const char *const language_names[] = {
82 static const char *const c_src_prolog[] = {
83 "#include <afsconfig.h>\n",
84 "#include <afs/param.h>\n",
85 "#include <afs/error_table.h>\n",
86 "static const char * const text[] = {\n",
90 static const char *const krc_src_prolog[] = {
92 "#define NOARGS void\n",
97 "#include <afs/param.h>\n",
98 "#include <afs/error_table.h>\n",
99 "static const char * const text[] = {\n",
103 static const char warning[] =
104 "/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n";
106 static const char msf_warning[] =
107 "$ \n$ %s:\n$ This file is automatically generated; please do not edit it.\n$ \n$set 1\n";
110 char c_file[MAXPATHLEN]; /* output file */
111 char h_file[MAXPATHLEN]; /* output */
112 char msf_file[MAXPATHLEN];
113 char et_file[MAXPATHLEN]; /* full path to input file */
119 "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-p prefix] [-v version]\n",
125 dup_err(char const *type, char const *one, char const *two)
127 fprintf(stderr, "%s: multiple %s specified: `%s' and `%s'\n", whoami,
132 #include "AFS_component_version_number.c"
135 main(int argc, char **argv)
138 char const *const *cpp;
139 int got_language = 0;
140 char *got_include = 0;
141 char *got_prefix = ".";
146 * The following signal action for AIX is necessary so that in case of a
147 * crash (i.e. core is generated) we can include the user's data section
148 * in the core dump. Unfortunately, by default, only a partial core is
149 * generated which, in many cases, isn't too useful.
151 struct sigaction nsa;
153 sigemptyset(&nsa.sa_mask);
154 nsa.sa_handler = SIG_DFL;
155 nsa.sa_flags = SA_FULLDUMP;
156 sigaction(SIGSEGV, &nsa, NULL);
158 /* argument parsing */
162 p = strrchr(whoami, '/');
165 while (argv++, --argc) {
169 dup_err("filenames", filename, arg);
173 if (check_arg(debug_args, arg))
175 else if (check_arg(lang_args, arg)) {
177 arg = *++argv, argc--;
181 dup_err("languanges", language_names[(int)language], arg);
183 #define check_lang(x,v) if (!strcasecmp(arg,x)) language = v
184 check_lang("c", lang_C);
185 check_lang("ansi_c", lang_C);
186 check_lang("ansi-c", lang_C);
187 check_lang("krc", lang_KRC);
188 check_lang("kr_c", lang_KRC);
189 check_lang("kr-c", lang_KRC);
190 check_lang("k&r-c", lang_KRC);
191 check_lang("k&r_c", lang_KRC);
192 check_lang("c++", lang_CPP);
193 check_lang("cplusplus", lang_CPP);
194 check_lang("c-plus-plus", lang_CPP);
198 fprintf(stderr, "%s: unknown language name `%s'\n",
200 fprintf(stderr, "\tpick one of: C K&R-C\n");
203 } else if (strcmp(arg, "h") == 0) {
204 arg = *++argv, argc--;
208 } else if (strcmp(arg, "p") == 0) {
209 arg = *++argv, argc--;
213 } else if (strcmp(arg, "v") == 0) {
214 arg = *++argv, argc--;
216 if (version != 1 && version != 2) {
217 fprintf(stderr, "%s: unknown control argument -`%s'\n",
225 fprintf(stderr, "%s: unknown control argument -`%s'\n",
235 else if (language == lang_CPP) {
236 fprintf(stderr, "%s: Sorry, C++ support is not yet finished.\n",
242 p = strrchr(filename, '/');
243 if (p == (char *)NULL)
247 ename = xmalloc(strlen(p) + 5);
250 /* Now, flush .et suffix if it exists. */
251 p = strrchr(ename, '.');
253 if (strcmp(p, ".et") == 0)
258 sprintf(msf_file, "%s.msf", ename);
260 sprintf(c_file, "%s.c", ename);
263 sprintf(h_file, "%s.h", got_include);
265 sprintf(h_file, "%s.h", ename);
267 p = strrchr(filename, '.');
269 p = xmalloc(strlen(filename) + 4);
270 sprintf(p, "%s.et", filename);
274 sprintf(et_file, "%s/%s", got_prefix, filename);
276 yyin = fopen(et_file, "r");
282 /* on NT, yyout is not initialized to stdout */
287 hfile = fopen(h_file, "w");
288 if (hfile == (FILE *) NULL) {
292 fprintf(hfile, warning, h_file);
295 char prolog_h_file[MAXPATHLEN];
299 strcpy(prolog_h_file, got_prefix);
300 strcat(prolog_h_file, "/");
301 strcat(prolog_h_file, got_include);
302 strcat(prolog_h_file, ".p.h");
303 prolog_hfile = fopen(prolog_h_file, "r");
305 fprintf(stderr, "Including %s at beginning of %s file.\n",
306 prolog_h_file, h_file);
307 fprintf(hfile, "/* Including %s at beginning of %s file. */\n\n",
308 prolog_h_file, h_file);
311 fread(buffer, sizeof(char), sizeof(buffer), prolog_hfile);
313 perror(prolog_h_file);
316 written = fwrite(buffer, sizeof(char), count, hfile);
317 if (count != written) {
318 perror(prolog_h_file);
322 fprintf(hfile, "\n/* End of prolog file %s. */\n\n",
328 msfile = fopen(msf_file, "w");
329 if (msfile == (FILE *) NULL) {
333 fprintf(msfile, msf_warning, msf_file);
335 cfile = fopen(c_file, "w");
336 if (cfile == (FILE *) NULL) {
340 fprintf(cfile, warning, c_file);
343 if (language == lang_C)
345 else if (language == lang_KRC)
346 cpp = krc_src_prolog;
350 fputs(*cpp++, cfile);
355 fclose(yyin); /* bye bye input file */
358 fputs(" 0\n};\n\n", cfile);
360 "static const struct error_table et = { text, %ldL, %d };\n\n",
361 (long int)table_number, current);
362 fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
363 fprintf(cfile, "void initialize_%s_error_table(void) {\n",
365 fputs(" afs_add_to_error_table(&etlink);\n", cfile);
370 fprintf(hfile, "extern void initialize_%s_error_table(void);\n",
373 fprintf(hfile, "#define initialize_%s_error_table(void)\n",
377 fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", table_name,
378 (long int)table_number);
379 /* compatibility... */
380 fprintf(hfile, "\n/* for compatibility with older versions... */\n");
381 fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
382 table_name, table_name);
383 fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
385 fprintf(hfile, "\n/* for compatibility with other users... */\n");
386 lcstring(lcname, table_name, sizeof(lcname));
387 fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", lcname,
388 (long int)table_number);
389 fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
392 "#define initialize_%s_error_table initialize_%s_error_table\n",
394 fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
396 fclose(hfile); /* bye bye include file */
403 yyerror(const char *s)
406 fprintf(stderr, "\nLine number %d; last token was '%s'\n", yylineno,