2 * Copyright (C) 2004-2009, 2012-2015 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
22 * Silence compiler warnings about using strcpy and friends.
24 #define _CRT_SECURE_NO_DEPRECATE 1
26 * We use snprintf which was defined late in Windows even it is in C99.
29 #define snprintf _snprintf
33 #include <sys/types.h>
43 #include "gen-win32.h"
48 #define INSIST(cond) \
50 fprintf(stderr, "%s:%d: INSIST(%s)\n", \
51 __FILE__, __LINE__, #cond); \
55 #define FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
56 #define FROMTEXTCLASS "rdclass"
57 #define FROMTEXTTYPE "type"
58 #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
60 #define TOTEXTARGS "rdata, tctx, target"
61 #define TOTEXTCLASS "rdata->rdclass"
62 #define TOTEXTTYPE "rdata->type"
63 #define TOTEXTDEF "use_default = ISC_TRUE"
65 #define FROMWIREARGS "rdclass, type, source, dctx, options, target"
66 #define FROMWIRECLASS "rdclass"
67 #define FROMWIRETYPE "type"
68 #define FROMWIREDEF "use_default = ISC_TRUE"
70 #define TOWIREARGS "rdata, cctx, target"
71 #define TOWIRECLASS "rdata->rdclass"
72 #define TOWIRETYPE "rdata->type"
73 #define TOWIREDEF "use_default = ISC_TRUE"
75 #define FROMSTRUCTARGS "rdclass, type, source, target"
76 #define FROMSTRUCTCLASS "rdclass"
77 #define FROMSTRUCTTYPE "type"
78 #define FROMSTRUCTDEF "use_default = ISC_TRUE"
80 #define TOSTRUCTARGS "rdata, target, mctx"
81 #define TOSTRUCTCLASS "rdata->rdclass"
82 #define TOSTRUCTTYPE "rdata->type"
83 #define TOSTRUCTDEF "use_default = ISC_TRUE"
85 #define FREESTRUCTARGS "source"
86 #define FREESTRUCTCLASS "common->rdclass"
87 #define FREESTRUCTTYPE "common->rdtype"
88 #define FREESTRUCTDEF NULL
90 #define COMPAREARGS "rdata1, rdata2"
91 #define COMPARECLASS "rdata1->rdclass"
92 #define COMPARETYPE "rdata1->type"
93 #define COMPAREDEF "use_default = ISC_TRUE"
95 #define ADDITIONALDATAARGS "rdata, add, arg"
96 #define ADDITIONALDATACLASS "rdata->rdclass"
97 #define ADDITIONALDATATYPE "rdata->type"
98 #define ADDITIONALDATADEF "use_default = ISC_TRUE"
100 #define DIGESTARGS "rdata, digest, arg"
101 #define DIGESTCLASS "rdata->rdclass"
102 #define DIGESTTYPE "rdata->type"
103 #define DIGESTDEF "use_default = ISC_TRUE"
105 #define CHECKOWNERARGS "name, rdclass, type, wildcard"
106 #define CHECKOWNERCLASS "rdclass"
107 #define CHECKOWNERTYPE "type"
108 #define CHECKOWNERDEF "result = ISC_TRUE"
110 #define CHECKNAMESARGS "rdata, owner, bad"
111 #define CHECKNAMESCLASS "rdata->rdclass"
112 #define CHECKNAMESTYPE "rdata->type"
113 #define CHECKNAMESDEF "result = ISC_TRUE"
115 static const char copyright[] =
117 " * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
118 " * Copyright (C) 1998-2003 Internet Software Consortium.\n"
120 " * Permission to use, copy, modify, and distribute this software for any\n"
121 " * purpose with or without fee is hereby granted, provided that the above\n"
122 " * copyright notice and this permission notice appear in all copies.\n"
124 " * THE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH\n"
125 " * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
126 " * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
127 " * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
128 " * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
129 " * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
130 " * PERFORMANCE OF THIS SOFTWARE.\n"
135 " *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
136 " *************** DO NOT EDIT!\n"
138 " ***************/\n"
143 #define STR_EXPAND(tok) #tok
144 #define STR(tok) STR_EXPAND(tok)
146 #define TYPENAMES 256
147 #define TYPECLASSLEN 20 /* DNS mnemonic size. Must be less than 100. */
148 #define TYPECLASSBUF (TYPECLASSLEN + 1)
149 #define TYPECLASSFMT "%" STR(TYPECLASSLEN) "[-0-9a-z]_%d"
150 #define ATTRIBUTESIZE 256
151 #define DIRNAMESIZE 256
156 char classname[TYPECLASSBUF];
163 char classname[TYPECLASSBUF];
164 char typename[TYPECLASSBUF];
165 char dirname[DIRNAMESIZE]; /* XXX Should be max path length */
168 static struct ttnam {
169 char typename[TYPECLASSBUF];
170 char macroname[TYPECLASSBUF];
171 char attr[ATTRIBUTESIZE];
174 } typenames[TYPENAMES];
176 static int maxtype = -1;
181 funname(const char *, char *);
183 doswitch(const char *, const char *, const char *, const char *,
184 const char *, const char *);
186 add(int, const char *, int, const char *, const char *);
188 sd(int, const char *, const char *, char);
190 insert_into_typenames(int, const char *, const char *);
193 * If you use more than 10 of these in, say, a printf(), you'll have problems.
197 static int buf_to_use = 0;
198 static char buf[10][256];
209 while ((c = (*s++) & 0xff))
210 *b++ = islower(c) ? toupper(c) : c;
212 return (buf[buf_to_use]);
216 funname(const char *s, char *buf) {
220 INSIST(strlen(s) < TYPECLASSBUF);
222 *b++ = (c == '-') ? '_' : c;
229 doswitch(const char *name, const char *function, const char *args,
230 const char *tsw, const char *csw, const char *res)
236 char buf1[TYPECLASSBUF], buf2[TYPECLASSBUF];
237 const char *result = " result =";
242 for (tt = types; tt != NULL; tt = tt->next) {
244 fprintf(stdout, "\n#define %s \\\n", name);
245 fprintf(stdout, "\tswitch (%s) { \\\n" /*}*/, tsw);
248 if (tt->type != lasttype && subswitch) {
250 fprintf(stdout, "\t\tdefault: break; \\\n");
253 "\t\tdefault: %s; break; \\\n", res);
254 fputs(/*{*/ "\t\t} \\\n", stdout);
255 fputs("\t\tbreak; \\\n", stdout);
258 if (tt->rdclass && tt->type != lasttype) {
259 fprintf(stdout, "\tcase %d: switch (%s) { \\\n" /*}*/,
263 if (tt->rdclass == 0)
265 "\tcase %d:%s %s_%s(%s); break;",
266 tt->type, result, function,
267 funname(tt->typename, buf1), args);
270 "\t\tcase %d:%s %s_%s_%s(%s); break;",
271 tt->rdclass, result, function,
272 funname(tt->classname, buf1),
273 funname(tt->typename, buf2), args);
274 fputs(" \\\n", stdout);
279 fprintf(stdout, "\t\tdefault: break; \\\n");
281 fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
282 fputs(/*{*/ "\t\t} \\\n", stdout);
283 fputs("\t\tbreak; \\\n", stdout);
287 fprintf(stdout, "\n#define %s\n", name);
289 fprintf(stdout, "\n#define %s %s;\n", name, res);
292 fprintf(stdout, "\tdefault: break; \\\n");
294 fprintf(stdout, "\tdefault: %s; break; \\\n", res);
295 fputs(/*{*/ "\t}\n", stdout);
299 static struct ttnam *
300 find_typename(int type) {
303 for (i = 0; i < TYPENAMES; i++) {
304 if (typenames[i].typename[0] != 0 &&
305 typenames[i].type == type)
306 return (&typenames[i]);
312 insert_into_typenames(int type, const char *typename, const char *attr) {
313 struct ttnam *ttn = NULL;
318 INSIST(strlen(typename) < TYPECLASSBUF);
319 for (i = 0; i < TYPENAMES; i++) {
320 if (typenames[i].typename[0] != 0 &&
321 typenames[i].type == type &&
322 strcmp(typename, typenames[i].typename) != 0) {
324 "Error: type %d has two names: %s, %s\n",
325 type, typenames[i].typename, typename);
328 if (typenames[i].typename[0] == 0 && ttn == NULL)
332 fprintf(stderr, "Error: typenames array too small\n");
336 /* XXXMUKS: This is redundant due to the INSIST above. */
337 if (strlen(typename) > sizeof(ttn->typename) - 1) {
338 fprintf(stderr, "Error: type name %s is too long\n",
343 strncpy(ttn->typename, typename, sizeof(ttn->typename));
344 ttn->typename[sizeof(ttn->typename) - 1] = '\0';
346 strncpy(ttn->macroname, ttn->typename, sizeof(ttn->macroname));
347 ttn->macroname[sizeof(ttn->macroname) - 1] = '\0';
350 c = strlen(ttn->macroname);
352 if (ttn->macroname[c - 1] == '-')
353 ttn->macroname[c - 1] = '_';
358 n = snprintf(tmp, sizeof(tmp),
359 "RRTYPE_%s_ATTRIBUTES", upper(ttn->macroname));
360 INSIST(n > 0 && (unsigned)n < sizeof(tmp));
364 if (ttn->attr[0] != 0 && strcmp(attr, ttn->attr) != 0) {
365 fprintf(stderr, "Error: type %d has different attributes: "
366 "%s, %s\n", type, ttn->attr, attr);
370 if (strlen(attr) > sizeof(ttn->attr) - 1) {
371 fprintf(stderr, "Error: attr (%s) [name %s] is too long\n",
376 strncpy(ttn->attr, attr, sizeof(ttn->attr));
377 ttn->attr[sizeof(ttn->attr) - 1] = '\0';
385 add(int rdclass, const char *classname, int type, const char *typename,
388 struct tt *newtt = (struct tt *)malloc(sizeof(*newtt));
389 struct tt *tt, *oldtt;
391 struct cc *cc, *oldcc;
393 INSIST(strlen(typename) < TYPECLASSBUF);
394 INSIST(strlen(classname) < TYPECLASSBUF);
395 INSIST(strlen(dirname) < DIRNAMESIZE);
397 insert_into_typenames(type, typename, NULL);
400 fprintf(stderr, "malloc() failed\n");
405 newtt->rdclass = rdclass;
408 strncpy(newtt->classname, classname, sizeof(newtt->classname));
409 newtt->classname[sizeof(newtt->classname) - 1] = '\0';
411 strncpy(newtt->typename, typename, sizeof(newtt->typename));
412 newtt->typename[sizeof(newtt->typename) - 1] = '\0';
414 if (strncmp(dirname, "./", 2) == 0)
416 strncpy(newtt->dirname, dirname, sizeof(newtt->dirname));
417 newtt->dirname[sizeof(newtt->dirname) - 1] = '\0';
422 while ((tt != NULL) && (tt->type < type)) {
427 while ((tt != NULL) && (tt->type == type) && (tt->rdclass < rdclass)) {
428 if (strcmp(tt->typename, typename) != 0)
434 if ((tt != NULL) && (tt->type == type) && (tt->rdclass == rdclass))
444 * Do a class switch for this type.
449 newcc = (struct cc *)malloc(sizeof(*newcc));
451 fprintf(stderr, "malloc() failed\n");
454 newcc->rdclass = rdclass;
455 strncpy(newcc->classname, classname, sizeof(newcc->classname));
456 newcc->classname[sizeof(newcc->classname) - 1] = '\0';
460 while ((cc != NULL) && (cc->rdclass < rdclass)) {
465 if ((cc != NULL) && cc->rdclass == rdclass) {
478 sd(int rdclass, const char *classname, const char *dirname, char filetype) {
479 char buf[TYPECLASSLEN + sizeof("_65535.h")];
480 char typename[TYPECLASSBUF];
484 if (!start_directory(dirname, &dir))
487 while (next_file(&dir)) {
488 if (sscanf(dir.filename, TYPECLASSFMT, typename, &type) != 2)
490 if ((type > 65535) || (type < 0))
493 n = snprintf(buf, sizeof(buf), "%s_%d.%c", typename,
495 INSIST(n > 0 && (unsigned)n < sizeof(buf));
496 if (strcmp(buf, dir.filename) != 0)
498 add(rdclass, classname, type, typename, dirname);
511 fprintf(stderr, "n == 0?\n");
514 a = tolower((unsigned char)string[0]);
515 b = tolower((unsigned char)string[n - 1]);
517 return ((a + n) * b) % 256;
521 main(int argc, char **argv) {
522 char buf[DIRNAMESIZE]; /* XXX Should be max path length */
523 char srcdir[DIRNAMESIZE]; /* XXX Should be max path length */
525 char classname[TYPECLASSBUF];
528 struct ttnam *ttn, *ttn2;
540 char buf1[TYPECLASSBUF];
548 for (i = 0; i < TYPENAMES; i++)
549 memset(&typenames[i], 0, sizeof(typenames[i]));
552 while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1)
587 if (strlen(isc_commandline_argument) >
588 DIRNAMESIZE - 2 * TYPECLASSLEN -
589 sizeof("/rdata/_65535_65535")) {
590 fprintf(stderr, "\"%s\" too long\n",
591 isc_commandline_argument);
594 n = snprintf(srcdir, sizeof(srcdir), "%s/",
595 isc_commandline_argument);
596 INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
599 file = isc_commandline_argument;
602 prefix = isc_commandline_argument;
605 suffix = isc_commandline_argument;
611 n = snprintf(buf, sizeof(buf), "%srdata", srcdir);
612 INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
614 if (!start_directory(buf, &dir))
617 while (next_file(&dir)) {
618 if (sscanf(dir.filename, TYPECLASSFMT, classname,
621 if ((rdclass > 65535) || (rdclass < 0))
624 n = snprintf(buf, sizeof(buf), "%srdata/%s_%d",
625 srcdir, classname, rdclass);
626 INSIST(n > 0 && (unsigned)n < sizeof(buf));
627 if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0)
629 sd(rdclass, classname, buf, filetype);
632 n = snprintf(buf, sizeof(buf), "%srdata/generic", srcdir);
633 INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
634 sd(0, "", buf, filetype);
636 if (time(&now) != -1) {
637 if ((tm = localtime(&now)) != NULL && tm->tm_year > 104) {
638 n = snprintf(year, sizeof(year), "-%d",
640 INSIST(n > 0 && (unsigned)n < sizeof(year));
646 if (!depend) fprintf(stdout, copyright, year);
649 fputs("#ifndef DNS_CODE_H\n", stdout);
650 fputs("#define DNS_CODE_H 1\n\n", stdout);
652 fputs("#include <isc/boolean.h>\n", stdout);
653 fputs("#include <isc/result.h>\n\n", stdout);
654 fputs("#include <dns/name.h>\n\n", stdout);
656 for (tt = types; tt != NULL; tt = tt->next)
657 fprintf(stdout, "#include \"%s/%s_%d.c\"\n",
658 tt->dirname, tt->typename, tt->type);
660 fputs("\n\n", stdout);
662 doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
663 FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
664 doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS,
665 TOTEXTTYPE, TOTEXTCLASS, TOTEXTDEF);
666 doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS,
667 FROMWIRETYPE, FROMWIRECLASS, FROMWIREDEF);
668 doswitch("TOWIRESWITCH", "towire", TOWIREARGS,
669 TOWIRETYPE, TOWIRECLASS, TOWIREDEF);
670 doswitch("COMPARESWITCH", "compare", COMPAREARGS,
671 COMPARETYPE, COMPARECLASS, COMPAREDEF);
672 doswitch("CASECOMPARESWITCH", "casecompare", COMPAREARGS,
673 COMPARETYPE, COMPARECLASS, COMPAREDEF);
674 doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS,
675 FROMSTRUCTTYPE, FROMSTRUCTCLASS, FROMSTRUCTDEF);
676 doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS,
677 TOSTRUCTTYPE, TOSTRUCTCLASS, TOSTRUCTDEF);
678 doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS,
679 FREESTRUCTTYPE, FREESTRUCTCLASS, FREESTRUCTDEF);
680 doswitch("ADDITIONALDATASWITCH", "additionaldata",
681 ADDITIONALDATAARGS, ADDITIONALDATATYPE,
682 ADDITIONALDATACLASS, ADDITIONALDATADEF);
683 doswitch("DIGESTSWITCH", "digest",
684 DIGESTARGS, DIGESTTYPE,
685 DIGESTCLASS, DIGESTDEF);
686 doswitch("CHECKOWNERSWITCH", "checkowner",
687 CHECKOWNERARGS, CHECKOWNERTYPE,
688 CHECKOWNERCLASS, CHECKOWNERDEF);
689 doswitch("CHECKNAMESSWITCH", "checknames",
690 CHECKNAMESARGS, CHECKNAMESTYPE,
691 CHECKNAMESCLASS, CHECKNAMESDEF);
694 * From here down, we are processing the rdata names and
698 #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
700 #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
701 "DNS_RDATATYPEATTR_NOTQUESTION"
702 #define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
703 "DNS_RDATATYPEATTR_QUESTIONONLY"
704 #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
707 * Add in reserved/special types. This will let us
708 * sort them without special cases.
710 insert_into_typenames(0, "reserved0", RESERVED);
711 insert_into_typenames(31, "eid", RESERVED);
712 insert_into_typenames(32, "nimloc", RESERVED);
713 insert_into_typenames(34, "atma", RESERVED);
714 insert_into_typenames(100, "uinfo", RESERVED);
715 insert_into_typenames(101, "uid", RESERVED);
716 insert_into_typenames(102, "gid", RESERVED);
717 insert_into_typenames(251, "ixfr", METAQUESTIONONLY);
718 insert_into_typenames(252, "axfr", METAQUESTIONONLY);
719 insert_into_typenames(253, "mailb", METAQUESTIONONLY);
720 insert_into_typenames(254, "maila", METAQUESTIONONLY);
721 insert_into_typenames(255, "any", METAQUESTIONONLY);
724 * Spit out a quick and dirty hash function. Here,
725 * we walk through the list of type names, and calculate
726 * a hash. This isn't perfect, but it will generate "pretty
727 * good" estimates. Lowercase the characters before
728 * computing in all cases.
730 * Here, walk the list from top to bottom, calculating
731 * the hash (mod 256) for each name.
733 fprintf(stdout, "#define RDATATYPE_COMPARE(_s, _d, _tn, _n, _tp) \\\n");
734 fprintf(stdout, "\tdo { \\\n");
735 fprintf(stdout, "\t\tif (sizeof(_s) - 1 == _n && \\\n"
736 "\t\t strncasecmp(_s,(_tn),"
737 "(sizeof(_s) - 1)) == 0) { \\\n");
738 fprintf(stdout, "\t\t\tif ((dns_rdatatype_attributes(_d) & "
739 "DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
740 fprintf(stdout, "\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
741 fprintf(stdout, "\t\t\t*(_tp) = _d; \\\n");
742 fprintf(stdout, "\t\t\treturn (ISC_R_SUCCESS); \\\n");
743 fprintf(stdout, "\t\t} \\\n");
744 fprintf(stdout, "\t} while (0)\n\n");
746 fprintf(stdout, "#define RDATATYPE_FROMTEXT_SW(_hash,"
747 "_typename,_length,_typep) \\\n");
748 fprintf(stdout, "\tswitch (_hash) { \\\n");
749 for (i = 0; i <= maxtype; i++) {
750 ttn = find_typename(i);
755 * Skip entries we already processed.
757 if (ttn->sorted != 0)
760 hash = HASH(ttn->typename);
761 fprintf(stdout, "\t\tcase %u: \\\n", hash);
764 * Find all other entries that happen to match
767 for (j = 0; j <= maxtype; j++) {
768 ttn2 = find_typename(j);
771 if (hash == HASH(ttn2->typename)) {
772 fprintf(stdout, "\t\t\tRDATATYPE_COMPARE"
774 "_typename, _length, _typep); \\\n",
775 ttn2->typename, ttn2->type);
779 fprintf(stdout, "\t\t\tbreak; \\\n");
781 fprintf(stdout, "\t}\n");
783 fprintf(stdout, "#define RDATATYPE_ATTRIBUTE_SW \\\n");
784 fprintf(stdout, "\tswitch (type) { \\\n");
785 for (i = 0; i <= maxtype; i++) {
786 ttn = find_typename(i);
789 fprintf(stdout, "\tcase %d: return (%s); \\\n",
790 i, upper(ttn->attr));
792 fprintf(stdout, "\t}\n");
794 fprintf(stdout, "#define RDATATYPE_TOTEXT_SW \\\n");
795 fprintf(stdout, "\tswitch (type) { \\\n");
796 for (i = 0; i <= maxtype; i++) {
797 ttn = find_typename(i);
801 * Remove KEYDATA (65533) from the type to memonic
802 * translation as it is internal use only. This
803 * stops the tools from displaying KEYDATA instead
808 fprintf(stdout, "\tcase %d: return "
809 "(str_totext(\"%s\", target)); \\\n",
810 i, upper(ttn->typename));
812 fprintf(stdout, "\t}\n");
814 fputs("#endif /* DNS_CODE_H */\n", stdout);
815 } else if (type_enum) {
818 fprintf(stdout, "#ifndef DNS_ENUMTYPE_H\n");
819 fprintf(stdout, "#define DNS_ENUMTYPE_H 1\n\n");
821 fprintf(stdout, "enum {\n");
822 fprintf(stdout, "\tdns_rdatatype_none = 0,\n");
825 for (tt = types; tt != NULL; tt = tt->next)
826 if (tt->type != lasttype)
828 "\tdns_rdatatype_%s = %d,\n",
829 funname(tt->typename, buf1),
830 lasttype = tt->type);
832 fprintf(stdout, "\tdns_rdatatype_ixfr = 251,\n");
833 fprintf(stdout, "\tdns_rdatatype_axfr = 252,\n");
834 fprintf(stdout, "\tdns_rdatatype_mailb = 253,\n");
835 fprintf(stdout, "\tdns_rdatatype_maila = 254,\n");
836 fprintf(stdout, "\tdns_rdatatype_any = 255\n");
838 fprintf(stdout, "};\n\n");
840 fprintf(stdout, "#define dns_rdatatype_none\t"
841 "((dns_rdatatype_t)dns_rdatatype_none)\n");
843 for (tt = types; tt != NULL; tt = tt->next)
844 if (tt->type != lasttype) {
845 s = funname(tt->typename, buf1);
847 "#define dns_rdatatype_%s\t%s"
848 "((dns_rdatatype_t)dns_rdatatype_%s)"
850 s, strlen(s) < 2U ? "\t" : "", s);
854 fprintf(stdout, "#define dns_rdatatype_ixfr\t"
855 "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
856 fprintf(stdout, "#define dns_rdatatype_axfr\t"
857 "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
858 fprintf(stdout, "#define dns_rdatatype_mailb\t"
859 "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
860 fprintf(stdout, "#define dns_rdatatype_maila\t"
861 "((dns_rdatatype_t)dns_rdatatype_maila)\n");
862 fprintf(stdout, "#define dns_rdatatype_any\t"
863 "((dns_rdatatype_t)dns_rdatatype_any)\n");
865 fprintf(stdout, "\n#endif /* DNS_ENUMTYPE_H */\n");
867 } else if (class_enum) {
871 fprintf(stdout, "#ifndef DNS_ENUMCLASS_H\n");
872 fprintf(stdout, "#define DNS_ENUMCLASS_H 1\n\n");
874 fprintf(stdout, "enum {\n");
876 fprintf(stdout, "\tdns_rdataclass_reserved0 = 0,\n");
877 fprintf(stdout, "#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
878 "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
880 #define PRINTCLASS(name, num) \
882 s = funname(name, buf1); \
884 fprintf(stdout, "\tdns_rdataclass_%s = %d%s\n", s, classnum, \
885 classnum != 255 ? "," : ""); \
886 fprintf(stdout, "#define dns_rdataclass_%s\t" \
887 "((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
890 for (cc = classes; cc != NULL; cc = cc->next) {
891 if (cc->rdclass == 3)
892 PRINTCLASS("chaos", 3);
893 else if (cc->rdclass == 255)
894 PRINTCLASS("none", 254);
895 PRINTCLASS(cc->classname, cc->rdclass);
900 fprintf(stdout, "};\n\n");
901 fprintf(stdout, "#endif /* DNS_ENUMCLASS_H */\n");
902 } else if (structs) {
903 if (prefix != NULL) {
904 if ((fd = fopen(prefix,"r")) != NULL) {
905 while (fgets(buf, sizeof(buf), fd) != NULL)
910 for (tt = types; tt != NULL; tt = tt->next) {
911 snprintf(buf, sizeof(buf), "%s/%s_%d.h",
912 tt->dirname, tt->typename, tt->type);
913 if ((fd = fopen(buf,"r")) != NULL) {
914 while (fgets(buf, sizeof(buf), fd) != NULL)
919 if (suffix != NULL) {
920 if ((fd = fopen(suffix,"r")) != NULL) {
921 while (fgets(buf, sizeof(buf), fd) != NULL)
927 for (tt = types; tt != NULL; tt = tt->next)
928 fprintf(stdout, "%s:\t%s/%s_%d.h\n", file,
929 tt->dirname, tt->typename, tt->type);
932 if (ferror(stdout) != 0)