2 * Copyright (C) 2004-2008 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.
18 /* $Id: gen.c,v 1.83 2008/09/25 04:02:38 tbox Exp $ */
24 * Silence compiler warnings about using strcpy and friends.
26 #define _CRT_SECURE_NO_DEPRECATE 1
29 #include <sys/types.h>
39 #include "gen-win32.h"
44 #define TYPECLASSLEN 21
46 #define FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
47 #define FROMTEXTCLASS "rdclass"
48 #define FROMTEXTTYPE "type"
49 #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
51 #define TOTEXTARGS "rdata, tctx, target"
52 #define TOTEXTCLASS "rdata->rdclass"
53 #define TOTEXTTYPE "rdata->type"
54 #define TOTEXTDEF "use_default = ISC_TRUE"
56 #define FROMWIREARGS "rdclass, type, source, dctx, options, target"
57 #define FROMWIRECLASS "rdclass"
58 #define FROMWIRETYPE "type"
59 #define FROMWIREDEF "use_default = ISC_TRUE"
61 #define TOWIREARGS "rdata, cctx, target"
62 #define TOWIRECLASS "rdata->rdclass"
63 #define TOWIRETYPE "rdata->type"
64 #define TOWIREDEF "use_default = ISC_TRUE"
66 #define FROMSTRUCTARGS "rdclass, type, source, target"
67 #define FROMSTRUCTCLASS "rdclass"
68 #define FROMSTRUCTTYPE "type"
69 #define FROMSTRUCTDEF "use_default = ISC_TRUE"
71 #define TOSTRUCTARGS "rdata, target, mctx"
72 #define TOSTRUCTCLASS "rdata->rdclass"
73 #define TOSTRUCTTYPE "rdata->type"
74 #define TOSTRUCTDEF "use_default = ISC_TRUE"
76 #define FREESTRUCTARGS "source"
77 #define FREESTRUCTCLASS "common->rdclass"
78 #define FREESTRUCTTYPE "common->rdtype"
79 #define FREESTRUCTDEF NULL
81 #define COMPAREARGS "rdata1, rdata2"
82 #define COMPARECLASS "rdata1->rdclass"
83 #define COMPARETYPE "rdata1->type"
84 #define COMPAREDEF "use_default = ISC_TRUE"
86 #define ADDITIONALDATAARGS "rdata, add, arg"
87 #define ADDITIONALDATACLASS "rdata->rdclass"
88 #define ADDITIONALDATATYPE "rdata->type"
89 #define ADDITIONALDATADEF "use_default = ISC_TRUE"
91 #define DIGESTARGS "rdata, digest, arg"
92 #define DIGESTCLASS "rdata->rdclass"
93 #define DIGESTTYPE "rdata->type"
94 #define DIGESTDEF "use_default = ISC_TRUE"
96 #define CHECKOWNERARGS "name, rdclass, type, wildcard"
97 #define CHECKOWNERCLASS "rdclass"
98 #define CHECKOWNERTYPE "type"
99 #define CHECKOWNERDEF "result = ISC_TRUE"
101 #define CHECKNAMESARGS "rdata, owner, bad"
102 #define CHECKNAMESCLASS "rdata->rdclass"
103 #define CHECKNAMESTYPE "rdata->type"
104 #define CHECKNAMESDEF "result = ISC_TRUE"
106 const char copyright[] =
108 " * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
109 " * Copyright (C) 1998-2003 Internet Software Consortium.\n"
111 " * Permission to use, copy, modify, and distribute this software for any\n"
112 " * purpose with or without fee is hereby granted, provided that the above\n"
113 " * copyright notice and this permission notice appear in all copies.\n"
115 " * THE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH\n"
116 " * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
117 " * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
118 " * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
119 " * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
120 " * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
121 " * PERFORMANCE OF THIS SOFTWARE.\n"
126 " *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
127 " *************** DO NOT EDIT!\n"
129 " ***************/\n"
134 #define TYPENAMES 256
139 char classname[TYPECLASSLEN];
146 char classname[TYPECLASSLEN];
147 char typename[TYPECLASSLEN];
148 char dirname[256]; /* XXX Should be max path length */
152 char typename[TYPECLASSLEN];
153 char macroname[TYPECLASSLEN];
157 } typenames[TYPENAMES];
164 funname(const char *, char *);
166 doswitch(const char *, const char *, const char *, const char *,
167 const char *, const char *);
169 dodecl(char *, char *, char *);
171 add(int, const char *, int, const char *, const char *);
173 sd(int, const char *, const char *, char);
175 insert_into_typenames(int, const char *, const char *);
178 * If you use more than 10 of these in, say, a printf(), you'll have problems.
182 static int buf_to_use = 0;
183 static char buf[10][256];
194 while ((c = (*s++) & 0xff))
195 *b++ = islower(c) ? toupper(c) : c;
197 return (buf[buf_to_use]);
201 funname(const char *s, char *buf) {
206 *b++ = (c == '-') ? '_' : c;
213 doswitch(const char *name, const char *function, const char *args,
214 const char *tsw, const char *csw, const char *res)
220 char buf1[TYPECLASSLEN], buf2[TYPECLASSLEN];
221 const char *result = " result =";
226 for (tt = types; tt != NULL; tt = tt->next) {
228 fprintf(stdout, "\n#define %s \\\n", name);
229 fprintf(stdout, "\tswitch (%s) { \\\n" /*}*/, tsw);
232 if (tt->type != lasttype && subswitch) {
234 fprintf(stdout, "\t\tdefault: break; \\\n");
237 "\t\tdefault: %s; break; \\\n", res);
238 fputs(/*{*/ "\t\t} \\\n", stdout);
239 fputs("\t\tbreak; \\\n", stdout);
242 if (tt->rdclass && tt->type != lasttype) {
243 fprintf(stdout, "\tcase %d: switch (%s) { \\\n" /*}*/,
247 if (tt->rdclass == 0)
249 "\tcase %d:%s %s_%s(%s); break;",
250 tt->type, result, function,
251 funname(tt->typename, buf1), args);
254 "\t\tcase %d:%s %s_%s_%s(%s); break;",
255 tt->rdclass, result, function,
256 funname(tt->classname, buf1),
257 funname(tt->typename, buf2), args);
258 fputs(" \\\n", stdout);
263 fprintf(stdout, "\t\tdefault: break; \\\n");
265 fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
266 fputs(/*{*/ "\t\t} \\\n", stdout);
267 fputs("\t\tbreak; \\\n", stdout);
271 fprintf(stdout, "\n#define %s\n", name);
273 fprintf(stdout, "\n#define %s %s;\n", name, res);
276 fprintf(stdout, "\tdefault: break; \\\n");
278 fprintf(stdout, "\tdefault: %s; break; \\\n", res);
279 fputs(/*{*/ "\t}\n", stdout);
284 dodecl(char *type, char *function, char *args) {
286 char buf1[TYPECLASSLEN], buf2[TYPECLASSLEN];
289 for (tt = types; tt; tt = tt->next)
292 "static inline %s %s_%s_%s(%s);\n",
294 funname(tt->classname, buf1),
295 funname(tt->typename, buf2), args);
298 "static inline %s %s_%s(%s);\n",
300 funname(tt->typename, buf1), args);
303 static struct ttnam *
304 find_typename(int type) {
307 for (i = 0; i < TYPENAMES; i++) {
308 if (typenames[i].typename[0] != 0 &&
309 typenames[i].type == type)
310 return (&typenames[i]);
316 insert_into_typenames(int type, const char *typename, const char *attr) {
317 struct ttnam *ttn = NULL;
321 for (i = 0; i < TYPENAMES; i++) {
322 if (typenames[i].typename[0] != 0 &&
323 typenames[i].type == type &&
324 strcmp(typename, typenames[i].typename) != 0) {
326 "Error: type %d has two names: %s, %s\n",
327 type, typenames[i].typename, typename);
330 if (typenames[i].typename[0] == 0 && ttn == NULL)
334 fprintf(stderr, "Error: typenames array too small\n");
338 if (strlen(typename) > sizeof(ttn->typename) - 1) {
339 fprintf(stderr, "Error: type name %s is too long\n",
343 strcpy(ttn->typename, typename);
346 strcpy(ttn->macroname, ttn->typename);
347 c = strlen(ttn->macroname);
349 if (ttn->macroname[c - 1] == '-')
350 ttn->macroname[c - 1] = '_';
355 sprintf(tmp, "RRTYPE_%s_ATTRIBUTES", upper(ttn->macroname));
359 if (ttn->attr[0] != 0 && strcmp(attr, ttn->attr) != 0) {
360 fprintf(stderr, "Error: type %d has different attributes: "
361 "%s, %s\n", type, ttn->attr, attr);
365 if (strlen(attr) > sizeof(ttn->attr) - 1) {
366 fprintf(stderr, "Error: attr (%s) [name %s] is too long\n",
370 strcpy(ttn->attr, attr);
377 add(int rdclass, const char *classname, int type, const char *typename,
380 struct tt *newtt = (struct tt *)malloc(sizeof(*newtt));
381 struct tt *tt, *oldtt;
383 struct cc *cc, *oldcc;
385 insert_into_typenames(type, typename, NULL);
388 fprintf(stderr, "malloc() failed\n");
393 newtt->rdclass = rdclass;
395 strcpy(newtt->classname, classname);
396 strcpy(newtt->typename, typename);
397 if (strncmp(dirname, "./", 2) == 0)
399 strcpy(newtt->dirname, dirname);
404 while ((tt != NULL) && (tt->type < type)) {
409 while ((tt != NULL) && (tt->type == type) && (tt->rdclass < rdclass)) {
410 if (strcmp(tt->typename, typename) != 0)
416 if ((tt != NULL) && (tt->type == type) && (tt->rdclass == rdclass))
426 * Do a class switch for this type.
431 newcc = (struct cc *)malloc(sizeof(*newcc));
432 newcc->rdclass = rdclass;
433 strcpy(newcc->classname, classname);
437 while ((cc != NULL) && (cc->rdclass < rdclass)) {
442 if ((cc != NULL) && cc->rdclass == rdclass) {
455 sd(int rdclass, const char *classname, const char *dirname, char filetype) {
456 char buf[sizeof("01234567890123456789_65535.h")];
457 char fmt[sizeof("%20[-0-9a-z]_%d.h")];
459 char typename[TYPECLASSLEN];
462 if (!start_directory(dirname, &dir))
465 sprintf(fmt,"%s%c", "%20[-0-9a-z]_%d.", filetype);
466 while (next_file(&dir)) {
467 if (sscanf(dir.filename, fmt, typename, &type) != 2)
469 if ((type > 65535) || (type < 0))
472 sprintf(buf, "%s_%d.%c", typename, type, filetype);
473 if (strcmp(buf, dir.filename) != 0)
475 add(rdclass, classname, type, typename, dirname);
488 fprintf(stderr, "n == 0?\n");
491 a = tolower((unsigned char)string[0]);
492 b = tolower((unsigned char)string[n - 1]);
494 return ((a + n) * b) % 256;
498 main(int argc, char **argv) {
499 char buf[256]; /* XXX Should be max path length */
500 char srcdir[256]; /* XXX Should be max path length */
502 char classname[TYPECLASSLEN];
505 struct ttnam *ttn, *ttn2;
517 char buf1[TYPECLASSLEN];
525 for (i = 0; i < TYPENAMES; i++)
526 memset(&typenames[i], 0, sizeof(typenames[i]));
529 while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1)
564 sprintf(srcdir, "%s/", isc_commandline_argument);
567 file = isc_commandline_argument;
570 prefix = isc_commandline_argument;
573 suffix = isc_commandline_argument;
579 sprintf(buf, "%srdata", srcdir);
581 if (!start_directory(buf, &dir))
584 while (next_file(&dir)) {
585 if (sscanf(dir.filename, "%10[0-9a-z]_%d",
586 classname, &rdclass) != 2)
588 if ((rdclass > 65535) || (rdclass < 0))
591 sprintf(buf, "%srdata/%s_%d", srcdir, classname, rdclass);
592 if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0)
594 sd(rdclass, classname, buf, filetype);
597 sprintf(buf, "%srdata/generic", srcdir);
598 sd(0, "", buf, filetype);
600 if (time(&now) != -1) {
601 if ((tm = localtime(&now)) != NULL && tm->tm_year > 104)
602 sprintf(year, "-%d", tm->tm_year + 1900);
608 if (!depend) fprintf(stdout, copyright, year);
611 fputs("#ifndef DNS_CODE_H\n", stdout);
612 fputs("#define DNS_CODE_H 1\n\n", stdout);
614 fputs("#include <isc/boolean.h>\n", stdout);
615 fputs("#include <isc/result.h>\n\n", stdout);
616 fputs("#include <dns/name.h>\n\n", stdout);
618 for (tt = types; tt != NULL; tt = tt->next)
619 fprintf(stdout, "#include \"%s/%s_%d.c\"\n",
620 tt->dirname, tt->typename, tt->type);
622 fputs("\n\n", stdout);
624 doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
625 FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
626 doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS,
627 TOTEXTTYPE, TOTEXTCLASS, TOTEXTDEF);
628 doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS,
629 FROMWIRETYPE, FROMWIRECLASS, FROMWIREDEF);
630 doswitch("TOWIRESWITCH", "towire", TOWIREARGS,
631 TOWIRETYPE, TOWIRECLASS, TOWIREDEF);
632 doswitch("COMPARESWITCH", "compare", COMPAREARGS,
633 COMPARETYPE, COMPARECLASS, COMPAREDEF);
634 doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS,
635 FROMSTRUCTTYPE, FROMSTRUCTCLASS, FROMSTRUCTDEF);
636 doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS,
637 TOSTRUCTTYPE, TOSTRUCTCLASS, TOSTRUCTDEF);
638 doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS,
639 FREESTRUCTTYPE, FREESTRUCTCLASS, FREESTRUCTDEF);
640 doswitch("ADDITIONALDATASWITCH", "additionaldata",
641 ADDITIONALDATAARGS, ADDITIONALDATATYPE,
642 ADDITIONALDATACLASS, ADDITIONALDATADEF);
643 doswitch("DIGESTSWITCH", "digest",
644 DIGESTARGS, DIGESTTYPE,
645 DIGESTCLASS, DIGESTDEF);
646 doswitch("CHECKOWNERSWITCH", "checkowner",
647 CHECKOWNERARGS, CHECKOWNERTYPE,
648 CHECKOWNERCLASS, CHECKOWNERDEF);
649 doswitch("CHECKNAMESSWITCH", "checknames",
650 CHECKNAMESARGS, CHECKNAMESTYPE,
651 CHECKNAMESCLASS, CHECKNAMESDEF);
654 * From here down, we are processing the rdata names and
658 #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
660 #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
661 "DNS_RDATATYPEATTR_NOTQUESTION"
662 #define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
663 "DNS_RDATATYPEATTR_QUESTIONONLY"
664 #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
667 * Add in reserved/special types. This will let us
668 * sort them without special cases.
670 insert_into_typenames(0, "reserved0", RESERVED);
671 insert_into_typenames(31, "eid", RESERVED);
672 insert_into_typenames(32, "nimloc", RESERVED);
673 insert_into_typenames(34, "atma", RESERVED);
674 insert_into_typenames(100, "uinfo", RESERVED);
675 insert_into_typenames(101, "uid", RESERVED);
676 insert_into_typenames(102, "gid", RESERVED);
677 insert_into_typenames(251, "ixfr", METAQUESTIONONLY);
678 insert_into_typenames(252, "axfr", METAQUESTIONONLY);
679 insert_into_typenames(253, "mailb", METAQUESTIONONLY);
680 insert_into_typenames(254, "maila", METAQUESTIONONLY);
681 insert_into_typenames(255, "any", METAQUESTIONONLY);
684 * Spit out a quick and dirty hash function. Here,
685 * we walk through the list of type names, and calculate
686 * a hash. This isn't perfect, but it will generate "pretty
687 * good" estimates. Lowercase the characters before
688 * computing in all cases.
690 * Here, walk the list from top to bottom, calculating
691 * the hash (mod 256) for each name.
693 fprintf(stdout, "#define RDATATYPE_COMPARE(_s, _d, _tn, _n, _tp) \\\n");
694 fprintf(stdout, "\tdo { \\\n");
695 fprintf(stdout, "\t\tif (sizeof(_s) - 1 == _n && \\\n"
696 "\t\t strncasecmp(_s,(_tn),"
697 "(sizeof(_s) - 1)) == 0) { \\\n");
698 fprintf(stdout, "\t\t\tif ((dns_rdatatype_attributes(_d) & "
699 "DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
700 fprintf(stdout, "\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
701 fprintf(stdout, "\t\t\t*(_tp) = _d; \\\n");
702 fprintf(stdout, "\t\t\treturn (ISC_R_SUCCESS); \\\n");
703 fprintf(stdout, "\t\t} \\\n");
704 fprintf(stdout, "\t} while (0)\n\n");
706 fprintf(stdout, "#define RDATATYPE_FROMTEXT_SW(_hash,"
707 "_typename,_length,_typep) \\\n");
708 fprintf(stdout, "\tswitch (_hash) { \\\n");
709 for (i = 0; i <= maxtype; i++) {
710 ttn = find_typename(i);
715 * Skip entries we already processed.
717 if (ttn->sorted != 0)
720 hash = HASH(ttn->typename);
721 fprintf(stdout, "\t\tcase %u: \\\n", hash);
724 * Find all other entries that happen to match
727 for (j = 0; j <= maxtype; j++) {
728 ttn2 = find_typename(j);
731 if (hash == HASH(ttn2->typename)) {
732 fprintf(stdout, "\t\t\tRDATATYPE_COMPARE"
734 "_typename, _length, _typep); \\\n",
735 ttn2->typename, ttn2->type);
739 fprintf(stdout, "\t\t\tbreak; \\\n");
741 fprintf(stdout, "\t}\n");
743 fprintf(stdout, "#define RDATATYPE_ATTRIBUTE_SW \\\n");
744 fprintf(stdout, "\tswitch (type) { \\\n");
745 for (i = 0; i <= maxtype; i++) {
746 ttn = find_typename(i);
749 fprintf(stdout, "\tcase %u: return (%s); \\\n",
750 i, upper(ttn->attr));
752 fprintf(stdout, "\t}\n");
754 fprintf(stdout, "#define RDATATYPE_TOTEXT_SW \\\n");
755 fprintf(stdout, "\tswitch (type) { \\\n");
756 for (i = 0; i <= maxtype; i++) {
757 ttn = find_typename(i);
760 fprintf(stdout, "\tcase %u: return "
761 "(str_totext(\"%s\", target)); \\\n",
762 i, upper(ttn->typename));
764 fprintf(stdout, "\t}\n");
766 fputs("#endif /* DNS_CODE_H */\n", stdout);
767 } else if (type_enum) {
770 fprintf(stdout, "#ifndef DNS_ENUMTYPE_H\n");
771 fprintf(stdout, "#define DNS_ENUMTYPE_H 1\n\n");
773 fprintf(stdout, "enum {\n");
774 fprintf(stdout, "\tdns_rdatatype_none = 0,\n");
777 for (tt = types; tt != NULL; tt = tt->next)
778 if (tt->type != lasttype)
780 "\tdns_rdatatype_%s = %d,\n",
781 funname(tt->typename, buf1),
782 lasttype = tt->type);
784 fprintf(stdout, "\tdns_rdatatype_ixfr = 251,\n");
785 fprintf(stdout, "\tdns_rdatatype_axfr = 252,\n");
786 fprintf(stdout, "\tdns_rdatatype_mailb = 253,\n");
787 fprintf(stdout, "\tdns_rdatatype_maila = 254,\n");
788 fprintf(stdout, "\tdns_rdatatype_any = 255\n");
790 fprintf(stdout, "};\n\n");
792 fprintf(stdout, "#define dns_rdatatype_none\t"
793 "((dns_rdatatype_t)dns_rdatatype_none)\n");
795 for (tt = types; tt != NULL; tt = tt->next)
796 if (tt->type != lasttype) {
797 s = funname(tt->typename, buf1);
799 "#define dns_rdatatype_%s\t%s"
800 "((dns_rdatatype_t)dns_rdatatype_%s)"
802 s, strlen(s) < 2U ? "\t" : "", s);
806 fprintf(stdout, "#define dns_rdatatype_ixfr\t"
807 "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
808 fprintf(stdout, "#define dns_rdatatype_axfr\t"
809 "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
810 fprintf(stdout, "#define dns_rdatatype_mailb\t"
811 "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
812 fprintf(stdout, "#define dns_rdatatype_maila\t"
813 "((dns_rdatatype_t)dns_rdatatype_maila)\n");
814 fprintf(stdout, "#define dns_rdatatype_any\t"
815 "((dns_rdatatype_t)dns_rdatatype_any)\n");
817 fprintf(stdout, "\n#endif /* DNS_ENUMTYPE_H */\n");
819 } else if (class_enum) {
823 fprintf(stdout, "#ifndef DNS_ENUMCLASS_H\n");
824 fprintf(stdout, "#define DNS_ENUMCLASS_H 1\n\n");
826 fprintf(stdout, "enum {\n");
828 fprintf(stdout, "\tdns_rdataclass_reserved0 = 0,\n");
829 fprintf(stdout, "#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
830 "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
832 #define PRINTCLASS(name, num) \
834 s = funname(name, buf1); \
836 fprintf(stdout, "\tdns_rdataclass_%s = %d%s\n", s, classnum, \
837 classnum != 255 ? "," : ""); \
838 fprintf(stdout, "#define dns_rdataclass_%s\t" \
839 "((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
842 for (cc = classes; cc != NULL; cc = cc->next) {
843 if (cc->rdclass == 3)
844 PRINTCLASS("chaos", 3);
845 else if (cc->rdclass == 255)
846 PRINTCLASS("none", 254);
847 PRINTCLASS(cc->classname, cc->rdclass);
852 fprintf(stdout, "};\n\n");
853 fprintf(stdout, "#endif /* DNS_ENUMCLASS_H */\n");
854 } else if (structs) {
855 if (prefix != NULL) {
856 if ((fd = fopen(prefix,"r")) != NULL) {
857 while (fgets(buf, sizeof(buf), fd) != NULL)
862 for (tt = types; tt != NULL; tt = tt->next) {
863 sprintf(buf, "%s/%s_%d.h",
864 tt->dirname, tt->typename, tt->type);
865 if ((fd = fopen(buf,"r")) != NULL) {
866 while (fgets(buf, sizeof(buf), fd) != NULL)
871 if (suffix != NULL) {
872 if ((fd = fopen(suffix,"r")) != NULL) {
873 while (fgets(buf, sizeof(buf), fd) != NULL)
879 for (tt = types; tt != NULL; tt = tt->next)
880 fprintf(stdout, "%s:\t%s/%s_%d.h\n", file,
881 tt->dirname, tt->typename, tt->type);
884 if (ferror(stdout) != 0)