5 * If __STDC__ is defined, function prototypes in the SunOS 5.5.1 lex
6 * and yacc templates are visible. We turn this on explicitly on
7 * NT because the prototypes help supress certain warning from the
8 * Microsoft C compiler.
24 char *current_token = (char *)NULL;
25 extern char *table_name;
27 char *ds(const char *string);
28 char *quote(const char *string);
29 void set_table_1num(char *string);
30 int char_to_1num(char c);
31 void add_ec(const char *name, const char *description);
32 void add_ec_val(const char *name, const char *val, const char *description);
34 void set_table_num(char *string);
35 void set_table_fun(char *astring);
42 %token ERROR_TABLE ERROR_CODE_ENTRY END
43 %token <dynstr> STRING QUOTED_STRING
44 %type <dynstr> ec_name description table_id table_fun header
50 error_table : ERROR_TABLE header error_codes END
51 { table_name = ds($2);
52 current_token = table_name;
56 header : table_fun table_id
61 set_table_fun(ds("1"));
79 error_codes : error_codes ec_entry
83 ec_entry : ERROR_CODE_ENTRY ec_name ',' description
87 | ERROR_CODE_ENTRY ec_name '=' STRING ',' description
88 { add_ec_val($2, $4, $6);
100 description : QUOTED_STRING
102 current_token = $$; }
108 * Copyright 1986, 1987 by the MIT Student Information Processing Board
110 * For copyright info, see mit-sipb-cr.h.
115 #include <afs/param.h>
120 #include <sys/types.h>
121 #include <afs/afsutil.h>
123 #include <sys/time.h>
125 #include <sys/timeb.h>
126 #include "error_table.h"
127 #include "mit-sipb-cr.h"
130 /* Copyright (C) 1998 Transarc Corporation. All rights reserved.
134 extern FILE *hfile, *cfile, *msfile;
137 static afs_int32 gensym_n = 0;
139 char *gensym(const char *x)
144 gettimeofday(&tv, (void *)0);
145 gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
147 symbol = (char *)malloc(32 * sizeof(char));
149 sprintf(symbol, "et%ld", (long int) gensym_n);
154 ds(const char *string)
157 rv = (char *)malloc(strlen(string)+1);
163 quote(const char *string)
166 rv = (char *)malloc(strlen(string)+3);
173 afs_int32 table_number = 0;
175 char **error_codes = (char **)NULL;
177 void add_ec(const char *name, const char *description)
182 fprintf(msfile, "%d\t%s\n", current, description);
184 fprintf(msfile, "%d %s\n", current, description);
187 fprintf(cfile, "\t\"%s\",\n", description);
189 if (error_codes == (char **)NULL) {
190 error_codes = (char **)malloc(sizeof(char *));
191 *error_codes = (char *)NULL;
193 error_codes = (char **)realloc((char *)error_codes,
194 (current + 2)*sizeof(char *));
195 error_codes[current++] = ds(name);
196 error_codes[current] = (char *)NULL;
199 void add_ec_val(const char *name, const char *val, const char *description)
201 const int ncurrent = atoi(val);
202 if (ncurrent < current) {
203 printf("Error code %s (%d) out of order", name,
208 while (ncurrent > current) {
210 fputs("\t(char *)NULL,\n", cfile);
216 fprintf(msfile, "%d\t%s\n", current, description);
218 fprintf(msfile, "%d %s\n", current, description);
221 fprintf(cfile, "\t\"%s\",\n", description);
223 if (error_codes == (char **)NULL) {
224 error_codes = (char **)malloc(sizeof(char *));
225 *error_codes = (char *)NULL;
227 error_codes = (char **)realloc((char *)error_codes,
228 (current + 2)*sizeof(char *));
229 error_codes[current++] = ds(name);
230 error_codes[current] = (char *)NULL;
236 for (i = 0; i < current; i++) {
237 if (error_codes[i] != (char *)NULL)
238 fprintf(hfile, "#define %-40s (%ldL)\n",
239 error_codes[i], (long int) table_number + i);
244 * char_to_num -- maps letters and numbers into a small numbering space
251 static const char char_set[] =
252 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
254 int char_to_num(char c)
259 where = strchr (char_set, c);
261 diff = where - char_set + 1;
262 assert (diff < (1 << ERRCODE_RANGE));
265 else if (isprint (c))
267 "Illegal character `%c' in error table name\n",
271 "Illegal character %03o in error table name\n",
276 void set_table_num(char *string)
277 { char ucname[6]; /* I think 5 is enough but et_name.c used 6... */
278 extern char *ucstring();
281 set_table_1num(string);
284 if (strlen(string) > 4) {
285 fprintf(stderr, "Table name %s too long, truncated ",
288 fprintf(stderr, "to %s\n", string);
290 string = ucstring (ucname, string, sizeof(ucname));
291 if (char_to_num (string[0]) > char_to_num ('z')) {
292 fprintf (stderr, "%s%s%s%s",
293 "First character of error table name must be ",
295 string, "'' rejected\n");
298 while (*string != '\0') {
299 table_number = (table_number << BITS_PER_CHAR)
300 + char_to_num(*string);
303 table_number = table_number << ERRCODE_RANGE;
306 void set_table_fun(char *astring)
311 for(tp=astring; (tc = *tp) != 0; tp++) {
313 fprintf(stderr, "Table function '%s' must be a decimal integer.\n",
319 table_number += (atoi(astring)) << 28;
322 /* for compatibility with old comerr's, we truncate package name to 4
323 * characters, but only store first 3 in the error code. Note that this
324 * function, as a side effect, truncates the table name down to 4 chars.
326 void set_table_1num(char *string)
331 if ((temp = strlen(string)) > 4) {
332 fprintf(stderr, "Table name %s too long, truncated ",
335 fprintf(stderr, "to %s\n", string);
338 fprintf(stderr, "Table name %s too long, only 3 characters fit in error code.\n",
341 if (char_to_1num (string[0]) > char_to_1num ('z')) {
342 fprintf (stderr, "%s%s%s%s",
343 "First character of error table name must be ",
345 string, "'' rejected\n");
349 for(ctr=0; ctr < 3; ctr++) { /* copy at most 3 chars to integer */
350 if (*string == '\0') break; /* and watch for early end */
351 temp = (temp * 050) /* "radix fifty" is base 050 = 40 */
352 + char_to_1num(*string);
355 table_number += temp << 12;
359 * char_to_num -- maps letters and numbers into very small space
361 * mixed case -> 10-35
363 * others are reserved
366 static const char char_1set[] =
367 "abcdefghijklmnopqrstuvwxyz_0123456789";
369 int char_to_1num(char c)
374 if (isupper(c)) c = tolower(c);
376 where = strchr (char_1set, c);
378 /* start at 1 so we can decode */
379 diff = where - char_1set;
380 assert (diff < 050); /* it is radix 50, after all */
383 else if (isprint (c))
385 "Illegal character `%c' in error table name\n",
389 "Illegal character %03o in error table name\n",
395 #include "et_lex.lex_nt.c"
397 #include "et_lex.lex.c"