2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.65.2.7 2004/03/15 04:45:00 marka Exp $ */
22 #include <sys/types.h>
32 #include "gen-win32.h"
37 #define FROMTEXTARGS "rdclass, type, lexer, origin, downcase, target, callbacks"
38 #define FROMTEXTCLASS "rdclass"
39 #define FROMTEXTTYPE "type"
40 #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
42 #define TOTEXTARGS "rdata, tctx, target"
43 #define TOTEXTCLASS "rdata->rdclass"
44 #define TOTEXTTYPE "rdata->type"
45 #define TOTEXTDEF "use_default = ISC_TRUE"
47 #define FROMWIREARGS "rdclass, type, source, dctx, downcase, target"
48 #define FROMWIRECLASS "rdclass"
49 #define FROMWIRETYPE "type"
50 #define FROMWIREDEF "use_default = ISC_TRUE"
52 #define TOWIREARGS "rdata, cctx, target"
53 #define TOWIRECLASS "rdata->rdclass"
54 #define TOWIRETYPE "rdata->type"
55 #define TOWIREDEF "use_default = ISC_TRUE"
57 #define FROMSTRUCTARGS "rdclass, type, source, target"
58 #define FROMSTRUCTCLASS "rdclass"
59 #define FROMSTRUCTTYPE "type"
60 #define FROMSTRUCTDEF "use_default = ISC_TRUE"
62 #define TOSTRUCTARGS "rdata, target, mctx"
63 #define TOSTRUCTCLASS "rdata->rdclass"
64 #define TOSTRUCTTYPE "rdata->type"
65 #define TOSTRUCTDEF "use_default = ISC_TRUE"
67 #define FREESTRUCTARGS "source"
68 #define FREESTRUCTCLASS "common->rdclass"
69 #define FREESTRUCTTYPE "common->rdtype"
70 #define FREESTRUCTDEF NULL
72 #define COMPAREARGS "rdata1, rdata2"
73 #define COMPARECLASS "rdata1->rdclass"
74 #define COMPARETYPE "rdata1->type"
75 #define COMPAREDEF "use_default = ISC_TRUE"
77 #define ADDITIONALDATAARGS "rdata, add, arg"
78 #define ADDITIONALDATACLASS "rdata->rdclass"
79 #define ADDITIONALDATATYPE "rdata->type"
80 #define ADDITIONALDATADEF "use_default = ISC_TRUE"
82 #define DIGESTARGS "rdata, digest, arg"
83 #define DIGESTCLASS "rdata->rdclass"
84 #define DIGESTTYPE "rdata->type"
85 #define DIGESTDEF "use_default = ISC_TRUE"
87 const char copyright
[] =
89 " * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
90 " * Copyright (C) 1998-2003 Internet Software Consortium.\n"
92 " * Permission to use, copy, modify, and distribute this software for any\n"
93 " * purpose with or without fee is hereby granted, provided that the above\n"
94 " * copyright notice and this permission notice appear in all copies.\n"
96 " * THE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH\n"
97 " * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
98 " * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
99 " * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
100 " * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
101 " * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
102 " * PERFORMANCE OF THIS SOFTWARE.\n"
107 " *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
108 " *************** DO NOT EDIT!\n"
110 " ***************/\n"
113 #define TYPENAMES 256
127 char dirname
[256]; /* XXX Should be max path length */
136 } typenames
[TYPENAMES
];
143 funname(const char *, char *);
145 doswitch(const char *, const char *, const char *, const char *,
146 const char *, const char *);
148 dodecl(char *, char *, char *);
150 add(int, const char *, int, const char *, const char *);
152 sd(int, const char *, const char *, char);
154 insert_into_typenames(int, const char *, const char *);
157 * If you use more than 10 of these in, say, a printf(), you'll have problems.
161 static int buf_to_use
= 0;
162 static char buf
[10][256];
173 while ((c
= (*s
++) & 0xff))
174 *b
++ = islower(c
) ? toupper(c
) : c
;
176 return (buf
[buf_to_use
]);
180 funname(const char *s
, char *buf
) {
185 *b
++ = (c
== '-') ? '_' : c
;
192 doswitch(const char *name
, const char *function
, const char *args
,
193 const char *tsw
, const char *csw
, const char *res
)
199 char buf1
[11], buf2
[11];
200 const char *result
= " result =";
205 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
207 fprintf(stdout
, "\n#define %s \\\n", name
);
208 fprintf(stdout
, "\tswitch (%s) { \\\n" /*}*/, tsw
);
211 if (tt
->type
!= lasttype
&& subswitch
) {
213 fprintf(stdout
, "\t\tdefault: break; \\\n");
216 "\t\tdefault: %s; break; \\\n", res
);
217 fputs(/*{*/ "\t\t} \\\n", stdout
);
218 fputs("\t\tbreak; \\\n", stdout
);
221 if (tt
->rdclass
&& tt
->type
!= lasttype
) {
222 fprintf(stdout
, "\tcase %d: switch (%s) { \\\n" /*}*/,
226 if (tt
->rdclass
== 0)
228 "\tcase %d:%s %s_%s(%s); break;",
229 tt
->type
, result
, function
,
230 funname(tt
->typename
, buf1
), args
);
233 "\t\tcase %d:%s %s_%s_%s(%s); break;",
234 tt
->rdclass
, result
, function
,
235 funname(tt
->classname
, buf1
),
236 funname(tt
->typename
, buf2
), args
);
237 fputs(" \\\n", stdout
);
242 fprintf(stdout
, "\t\tdefault: break; \\\n");
244 fprintf(stdout
, "\t\tdefault: %s; break; \\\n", res
);
245 fputs(/*{*/ "\t\t} \\\n", stdout
);
246 fputs("\t\tbreak; \\\n", stdout
);
250 fprintf(stdout
, "\n#define %s\n", name
);
252 fprintf(stdout
, "\n#define %s %s;\n", name
, res
);
255 fprintf(stdout
, "\tdefault: break; \\\n");
257 fprintf(stdout
, "\tdefault: %s; break; \\\n", res
);
258 fputs(/*{*/ "\t}\n", stdout
);
263 dodecl(char *type
, char *function
, char *args
) {
265 char buf1
[11], buf2
[11];
268 for (tt
= types
; tt
; tt
= tt
->next
)
271 "static inline %s %s_%s_%s(%s);\n",
273 funname(tt
->classname
, buf1
),
274 funname(tt
->typename
, buf2
), args
);
277 "static inline %s %s_%s(%s);\n",
279 funname(tt
->typename
, buf1
), args
);
282 static struct ttnam
*
283 find_typename(int type
) {
286 for (i
= 0; i
< TYPENAMES
; i
++) {
287 if (typenames
[i
].typename
[0] != 0 &&
288 typenames
[i
].type
== type
)
289 return (&typenames
[i
]);
295 insert_into_typenames(int type
, const char *typename
, const char *attr
) {
296 struct ttnam
*ttn
= NULL
;
300 for (i
= 0; i
< TYPENAMES
; i
++) {
301 if (typenames
[i
].typename
[0] != 0 &&
302 typenames
[i
].type
== type
&&
303 strcmp(typename
, typenames
[i
].typename
) != 0) {
305 "Error: type %d has two names: %s, %s\n",
306 type
, typenames
[i
].typename
, typename
);
309 if (typenames
[i
].typename
[0] == 0 && ttn
== NULL
)
313 fprintf(stderr
, "Error: typenames array too small\n");
317 if (strlen(typename
) > sizeof(ttn
->typename
) - 1) {
318 fprintf(stderr
, "Error: type name %s is too long\n",
322 strcpy(ttn
->typename
, typename
);
325 strcpy(ttn
->macroname
, ttn
->typename
);
326 c
= strlen(ttn
->macroname
);
328 if (ttn
->macroname
[c
- 1] == '-')
329 ttn
->macroname
[c
- 1] = '_';
334 sprintf(tmp
, "RRTYPE_%s_ATTRIBUTES", upper(ttn
->macroname
));
338 if (ttn
->attr
[0] != 0 && strcmp(attr
, ttn
->attr
) != 0) {
339 fprintf(stderr
, "Error: type %d has different attributes: "
340 "%s, %s\n", type
, ttn
->attr
, attr
);
344 if (strlen(attr
) > sizeof(ttn
->attr
) - 1) {
345 fprintf(stderr
, "Error: attr (%s) [name %s] is too long\n",
349 strcpy(ttn
->attr
, attr
);
356 add(int rdclass
, const char *classname
, int type
, const char *typename
,
359 struct tt
*newtt
= (struct tt
*)malloc(sizeof *newtt
);
360 struct tt
*tt
, *oldtt
;
362 struct cc
*cc
, *oldcc
;
364 insert_into_typenames(type
, typename
, NULL
);
367 fprintf(stderr
, "malloc() failed\n");
372 newtt
->rdclass
= rdclass
;
374 strcpy(newtt
->classname
, classname
);
375 strcpy(newtt
->typename
, typename
);
376 strcpy(newtt
->dirname
, dirname
);
381 while ((tt
!= NULL
) && (tt
->type
< type
)) {
386 while ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
< rdclass
)) {
387 if (strcmp(tt
->typename
, typename
) != 0)
393 if ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
== rdclass
))
403 * Do a class switch for this type.
408 newcc
= (struct cc
*)malloc(sizeof *newcc
);
409 newcc
->rdclass
= rdclass
;
410 strcpy(newcc
->classname
, classname
);
414 while ((cc
!= NULL
) && (cc
->rdclass
< rdclass
)) {
419 if ((cc
!= NULL
) && cc
->rdclass
== rdclass
) {
432 sd(int rdclass
, const char *classname
, const char *dirname
, char filetype
) {
433 char buf
[sizeof "0123456789_65535.h"];
434 char fmt
[sizeof "%10[-0-9a-z]_%d.h"];
439 if (!start_directory(dirname
, &dir
))
442 sprintf(fmt
,"%s%c", "%10[-0-9a-z]_%d.", filetype
);
443 while (next_file(&dir
)) {
444 if (sscanf(dir
.filename
, fmt
, typename
, &type
) != 2)
446 if ((type
> 65535) || (type
< 0))
449 sprintf(buf
, "%s_%d.%c", typename
, type
, filetype
);
450 if (strcmp(buf
, dir
.filename
) != 0)
452 add(rdclass
, classname
, type
, typename
, dirname
);
465 fprintf(stderr
, "n == 0?\n");
468 a
= tolower((unsigned char)string
[0]);
469 b
= tolower((unsigned char)string
[n
- 1]);
471 return ((a
+ n
) * b
) % 256;
475 main(int argc
, char **argv
) {
476 char buf
[256]; /* XXX Should be max path length */
477 char srcdir
[256]; /* XXX Should be max path length */
482 struct ttnam
*ttn
, *ttn2
;
502 for (i
= 0; i
< TYPENAMES
; i
++)
503 memset(&typenames
[i
], 0, sizeof(typenames
[i
]));
506 while ((c
= isc_commandline_parse(argc
, argv
, "cdits:F:P:S:")) != -1)
541 sprintf(srcdir
, "%s/", isc_commandline_argument
);
544 file
= isc_commandline_argument
;
547 prefix
= isc_commandline_argument
;
550 suffix
= isc_commandline_argument
;
556 sprintf(buf
, "%srdata", srcdir
);
558 if (!start_directory(buf
, &dir
))
561 while (next_file(&dir
)) {
562 if (sscanf(dir
.filename
, "%10[0-9a-z]_%d",
563 classname
, &rdclass
) != 2)
565 if ((rdclass
> 65535) || (rdclass
< 0))
568 sprintf(buf
, "%srdata/%s_%d", srcdir
, classname
, rdclass
);
569 if (strcmp(buf
+ 6 + strlen(srcdir
), dir
.filename
) != 0)
571 sd(rdclass
, classname
, buf
, filetype
);
574 sprintf(buf
, "%srdata/generic", srcdir
);
575 sd(0, "", buf
, filetype
);
577 if (time(&now
) != -1) {
578 if ((tm
= localtime(&now
)) != NULL
&& tm
->tm_year
> 104)
579 sprintf(year
, "-%d", tm
->tm_year
+ 1900);
585 if (!depend
) fprintf(stdout
, copyright
, year
);
588 fputs("#ifndef DNS_CODE_H\n", stdout
);
589 fputs("#define DNS_CODE_H 1\n\n", stdout
);
591 fputs("#include <isc/boolean.h>\n", stdout
);
592 fputs("#include <isc/result.h>\n\n", stdout
);
593 fputs("#include <dns/name.h>\n\n", stdout
);
595 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
596 fprintf(stdout
, "#include \"%s/%s_%d.c\"\n",
597 tt
->dirname
, tt
->typename
, tt
->type
);
599 fputs("\n\n", stdout
);
601 doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS
,
602 FROMTEXTTYPE
, FROMTEXTCLASS
, FROMTEXTDEF
);
603 doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS
,
604 TOTEXTTYPE
, TOTEXTCLASS
, TOTEXTDEF
);
605 doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS
,
606 FROMWIRETYPE
, FROMWIRECLASS
, FROMWIREDEF
);
607 doswitch("TOWIRESWITCH", "towire", TOWIREARGS
,
608 TOWIRETYPE
, TOWIRECLASS
, TOWIREDEF
);
609 doswitch("COMPARESWITCH", "compare", COMPAREARGS
,
610 COMPARETYPE
, COMPARECLASS
, COMPAREDEF
);
611 doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS
,
612 FROMSTRUCTTYPE
, FROMSTRUCTCLASS
, FROMSTRUCTDEF
);
613 doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS
,
614 TOSTRUCTTYPE
, TOSTRUCTCLASS
, TOSTRUCTDEF
);
615 doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS
,
616 FREESTRUCTTYPE
, FREESTRUCTCLASS
, FREESTRUCTDEF
);
617 doswitch("ADDITIONALDATASWITCH", "additionaldata",
618 ADDITIONALDATAARGS
, ADDITIONALDATATYPE
,
619 ADDITIONALDATACLASS
, ADDITIONALDATADEF
);
620 doswitch("DIGESTSWITCH", "digest",
621 DIGESTARGS
, DIGESTTYPE
,
622 DIGESTCLASS
, DIGESTDEF
);
625 * From here down, we are processing the rdata names and
629 #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
631 #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
632 "DNS_RDATATYPEATTR_NOTQUESTION"
633 #define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
634 "DNS_RDATATYPEATTR_QUESTIONONLY"
635 #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
638 * Add in reserved/special types. This will let us
639 * sort them without special cases.
641 insert_into_typenames(0, "reserved0", RESERVED
);
642 insert_into_typenames(31, "eid", RESERVED
);
643 insert_into_typenames(32, "nimloc", RESERVED
);
644 insert_into_typenames(34, "atma", RESERVED
);
645 insert_into_typenames(100, "uinfo", RESERVED
);
646 insert_into_typenames(101, "uid", RESERVED
);
647 insert_into_typenames(102, "gid", RESERVED
);
648 insert_into_typenames(251, "ixfr", METAQUESTIONONLY
);
649 insert_into_typenames(252, "axfr", METAQUESTIONONLY
);
650 insert_into_typenames(253, "mailb", METAQUESTIONONLY
);
651 insert_into_typenames(254, "maila", METAQUESTIONONLY
);
652 insert_into_typenames(255, "any", METAQUESTIONONLY
);
654 fprintf(stdout
, "\ntypedef struct {\n");
655 fprintf(stdout
, "\tconst char *name;\n");
656 fprintf(stdout
, "\tunsigned int flags;\n");
657 fprintf(stdout
, "} typeattr_t;\n");
658 fprintf(stdout
, "static typeattr_t typeattr[] = {\n");
659 for (i
= 0; i
<= maxtype
; i
++) {
660 ttn
= find_typename(i
);
663 if (i
>= 128 && i
< 255)
664 attrs
= "DNS_RDATATYPEATTR_UNKNOWN | "
665 "DNS_RDATATYPEATTR_META";
667 attrs
= "DNS_RDATATYPEATTR_UNKNOWN";
668 fprintf(stdout
, "\t{ \"TYPE%d\", %s}%s\n",
669 i
, attrs
, PRINT_COMMA(i
));
671 fprintf(stdout
, "\t{ \"%s\", %s }%s\n",
672 upper(ttn
->typename
),
677 fprintf(stdout
, "};\n");
680 * Spit out a quick and dirty hash function. Here,
681 * we walk through the list of type names, and calculate
682 * a hash. This isn't perfect, but it will generate "pretty
683 * good" estimates. Lowercase the characters before
684 * computing in all cases.
686 * Here, walk the list from top to bottom, calculating
687 * the hash (mod 256) for each name.
689 fprintf(stdout
, "#define RDATATYPE_COMPARE(_s, _d, _tn, _n, _tp) \\\n");
690 fprintf(stdout
, "\tdo { \\\n");
691 fprintf(stdout
, "\t\tif (sizeof(_s) - 1 == _n && \\\n"
692 "\t\t strncasecmp(_s,(_tn),"
693 "(sizeof(_s) - 1)) == 0) { \\\n");
694 fprintf(stdout
, "\t\t\tif ((typeattr[_d].flags & "
695 "DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
696 fprintf(stdout
, "\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
697 fprintf(stdout
, "\t\t\t*(_tp) = _d; \\\n");
698 fprintf(stdout
, "\t\t\treturn (ISC_R_SUCCESS); \\\n");
699 fprintf(stdout
, "\t\t} \\\n");
700 fprintf(stdout
, "\t} while (0)\n\n");
702 fprintf(stdout
, "#define RDATATYPE_FROMTEXT_SW(_hash,"
703 "_typename,_length,_typep) \\\n");
704 fprintf(stdout
, "\tswitch (_hash) { \\\n");
705 for (i
= 0; i
<= maxtype
; i
++) {
706 ttn
= find_typename(i
);
711 * Skip entries we already processed.
713 if (ttn
->sorted
!= 0)
716 hash
= HASH(ttn
->typename
);
717 fprintf(stdout
, "\t\tcase %u: \\\n", hash
);
720 * Find all other entries that happen to match
723 for (j
= 0; j
<= maxtype
; j
++) {
724 ttn2
= find_typename(j
);
727 if (hash
== HASH(ttn2
->typename
)) {
728 fprintf(stdout
, "\t\t\tRDATATYPE_COMPARE"
730 "_typename, _length, _typep); \\\n",
731 ttn2
->typename
, ttn2
->type
);
735 fprintf(stdout
, "\t\t\tbreak; \\\n");
737 fprintf(stdout
, "\t}\n");
739 fputs("#endif /* DNS_CODE_H */\n", stdout
);
740 } else if (type_enum
) {
743 fprintf(stdout
, "#ifndef DNS_ENUMTYPE_H\n");
744 fprintf(stdout
, "#define DNS_ENUMTYPE_H 1\n\n");
746 fprintf(stdout
, "enum {\n");
747 fprintf(stdout
, "\tdns_rdatatype_none = 0,\n");
750 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
751 if (tt
->type
!= lasttype
)
753 "\tdns_rdatatype_%s = %d,\n",
754 funname(tt
->typename
, buf1
),
755 lasttype
= tt
->type
);
757 fprintf(stdout
, "\tdns_rdatatype_ixfr = 251,\n");
758 fprintf(stdout
, "\tdns_rdatatype_axfr = 252,\n");
759 fprintf(stdout
, "\tdns_rdatatype_mailb = 253,\n");
760 fprintf(stdout
, "\tdns_rdatatype_maila = 254,\n");
761 fprintf(stdout
, "\tdns_rdatatype_any = 255\n");
763 fprintf(stdout
, "};\n\n");
765 fprintf(stdout
, "#define dns_rdatatype_none\t"
766 "((dns_rdatatype_t)dns_rdatatype_none)\n");
768 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
769 if (tt
->type
!= lasttype
) {
770 s
= funname(tt
->typename
, buf1
);
772 "#define dns_rdatatype_%s\t%s"
773 "((dns_rdatatype_t)dns_rdatatype_%s)"
775 s
, strlen(s
) < 2U ? "\t" : "", s
);
779 fprintf(stdout
, "#define dns_rdatatype_ixfr\t"
780 "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
781 fprintf(stdout
, "#define dns_rdatatype_axfr\t"
782 "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
783 fprintf(stdout
, "#define dns_rdatatype_mailb\t"
784 "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
785 fprintf(stdout
, "#define dns_rdatatype_maila\t"
786 "((dns_rdatatype_t)dns_rdatatype_maila)\n");
787 fprintf(stdout
, "#define dns_rdatatype_any\t"
788 "((dns_rdatatype_t)dns_rdatatype_any)\n");
790 fprintf(stdout
, "\n#endif /* DNS_ENUMTYPE_H */\n");
792 } else if (class_enum
) {
796 fprintf(stdout
, "#ifndef DNS_ENUMCLASS_H\n");
797 fprintf(stdout
, "#define DNS_ENUMCLASS_H 1\n\n");
799 fprintf(stdout
, "enum {\n");
801 fprintf(stdout
, "\tdns_rdataclass_reserved0 = 0,\n");
802 fprintf(stdout
, "#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
803 "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
805 #define PRINTCLASS(name, num) \
807 s = funname(name, buf1); \
809 fprintf(stdout, "\tdns_rdataclass_%s = %d%s\n", s, classnum, \
810 classnum != 255 ? "," : ""); \
811 fprintf(stdout, "#define dns_rdataclass_%s\t" \
812 "((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
815 for (cc
= classes
; cc
!= NULL
; cc
= cc
->next
) {
816 if (cc
->rdclass
== 4) {
818 PRINTCLASS("chaos", 3);
820 } else if (cc
->rdclass
== 255) {
821 PRINTCLASS("none", 254);
823 PRINTCLASS(cc
->classname
, cc
->rdclass
);
828 fprintf(stdout
, "};\n\n");
829 fprintf(stdout
, "#endif /* DNS_ENUMCLASS_H */\n");
830 } else if (structs
) {
831 if (prefix
!= NULL
) {
832 if ((fd
= fopen(prefix
,"r")) != NULL
) {
833 while (fgets(buf
, sizeof buf
, fd
) != NULL
)
838 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
839 sprintf(buf
, "%s/%s_%d.h",
840 tt
->dirname
, tt
->typename
, tt
->type
);
841 if ((fd
= fopen(buf
,"r")) != NULL
) {
842 while (fgets(buf
, sizeof buf
, fd
) != NULL
)
847 if (suffix
!= NULL
) {
848 if ((fd
= fopen(suffix
,"r")) != NULL
) {
849 while (fgets(buf
, sizeof buf
, fd
) != NULL
)
855 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
856 fprintf(stdout
, "%s:\t%s/%s_%d.h\n", file
,
857 tt
->dirname
, tt
->typename
, tt
->type
);
860 if (ferror(stdout
) != 0)