4 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: gen.c,v 1.85 2009/12/04 22:06:37 tbox Exp */
26 * Silence compiler warnings about using strcpy and friends.
28 #define _CRT_SECURE_NO_DEPRECATE 1
31 #include <sys/types.h>
41 #include "gen-win32.h"
46 #define TYPECLASSLEN 21
48 #define FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
49 #define FROMTEXTCLASS "rdclass"
50 #define FROMTEXTTYPE "type"
51 #define FROMTEXTDEF "result = DNS_R_UNKNOWN"
53 #define TOTEXTARGS "rdata, tctx, target"
54 #define TOTEXTCLASS "rdata->rdclass"
55 #define TOTEXTTYPE "rdata->type"
56 #define TOTEXTDEF "use_default = ISC_TRUE"
58 #define FROMWIREARGS "rdclass, type, source, dctx, options, target"
59 #define FROMWIRECLASS "rdclass"
60 #define FROMWIRETYPE "type"
61 #define FROMWIREDEF "use_default = ISC_TRUE"
63 #define TOWIREARGS "rdata, cctx, target"
64 #define TOWIRECLASS "rdata->rdclass"
65 #define TOWIRETYPE "rdata->type"
66 #define TOWIREDEF "use_default = ISC_TRUE"
68 #define FROMSTRUCTARGS "rdclass, type, source, target"
69 #define FROMSTRUCTCLASS "rdclass"
70 #define FROMSTRUCTTYPE "type"
71 #define FROMSTRUCTDEF "use_default = ISC_TRUE"
73 #define TOSTRUCTARGS "rdata, target, mctx"
74 #define TOSTRUCTCLASS "rdata->rdclass"
75 #define TOSTRUCTTYPE "rdata->type"
76 #define TOSTRUCTDEF "use_default = ISC_TRUE"
78 #define FREESTRUCTARGS "source"
79 #define FREESTRUCTCLASS "common->rdclass"
80 #define FREESTRUCTTYPE "common->rdtype"
81 #define FREESTRUCTDEF NULL
83 #define COMPAREARGS "rdata1, rdata2"
84 #define COMPARECLASS "rdata1->rdclass"
85 #define COMPARETYPE "rdata1->type"
86 #define COMPAREDEF "use_default = ISC_TRUE"
88 #define ADDITIONALDATAARGS "rdata, add, arg"
89 #define ADDITIONALDATACLASS "rdata->rdclass"
90 #define ADDITIONALDATATYPE "rdata->type"
91 #define ADDITIONALDATADEF "use_default = ISC_TRUE"
93 #define DIGESTARGS "rdata, digest, arg"
94 #define DIGESTCLASS "rdata->rdclass"
95 #define DIGESTTYPE "rdata->type"
96 #define DIGESTDEF "use_default = ISC_TRUE"
98 #define CHECKOWNERARGS "name, rdclass, type, wildcard"
99 #define CHECKOWNERCLASS "rdclass"
100 #define CHECKOWNERTYPE "type"
101 #define CHECKOWNERDEF "result = ISC_TRUE"
103 #define CHECKNAMESARGS "rdata, owner, bad"
104 #define CHECKNAMESCLASS "rdata->rdclass"
105 #define CHECKNAMESTYPE "rdata->type"
106 #define CHECKNAMESDEF "result = ISC_TRUE"
108 const char copyright
[] =
110 " * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
111 " * Copyright (C) 1998-2003 Internet Software Consortium.\n"
113 " * Permission to use, copy, modify, and distribute this software for any\n"
114 " * purpose with or without fee is hereby granted, provided that the above\n"
115 " * copyright notice and this permission notice appear in all copies.\n"
117 " * THE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH\n"
118 " * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
119 " * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
120 " * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
121 " * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
122 " * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
123 " * PERFORMANCE OF THIS SOFTWARE.\n"
128 " *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
129 " *************** DO NOT EDIT!\n"
131 " ***************/\n"
136 #define TYPENAMES 256
141 char classname
[TYPECLASSLEN
];
148 char classname
[TYPECLASSLEN
];
149 char typename
[TYPECLASSLEN
];
150 char dirname
[256]; /* XXX Should be max path length */
154 char typename
[TYPECLASSLEN
];
155 char macroname
[TYPECLASSLEN
];
159 } typenames
[TYPENAMES
];
166 funname(const char *, char *);
168 doswitch(const char *, const char *, const char *, const char *,
169 const char *, const char *);
171 dodecl(char *, char *, char *);
173 add(int, const char *, int, const char *, const char *);
175 sd(int, const char *, const char *, char);
177 insert_into_typenames(int, const char *, const char *);
180 * If you use more than 10 of these in, say, a printf(), you'll have problems.
184 static int buf_to_use
= 0;
185 static char buf
[10][256];
196 while ((c
= (*s
++) & 0xff))
197 *b
++ = islower(c
) ? toupper(c
) : c
;
199 return (buf
[buf_to_use
]);
203 funname(const char *s
, char *buf
) {
208 *b
++ = (c
== '-') ? '_' : c
;
215 doswitch(const char *name
, const char *function
, const char *args
,
216 const char *tsw
, const char *csw
, const char *res
)
222 char buf1
[TYPECLASSLEN
], buf2
[TYPECLASSLEN
];
223 const char *result
= " result =";
228 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
230 fprintf(stdout
, "\n#define %s \\\n", name
);
231 fprintf(stdout
, "\tswitch (%s) { \\\n" /*}*/, tsw
);
234 if (tt
->type
!= lasttype
&& subswitch
) {
236 fprintf(stdout
, "\t\tdefault: break; \\\n");
239 "\t\tdefault: %s; break; \\\n", res
);
240 fputs(/*{*/ "\t\t} \\\n", stdout
);
241 fputs("\t\tbreak; \\\n", stdout
);
244 if (tt
->rdclass
&& tt
->type
!= lasttype
) {
245 fprintf(stdout
, "\tcase %d: switch (%s) { \\\n" /*}*/,
249 if (tt
->rdclass
== 0)
251 "\tcase %d:%s %s_%s(%s); break;",
252 tt
->type
, result
, function
,
253 funname(tt
->typename
, buf1
), args
);
256 "\t\tcase %d:%s %s_%s_%s(%s); break;",
257 tt
->rdclass
, result
, function
,
258 funname(tt
->classname
, buf1
),
259 funname(tt
->typename
, buf2
), args
);
260 fputs(" \\\n", stdout
);
265 fprintf(stdout
, "\t\tdefault: break; \\\n");
267 fprintf(stdout
, "\t\tdefault: %s; break; \\\n", res
);
268 fputs(/*{*/ "\t\t} \\\n", stdout
);
269 fputs("\t\tbreak; \\\n", stdout
);
273 fprintf(stdout
, "\n#define %s\n", name
);
275 fprintf(stdout
, "\n#define %s %s;\n", name
, res
);
278 fprintf(stdout
, "\tdefault: break; \\\n");
280 fprintf(stdout
, "\tdefault: %s; break; \\\n", res
);
281 fputs(/*{*/ "\t}\n", stdout
);
286 dodecl(char *type
, char *function
, char *args
) {
288 char buf1
[TYPECLASSLEN
], buf2
[TYPECLASSLEN
];
291 for (tt
= types
; tt
; tt
= tt
->next
)
294 "static inline %s %s_%s_%s(%s);\n",
296 funname(tt
->classname
, buf1
),
297 funname(tt
->typename
, buf2
), args
);
300 "static inline %s %s_%s(%s);\n",
302 funname(tt
->typename
, buf1
), args
);
305 static struct ttnam
*
306 find_typename(int type
) {
309 for (i
= 0; i
< TYPENAMES
; i
++) {
310 if (typenames
[i
].typename
[0] != 0 &&
311 typenames
[i
].type
== type
)
312 return (&typenames
[i
]);
318 insert_into_typenames(int type
, const char *typename
, const char *attr
) {
319 struct ttnam
*ttn
= NULL
;
323 for (i
= 0; i
< TYPENAMES
; i
++) {
324 if (typenames
[i
].typename
[0] != 0 &&
325 typenames
[i
].type
== type
&&
326 strcmp(typename
, typenames
[i
].typename
) != 0) {
328 "Error: type %d has two names: %s, %s\n",
329 type
, typenames
[i
].typename
, typename
);
332 if (typenames
[i
].typename
[0] == 0 && ttn
== NULL
)
336 fprintf(stderr
, "Error: typenames array too small\n");
340 if (strlen(typename
) > sizeof(ttn
->typename
) - 1) {
341 fprintf(stderr
, "Error: type name %s is too long\n",
345 strcpy(ttn
->typename
, typename
);
348 strcpy(ttn
->macroname
, ttn
->typename
);
349 c
= strlen(ttn
->macroname
);
351 if (ttn
->macroname
[c
- 1] == '-')
352 ttn
->macroname
[c
- 1] = '_';
357 sprintf(tmp
, "RRTYPE_%s_ATTRIBUTES", upper(ttn
->macroname
));
361 if (ttn
->attr
[0] != 0 && strcmp(attr
, ttn
->attr
) != 0) {
362 fprintf(stderr
, "Error: type %d has different attributes: "
363 "%s, %s\n", type
, ttn
->attr
, attr
);
367 if (strlen(attr
) > sizeof(ttn
->attr
) - 1) {
368 fprintf(stderr
, "Error: attr (%s) [name %s] is too long\n",
372 strcpy(ttn
->attr
, attr
);
379 add(int rdclass
, const char *classname
, int type
, const char *typename
,
382 struct tt
*newtt
= (struct tt
*)malloc(sizeof(*newtt
));
383 struct tt
*tt
, *oldtt
;
385 struct cc
*cc
, *oldcc
;
387 insert_into_typenames(type
, typename
, NULL
);
390 fprintf(stderr
, "malloc() failed\n");
395 newtt
->rdclass
= rdclass
;
397 strcpy(newtt
->classname
, classname
);
398 strcpy(newtt
->typename
, typename
);
399 if (strncmp(dirname
, "./", 2) == 0)
401 strcpy(newtt
->dirname
, dirname
);
406 while ((tt
!= NULL
) && (tt
->type
< type
)) {
411 while ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
< rdclass
)) {
412 if (strcmp(tt
->typename
, typename
) != 0)
418 if ((tt
!= NULL
) && (tt
->type
== type
) && (tt
->rdclass
== rdclass
))
428 * Do a class switch for this type.
433 newcc
= (struct cc
*)malloc(sizeof(*newcc
));
434 newcc
->rdclass
= rdclass
;
435 strcpy(newcc
->classname
, classname
);
439 while ((cc
!= NULL
) && (cc
->rdclass
< rdclass
)) {
444 if ((cc
!= NULL
) && cc
->rdclass
== rdclass
) {
457 sd(int rdclass
, const char *classname
, const char *dirname
, char filetype
) {
458 char buf
[sizeof("01234567890123456789_65535.h")];
459 char fmt
[sizeof("%20[-0-9a-z]_%d.h")];
461 char typename
[TYPECLASSLEN
];
464 if (!start_directory(dirname
, &dir
))
467 sprintf(fmt
,"%s%c", "%20[-0-9a-z]_%d.", filetype
);
468 while (next_file(&dir
)) {
469 if (sscanf(dir
.filename
, fmt
, typename
, &type
) != 2)
471 if ((type
> 65535) || (type
< 0))
474 sprintf(buf
, "%s_%d.%c", typename
, type
, filetype
);
475 if (strcmp(buf
, dir
.filename
) != 0)
477 add(rdclass
, classname
, type
, typename
, dirname
);
490 fprintf(stderr
, "n == 0?\n");
493 a
= tolower((unsigned char)string
[0]);
494 b
= tolower((unsigned char)string
[n
- 1]);
496 return ((a
+ n
) * b
) % 256;
500 main(int argc
, char **argv
) {
501 char buf
[256]; /* XXX Should be max path length */
502 char srcdir
[256]; /* XXX Should be max path length */
504 char classname
[TYPECLASSLEN
];
507 struct ttnam
*ttn
, *ttn2
;
519 char buf1
[TYPECLASSLEN
];
527 for (i
= 0; i
< TYPENAMES
; i
++)
528 memset(&typenames
[i
], 0, sizeof(typenames
[i
]));
531 while ((c
= isc_commandline_parse(argc
, argv
, "cdits:F:P:S:")) != -1)
566 sprintf(srcdir
, "%s/", isc_commandline_argument
);
569 file
= isc_commandline_argument
;
572 prefix
= isc_commandline_argument
;
575 suffix
= isc_commandline_argument
;
581 sprintf(buf
, "%srdata", srcdir
);
583 if (!start_directory(buf
, &dir
))
586 while (next_file(&dir
)) {
587 if (sscanf(dir
.filename
, "%10[0-9a-z]_%d",
588 classname
, &rdclass
) != 2)
590 if ((rdclass
> 65535) || (rdclass
< 0))
593 sprintf(buf
, "%srdata/%s_%d", srcdir
, classname
, rdclass
);
594 if (strcmp(buf
+ 6 + strlen(srcdir
), dir
.filename
) != 0)
596 sd(rdclass
, classname
, buf
, filetype
);
599 sprintf(buf
, "%srdata/generic", srcdir
);
600 sd(0, "", buf
, filetype
);
602 if (time(&now
) != -1) {
603 if ((tm
= localtime(&now
)) != NULL
&& tm
->tm_year
> 104)
604 sprintf(year
, "-%d", tm
->tm_year
+ 1900);
610 if (!depend
) fprintf(stdout
, copyright
, year
);
613 fputs("#ifndef DNS_CODE_H\n", stdout
);
614 fputs("#define DNS_CODE_H 1\n\n", stdout
);
616 fputs("#include <isc/boolean.h>\n", stdout
);
617 fputs("#include <isc/result.h>\n\n", stdout
);
618 fputs("#include <dns/name.h>\n\n", stdout
);
620 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
621 fprintf(stdout
, "#include \"%s/%s_%d.c\"\n",
622 tt
->dirname
, tt
->typename
, tt
->type
);
624 fputs("\n\n", stdout
);
626 doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS
,
627 FROMTEXTTYPE
, FROMTEXTCLASS
, FROMTEXTDEF
);
628 doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS
,
629 TOTEXTTYPE
, TOTEXTCLASS
, TOTEXTDEF
);
630 doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS
,
631 FROMWIRETYPE
, FROMWIRECLASS
, FROMWIREDEF
);
632 doswitch("TOWIRESWITCH", "towire", TOWIREARGS
,
633 TOWIRETYPE
, TOWIRECLASS
, TOWIREDEF
);
634 doswitch("COMPARESWITCH", "compare", COMPAREARGS
,
635 COMPARETYPE
, COMPARECLASS
, COMPAREDEF
);
636 doswitch("CASECOMPARESWITCH", "casecompare", COMPAREARGS
,
637 COMPARETYPE
, COMPARECLASS
, COMPAREDEF
);
638 doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS
,
639 FROMSTRUCTTYPE
, FROMSTRUCTCLASS
, FROMSTRUCTDEF
);
640 doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS
,
641 TOSTRUCTTYPE
, TOSTRUCTCLASS
, TOSTRUCTDEF
);
642 doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS
,
643 FREESTRUCTTYPE
, FREESTRUCTCLASS
, FREESTRUCTDEF
);
644 doswitch("ADDITIONALDATASWITCH", "additionaldata",
645 ADDITIONALDATAARGS
, ADDITIONALDATATYPE
,
646 ADDITIONALDATACLASS
, ADDITIONALDATADEF
);
647 doswitch("DIGESTSWITCH", "digest",
648 DIGESTARGS
, DIGESTTYPE
,
649 DIGESTCLASS
, DIGESTDEF
);
650 doswitch("CHECKOWNERSWITCH", "checkowner",
651 CHECKOWNERARGS
, CHECKOWNERTYPE
,
652 CHECKOWNERCLASS
, CHECKOWNERDEF
);
653 doswitch("CHECKNAMESSWITCH", "checknames",
654 CHECKNAMESARGS
, CHECKNAMESTYPE
,
655 CHECKNAMESCLASS
, CHECKNAMESDEF
);
658 * From here down, we are processing the rdata names and
662 #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
664 #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
665 "DNS_RDATATYPEATTR_NOTQUESTION"
666 #define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
667 "DNS_RDATATYPEATTR_QUESTIONONLY"
668 #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
671 * Add in reserved/special types. This will let us
672 * sort them without special cases.
674 insert_into_typenames(0, "reserved0", RESERVED
);
675 insert_into_typenames(31, "eid", RESERVED
);
676 insert_into_typenames(32, "nimloc", RESERVED
);
677 insert_into_typenames(34, "atma", RESERVED
);
678 insert_into_typenames(100, "uinfo", RESERVED
);
679 insert_into_typenames(101, "uid", RESERVED
);
680 insert_into_typenames(102, "gid", RESERVED
);
681 insert_into_typenames(251, "ixfr", METAQUESTIONONLY
);
682 insert_into_typenames(252, "axfr", METAQUESTIONONLY
);
683 insert_into_typenames(253, "mailb", METAQUESTIONONLY
);
684 insert_into_typenames(254, "maila", METAQUESTIONONLY
);
685 insert_into_typenames(255, "any", METAQUESTIONONLY
);
688 * Spit out a quick and dirty hash function. Here,
689 * we walk through the list of type names, and calculate
690 * a hash. This isn't perfect, but it will generate "pretty
691 * good" estimates. Lowercase the characters before
692 * computing in all cases.
694 * Here, walk the list from top to bottom, calculating
695 * the hash (mod 256) for each name.
697 fprintf(stdout
, "#define RDATATYPE_COMPARE(_s, _d, _tn, _n, _tp) \\\n");
698 fprintf(stdout
, "\tdo { \\\n");
699 fprintf(stdout
, "\t\tif (sizeof(_s) - 1 == _n && \\\n"
700 "\t\t strncasecmp(_s,(_tn),"
701 "(sizeof(_s) - 1)) == 0) { \\\n");
702 fprintf(stdout
, "\t\t\tif ((dns_rdatatype_attributes(_d) & "
703 "DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
704 fprintf(stdout
, "\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
705 fprintf(stdout
, "\t\t\t*(_tp) = _d; \\\n");
706 fprintf(stdout
, "\t\t\treturn (ISC_R_SUCCESS); \\\n");
707 fprintf(stdout
, "\t\t} \\\n");
708 fprintf(stdout
, "\t} while (0)\n\n");
710 fprintf(stdout
, "#define RDATATYPE_FROMTEXT_SW(_hash,"
711 "_typename,_length,_typep) \\\n");
712 fprintf(stdout
, "\tswitch (_hash) { \\\n");
713 for (i
= 0; i
<= maxtype
; i
++) {
714 ttn
= find_typename(i
);
719 * Skip entries we already processed.
721 if (ttn
->sorted
!= 0)
724 hash
= HASH(ttn
->typename
);
725 fprintf(stdout
, "\t\tcase %u: \\\n", hash
);
728 * Find all other entries that happen to match
731 for (j
= 0; j
<= maxtype
; j
++) {
732 ttn2
= find_typename(j
);
735 if (hash
== HASH(ttn2
->typename
)) {
736 fprintf(stdout
, "\t\t\tRDATATYPE_COMPARE"
738 "_typename, _length, _typep); \\\n",
739 ttn2
->typename
, ttn2
->type
);
743 fprintf(stdout
, "\t\t\tbreak; \\\n");
745 fprintf(stdout
, "\t}\n");
747 fprintf(stdout
, "#define RDATATYPE_ATTRIBUTE_SW \\\n");
748 fprintf(stdout
, "\tswitch (type) { \\\n");
749 for (i
= 0; i
<= maxtype
; i
++) {
750 ttn
= find_typename(i
);
753 fprintf(stdout
, "\tcase %u: return (%s); \\\n",
754 i
, upper(ttn
->attr
));
756 fprintf(stdout
, "\t}\n");
758 fprintf(stdout
, "#define RDATATYPE_TOTEXT_SW \\\n");
759 fprintf(stdout
, "\tswitch (type) { \\\n");
760 for (i
= 0; i
<= maxtype
; i
++) {
761 ttn
= find_typename(i
);
764 fprintf(stdout
, "\tcase %u: return "
765 "(str_totext(\"%s\", target)); \\\n",
766 i
, upper(ttn
->typename
));
768 fprintf(stdout
, "\t}\n");
770 fputs("#endif /* DNS_CODE_H */\n", stdout
);
771 } else if (type_enum
) {
774 fprintf(stdout
, "#ifndef DNS_ENUMTYPE_H\n");
775 fprintf(stdout
, "#define DNS_ENUMTYPE_H 1\n\n");
777 fprintf(stdout
, "enum {\n");
778 fprintf(stdout
, "\tdns_rdatatype_none = 0,\n");
781 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
782 if (tt
->type
!= lasttype
)
784 "\tdns_rdatatype_%s = %d,\n",
785 funname(tt
->typename
, buf1
),
786 lasttype
= tt
->type
);
788 fprintf(stdout
, "\tdns_rdatatype_ixfr = 251,\n");
789 fprintf(stdout
, "\tdns_rdatatype_axfr = 252,\n");
790 fprintf(stdout
, "\tdns_rdatatype_mailb = 253,\n");
791 fprintf(stdout
, "\tdns_rdatatype_maila = 254,\n");
792 fprintf(stdout
, "\tdns_rdatatype_any = 255\n");
794 fprintf(stdout
, "};\n\n");
796 fprintf(stdout
, "#define dns_rdatatype_none\t"
797 "((dns_rdatatype_t)dns_rdatatype_none)\n");
799 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
800 if (tt
->type
!= lasttype
) {
801 s
= funname(tt
->typename
, buf1
);
803 "#define dns_rdatatype_%s\t%s"
804 "((dns_rdatatype_t)dns_rdatatype_%s)"
806 s
, strlen(s
) < 2U ? "\t" : "", s
);
810 fprintf(stdout
, "#define dns_rdatatype_ixfr\t"
811 "((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
812 fprintf(stdout
, "#define dns_rdatatype_axfr\t"
813 "((dns_rdatatype_t)dns_rdatatype_axfr)\n");
814 fprintf(stdout
, "#define dns_rdatatype_mailb\t"
815 "((dns_rdatatype_t)dns_rdatatype_mailb)\n");
816 fprintf(stdout
, "#define dns_rdatatype_maila\t"
817 "((dns_rdatatype_t)dns_rdatatype_maila)\n");
818 fprintf(stdout
, "#define dns_rdatatype_any\t"
819 "((dns_rdatatype_t)dns_rdatatype_any)\n");
821 fprintf(stdout
, "\n#endif /* DNS_ENUMTYPE_H */\n");
823 } else if (class_enum
) {
827 fprintf(stdout
, "#ifndef DNS_ENUMCLASS_H\n");
828 fprintf(stdout
, "#define DNS_ENUMCLASS_H 1\n\n");
830 fprintf(stdout
, "enum {\n");
832 fprintf(stdout
, "\tdns_rdataclass_reserved0 = 0,\n");
833 fprintf(stdout
, "#define dns_rdataclass_reserved0 \\\n\t\t\t\t"
834 "((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
836 #define PRINTCLASS(name, num) \
838 s = funname(name, buf1); \
840 fprintf(stdout, "\tdns_rdataclass_%s = %d%s\n", s, classnum, \
841 classnum != 255 ? "," : ""); \
842 fprintf(stdout, "#define dns_rdataclass_%s\t" \
843 "((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
846 for (cc
= classes
; cc
!= NULL
; cc
= cc
->next
) {
847 if (cc
->rdclass
== 3)
848 PRINTCLASS("chaos", 3);
849 else if (cc
->rdclass
== 255)
850 PRINTCLASS("none", 254);
851 PRINTCLASS(cc
->classname
, cc
->rdclass
);
856 fprintf(stdout
, "};\n\n");
857 fprintf(stdout
, "#endif /* DNS_ENUMCLASS_H */\n");
858 } else if (structs
) {
859 if (prefix
!= NULL
) {
860 if ((fd
= fopen(prefix
,"r")) != NULL
) {
861 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
866 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
) {
867 sprintf(buf
, "%s/%s_%d.h",
868 tt
->dirname
, tt
->typename
, tt
->type
);
869 if ((fd
= fopen(buf
,"r")) != NULL
) {
870 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
875 if (suffix
!= NULL
) {
876 if ((fd
= fopen(suffix
,"r")) != NULL
) {
877 while (fgets(buf
, sizeof(buf
), fd
) != NULL
)
883 for (tt
= types
; tt
!= NULL
; tt
= tt
->next
)
884 fprintf(stdout
, "%s:\t%s/%s_%d.h\n", file
,
885 tt
->dirname
, tt
->typename
, tt
->type
);
888 if (ferror(stdout
) != 0)