7 * Copyright 1986, 1987 by the MIT Student Information Processing Board
9 * For copyright info, see mit-sipb-cr.h.
18 #include <sys/types.h>
19 #include <afs/afsutil.h>
23 #include <sys/timeb.h>
24 #include "error_table.h"
25 #include "mit-sipb-cr.h"
28 * If __STDC__ is defined, function prototypes in the SunOS 5.5.1 lex
29 * and yacc templates are visible. We turn this on explicitly on
30 * NT because the prototypes help supress certain warning from the
31 * Microsoft C compiler.
47 int char_to_num(char c);
48 char *gensym(const char *x);
49 char *current_token = (char *)NULL;
50 extern char *table_name;
52 char *ds(const char *string);
53 char *quote(const char *string);
54 void set_table_1num(char *string);
55 int char_to_1num(char c);
56 void add_ec(const char *name, const char *description);
57 void add_ec_val(const char *name, const char *val, const char *description);
59 void set_table_num(char *string);
60 void set_table_fun(char *astring);
62 extern int yylex (void);
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 = $$; }
135 * Copyright 2000, International Business Machines Corporation and others.
136 * All Rights Reserved.
138 * This software has been released under the terms of the IBM Public
139 * License. For details, see the LICENSE file in the top-level source
140 * directory or online at http://www.openafs.org/dl/license10.html
143 extern FILE *hfile, *cfile, *msfile;
146 static afs_int32 gensym_n = 0;
148 char *gensym(const char *x)
153 gettimeofday(&tv, (void *)0);
154 gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
156 symbol = (char *)malloc(32 * sizeof(char));
158 sprintf(symbol, "et%ld", (long int) gensym_n);
163 ds(const char *string)
166 rv = (char *)malloc(strlen(string)+1);
172 quote(const char *string)
175 rv = (char *)malloc(strlen(string)+3);
182 afs_int32 table_number = 0;
184 char **error_codes = (char **)NULL;
186 void add_ec(const char *name, const char *description)
191 fprintf(msfile, "%d\t%s\n", current, description);
193 fprintf(msfile, "%d %s\n", current, description);
196 fprintf(cfile, "\t\"%s\",\n", description);
198 if (error_codes == (char **)NULL) {
199 error_codes = (char **)malloc(sizeof(char *));
200 *error_codes = (char *)NULL;
202 error_codes = (char **)realloc((char *)error_codes,
203 (current + 2)*sizeof(char *));
204 error_codes[current++] = ds(name);
205 error_codes[current] = (char *)NULL;
208 void add_ec_val(const char *name, const char *val, const char *description)
210 const int ncurrent = atoi(val);
211 if (ncurrent < current) {
212 printf("Error code %s (%d) out of order", name,
217 while (ncurrent > current) {
219 fputs("\t(char *)NULL,\n", cfile);
225 fprintf(msfile, "%d\t%s\n", current, description);
227 fprintf(msfile, "%d %s\n", current, description);
230 fprintf(cfile, "\t\"%s\",\n", description);
232 if (error_codes == (char **)NULL) {
233 error_codes = (char **)malloc(sizeof(char *));
234 *error_codes = (char *)NULL;
236 error_codes = (char **)realloc((char *)error_codes,
237 (current + 2)*sizeof(char *));
238 error_codes[current++] = ds(name);
239 error_codes[current] = (char *)NULL;
245 for (i = 0; i < current; i++) {
246 if (error_codes[i] != (char *)NULL)
247 fprintf(hfile, "#define %-40s (%ldL)\n",
248 error_codes[i], (long int) table_number + i);
253 * char_to_num -- maps letters and numbers into a small numbering space
260 static const char char_set[] =
261 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
263 int char_to_num(char c)
268 where = strchr (char_set, c);
270 diff = where - char_set + 1;
271 assert (diff < (1 << ERRCODE_RANGE));
274 else if (isprint (c))
276 "Illegal character `%c' in error table name\n",
280 "Illegal character %03o in error table name\n",
285 void set_table_num(char *string)
288 set_table_1num(string);
291 if (strlen(string) > 4) {
292 fprintf(stderr, "Table name %s too long, truncated ",
295 fprintf(stderr, "to %s\n", string);
297 if (char_to_num (string[0]) > char_to_num ('z')) {
298 fprintf (stderr, "%s%s%s%s",
299 "First character of error table name must be ",
301 string, "'' rejected\n");
304 while (*string != '\0') {
305 table_number = (table_number << BITS_PER_CHAR)
306 + char_to_num(*string);
309 table_number = table_number << ERRCODE_RANGE;
312 void set_table_fun(char *astring)
317 for(tp=astring; (tc = *tp) != 0; tp++) {
319 fprintf(stderr, "Table function '%s' must be a decimal integer.\n",
325 table_number += (atoi(astring)) << 28;
328 /* for compatibility with old comerr's, we truncate package name to 4
329 * characters, but only store first 3 in the error code. Note that this
330 * function, as a side effect, truncates the table name down to 4 chars.
332 void set_table_1num(char *string)
337 if ((temp = strlen(string)) > 4) {
338 fprintf(stderr, "Table name %s too long, truncated ",
341 fprintf(stderr, "to %s\n", string);
344 fprintf(stderr, "Table name %s too long, only 3 characters fit in error code.\n",
347 if (char_to_1num (string[0]) > char_to_1num ('z')) {
348 fprintf (stderr, "%s%s%s%s",
349 "First character of error table name must be ",
351 string, "'' rejected\n");
355 for(ctr=0; ctr < 3; ctr++) { /* copy at most 3 chars to integer */
356 if (*string == '\0') break; /* and watch for early end */
357 temp = (temp * 050) /* "radix fifty" is base 050 = 40 */
358 + char_to_1num(*string);
361 table_number += temp << 12;
365 * char_to_num -- maps letters and numbers into very small space
367 * mixed case -> 10-35
369 * others are reserved
372 static const char char_1set[] =
373 "abcdefghijklmnopqrstuvwxyz_0123456789";
375 int char_to_1num(char c)
380 if (isupper(c)) c = tolower(c);
382 where = strchr (char_1set, c);
384 /* start at 1 so we can decode */
385 diff = where - char_1set;
386 assert (diff < 050); /* it is radix 50, after all */
389 else if (isprint (c))
391 "Illegal character `%c' in error table name\n",
395 "Illegal character %03o in error table name\n",
401 #include "et_lex.lex_nt.c"
403 #include "et_lex.lex.c"