2 * Copyright (C) 2004-2007 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.81 2007/06/19 23:47:16 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 FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
45 #define FROMTEXTCLASS "rdclass"
46 #define FROMTEXTTYPE "type"
47 #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
49 #define TOTEXTARGS "rdata, tctx, target"
50 #define TOTEXTCLASS "rdata->rdclass"
51 #define TOTEXTTYPE "rdata->type"
52 #define TOTEXTDEF "use_default = ISC_TRUE"
54 #define FROMWIREARGS "rdclass, type, source, dctx, options, target"
55 #define FROMWIRECLASS "rdclass"
56 #define FROMWIRETYPE "type"
57 #define FROMWIREDEF "use_default = ISC_TRUE"
59 #define TOWIREARGS "rdata, cctx, target"
60 #define TOWIRECLASS "rdata->rdclass"
61 #define TOWIRETYPE "rdata->type"
62 #define TOWIREDEF "use_default = ISC_TRUE"
64 #define FROMSTRUCTARGS "rdclass, type, source, target"
65 #define FROMSTRUCTCLASS "rdclass"
66 #define FROMSTRUCTTYPE "type"
67 #define FROMSTRUCTDEF "use_default = ISC_TRUE"
69 #define TOSTRUCTARGS "rdata, target, mctx"
70 #define TOSTRUCTCLASS "rdata->rdclass"
71 #define TOSTRUCTTYPE "rdata->type"
72 #define TOSTRUCTDEF "use_default = ISC_TRUE"
74 #define FREESTRUCTARGS "source"
75 #define FREESTRUCTCLASS "common->rdclass"
76 #define FREESTRUCTTYPE "common->rdtype"
77 #define FREESTRUCTDEF NULL
79 #define COMPAREARGS "rdata1, rdata2"
80 #define COMPARECLASS "rdata1->rdclass"
81 #define COMPARETYPE "rdata1->type"
82 #define COMPAREDEF "use_default = ISC_TRUE"
84 #define ADDITIONALDATAARGS "rdata, add, arg"
85 #define ADDITIONALDATACLASS "rdata->rdclass"
86 #define ADDITIONALDATATYPE "rdata->type"
87 #define ADDITIONALDATADEF "use_default = ISC_TRUE"
89 #define DIGESTARGS "rdata, digest, arg"
90 #define DIGESTCLASS "rdata->rdclass"
91 #define DIGESTTYPE "rdata->type"
92 #define DIGESTDEF "use_default = ISC_TRUE"
94 #define CHECKOWNERARGS "name, rdclass, type, wildcard"
95 #define CHECKOWNERCLASS "rdclass"
96 #define CHECKOWNERTYPE "type"
97 #define CHECKOWNERDEF "result = ISC_TRUE"
99 #define CHECKNAMESARGS "rdata, owner, bad"
100 #define CHECKNAMESCLASS "rdata->rdclass"
101 #define CHECKNAMESTYPE "rdata->type"
102 #define CHECKNAMESDEF "result = ISC_TRUE"
104 const char copyright
[] =
106 " * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
107 " * Copyright (C) 1998-2003 Internet Software Consortium.\n"
109 " * Permission to use, copy, modify, and distribute this software for any\n"
110 " * purpose with or without fee is hereby granted, provided that the above\n"
111 " * copyright notice and this permission notice appear in all copies.\n"
113 " * THE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH\n"
114 " * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
115 " * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
116 " * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
117 " * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
118 " * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
119 " * PERFORMANCE OF THIS SOFTWARE.\n"
124 " *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
125 " *************** DO NOT EDIT!\n"
127 " ***************/\n"
132 #define TYPENAMES 256
146 char dirname
[256]; /* XXX Should be max path length */
155 } typenames
[TYPENAMES
];
162 funname(const char *, char *);
164 doswitch(const char *, const char *, const char *, const char *,
165 const char *, const char *);
167 dodecl(char *, char *, char *);
169 add(int, const char *, int, const char *, const char *);
171 sd(int, const char *, const char *, char);
173 insert_into_typenames(int, const char *, const char *);
176 * If you use more than 10 of these in, say, a printf(), you'll have problems.
180 static int buf_to_use
= 0;
181 static char buf
[10][256];
192 while ((c
= (*s
++) & 0xff))
193 *b
++ = islower(c
) ? toupper(c
) : c
;
195 return (buf
[buf_to_use
]);
199 funname(const char *s
, char *buf
) {
204 *b
++ = (c
== '-') ? '_' : c
;
211 doswitch(const char *name
, const char *function
, const char *args
,
212 const char *tsw
, const char *csw
, const char *res
)
218 char buf1
[11], buf2
[11];
219 const char *result
= " result =";
224 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
226 fprintf(stdout
, "\n#define %s \\\n", name
);
227 fprintf(stdout
, "\tswitch (%s) { \\\n" /*}*/, tsw
);
230 if (tt
->type
!= lasttype
&& subswitch
) {
232 fprintf(stdout
, "\t\tdefault: break; \\\n");
235 "\t\tdefault: %s; break; \\\n", res
);
236 fputs(/*{*/ "\t\t} \\\n", stdout
);
237 fputs("\t\tbreak; \\\n", stdout
);
240 if (tt
->rdclass
&& tt
->type
!= lasttype
) {
241 fprintf(stdout
, "\tcase %d: switch (%s) { \\\n" /*}*/,
245 if (tt
->rdclass
== 0)
247 "\tcase %d:%s %s_%s(%s); break;",
248 tt
->type
, result
, function
,
249 funname(tt
->typename
, buf1
), args
);
252 "\t\tcase %d:%s %s_%s_%s(%s); break;",
253 tt
->rdclass
, result
, function
,
254 funname(tt
->classname
, buf1
),
255 funname(tt
->typename
, buf2
), args
);
256 fputs(" \\\n", stdout
);
261 fprintf(stdout
, "\t\tdefault: break; \\\n");
263 fprintf(stdout
, "\t\tdefault: %s; break; \\\n", res
);
264 fputs(/*{*/ "\t\t} \\\n", stdout
);
265 fputs("\t\tbreak; \\\n", stdout
);
269 fprintf(stdout
, "\n#define %s\n", name
);
271 fprintf(stdout
, "\n#define %s %s;\n", name
, res
);
274 fprintf(stdout
, "\tdefault: break; \\\n");
276 fprintf(stdout
, "\tdefault: %s; break; \\\n", res
);
277 fputs(/*{*/ "\t}\n", stdout
);
282 dodecl(char *type
, char *function
, char *args
) {
284 char buf1
[11], buf2
[11];
287 for (tt
= types
; tt
; tt
= tt
->next
)
290 "static inline %s %s_%s_%s(%s);\n",
292 funname(tt
->classname
, buf1
),
293 funname(tt
->typename
, buf2
), args
);
296 "static inline %s %s_%s(%s);\n",
298 funname(tt
->typename
, buf1
), args
);
301 static struct ttnam
*
302 find_typename(int type
) {
305 for (i
= 0; i
< TYPENAMES
; i
++) {
306 if (typenames
[i
].typename
[0] != 0 &&
307 typenames
[i
].type
== type
)
308 return (&typenames
[i
]);
314 insert_into_typenames(int type
, const char *typename
, const char *attr
) {
315 struct ttnam
*ttn
= NULL
;
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 if (strlen(typename
) > sizeof(ttn
->typename
) - 1) {
337 fprintf(stderr
, "Error: type name %s is too long\n",
341 strcpy(ttn
->typename
, typename
);
344 strcpy(ttn
->macroname
, ttn
->typename
);
345 c
= strlen(ttn
->macroname
);
347 if (ttn
->macroname
[c
- 1] == '-')
348 ttn
->macroname
[c
- 1] = '_';
353 sprintf(tmp
, "RRTYPE_%s_ATTRIBUTES", upper(ttn
->macroname
));
357 if (ttn
->attr
[0] != 0 && strcmp(attr
, ttn
->attr
) != 0) {
358 fprintf(stderr
, "Error: type %d has different attributes: "
359 "%s, %s\n", type
, ttn
->attr
, attr
);
363 if (strlen(attr
) > sizeof(ttn
->attr
) - 1) {
364 fprintf(stderr
, "Error: attr (%s) [name %s] is too long\n",
368 strcpy(ttn
->attr
, attr
);
375 add(int rdclass
, const char *classname
, int type
, const char *typename
,
378 struct tt
*newtt
= (struct tt
*)malloc(sizeof(*newtt
));
379 struct tt
*tt
, *oldtt
;
381 struct cc
*cc
, *oldcc
;
383 insert_into_typenames(type
, typename
, NULL
);
386 fprintf(stderr
, "malloc() failed\n");
391 newtt
->rdclass
= rdclass
;
393 strcpy(newtt
->classname
, classname
);
394 strcpy(newtt
->typename
, typename
);
395 strcpy(newtt
->dirname
, dirname
);
400 while ((tt
!= NULL
) && (tt
->type
< type
)) {
405 while ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
< rdclass
)) {
406 if (strcmp(tt
->typename
, typename
) != 0)
412 if ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
== rdclass
))
422 * Do a class switch for this type.
427 newcc
= (struct cc
*)malloc(sizeof(*newcc
));
428 newcc
->rdclass
= rdclass
;
429 strcpy(newcc
->classname
, classname
);
433 while ((cc
!= NULL
) && (cc
->rdclass
< rdclass
)) {
438 if ((cc
!= NULL
) && cc
->rdclass
== rdclass
) {
451 sd(int rdclass
, const char *classname
, const char *dirname
, char filetype
) {
452 char buf
[sizeof("0123456789_65535.h")];
453 char fmt
[sizeof("%10[-0-9a-z]_%d.h")];
458 if (!start_directory(dirname
, &dir
))
461 sprintf(fmt
,"%s%c", "%10[-0-9a-z]_%d.", filetype
);
462 while (next_file(&dir
)) {
463 if (sscanf(dir
.filename
, fmt
, typename
, &type
) != 2)
465 if ((type
> 65535) || (type
< 0))
468 sprintf(buf
, "%s_%d.%c", typename
, type
, filetype
);
469 if (strcmp(buf
, dir
.filename
) != 0)
471 add(rdclass
, classname
, type
, typename
, dirname
);
484 fprintf(stderr
, "n == 0?\n");
487 a
= tolower((unsigned char)string
[0]);
488 b
= tolower((unsigned char)string
[n
- 1]);
490 return ((a
+ n
) * b
) % 256;
494 main(int argc
, char **argv
) {
495 char buf
[256]; /* XXX Should be max path length */
496 char srcdir
[256]; /* XXX Should be max path length */
501 struct ttnam
*ttn
, *ttn2
;
521 for (i
= 0; i
< TYPENAMES
; i
++)
522 memset(&typenames
[i
], 0, sizeof(typenames
[i
]));
525 while ((c
= isc_commandline_parse(argc
, argv
, "cdits:F:P:S:")) != -1)
560 sprintf(srcdir
, "%s/", isc_commandline_argument
);
563 file
= isc_commandline_argument
;
566 prefix
= isc_commandline_argument
;
569 suffix
= isc_commandline_argument
;
575 sprintf(buf
, "%srdata", srcdir
);
577 if (!start_directory(buf
, &dir
))
580 while (next_file(&dir
)) {
581 if (sscanf(dir
.filename
, "%10[0-9a-z]_%d",
582 classname
, &rdclass
) != 2)
584 if ((rdclass
> 65535) || (rdclass
< 0))
587 sprintf(buf
, "%srdata/%s_%d", srcdir
, classname
, rdclass
);
588 if (strcmp(buf
+ 6 + strlen(srcdir
), dir
.filename
) != 0)
590 sd(rdclass
, classname
, buf
, filetype
);
593 sprintf(buf
, "%srdata/generic", srcdir
);
594 sd(0, "", buf
, filetype
);
596 if (time(&now
) != -1) {
597 if ((tm
= localtime(&now
)) != NULL
&& tm
->tm_year
> 104)
598 sprintf(year
, "-%d", tm
->tm_year
+ 1900);
604 if (!depend
) fprintf(stdout
, copyright
, year
);
607 fputs("#ifndef DNS_CODE_H\n", stdout
);
608 fputs("#define DNS_CODE_H 1\n\n", stdout
);
610 fputs("#include <isc/boolean.h>\n", stdout
);
611 fputs("#include <isc/result.h>\n\n", stdout
);
612 fputs("#include <dns/name.h>\n\n", stdout
);
614 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
615 fprintf(stdout
, "#include \"%s/%s_%d.c\"\n",
616 tt
->dirname
, tt
->typename
, tt
->type
);
618 fputs("\n\n", stdout
);
620 doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS
,
621 FROMTEXTTYPE
, FROMTEXTCLASS
, FROMTEXTDEF
);
622 doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS
,
623 TOTEXTTYPE
, TOTEXTCLASS
, TOTEXTDEF
);
624 doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS
,
625 FROMWIRETYPE
, FROMWIRECLASS
, FROMWIREDEF
);
626 doswitch("TOWIRESWITCH", "towire", TOWIREARGS
,
627 TOWIRETYPE
, TOWIRECLASS
, TOWIREDEF
);
628 doswitch("COMPARESWITCH", "compare", COMPAREARGS
,
629 COMPARETYPE
, COMPARECLASS
, COMPAREDEF
);
630 doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS
,
631 FROMSTRUCTTYPE
, FROMSTRUCTCLASS
, FROMSTRUCTDEF
);
632 doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS
,
633 TOSTRUCTTYPE
, TOSTRUCTCLASS
, TOSTRUCTDEF
);
634 doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS
,
635 FREESTRUCTTYPE
, FREESTRUCTCLASS
, FREESTRUCTDEF
);
636 doswitch("ADDITIONALDATASWITCH", "additionaldata",
637 ADDITIONALDATAARGS
, ADDITIONALDATATYPE
,
638 ADDITIONALDATACLASS
, ADDITIONALDATADEF
);
639 doswitch("DIGESTSWITCH", "digest",
640 DIGESTARGS
, DIGESTTYPE
,
641 DIGESTCLASS
, DIGESTDEF
);
642 doswitch("CHECKOWNERSWITCH", "checkowner",
643 CHECKOWNERARGS
, CHECKOWNERTYPE
,
644 CHECKOWNERCLASS
, CHECKOWNERDEF
);
645 doswitch("CHECKNAMESSWITCH", "checknames",
646 CHECKNAMESARGS
, CHECKNAMESTYPE
,
647 CHECKNAMESCLASS
, CHECKNAMESDEF
);
650 * From here down, we are processing the rdata names and
654 #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
656 #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
657 "DNS_RDATATYPEATTR_NOTQUESTION"
658 #define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
659 "DNS_RDATATYPEATTR_QUESTIONONLY"
660 #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
663 * Add in reserved/special types. This will let us
664 * sort them without special cases.
666 insert_into_typenames(0, "reserved0", RESERVED
);
667 insert_into_typenames(31, "eid", RESERVED
);
668 insert_into_typenames(32, "nimloc", RESERVED
);
669 insert_into_typenames(34, "atma", RESERVED
);
670 insert_into_typenames(100, "uinfo", RESERVED
);
671 insert_into_typenames(101, "uid", RESERVED
);
672 insert_into_typenames(102, "gid", RESERVED
);
673 insert_into_typenames(251, "ixfr", METAQUESTIONONLY
);
674 insert_into_typenames(252, "axfr", METAQUESTIONONLY
);
675 insert_into_typenames(253, "mailb", METAQUESTIONONLY
);
676 insert_into_typenames(254, "maila", METAQUESTIONONLY
);
677 insert_into_typenames(255, "any", METAQUESTIONONLY
);
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 ((dns_rdatatype_attributes(_d) & "
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 fprintf(stdout
, "#define RDATATYPE_ATTRIBUTE_SW \\\n");
740 fprintf(stdout
, "\tswitch (type) { \\\n");
741 for (i
= 0; i
<= maxtype
; i
++) {
742 ttn
= find_typename(i
);
745 fprintf(stdout
, "\tcase %u: return (%s); \\\n",
746 i
, upper(ttn
->attr
));
748 fprintf(stdout
, "\t}\n");
750 fprintf(stdout
, "#define RDATATYPE_TOTEXT_SW \\\n");
751 fprintf(stdout
, "\tswitch (type) { \\\n");
752 for (i
= 0; i
<= maxtype
; i
++) {
753 ttn
= find_typename(i
);
756 fprintf(stdout
, "\tcase %u: return "
757 "(str_totext(\"%s\", target)); \\\n",
758 i
, upper(ttn
->typename
));
760 fprintf(stdout
, "\t}\n");
762 fputs("#endif /* DNS_CODE_H */\n", stdout
);
763 } else if (type_enum
) {
766 fprintf(stdout
, "#ifndef DNS_ENUMTYPE_H\n");
767 fprintf(stdout
, "#define DNS_ENUMTYPE_H 1\n\n");
769 fprintf(stdout
, "enum {\n");
770 fprintf(stdout
, "\tdns_rdatatype_none = 0,\n");
773 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
774 if (tt
->type
!= lasttype
)
776 "\tdns_rdatatype_%s = %d,\n",
777 funname(tt
->typename
, buf1
),
778 lasttype
= tt
->type
);
780 fprintf(stdout
, "\tdns_rdatatype_ixfr = 251,\n");
781 fprintf(stdout
, "\tdns_rdatatype_axfr = 252,\n");
782 fprintf(stdout
, "\tdns_rdatatype_mailb = 253,\n");
783 fprintf(stdout
, "\tdns_rdatatype_maila = 254,\n");
784 fprintf(stdout
, "\tdns_rdatatype_any = 255\n");
786 fprintf(stdout
, "};\n\n");
788 fprintf(stdout
, "#define dns_rdatatype_none\t"
789 "((dns_rdatatype_t)dns_rdatatype_none)\n");
791 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
792 if (tt
->type
!= lasttype
) {
793 s
= funname(tt
->typename
, buf1
);
795 "#define dns_rdatatype_%s\t%s"
796 "((dns_rdatatype_t)dns_rdatatype_%s)"
798 s
, strlen(s
) < 2U ? "\t" : "", s
);
802 fprintf(stdout
, "#define dns_rdatatype_ixfr\t"
803 "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
804 fprintf(stdout
, "#define dns_rdatatype_axfr\t"
805 "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
806 fprintf(stdout
, "#define dns_rdatatype_mailb\t"
807 "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
808 fprintf(stdout
, "#define dns_rdatatype_maila\t"
809 "((dns_rdatatype_t)dns_rdatatype_maila)\n");
810 fprintf(stdout
, "#define dns_rdatatype_any\t"
811 "((dns_rdatatype_t)dns_rdatatype_any)\n");
813 fprintf(stdout
, "\n#endif /* DNS_ENUMTYPE_H */\n");
815 } else if (class_enum
) {
819 fprintf(stdout
, "#ifndef DNS_ENUMCLASS_H\n");
820 fprintf(stdout
, "#define DNS_ENUMCLASS_H 1\n\n");
822 fprintf(stdout
, "enum {\n");
824 fprintf(stdout
, "\tdns_rdataclass_reserved0 = 0,\n");
825 fprintf(stdout
, "#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
826 "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
828 #define PRINTCLASS(name, num) \
830 s = funname(name, buf1); \
832 fprintf(stdout, "\tdns_rdataclass_%s = %d%s\n", s, classnum, \
833 classnum != 255 ? "," : ""); \
834 fprintf(stdout, "#define dns_rdataclass_%s\t" \
835 "((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
838 for (cc
= classes
; cc
!= NULL
; cc
= cc
->next
) {
839 if (cc
->rdclass
== 3)
840 PRINTCLASS("chaos", 3);
841 else if (cc
->rdclass
== 255)
842 PRINTCLASS("none", 254);
843 PRINTCLASS(cc
->classname
, cc
->rdclass
);
848 fprintf(stdout
, "};\n\n");
849 fprintf(stdout
, "#endif /* DNS_ENUMCLASS_H */\n");
850 } else if (structs
) {
851 if (prefix
!= NULL
) {
852 if ((fd
= fopen(prefix
,"r")) != NULL
) {
853 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
858 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
859 sprintf(buf
, "%s/%s_%d.h",
860 tt
->dirname
, tt
->typename
, tt
->type
);
861 if ((fd
= fopen(buf
,"r")) != NULL
) {
862 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
867 if (suffix
!= NULL
) {
868 if ((fd
= fopen(suffix
,"r")) != NULL
) {
869 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
875 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
876 fprintf(stdout
, "%s:\t%s/%s_%d.h\n", file
,
877 tt
->dirname
, tt
->typename
, tt
->type
);
880 if (ferror(stdout
) != 0)