gen.c revision 1.12 1 1.11 christos /* $NetBSD: gen.c,v 1.12 2024/02/21 22:52:06 christos Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 1.1 christos *
6 1.10 christos * SPDX-License-Identifier: MPL-2.0
7 1.10 christos *
8 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public
9 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this
10 1.7 christos * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 1.1 christos *
12 1.1 christos * See the COPYRIGHT file distributed with this work for additional
13 1.1 christos * information regarding copyright ownership.
14 1.1 christos */
15 1.1 christos
16 1.1 christos /*! \file */
17 1.1 christos
18 1.1 christos #include <ctype.h>
19 1.12 christos #include <dirent.h>
20 1.6 christos #include <errno.h>
21 1.4 christos #include <limits.h>
22 1.12 christos #include <stdbool.h>
23 1.4 christos #include <stdint.h>
24 1.1 christos #include <stdio.h>
25 1.1 christos #include <stdlib.h>
26 1.1 christos #include <string.h>
27 1.6 christos #include <sys/types.h>
28 1.1 christos #include <time.h>
29 1.12 christos #include <unistd.h>
30 1.6 christos
31 1.6 christos #ifndef PATH_MAX
32 1.6 christos #define PATH_MAX 1024
33 1.6 christos #endif /* ifndef PATH_MAX */
34 1.1 christos
35 1.5 christos #ifndef ULLONG_MAX
36 1.5 christos #define ULLONG_MAX (~0ULL)
37 1.6 christos #endif /* ifndef ULLONG_MAX */
38 1.5 christos
39 1.6 christos #define INSIST(cond) \
40 1.6 christos if (!(cond)) { \
41 1.6 christos fprintf(stderr, "%s:%d: INSIST(%s)\n", __FILE__, __LINE__, \
42 1.6 christos #cond); \
43 1.6 christos abort(); \
44 1.1 christos }
45 1.1 christos
46 1.6 christos #define FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
47 1.1 christos #define FROMTEXTCLASS "rdclass"
48 1.6 christos #define FROMTEXTTYPE "type"
49 1.6 christos #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
50 1.1 christos
51 1.6 christos #define TOTEXTARGS "rdata, tctx, target"
52 1.1 christos #define TOTEXTCLASS "rdata->rdclass"
53 1.6 christos #define TOTEXTTYPE "rdata->type"
54 1.6 christos #define TOTEXTDEF "use_default = true"
55 1.1 christos
56 1.6 christos #define FROMWIREARGS "rdclass, type, source, dctx, options, target"
57 1.1 christos #define FROMWIRECLASS "rdclass"
58 1.6 christos #define FROMWIRETYPE "type"
59 1.6 christos #define FROMWIREDEF "use_default = true"
60 1.1 christos
61 1.6 christos #define TOWIREARGS "rdata, cctx, target"
62 1.1 christos #define TOWIRECLASS "rdata->rdclass"
63 1.6 christos #define TOWIRETYPE "rdata->type"
64 1.6 christos #define TOWIREDEF "use_default = true"
65 1.1 christos
66 1.6 christos #define FROMSTRUCTARGS "rdclass, type, source, target"
67 1.1 christos #define FROMSTRUCTCLASS "rdclass"
68 1.6 christos #define FROMSTRUCTTYPE "type"
69 1.6 christos #define FROMSTRUCTDEF "use_default = true"
70 1.1 christos
71 1.6 christos #define TOSTRUCTARGS "rdata, target, mctx"
72 1.1 christos #define TOSTRUCTCLASS "rdata->rdclass"
73 1.6 christos #define TOSTRUCTTYPE "rdata->type"
74 1.6 christos #define TOSTRUCTDEF "use_default = true"
75 1.1 christos
76 1.6 christos #define FREESTRUCTARGS "source"
77 1.1 christos #define FREESTRUCTCLASS "common->rdclass"
78 1.6 christos #define FREESTRUCTTYPE "common->rdtype"
79 1.6 christos #define FREESTRUCTDEF NULL
80 1.1 christos
81 1.6 christos #define COMPAREARGS "rdata1, rdata2"
82 1.1 christos #define COMPARECLASS "rdata1->rdclass"
83 1.6 christos #define COMPARETYPE "rdata1->type"
84 1.6 christos #define COMPAREDEF "use_default = true"
85 1.1 christos
86 1.12 christos #define ADDITIONALDATAARGS "rdata, owner, add, arg"
87 1.1 christos #define ADDITIONALDATACLASS "rdata->rdclass"
88 1.6 christos #define ADDITIONALDATATYPE "rdata->type"
89 1.6 christos #define ADDITIONALDATADEF "use_default = true"
90 1.1 christos
91 1.6 christos #define DIGESTARGS "rdata, digest, arg"
92 1.1 christos #define DIGESTCLASS "rdata->rdclass"
93 1.6 christos #define DIGESTTYPE "rdata->type"
94 1.6 christos #define DIGESTDEF "use_default = true"
95 1.1 christos
96 1.6 christos #define CHECKOWNERARGS "name, rdclass, type, wildcard"
97 1.1 christos #define CHECKOWNERCLASS "rdclass"
98 1.6 christos #define CHECKOWNERTYPE "type"
99 1.6 christos #define CHECKOWNERDEF "result = true"
100 1.1 christos
101 1.6 christos #define CHECKNAMESARGS "rdata, owner, bad"
102 1.1 christos #define CHECKNAMESCLASS "rdata->rdclass"
103 1.6 christos #define CHECKNAMESTYPE "rdata->type"
104 1.6 christos #define CHECKNAMESDEF "result = true"
105 1.1 christos
106 1.6 christos static const char copyright[] = "/*\n"
107 1.6 christos " * Copyright (C) 1998%s Internet Systems "
108 1.6 christos "Consortium, Inc. (\"ISC\")\n"
109 1.6 christos " *\n"
110 1.6 christos " * This Source Code Form is subject to the "
111 1.6 christos "terms of the Mozilla Public\n"
112 1.6 christos " * License, v. 2.0. If a copy of the MPL was "
113 1.6 christos "not distributed with this\n"
114 1.10 christos " * file, you can obtain one at "
115 1.10 christos "https://mozilla.org/MPL/2.0/.\n"
116 1.6 christos " */\n"
117 1.6 christos "\n"
118 1.6 christos "/***************\n"
119 1.6 christos " ***************\n"
120 1.6 christos " *************** THIS FILE IS AUTOMATICALLY "
121 1.6 christos "GENERATED BY gen.c.\n"
122 1.6 christos " *************** DO NOT EDIT!\n"
123 1.6 christos " ***************\n"
124 1.6 christos " ***************/\n"
125 1.6 christos "\n"
126 1.6 christos "/*! \\file */\n"
127 1.6 christos "\n";
128 1.1 christos
129 1.1 christos #define STR_EXPAND(tok) #tok
130 1.6 christos #define STR(tok) STR_EXPAND(tok)
131 1.1 christos
132 1.6 christos #define TYPENAMES 256
133 1.6 christos #define TYPECLASSLEN 20 /* DNS mnemonic size. Must be less than 100. */
134 1.6 christos #define TYPECLASSBUF (TYPECLASSLEN + 1)
135 1.12 christos #define TYPECLASSFMT "%" STR(TYPECLASSLEN) "[-0-9a-z]_%u"
136 1.1 christos #define ATTRIBUTESIZE 256
137 1.4 christos
138 1.1 christos static struct cc {
139 1.1 christos struct cc *next;
140 1.1 christos int rdclass;
141 1.3 christos char classbuf[TYPECLASSBUF];
142 1.11 christos } *classes;
143 1.1 christos
144 1.1 christos static struct tt {
145 1.1 christos struct tt *next;
146 1.4 christos uint16_t rdclass;
147 1.4 christos uint16_t type;
148 1.3 christos char classbuf[TYPECLASSBUF];
149 1.3 christos char typebuf[TYPECLASSBUF];
150 1.6 christos char dirbuf[PATH_MAX - 30];
151 1.11 christos } *types;
152 1.1 christos
153 1.1 christos static struct ttnam {
154 1.3 christos char typebuf[TYPECLASSBUF];
155 1.1 christos char macroname[TYPECLASSBUF];
156 1.1 christos char attr[ATTRIBUTESIZE];
157 1.1 christos unsigned int sorted;
158 1.4 christos uint16_t type;
159 1.1 christos } typenames[TYPENAMES];
160 1.1 christos
161 1.1 christos static int maxtype = -1;
162 1.1 christos
163 1.12 christos typedef struct {
164 1.12 christos DIR *handle;
165 1.12 christos char *filename;
166 1.12 christos } isc_dir_t;
167 1.12 christos
168 1.1 christos static char *
169 1.1 christos upper(char *);
170 1.1 christos static char *
171 1.1 christos funname(const char *, char *);
172 1.1 christos static void
173 1.6 christos doswitch(const char *, const char *, const char *, const char *, const char *,
174 1.6 christos const char *);
175 1.1 christos static void
176 1.12 christos add(unsigned int, const char *, int, const char *, const char *);
177 1.1 christos static void
178 1.12 christos sd(unsigned int, const char *, const char *, char);
179 1.1 christos static void
180 1.1 christos insert_into_typenames(int, const char *, const char *);
181 1.1 christos
182 1.12 christos static bool
183 1.12 christos start_directory(const char *path, isc_dir_t *dir) {
184 1.12 christos dir->handle = opendir(path);
185 1.12 christos
186 1.12 christos if (dir->handle != NULL) {
187 1.12 christos return (true);
188 1.12 christos } else {
189 1.12 christos return (false);
190 1.12 christos }
191 1.12 christos }
192 1.12 christos
193 1.12 christos static bool
194 1.12 christos next_file(isc_dir_t *dir) {
195 1.12 christos struct dirent *dirent;
196 1.12 christos
197 1.12 christos dir->filename = NULL;
198 1.12 christos
199 1.12 christos if (dir->handle != NULL) {
200 1.12 christos errno = 0;
201 1.12 christos dirent = readdir(dir->handle);
202 1.12 christos if (dirent != NULL) {
203 1.12 christos dir->filename = dirent->d_name;
204 1.12 christos } else {
205 1.12 christos if (errno != 0) {
206 1.12 christos fprintf(stderr,
207 1.12 christos "Error: reading directory: %s\n",
208 1.12 christos strerror(errno));
209 1.12 christos exit(1);
210 1.12 christos }
211 1.12 christos }
212 1.12 christos }
213 1.12 christos
214 1.12 christos if (dir->filename != NULL) {
215 1.12 christos return (true);
216 1.12 christos } else {
217 1.12 christos return (false);
218 1.12 christos }
219 1.12 christos }
220 1.12 christos
221 1.12 christos static void
222 1.12 christos end_directory(isc_dir_t *dir) {
223 1.12 christos if (dir->handle != NULL) {
224 1.12 christos (void)closedir(dir->handle);
225 1.12 christos }
226 1.12 christos
227 1.12 christos dir->handle = NULL;
228 1.12 christos }
229 1.12 christos
230 1.1 christos /*%
231 1.1 christos * If you use more than 10 of these in, say, a printf(), you'll have problems.
232 1.1 christos */
233 1.1 christos static char *
234 1.1 christos upper(char *s) {
235 1.1 christos static int buf_to_use = 0;
236 1.1 christos static char buf[10][256];
237 1.1 christos char *b;
238 1.1 christos int c;
239 1.1 christos
240 1.1 christos buf_to_use++;
241 1.6 christos if (buf_to_use > 9) {
242 1.1 christos buf_to_use = 0;
243 1.6 christos }
244 1.1 christos
245 1.1 christos b = buf[buf_to_use];
246 1.1 christos memset(b, 0, 256);
247 1.1 christos
248 1.6 christos while ((c = (*s++) & 0xff)) {
249 1.1 christos *b++ = islower(c) ? toupper(c) : c;
250 1.6 christos }
251 1.1 christos *b = '\0';
252 1.1 christos return (buf[buf_to_use]);
253 1.1 christos }
254 1.1 christos
255 1.1 christos static char *
256 1.1 christos funname(const char *s, char *buf) {
257 1.1 christos char *b = buf;
258 1.1 christos char c;
259 1.1 christos
260 1.1 christos INSIST(strlen(s) < TYPECLASSBUF);
261 1.1 christos while ((c = *s++)) {
262 1.1 christos *b++ = (c == '-') ? '_' : c;
263 1.1 christos }
264 1.1 christos *b = '\0';
265 1.1 christos return (buf);
266 1.1 christos }
267 1.1 christos
268 1.1 christos static void
269 1.1 christos doswitch(const char *name, const char *function, const char *args,
270 1.6 christos const char *tsw, const char *csw, const char *res) {
271 1.1 christos struct tt *tt;
272 1.1 christos int first = 1;
273 1.1 christos int lasttype = 0;
274 1.1 christos int subswitch = 0;
275 1.1 christos char buf1[TYPECLASSBUF], buf2[TYPECLASSBUF];
276 1.1 christos const char *result = " result =";
277 1.1 christos
278 1.6 christos if (res == NULL) {
279 1.1 christos result = "";
280 1.6 christos }
281 1.1 christos
282 1.1 christos for (tt = types; tt != NULL; tt = tt->next) {
283 1.1 christos if (first) {
284 1.12 christos printf("\n#define %s \\\n", name);
285 1.12 christos printf("\tswitch (%s) { \\\n" /*}*/, tsw);
286 1.1 christos first = 0;
287 1.1 christos }
288 1.1 christos if (tt->type != lasttype && subswitch) {
289 1.6 christos if (res == NULL) {
290 1.12 christos printf("\t\tdefault: break; \\\n");
291 1.6 christos } else {
292 1.12 christos printf("\t\tdefault: %s; break; \\\n", res);
293 1.6 christos }
294 1.12 christos printf("\t\t} \\\n");
295 1.12 christos printf("\t\tbreak; \\\n");
296 1.1 christos subswitch = 0;
297 1.1 christos }
298 1.1 christos if (tt->rdclass && tt->type != lasttype) {
299 1.12 christos printf("\tcase %d: switch (%s) { \\\n" /*}*/, tt->type,
300 1.12 christos csw);
301 1.1 christos subswitch = 1;
302 1.1 christos }
303 1.6 christos if (tt->rdclass == 0) {
304 1.12 christos printf("\tcase %d:%s %s_%s(%s); break;", tt->type,
305 1.12 christos result, function, funname(tt->typebuf, buf1),
306 1.12 christos args);
307 1.6 christos } else {
308 1.12 christos printf("\t\tcase %d:%s %s_%s_%s(%s); break;",
309 1.12 christos tt->rdclass, result, function,
310 1.12 christos funname(tt->classbuf, buf1),
311 1.12 christos funname(tt->typebuf, buf2), args);
312 1.6 christos }
313 1.12 christos printf(" \\\n");
314 1.1 christos lasttype = tt->type;
315 1.1 christos }
316 1.1 christos if (subswitch) {
317 1.6 christos if (res == NULL) {
318 1.12 christos printf("\t\tdefault: break; \\\n");
319 1.6 christos } else {
320 1.12 christos printf("\t\tdefault: %s; break; \\\n", res);
321 1.6 christos }
322 1.12 christos printf("\t\t} \\\n");
323 1.12 christos printf("\t\tbreak; \\\n");
324 1.1 christos }
325 1.1 christos if (first) {
326 1.6 christos if (res == NULL) {
327 1.12 christos printf("\n#define %s\n", name);
328 1.6 christos } else {
329 1.12 christos printf("\n#define %s %s;\n", name, res);
330 1.6 christos }
331 1.1 christos } else {
332 1.6 christos if (res == NULL) {
333 1.12 christos printf("\tdefault: break; \\\n");
334 1.6 christos } else {
335 1.12 christos printf("\tdefault: %s; break; \\\n", res);
336 1.6 christos }
337 1.12 christos printf("\t}\n");
338 1.1 christos }
339 1.1 christos }
340 1.1 christos
341 1.1 christos static struct ttnam *
342 1.1 christos find_typename(int type) {
343 1.1 christos int i;
344 1.1 christos
345 1.1 christos for (i = 0; i < TYPENAMES; i++) {
346 1.6 christos if (typenames[i].typebuf[0] != 0 && typenames[i].type == type) {
347 1.1 christos return (&typenames[i]);
348 1.3 christos }
349 1.1 christos }
350 1.1 christos return (NULL);
351 1.1 christos }
352 1.1 christos
353 1.1 christos static void
354 1.3 christos insert_into_typenames(int type, const char *typebuf, const char *attr) {
355 1.1 christos struct ttnam *ttn = NULL;
356 1.1 christos size_t c;
357 1.1 christos int i, n;
358 1.1 christos char tmp[256];
359 1.1 christos
360 1.3 christos INSIST(strlen(typebuf) < TYPECLASSBUF);
361 1.1 christos for (i = 0; i < TYPENAMES; i++) {
362 1.6 christos if (typenames[i].typebuf[0] != 0 && typenames[i].type == type &&
363 1.3 christos strcmp(typebuf, typenames[i].typebuf) != 0)
364 1.3 christos {
365 1.1 christos fprintf(stderr,
366 1.6 christos "Error: type %d has two names: %s, %s\n", type,
367 1.6 christos typenames[i].typebuf, typebuf);
368 1.1 christos exit(1);
369 1.1 christos }
370 1.3 christos if (typenames[i].typebuf[0] == 0 && ttn == NULL) {
371 1.1 christos ttn = &typenames[i];
372 1.3 christos }
373 1.1 christos }
374 1.1 christos if (ttn == NULL) {
375 1.1 christos fprintf(stderr, "Error: typenames array too small\n");
376 1.1 christos exit(1);
377 1.1 christos }
378 1.1 christos
379 1.1 christos /* XXXMUKS: This is redundant due to the INSIST above. */
380 1.3 christos if (strlen(typebuf) > sizeof(ttn->typebuf) - 1) {
381 1.6 christos fprintf(stderr, "Error: type name %s is too long\n", typebuf);
382 1.1 christos exit(1);
383 1.1 christos }
384 1.1 christos
385 1.3 christos strncpy(ttn->typebuf, typebuf, sizeof(ttn->typebuf));
386 1.3 christos ttn->typebuf[sizeof(ttn->typebuf) - 1] = '\0';
387 1.1 christos
388 1.3 christos strncpy(ttn->macroname, ttn->typebuf, sizeof(ttn->macroname));
389 1.1 christos ttn->macroname[sizeof(ttn->macroname) - 1] = '\0';
390 1.1 christos
391 1.1 christos ttn->type = type;
392 1.1 christos c = strlen(ttn->macroname);
393 1.1 christos while (c > 0) {
394 1.3 christos if (ttn->macroname[c - 1] == '-') {
395 1.1 christos ttn->macroname[c - 1] = '_';
396 1.3 christos }
397 1.1 christos c--;
398 1.1 christos }
399 1.1 christos
400 1.1 christos if (attr == NULL) {
401 1.6 christos n = snprintf(tmp, sizeof(tmp), "RRTYPE_%s_ATTRIBUTES",
402 1.6 christos upper(ttn->macroname));
403 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(tmp));
404 1.1 christos attr = tmp;
405 1.1 christos }
406 1.1 christos
407 1.1 christos if (ttn->attr[0] != 0 && strcmp(attr, ttn->attr) != 0) {
408 1.6 christos fprintf(stderr,
409 1.6 christos "Error: type %d has different attributes: "
410 1.6 christos "%s, %s\n",
411 1.6 christos type, ttn->attr, attr);
412 1.1 christos exit(1);
413 1.1 christos }
414 1.1 christos
415 1.1 christos if (strlen(attr) > sizeof(ttn->attr) - 1) {
416 1.1 christos fprintf(stderr, "Error: attr (%s) [name %s] is too long\n",
417 1.3 christos attr, typebuf);
418 1.1 christos exit(1);
419 1.1 christos }
420 1.1 christos
421 1.1 christos strncpy(ttn->attr, attr, sizeof(ttn->attr));
422 1.1 christos ttn->attr[sizeof(ttn->attr) - 1] = '\0';
423 1.1 christos
424 1.1 christos ttn->sorted = 0;
425 1.3 christos if (maxtype < type) {
426 1.1 christos maxtype = type;
427 1.3 christos }
428 1.1 christos }
429 1.1 christos
430 1.1 christos static void
431 1.12 christos add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf,
432 1.6 christos const char *dirbuf) {
433 1.1 christos struct tt *newtt = (struct tt *)malloc(sizeof(*newtt));
434 1.1 christos struct tt *tt, *oldtt;
435 1.1 christos struct cc *newcc;
436 1.1 christos struct cc *cc, *oldcc;
437 1.1 christos
438 1.3 christos INSIST(strlen(typebuf) < TYPECLASSBUF);
439 1.3 christos INSIST(strlen(classbuf) < TYPECLASSBUF);
440 1.4 christos INSIST(strlen(dirbuf) < PATH_MAX);
441 1.1 christos
442 1.3 christos insert_into_typenames(type, typebuf, NULL);
443 1.1 christos
444 1.1 christos if (newtt == NULL) {
445 1.1 christos fprintf(stderr, "malloc() failed\n");
446 1.1 christos exit(1);
447 1.1 christos }
448 1.1 christos
449 1.1 christos newtt->next = NULL;
450 1.1 christos newtt->rdclass = rdclass;
451 1.1 christos newtt->type = type;
452 1.1 christos
453 1.3 christos strncpy(newtt->classbuf, classbuf, sizeof(newtt->classbuf));
454 1.3 christos newtt->classbuf[sizeof(newtt->classbuf) - 1] = '\0';
455 1.1 christos
456 1.3 christos strncpy(newtt->typebuf, typebuf, sizeof(newtt->typebuf));
457 1.3 christos newtt->typebuf[sizeof(newtt->typebuf) - 1] = '\0';
458 1.1 christos
459 1.3 christos if (strncmp(dirbuf, "./", 2) == 0) {
460 1.3 christos dirbuf += 2;
461 1.3 christos }
462 1.3 christos strncpy(newtt->dirbuf, dirbuf, sizeof(newtt->dirbuf));
463 1.3 christos newtt->dirbuf[sizeof(newtt->dirbuf) - 1] = '\0';
464 1.1 christos
465 1.1 christos tt = types;
466 1.1 christos oldtt = NULL;
467 1.1 christos
468 1.1 christos while ((tt != NULL) && (tt->type < type)) {
469 1.1 christos oldtt = tt;
470 1.1 christos tt = tt->next;
471 1.1 christos }
472 1.1 christos
473 1.1 christos while ((tt != NULL) && (tt->type == type) && (tt->rdclass < rdclass)) {
474 1.3 christos if (strcmp(tt->typebuf, typebuf) != 0) {
475 1.1 christos exit(1);
476 1.3 christos }
477 1.1 christos oldtt = tt;
478 1.1 christos tt = tt->next;
479 1.1 christos }
480 1.1 christos
481 1.3 christos if ((tt != NULL) && (tt->type == type) && (tt->rdclass == rdclass)) {
482 1.1 christos exit(1);
483 1.3 christos }
484 1.1 christos
485 1.1 christos newtt->next = tt;
486 1.3 christos if (oldtt != NULL) {
487 1.1 christos oldtt->next = newtt;
488 1.3 christos } else {
489 1.1 christos types = newtt;
490 1.3 christos }
491 1.1 christos
492 1.1 christos /*
493 1.1 christos * Do a class switch for this type.
494 1.1 christos */
495 1.3 christos if (rdclass == 0) {
496 1.1 christos return;
497 1.3 christos }
498 1.1 christos
499 1.1 christos newcc = (struct cc *)malloc(sizeof(*newcc));
500 1.1 christos if (newcc == NULL) {
501 1.1 christos fprintf(stderr, "malloc() failed\n");
502 1.1 christos exit(1);
503 1.1 christos }
504 1.1 christos newcc->rdclass = rdclass;
505 1.3 christos strncpy(newcc->classbuf, classbuf, sizeof(newcc->classbuf));
506 1.3 christos newcc->classbuf[sizeof(newcc->classbuf) - 1] = '\0';
507 1.1 christos cc = classes;
508 1.1 christos oldcc = NULL;
509 1.1 christos
510 1.1 christos while ((cc != NULL) && (cc->rdclass < rdclass)) {
511 1.1 christos oldcc = cc;
512 1.1 christos cc = cc->next;
513 1.1 christos }
514 1.1 christos
515 1.1 christos if ((cc != NULL) && cc->rdclass == rdclass) {
516 1.1 christos free((char *)newcc);
517 1.1 christos return;
518 1.1 christos }
519 1.1 christos
520 1.1 christos newcc->next = cc;
521 1.3 christos if (oldcc != NULL) {
522 1.1 christos oldcc->next = newcc;
523 1.3 christos } else {
524 1.1 christos classes = newcc;
525 1.3 christos }
526 1.1 christos }
527 1.1 christos
528 1.1 christos static void
529 1.12 christos sd(unsigned int rdclass, const char *classbuf, const char *dirbuf,
530 1.12 christos char filetype) {
531 1.12 christos char buf[TYPECLASSLEN + sizeof("_4294967295.h")];
532 1.3 christos char typebuf[TYPECLASSBUF];
533 1.12 christos unsigned int type;
534 1.12 christos int n;
535 1.1 christos isc_dir_t dir;
536 1.1 christos
537 1.3 christos if (!start_directory(dirbuf, &dir)) {
538 1.1 christos return;
539 1.3 christos }
540 1.1 christos
541 1.1 christos while (next_file(&dir)) {
542 1.3 christos if (sscanf(dir.filename, TYPECLASSFMT, typebuf, &type) != 2) {
543 1.1 christos continue;
544 1.3 christos }
545 1.1 christos
546 1.12 christos /*
547 1.12 christos * sscanf accepts leading sign and zeros before type so
548 1.12 christos * compare the scanned items against the filename. Filter
549 1.12 christos * out mismatches. Also filter out bad file extensions.
550 1.12 christos */
551 1.12 christos n = snprintf(buf, sizeof(buf), "%s_%u.%c", typebuf, type,
552 1.6 christos filetype);
553 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(buf));
554 1.3 christos if (strcmp(buf, dir.filename) != 0) {
555 1.1 christos continue;
556 1.3 christos }
557 1.12 christos if (type > 65535) {
558 1.12 christos fprintf(stderr, "Error: type value > 65535 (%s)\n",
559 1.12 christos dir.filename);
560 1.12 christos exit(1);
561 1.12 christos }
562 1.3 christos add(rdclass, classbuf, type, typebuf, dirbuf);
563 1.1 christos }
564 1.1 christos
565 1.1 christos end_directory(&dir);
566 1.1 christos }
567 1.1 christos
568 1.1 christos static unsigned int
569 1.1 christos HASH(char *string) {
570 1.1 christos size_t n;
571 1.1 christos unsigned char a, b;
572 1.1 christos
573 1.1 christos n = strlen(string);
574 1.1 christos if (n == 0) {
575 1.1 christos fprintf(stderr, "n == 0?\n");
576 1.1 christos exit(1);
577 1.1 christos }
578 1.1 christos a = tolower((unsigned char)string[0]);
579 1.1 christos b = tolower((unsigned char)string[n - 1]);
580 1.1 christos
581 1.6 christos return (((a + n) * b) % 256);
582 1.1 christos }
583 1.1 christos
584 1.1 christos int
585 1.1 christos main(int argc, char **argv) {
586 1.4 christos char buf[PATH_MAX];
587 1.4 christos char srcdir[PATH_MAX];
588 1.12 christos unsigned int rdclass;
589 1.3 christos char classbuf[TYPECLASSBUF];
590 1.1 christos struct tt *tt;
591 1.1 christos struct cc *cc;
592 1.1 christos struct ttnam *ttn, *ttn2;
593 1.1 christos unsigned int hash;
594 1.1 christos time_t now;
595 1.1 christos char year[11];
596 1.1 christos int lasttype;
597 1.1 christos int code = 1;
598 1.1 christos int class_enum = 0;
599 1.1 christos int type_enum = 0;
600 1.1 christos int structs = 0;
601 1.1 christos int depend = 0;
602 1.1 christos int c, i, j, n;
603 1.1 christos char buf1[TYPECLASSBUF];
604 1.1 christos char filetype = 'c';
605 1.1 christos FILE *fd;
606 1.1 christos char *prefix = NULL;
607 1.1 christos char *suffix = NULL;
608 1.1 christos char *file = NULL;
609 1.5 christos char *source_date_epoch;
610 1.5 christos unsigned long long epoch;
611 1.5 christos char *endptr;
612 1.1 christos isc_dir_t dir;
613 1.1 christos
614 1.6 christos for (i = 0; i < TYPENAMES; i++) {
615 1.1 christos memset(&typenames[i], 0, sizeof(typenames[i]));
616 1.6 christos }
617 1.1 christos
618 1.1 christos srcdir[0] = '\0';
619 1.12 christos while ((c = getopt(argc, argv, "cdits:F:P:S:")) != -1) {
620 1.1 christos switch (c) {
621 1.1 christos case 'c':
622 1.1 christos code = 0;
623 1.1 christos depend = 0;
624 1.1 christos type_enum = 0;
625 1.1 christos class_enum = 1;
626 1.1 christos filetype = 'c';
627 1.1 christos structs = 0;
628 1.1 christos break;
629 1.1 christos case 'd':
630 1.1 christos code = 0;
631 1.1 christos depend = 1;
632 1.1 christos class_enum = 0;
633 1.1 christos type_enum = 0;
634 1.1 christos structs = 0;
635 1.1 christos filetype = 'h';
636 1.1 christos break;
637 1.1 christos case 't':
638 1.1 christos code = 0;
639 1.1 christos depend = 0;
640 1.1 christos class_enum = 0;
641 1.1 christos type_enum = 1;
642 1.1 christos filetype = 'c';
643 1.1 christos structs = 0;
644 1.1 christos break;
645 1.1 christos case 'i':
646 1.1 christos code = 0;
647 1.1 christos depend = 0;
648 1.1 christos class_enum = 0;
649 1.1 christos type_enum = 0;
650 1.1 christos structs = 1;
651 1.1 christos filetype = 'h';
652 1.1 christos break;
653 1.1 christos case 's':
654 1.12 christos if (strlen(optarg) >
655 1.6 christos PATH_MAX - 2 * TYPECLASSLEN -
656 1.6 christos sizeof("/rdata/_65535_65535"))
657 1.3 christos {
658 1.12 christos fprintf(stderr, "\"%s\" too long\n", optarg);
659 1.1 christos exit(1);
660 1.1 christos }
661 1.12 christos n = snprintf(srcdir, sizeof(srcdir), "%s/", optarg);
662 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
663 1.1 christos break;
664 1.1 christos case 'F':
665 1.12 christos file = optarg;
666 1.1 christos break;
667 1.1 christos case 'P':
668 1.12 christos prefix = optarg;
669 1.1 christos break;
670 1.1 christos case 'S':
671 1.12 christos suffix = optarg;
672 1.1 christos break;
673 1.1 christos case '?':
674 1.1 christos exit(1);
675 1.1 christos }
676 1.6 christos }
677 1.1 christos
678 1.1 christos n = snprintf(buf, sizeof(buf), "%srdata", srcdir);
679 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
680 1.1 christos
681 1.3 christos if (!start_directory(buf, &dir)) {
682 1.1 christos exit(1);
683 1.3 christos }
684 1.1 christos
685 1.1 christos while (next_file(&dir)) {
686 1.6 christos if (sscanf(dir.filename, TYPECLASSFMT, classbuf, &rdclass) != 2)
687 1.3 christos {
688 1.1 christos continue;
689 1.3 christos }
690 1.1 christos
691 1.12 christos /*
692 1.12 christos * sscanf accepts leading sign and zeros before type so
693 1.12 christos * compare the scanned items against the filename. Filter
694 1.12 christos * out mismatches.
695 1.12 christos */
696 1.12 christos n = snprintf(buf, sizeof(buf), "%srdata/%s_%u", srcdir,
697 1.6 christos classbuf, rdclass);
698 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(buf));
699 1.3 christos if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0) {
700 1.1 christos continue;
701 1.3 christos }
702 1.12 christos if (rdclass > 65535) {
703 1.12 christos fprintf(stderr, "Error: class value > 65535 (%s)\n",
704 1.12 christos dir.filename);
705 1.12 christos exit(1);
706 1.12 christos }
707 1.3 christos sd(rdclass, classbuf, buf, filetype);
708 1.1 christos }
709 1.1 christos end_directory(&dir);
710 1.1 christos n = snprintf(buf, sizeof(buf), "%srdata/generic", srcdir);
711 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
712 1.1 christos sd(0, "", buf, filetype);
713 1.1 christos
714 1.5 christos source_date_epoch = getenv("SOURCE_DATE_EPOCH");
715 1.5 christos if (source_date_epoch) {
716 1.5 christos errno = 0;
717 1.5 christos epoch = strtoull(source_date_epoch, &endptr, 10);
718 1.6 christos if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) ||
719 1.6 christos (errno != 0 && epoch == 0))
720 1.6 christos {
721 1.6 christos fprintf(stderr,
722 1.6 christos "Environment variable "
723 1.5 christos "$SOURCE_DATE_EPOCH: strtoull: %s\n",
724 1.5 christos strerror(errno));
725 1.6 christos exit(EXIT_FAILURE);
726 1.5 christos }
727 1.5 christos if (endptr == source_date_epoch) {
728 1.6 christos fprintf(stderr,
729 1.6 christos "Environment variable "
730 1.5 christos "$SOURCE_DATE_EPOCH: "
731 1.5 christos "No digits were found: %s\n",
732 1.5 christos endptr);
733 1.6 christos exit(EXIT_FAILURE);
734 1.5 christos }
735 1.5 christos if (*endptr != '\0') {
736 1.6 christos fprintf(stderr,
737 1.6 christos "Environment variable "
738 1.5 christos "$SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
739 1.5 christos endptr);
740 1.6 christos exit(EXIT_FAILURE);
741 1.5 christos }
742 1.5 christos if (epoch > ULONG_MAX) {
743 1.6 christos fprintf(stderr,
744 1.6 christos "Environment variable "
745 1.5 christos "$SOURCE_DATE_EPOCH: value must be "
746 1.5 christos "smaller than or equal to: %lu but "
747 1.5 christos "was found to be: %llu \n",
748 1.5 christos ULONG_MAX, epoch);
749 1.6 christos exit(EXIT_FAILURE);
750 1.5 christos }
751 1.5 christos now = epoch;
752 1.5 christos } else {
753 1.5 christos time(&now);
754 1.5 christos }
755 1.5 christos
756 1.5 christos if (now != -1) {
757 1.6 christos struct tm t, *tm = gmtime_r(&now, &t);
758 1.6 christos
759 1.5 christos if (tm != NULL && tm->tm_year > 104) {
760 1.1 christos n = snprintf(year, sizeof(year), "-%d",
761 1.1 christos tm->tm_year + 1900);
762 1.1 christos INSIST(n > 0 && (unsigned)n < sizeof(year));
763 1.1 christos } else {
764 1.1 christos snprintf(year, sizeof(year), "-2016");
765 1.1 christos }
766 1.1 christos } else {
767 1.1 christos snprintf(year, sizeof(year), "-2016");
768 1.1 christos }
769 1.1 christos
770 1.3 christos if (!depend) {
771 1.12 christos printf(copyright, year);
772 1.3 christos }
773 1.1 christos
774 1.1 christos if (code) {
775 1.12 christos printf("#pragma once\n");
776 1.1 christos
777 1.12 christos printf("#include <stdbool.h>\n");
778 1.12 christos printf("#include <isc/result.h>\n\n");
779 1.12 christos printf("#include <dns/name.h>\n\n");
780 1.1 christos
781 1.3 christos for (tt = types; tt != NULL; tt = tt->next) {
782 1.12 christos printf("#include \"%s/%s_%d.c\"\n", tt->dirbuf,
783 1.12 christos tt->typebuf, tt->type);
784 1.3 christos }
785 1.1 christos
786 1.12 christos printf("\n\n");
787 1.1 christos
788 1.1 christos doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
789 1.1 christos FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
790 1.6 christos doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS, TOTEXTTYPE,
791 1.6 christos TOTEXTCLASS, TOTEXTDEF);
792 1.1 christos doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS,
793 1.1 christos FROMWIRETYPE, FROMWIRECLASS, FROMWIREDEF);
794 1.6 christos doswitch("TOWIRESWITCH", "towire", TOWIREARGS, TOWIRETYPE,
795 1.6 christos TOWIRECLASS, TOWIREDEF);
796 1.6 christos doswitch("COMPARESWITCH", "compare", COMPAREARGS, COMPARETYPE,
797 1.6 christos COMPARECLASS, COMPAREDEF);
798 1.1 christos doswitch("CASECOMPARESWITCH", "casecompare", COMPAREARGS,
799 1.6 christos COMPARETYPE, COMPARECLASS, COMPAREDEF);
800 1.1 christos doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS,
801 1.6 christos FROMSTRUCTTYPE, FROMSTRUCTCLASS, FROMSTRUCTDEF);
802 1.1 christos doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS,
803 1.6 christos TOSTRUCTTYPE, TOSTRUCTCLASS, TOSTRUCTDEF);
804 1.1 christos doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS,
805 1.6 christos FREESTRUCTTYPE, FREESTRUCTCLASS, FREESTRUCTDEF);
806 1.1 christos doswitch("ADDITIONALDATASWITCH", "additionaldata",
807 1.1 christos ADDITIONALDATAARGS, ADDITIONALDATATYPE,
808 1.1 christos ADDITIONALDATACLASS, ADDITIONALDATADEF);
809 1.6 christos doswitch("DIGESTSWITCH", "digest", DIGESTARGS, DIGESTTYPE,
810 1.1 christos DIGESTCLASS, DIGESTDEF);
811 1.6 christos doswitch("CHECKOWNERSWITCH", "checkowner", CHECKOWNERARGS,
812 1.6 christos CHECKOWNERTYPE, CHECKOWNERCLASS, CHECKOWNERDEF);
813 1.6 christos doswitch("CHECKNAMESSWITCH", "checknames", CHECKNAMESARGS,
814 1.6 christos CHECKNAMESTYPE, CHECKNAMESCLASS, CHECKNAMESDEF);
815 1.1 christos
816 1.1 christos /*
817 1.1 christos * From here down, we are processing the rdata names and
818 1.1 christos * attributes.
819 1.1 christos */
820 1.1 christos
821 1.1 christos #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
822 1.1 christos
823 1.6 christos #define METANOTQUESTION \
824 1.6 christos "DNS_RDATATYPEATTR_META | " \
825 1.6 christos "DNS_RDATATYPEATTR_NOTQUESTION"
826 1.6 christos #define METAQUESTIONONLY \
827 1.6 christos "DNS_RDATATYPEATTR_META | " \
828 1.6 christos "DNS_RDATATYPEATTR_QUESTIONONLY"
829 1.6 christos #define RESERVEDNAME "0"
830 1.6 christos #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
831 1.1 christos
832 1.1 christos /*
833 1.1 christos * Add in reserved/special types. This will let us
834 1.1 christos * sort them without special cases.
835 1.1 christos */
836 1.3 christos insert_into_typenames(100, "uinfo", RESERVEDNAME);
837 1.3 christos insert_into_typenames(101, "uid", RESERVEDNAME);
838 1.3 christos insert_into_typenames(102, "gid", RESERVEDNAME);
839 1.5 christos insert_into_typenames(103, "unspec", RESERVEDNAME);
840 1.1 christos insert_into_typenames(251, "ixfr", METAQUESTIONONLY);
841 1.1 christos insert_into_typenames(252, "axfr", METAQUESTIONONLY);
842 1.1 christos insert_into_typenames(253, "mailb", METAQUESTIONONLY);
843 1.1 christos insert_into_typenames(254, "maila", METAQUESTIONONLY);
844 1.1 christos insert_into_typenames(255, "any", METAQUESTIONONLY);
845 1.1 christos
846 1.1 christos /*
847 1.1 christos * Spit out a quick and dirty hash function. Here,
848 1.1 christos * we walk through the list of type names, and calculate
849 1.1 christos * a hash. This isn't perfect, but it will generate "pretty
850 1.1 christos * good" estimates. Lowercase the characters before
851 1.1 christos * computing in all cases.
852 1.1 christos *
853 1.1 christos * Here, walk the list from top to bottom, calculating
854 1.1 christos * the hash (mod 256) for each name.
855 1.1 christos */
856 1.12 christos printf("#define RDATATYPE_COMPARE(_s, _d, _tn, _n, _tp) \\\n");
857 1.12 christos printf("\tdo { \\\n");
858 1.12 christos printf("\t\tif (sizeof(_s) - 1 == _n && \\\n"
859 1.12 christos "\t\t strncasecmp(_s,(_tn),"
860 1.12 christos "(sizeof(_s) - 1)) == 0) { \\\n");
861 1.12 christos printf("\t\t\tif ((dns_rdatatype_attributes(_d) & "
862 1.12 christos "DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
863 1.12 christos printf("\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
864 1.12 christos printf("\t\t\t*(_tp) = _d; \\\n");
865 1.12 christos printf("\t\t\treturn (ISC_R_SUCCESS); \\\n");
866 1.12 christos printf("\t\t} \\\n");
867 1.12 christos printf("\t} while (0)\n\n");
868 1.12 christos
869 1.12 christos printf("#define RDATATYPE_FROMTEXT_SW(_hash,"
870 1.12 christos "_typename,_length,_typep) \\\n");
871 1.12 christos printf("\tswitch (_hash) { \\\n");
872 1.1 christos for (i = 0; i <= maxtype; i++) {
873 1.1 christos ttn = find_typename(i);
874 1.3 christos if (ttn == NULL) {
875 1.1 christos continue;
876 1.3 christos }
877 1.1 christos
878 1.1 christos /*
879 1.1 christos * Skip entries we already processed.
880 1.1 christos */
881 1.3 christos if (ttn->sorted != 0) {
882 1.1 christos continue;
883 1.3 christos }
884 1.1 christos
885 1.3 christos hash = HASH(ttn->typebuf);
886 1.12 christos printf("\t\tcase %u: \\\n", hash);
887 1.1 christos
888 1.1 christos /*
889 1.1 christos * Find all other entries that happen to match
890 1.1 christos * this hash.
891 1.1 christos */
892 1.1 christos for (j = 0; j <= maxtype; j++) {
893 1.1 christos ttn2 = find_typename(j);
894 1.3 christos if (ttn2 == NULL) {
895 1.1 christos continue;
896 1.3 christos }
897 1.3 christos if (hash == HASH(ttn2->typebuf)) {
898 1.12 christos printf("\t\t\tRDATATYPE_COMPARE"
899 1.12 christos "(\"%s\", %d, _typename, "
900 1.12 christos " _length, _typep); \\\n",
901 1.12 christos ttn2->typebuf, ttn2->type);
902 1.1 christos ttn2->sorted = 1;
903 1.1 christos }
904 1.1 christos }
905 1.12 christos printf("\t\t\tbreak; \\\n");
906 1.1 christos }
907 1.12 christos printf("\t}\n");
908 1.1 christos
909 1.12 christos printf("#define RDATATYPE_ATTRIBUTE_SW \\\n");
910 1.12 christos printf("\tswitch (type) { \\\n");
911 1.1 christos for (i = 0; i <= maxtype; i++) {
912 1.1 christos ttn = find_typename(i);
913 1.3 christos if (ttn == NULL) {
914 1.1 christos continue;
915 1.3 christos }
916 1.12 christos printf("\tcase %d: return (%s); \\\n", i,
917 1.12 christos upper(ttn->attr));
918 1.1 christos }
919 1.12 christos printf("\t}\n");
920 1.1 christos
921 1.12 christos printf("#define RDATATYPE_TOTEXT_SW \\\n");
922 1.12 christos printf("\tswitch (type) { \\\n");
923 1.1 christos for (i = 0; i <= maxtype; i++) {
924 1.1 christos ttn = find_typename(i);
925 1.3 christos if (ttn == NULL) {
926 1.1 christos continue;
927 1.3 christos }
928 1.1 christos /*
929 1.1 christos * Remove KEYDATA (65533) from the type to memonic
930 1.1 christos * translation as it is internal use only. This
931 1.1 christos * stops the tools from displaying KEYDATA instead
932 1.1 christos * of TYPE65533.
933 1.1 christos */
934 1.3 christos if (i == 65533U) {
935 1.1 christos continue;
936 1.3 christos }
937 1.12 christos printf("\tcase %d: return "
938 1.12 christos "(str_totext(\"%s\", target)); \\\n",
939 1.12 christos i, upper(ttn->typebuf));
940 1.1 christos }
941 1.12 christos printf("\t}\n");
942 1.1 christos } else if (type_enum) {
943 1.1 christos char *s;
944 1.1 christos
945 1.12 christos printf("#pragma once\n");
946 1.1 christos
947 1.12 christos printf("enum {\n");
948 1.12 christos printf("\tdns_rdatatype_none = 0,\n");
949 1.1 christos
950 1.1 christos lasttype = 0;
951 1.3 christos for (tt = types; tt != NULL; tt = tt->next) {
952 1.3 christos if (tt->type != lasttype) {
953 1.12 christos printf("\tdns_rdatatype_%s = %d,\n",
954 1.12 christos funname(tt->typebuf, buf1),
955 1.12 christos lasttype = tt->type);
956 1.3 christos }
957 1.3 christos }
958 1.1 christos
959 1.12 christos printf("\tdns_rdatatype_ixfr = 251,\n");
960 1.12 christos printf("\tdns_rdatatype_axfr = 252,\n");
961 1.12 christos printf("\tdns_rdatatype_mailb = 253,\n");
962 1.12 christos printf("\tdns_rdatatype_maila = 254,\n");
963 1.12 christos printf("\tdns_rdatatype_any = 255\n");
964 1.1 christos
965 1.12 christos printf("};\n\n");
966 1.1 christos
967 1.12 christos printf("#define dns_rdatatype_none\t"
968 1.12 christos "((dns_rdatatype_t)dns_rdatatype_none)\n");
969 1.1 christos
970 1.3 christos for (tt = types; tt != NULL; tt = tt->next) {
971 1.1 christos if (tt->type != lasttype) {
972 1.3 christos s = funname(tt->typebuf, buf1);
973 1.12 christos printf("#define dns_rdatatype_%s\t%s"
974 1.12 christos "((dns_rdatatype_t)dns_rdatatype_%s)\n",
975 1.12 christos s, strlen(s) < 2U ? "\t" : "", s);
976 1.1 christos lasttype = tt->type;
977 1.1 christos }
978 1.3 christos }
979 1.1 christos
980 1.12 christos printf("#define dns_rdatatype_ixfr\t"
981 1.12 christos "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
982 1.12 christos printf("#define dns_rdatatype_axfr\t"
983 1.12 christos "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
984 1.12 christos printf("#define dns_rdatatype_mailb\t"
985 1.12 christos "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
986 1.12 christos printf("#define dns_rdatatype_maila\t"
987 1.12 christos "((dns_rdatatype_t)dns_rdatatype_maila)\n");
988 1.12 christos printf("#define dns_rdatatype_any\t"
989 1.12 christos "((dns_rdatatype_t)dns_rdatatype_any)\n");
990 1.1 christos } else if (class_enum) {
991 1.1 christos char *s;
992 1.1 christos int classnum;
993 1.1 christos
994 1.12 christos printf("#pragma once\n");
995 1.1 christos
996 1.12 christos printf("enum {\n");
997 1.1 christos
998 1.12 christos printf("\tdns_rdataclass_reserved0 = 0,\n");
999 1.12 christos printf("#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
1000 1.12 christos "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
1001 1.12 christos
1002 1.12 christos #define PRINTCLASS(name, num) \
1003 1.12 christos do { \
1004 1.12 christos s = funname(name, buf1); \
1005 1.12 christos classnum = num; \
1006 1.12 christos printf("\tdns_rdataclass_%s = %d%s\n", s, classnum, \
1007 1.12 christos classnum != 255 ? "," : ""); \
1008 1.12 christos printf("#define dns_rdataclass_%s\t" \
1009 1.12 christos "((dns_rdataclass_t)dns_rdataclass_%s)\n", \
1010 1.12 christos s, s); \
1011 1.8 rillig } while (0)
1012 1.1 christos
1013 1.1 christos for (cc = classes; cc != NULL; cc = cc->next) {
1014 1.3 christos if (cc->rdclass == 3) {
1015 1.1 christos PRINTCLASS("chaos", 3);
1016 1.3 christos } else if (cc->rdclass == 255) {
1017 1.1 christos PRINTCLASS("none", 254);
1018 1.3 christos }
1019 1.3 christos PRINTCLASS(cc->classbuf, cc->rdclass);
1020 1.1 christos }
1021 1.1 christos
1022 1.1 christos #undef PRINTCLASS
1023 1.1 christos
1024 1.12 christos printf("};\n\n");
1025 1.1 christos } else if (structs) {
1026 1.1 christos if (prefix != NULL) {
1027 1.6 christos if ((fd = fopen(prefix, "r")) != NULL) {
1028 1.3 christos while (fgets(buf, sizeof(buf), fd) != NULL) {
1029 1.12 christos printf("%s", buf);
1030 1.3 christos }
1031 1.1 christos fclose(fd);
1032 1.1 christos }
1033 1.1 christos }
1034 1.1 christos for (tt = types; tt != NULL; tt = tt->next) {
1035 1.6 christos snprintf(buf, sizeof(buf), "%s/%s_%d.h", tt->dirbuf,
1036 1.6 christos tt->typebuf, tt->type);
1037 1.6 christos if ((fd = fopen(buf, "r")) != NULL) {
1038 1.3 christos while (fgets(buf, sizeof(buf), fd) != NULL) {
1039 1.12 christos printf("%s", buf);
1040 1.3 christos }
1041 1.1 christos fclose(fd);
1042 1.1 christos }
1043 1.1 christos }
1044 1.1 christos if (suffix != NULL) {
1045 1.6 christos if ((fd = fopen(suffix, "r")) != NULL) {
1046 1.3 christos while (fgets(buf, sizeof(buf), fd) != NULL) {
1047 1.12 christos printf("%s", buf);
1048 1.3 christos }
1049 1.1 christos fclose(fd);
1050 1.1 christos }
1051 1.1 christos }
1052 1.1 christos } else if (depend) {
1053 1.3 christos for (tt = types; tt != NULL; tt = tt->next) {
1054 1.12 christos printf("%s:\t%s/%s_%d.h\n", file, tt->dirbuf,
1055 1.12 christos tt->typebuf, tt->type);
1056 1.3 christos }
1057 1.1 christos }
1058 1.1 christos
1059 1.3 christos if (ferror(stdout) != 0) {
1060 1.1 christos exit(1);
1061 1.3 christos }
1062 1.1 christos
1063 1.1 christos return (0);
1064 1.1 christos }
1065