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 = NULL;
50 extern char *table_name;
52 char *quote(const char *string);
53 void set_table_1num(char *string);
54 int char_to_1num(char c);
55 void add_ec(const char *name, const char *description);
56 void add_ec_val(const char *name, const char *val, const char *description);
58 void set_table_num(char *string);
59 void set_table_fun(char *astring);
61 extern int yylex (void);
68 %token ERROR_TABLE ERROR_CODE_ENTRY END
69 %token <dynstr> STRING QUOTED_STRING
70 %type <dynstr> ec_name description table_id table_fun header
76 error_table : ERROR_TABLE header error_codes END
77 { table_name = strdup($2);
78 current_token = table_name;
82 header : table_fun table_id
87 set_table_fun(strdup("1"));
100 { current_token = $1;
105 error_codes : error_codes ec_entry
109 ec_entry : ERROR_CODE_ENTRY ec_name ',' description
113 | ERROR_CODE_ENTRY ec_name '=' STRING ',' description
114 { add_ec_val($2, $4, $6);
123 current_token = $$; }
126 description : QUOTED_STRING
128 current_token = $$; }
134 * Copyright 2000, International Business Machines Corporation and others.
135 * All Rights Reserved.
137 * This software has been released under the terms of the IBM Public
138 * License. For details, see the LICENSE file in the top-level source
139 * directory or online at http://www.openafs.org/dl/license10.html
142 extern FILE *hfile, *cfile, *msfile;
145 static afs_int32 gensym_n = 0;
147 char *gensym(const char *x)
152 gettimeofday(&tv, (void *)0);
153 gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
155 symbol = malloc(32 * sizeof(char));
157 sprintf(symbol, "et%ld", (long int) gensym_n);
162 quote(const char *string)
165 rv = malloc(strlen(string)+3);
172 afs_int32 table_number = 0;
174 char **error_codes = NULL;
176 void add_ec(const char *name, const char *description)
181 fprintf(msfile, "%d\t%s\n", current, description);
183 fprintf(msfile, "%d %s\n", current, description);
186 fprintf(cfile, "\t\"%s\",\n", description);
188 if (error_codes == NULL) {
189 error_codes = malloc(sizeof(char *));
192 error_codes = (char **)realloc((char *)error_codes,
193 (current + 2)*sizeof(char *));
194 error_codes[current++] = strdup(name);
195 error_codes[current] = NULL;
198 void add_ec_val(const char *name, const char *val, const char *description)
200 const int ncurrent = atoi(val);
201 if (ncurrent < current) {
202 printf("Error code %s (%d) out of order", name,
207 while (ncurrent > current) {
209 fputs("\tNULL,\n", cfile);
215 fprintf(msfile, "%d\t%s\n", current, description);
217 fprintf(msfile, "%d %s\n", current, description);
220 fprintf(cfile, "\t\"%s\",\n", description);
222 if (error_codes == NULL) {
223 error_codes = malloc(sizeof(char *));
226 error_codes = (char **)realloc((char *)error_codes,
227 (current + 2)*sizeof(char *));
228 error_codes[current++] = strdup(name);
229 error_codes[current] = NULL;
235 for (i = 0; i < current; i++) {
236 if (error_codes[i] != NULL)
237 fprintf(hfile, "#define %-40s (%ldL)\n",
238 error_codes[i], (long int) table_number + i);
243 * char_to_num -- maps letters and numbers into a small numbering space
250 static const char char_set[] =
251 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
253 int char_to_num(char c)
258 where = strchr (char_set, c);
260 diff = where - char_set + 1;
261 assert (diff < (1 << ERRCODE_RANGE));
264 else if (isprint (c))
266 "Illegal character `%c' in error table name\n",
270 "Illegal character %03o in error table name\n",
275 void set_table_num(char *string)
278 set_table_1num(string);
281 if (strlen(string) > 4) {
282 fprintf(stderr, "Table name %s too long, truncated ",
285 fprintf(stderr, "to %s\n", string);
287 if (char_to_num (string[0]) > char_to_num ('z')) {
288 fprintf (stderr, "%s%s%s%s",
289 "First character of error table name must be ",
291 string, "'' rejected\n");
294 while (*string != '\0') {
295 table_number = (table_number << BITS_PER_CHAR)
296 + char_to_num(*string);
299 table_number = table_number << ERRCODE_RANGE;
302 void set_table_fun(char *astring)
307 for(tp=astring; (tc = *tp) != 0; tp++) {
309 fprintf(stderr, "Table function '%s' must be a decimal integer.\n",
315 table_number += (atoi(astring)) << 28;
318 /* for compatibility with old comerr's, we truncate package name to 4
319 * characters, but only store first 3 in the error code. Note that this
320 * function, as a side effect, truncates the table name down to 4 chars.
322 void set_table_1num(char *string)
327 if ((temp = strlen(string)) > 4) {
328 fprintf(stderr, "Table name %s too long, truncated ",
331 fprintf(stderr, "to %s\n", string);
334 fprintf(stderr, "Table name %s too long, only 3 characters fit in error code.\n",
337 if (char_to_1num (string[0]) > char_to_1num ('z')) {
338 fprintf (stderr, "%s%s%s%s",
339 "First character of error table name must be ",
341 string, "'' rejected\n");
345 for(ctr=0; ctr < 3; ctr++) { /* copy at most 3 chars to integer */
346 if (*string == '\0') break; /* and watch for early end */
347 temp = (temp * 050) /* "radix fifty" is base 050 = 40 */
348 + char_to_1num(*string);
351 table_number += temp << 12;
355 * char_to_num -- maps letters and numbers into very small space
357 * mixed case -> 10-35
359 * others are reserved
362 static const char char_1set[] =
363 "abcdefghijklmnopqrstuvwxyz_0123456789";
365 int char_to_1num(char c)
370 if (isupper(c)) c = tolower(c);
372 where = strchr (char_1set, c);
374 /* start at 1 so we can decode */
375 diff = where - char_1set;
376 assert (diff < 050); /* it is radix 50, after all */
379 else if (isprint (c))
381 "Illegal character `%c' in error table name\n",
385 "Illegal character %03o in error table name\n",
391 #include "et_lex.lex_nt.c"
393 #include "et_lex.lex.c"