8 * Copyright 1986, 1987 by the MIT Student Information Processing Board
10 * For copyright info, see mit-sipb-cr.h.
19 #include <sys/types.h>
20 #include <afs/afsutil.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
;
237 for
(i
= 0; i
< current
; i
++) {
238 if
(error_codes
[i
] != NULL
)
239 fprintf
(hfile
, "#define %-40s (%ldL)\n",
240 error_codes
[i
], (long int) table_number
+ i
);
245 * char_to_num -- maps letters and numbers into a small numbering space
252 static const char char_set
[] =
253 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
255 int char_to_num
(char c
)
260 where
= strchr
(char_set
, c
);
262 diff
= where
- char_set
+ 1;
263 assert
(diff
< (1 << ERRCODE_RANGE
));
266 else if
(isprint
(c
))
268 "Illegal character `%c' in error table name\n",
272 "Illegal character %03o in error table name\n",
277 void set_table_num
(char *string)
280 set_table_1num
(string);
283 if
(strlen
(string) > 4) {
284 fprintf
(stderr
, "Table name %s too long, truncated ",
287 fprintf
(stderr
, "to %s\n", string);
289 if
(char_to_num
(string[0]) > char_to_num
('z')) {
290 fprintf
(stderr
, "%s%s%s%s",
291 "First character of error table name must be ",
293 string, "'' rejected\n");
296 while
(*string != '\0') {
297 table_number
= (table_number
<< BITS_PER_CHAR
)
298 + char_to_num
(*string);
301 table_number
= table_number
<< ERRCODE_RANGE
;
304 void set_table_fun
(char *astring
)
309 for
(tp
=astring
; (tc
= *tp
) != 0; tp
++) {
311 fprintf
(stderr
, "Table function '%s' must be a decimal integer.\n",
317 table_number
+= (atoi
(astring
)) << 28;
320 /* for compatibility with old comerr's, we truncate package name to 4
321 * characters, but only store first 3 in the error code. Note that this
322 * function, as a side effect, truncates the table name down to 4 chars.
324 void set_table_1num
(char *string)
329 if
((temp
= strlen
(string)) > 4) {
330 fprintf
(stderr
, "Table name %s too long, truncated ",
333 fprintf
(stderr
, "to %s\n", string);
336 fprintf
(stderr
, "Table name %s too long, only 3 characters fit in error code.\n",
339 if
(char_to_1num
(string[0]) > char_to_1num
('z')) {
340 fprintf
(stderr
, "%s%s%s%s",
341 "First character of error table name must be ",
343 string, "'' rejected\n");
347 for
(ctr
=0; ctr
< 3; ctr
++) { /* copy at most 3 chars to integer */
348 if
(*string == '\0') break
; /* and watch for early end */
349 temp
= (temp
* 050) /* "radix fifty" is base 050 = 40 */
350 + char_to_1num
(*string);
353 table_number
+= temp
<< 12;
357 * char_to_num -- maps letters and numbers into very small space
359 * mixed case -> 10-35
361 * others are reserved
364 static const char char_1set
[] =
365 "abcdefghijklmnopqrstuvwxyz_0123456789";
367 int char_to_1num
(char c
)
372 if
(isupper
(c
)) c
= tolower
(c
);
374 where
= strchr
(char_1set
, c
);
376 /* start at 1 so we can decode */
377 diff
= where
- char_1set
;
378 assert
(diff
< 050); /* it is radix 50, after all */
381 else if
(isprint
(c
))
383 "Illegal character `%c' in error table name\n",
387 "Illegal character %03o in error table name\n",
393 #include "et_lex.lex_nt.c"
395 #include "et_lex.lex.c"