3 char *str_concat(), *ds(), *quote(), *malloc(), *realloc();
4 char *current_token = (char *)NULL;
5 extern char *table_name;
11 %token ERROR_TABLE ERROR_CODE_ENTRY END
12 %token <dynstr> STRING QUOTED_STRING
13 %type <dynstr> ec_name description table_id
19 error_table : ERROR_TABLE table_id error_codes END
20 { table_name = ds($2);
21 current_token = table_name;
31 error_codes : error_codes ec_entry
35 ec_entry : ERROR_CODE_ENTRY ec_name ',' description
39 | ERROR_CODE_ENTRY ec_name '=' STRING ',' description
40 { add_ec_val($2, $4, $6);
52 description : QUOTED_STRING
60 * Copyright 1986, 1987 by the MIT Student Information Processing Board
62 * For copyright info, see mit-sipb-copyright.h.
68 #include <sys/types.h>
71 #include "error_table.h"
72 #include "mit-sipb-copyright.h"
75 static char const rcsid_error_table_y[] =
79 char *malloc(), *realloc();
80 extern FILE *hfile, *cfile;
82 static long gensym_n = 0;
91 gettimeofday(&tv, &tzp);
92 gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
94 symbol = malloc(32 * sizeof(char));
96 sprintf(symbol, "et%ld", gensym_n);
105 rv = malloc(strlen(string)+1);
115 rv = malloc(strlen(string)+3);
124 char **error_codes = (char **)NULL;
126 add_ec(name, description)
127 char const *name, *description;
129 fprintf(cfile, "\t\"%s\",\n", description);
130 if (error_codes == (char **)NULL) {
131 error_codes = (char **)malloc(sizeof(char *));
132 *error_codes = (char *)NULL;
134 error_codes = (char **)realloc((char *)error_codes,
135 (current + 2)*sizeof(char *));
136 error_codes[current++] = ds(name);
137 error_codes[current] = (char *)NULL;
140 add_ec_val(name, val, description)
141 char const *name, *val, *description;
143 const int ncurrent = atoi(val);
144 if (ncurrent < current) {
145 printf("Error code %s (%d) out of order", name,
150 while (ncurrent > current)
151 fputs("\t(char *)NULL,\n", cfile), current++;
153 fprintf(cfile, "\t\"%s\",\n", description);
154 if (error_codes == (char **)NULL) {
155 error_codes = (char **)malloc(sizeof(char *));
156 *error_codes = (char *)NULL;
158 error_codes = (char **)realloc((char *)error_codes,
159 (current + 2)*sizeof(char *));
160 error_codes[current++] = ds(name);
161 error_codes[current] = (char *)NULL;
167 for (i = 0; i < current; i++) {
168 if (error_codes[i] != (char *)NULL)
169 fprintf(hfile, "#define %-40s (%ldL)\n",
170 error_codes[i], table_number + i);
175 * char_to_num -- maps letters and numbers into a small numbering space
182 static const char char_set[] =
183 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
191 where = strchr (char_set, c);
193 diff = where - char_set + 1;
194 assert (diff < (1 << ERRCODE_RANGE));
197 else if (isprint (c))
199 "Illegal character `%c' in error table name\n",
203 "Illegal character %03o in error table name\n",
208 set_table_num(string)
211 if (char_to_num (string[0]) > char_to_num ('z')) {
212 fprintf (stderr, "%s%s%s%s",
213 "First character of error table name must be ",
215 string, "'' rejected\n");
218 if (strlen(string) > 4) {
219 fprintf(stderr, "Table name %s too long, truncated ",
222 fprintf(stderr, "to %s\n", string);
224 while (*string != '\0') {
225 table_number = (table_number << BITS_PER_CHAR)
226 + char_to_num(*string);
229 table_number = table_number << ERRCODE_RANGE;
232 #include "et_lex.lex.c"