9 * Copyright 1986, 1987 by the MIT Student Information Processing Board
11 * For copyright info, see mit-sipb-cr.h.
20 #include <sys/types.h>
21 #include <afs/afsutil.h>
25 #include <sys/timeb.h>
26 #include "error_table.h"
27 #include "mit-sipb-cr.h"
30 * If __STDC__ is defined, function prototypes in the SunOS 5.5.1 lex
31 * and yacc templates are visible. We turn this on explicitly on
32 * NT because the prototypes help supress certain warning from the
33 * Microsoft C compiler.
49 int char_to_num(char c);
50 char *gensym(const char *x);
51 char *current_token = (char *)NULL;
52 extern char *table_name;
54 char *ds(const char *string);
55 char *quote(const char *string);
56 void set_table_1num(char *string);
57 int char_to_1num(char c);
58 void add_ec(const char *name, const char *description);
59 void add_ec_val(const char *name, const char *val, const char *description);
61 void set_table_num(char *string);
62 void set_table_fun(char *astring);
69 %token ERROR_TABLE ERROR_CODE_ENTRY END
70 %token <dynstr> STRING QUOTED_STRING
71 %type <dynstr> ec_name description table_id table_fun header
77 error_table : ERROR_TABLE header error_codes END
78 { table_name = ds($2);
79 current_token = table_name;
83 header : table_fun table_id
88 set_table_fun(ds("1"));
101 { current_token = $1;
106 error_codes : error_codes ec_entry
110 ec_entry : ERROR_CODE_ENTRY ec_name ',' description
114 | ERROR_CODE_ENTRY ec_name '=' STRING ',' description
115 { add_ec_val($2, $4, $6);
124 current_token = $$; }
127 description : QUOTED_STRING
129 current_token = $$; }
134 /* Copyright (C) 1998 Transarc Corporation. All rights reserved.
138 extern FILE *hfile, *cfile, *msfile;
141 static afs_int32 gensym_n = 0;
143 char *gensym(const char *x)
148 gettimeofday(&tv, (void *)0);
149 gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
151 symbol = (char *)malloc(32 * sizeof(char));
153 sprintf(symbol, "et%ld", (long int) gensym_n);
158 ds(const char *string)
161 rv = (char *)malloc(strlen(string)+1);
167 quote(const char *string)
170 rv = (char *)malloc(strlen(string)+3);
177 afs_int32 table_number = 0;
179 char **error_codes = (char **)NULL;
181 void add_ec(const char *name, const char *description)
186 fprintf(msfile, "%d\t%s\n", current, description);
188 fprintf(msfile, "%d %s\n", current, description);
191 fprintf(cfile, "\t\"%s\",\n", description);
193 if (error_codes == (char **)NULL) {
194 error_codes = (char **)malloc(sizeof(char *));
195 *error_codes = (char *)NULL;
197 error_codes = (char **)realloc((char *)error_codes,
198 (current + 2)*sizeof(char *));
199 error_codes[current++] = ds(name);
200 error_codes[current] = (char *)NULL;
203 void add_ec_val(const char *name, const char *val, const char *description)
205 const int ncurrent = atoi(val);
206 if (ncurrent < current) {
207 printf("Error code %s (%d) out of order", name,
212 while (ncurrent > current) {
214 fputs("\t(char *)NULL,\n", cfile);
220 fprintf(msfile, "%d\t%s\n", current, description);
222 fprintf(msfile, "%d %s\n", current, description);
225 fprintf(cfile, "\t\"%s\",\n", description);
227 if (error_codes == (char **)NULL) {
228 error_codes = (char **)malloc(sizeof(char *));
229 *error_codes = (char *)NULL;
231 error_codes = (char **)realloc((char *)error_codes,
232 (current + 2)*sizeof(char *));
233 error_codes[current++] = ds(name);
234 error_codes[current] = (char *)NULL;
240 for (i = 0; i < current; i++) {
241 if (error_codes[i] != (char *)NULL)
242 fprintf(hfile, "#define %-40s (%ldL)\n",
243 error_codes[i], (long int) table_number + i);
248 * char_to_num -- maps letters and numbers into a small numbering space
255 static const char char_set[] =
256 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
258 int char_to_num(char c)
263 where = strchr (char_set, c);
265 diff = where - char_set + 1;
266 assert (diff < (1 << ERRCODE_RANGE));
269 else if (isprint (c))
271 "Illegal character `%c' in error table name\n",
275 "Illegal character %03o in error table name\n",
280 void set_table_num(char *string)
283 set_table_1num(string);
286 if (strlen(string) > 4) {
287 fprintf(stderr, "Table name %s too long, truncated ",
290 fprintf(stderr, "to %s\n", string);
292 if (char_to_num (string[0]) > char_to_num ('z')) {
293 fprintf (stderr, "%s%s%s%s",
294 "First character of error table name must be ",
296 string, "'' rejected\n");
299 while (*string != '\0') {
300 table_number = (table_number << BITS_PER_CHAR)
301 + char_to_num(*string);
304 table_number = table_number << ERRCODE_RANGE;
307 void set_table_fun(char *astring)
312 for(tp=astring; (tc = *tp) != 0; tp++) {
314 fprintf(stderr, "Table function '%s' must be a decimal integer.\n",
320 table_number += (atoi(astring)) << 28;
323 /* for compatibility with old comerr's, we truncate package name to 4
324 * characters, but only store first 3 in the error code. Note that this
325 * function, as a side effect, truncates the table name down to 4 chars.
327 void set_table_1num(char *string)
332 if ((temp = strlen(string)) > 4) {
333 fprintf(stderr, "Table name %s too long, truncated ",
336 fprintf(stderr, "to %s\n", string);
339 fprintf(stderr, "Table name %s too long, only 3 characters fit in error code.\n",
342 if (char_to_1num (string[0]) > char_to_1num ('z')) {
343 fprintf (stderr, "%s%s%s%s",
344 "First character of error table name must be ",
346 string, "'' rejected\n");
350 for(ctr=0; ctr < 3; ctr++) { /* copy at most 3 chars to integer */
351 if (*string == '\0') break; /* and watch for early end */
352 temp = (temp * 050) /* "radix fifty" is base 050 = 40 */
353 + char_to_1num(*string);
356 table_number += temp << 12;
360 * char_to_num -- maps letters and numbers into very small space
362 * mixed case -> 10-35
364 * others are reserved
367 static const char char_1set[] =
368 "abcdefghijklmnopqrstuvwxyz_0123456789";
370 int char_to_1num(char c)
375 if (isupper(c)) c = tolower(c);
377 where = strchr (char_1set, c);
379 /* start at 1 so we can decode */
380 diff = where - char_1set;
381 assert (diff < 050); /* it is radix 50, after all */
384 else if (isprint (c))
386 "Illegal character `%c' in error table name\n",
390 "Illegal character %03o in error table name\n",
396 #include "et_lex.lex_nt.c"
398 #include "et_lex.lex.c"