gen.c revision 94a537e6ab3069f8d34e12e5ea722250be2b89c8
/*
* Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: gen.c,v 1.39 2000/04/25 19:09:06 explorer Exp $ */
#include <config.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef WIN32
#include "gen-win32.h"
#else
#include "gen-unix.h"
#endif
#define FROMTEXTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_lex_t *lexer, dns_name_t *origin, isc_boolean_t downcase, isc_buffer_t *target"
#define FROMTEXTARGS "rdclass, type, lexer, origin, downcase, target"
#define FROMTEXTCLASS "rdclass"
#define FROMTEXTTYPE "type"
#define FROMTEXTDEF "use_default = ISC_TRUE"
#define TOTEXTDECL "dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, isc_buffer_t *target"
#define TOTEXTARGS "rdata, tctx, target"
#define TOTEXTCLASS "rdata->rdclass"
#define TOTEXTTYPE "rdata->type"
#define TOTEXTDEF "use_default = ISC_TRUE"
#define FROMWIREDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *source, dns_decompress_t *dctx, isc_boolean_t downcase, isc_buffer_t *target"
#define FROMWIREARGS "rdclass, type, source, dctx, downcase, target"
#define FROMWIRECLASS "rdclass"
#define FROMWIRETYPE "type"
#define FROMWIREDEF "use_default = ISC_TRUE"
#define TOWIREDECL "dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target"
#define TOWIREARGS "rdata, cctx, target"
#define TOWIRECLASS "rdata->rdclass"
#define TOWIRETYPE "rdata->type"
#define TOWIREDEF "use_default = ISC_TRUE"
#define FROMSTRUCTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source, isc_buffer_t *target"
#define FROMSTRUCTARGS "rdclass, type, source, target"
#define FROMSTRUCTCLASS "rdclass"
#define FROMSTRUCTTYPE "type"
#define FROMSTRUCTDEF "use_default = ISC_TRUE"
#define TOSTRUCTDECL "dns_rdata_t *rdata, void *target, isc_mem_t *mctx"
#define TOSTRUCTARGS "rdata, target, mctx"
#define TOSTRUCTCLASS "rdata->rdclass"
#define TOSTRUCTTYPE "rdata->type"
#define TOSTRUCTDEF "use_default = ISC_TRUE"
#define FREESTRUCTDECL "void *source"
#define FREESTRUCTARGS "source"
#define FREESTRUCTCLASS "common->rdclass"
#define FREESTRUCTTYPE "common->rdtype"
#define FREESTRUCTDEF NULL
#define COMPAREDECL "dns_rdata_t *rdata1, dns_rdata_t *rdata2"
#define COMPAREARGS "rdata1, rdata2"
#define COMPARECLASS "rdata1->rdclass"
#define COMPARETYPE "rdata1->type"
#define COMPAREDEF "use_default = ISC_TRUE"
#define ADDITIONALDATADECL \
"dns_rdata_t *rdata, dns_additionaldatafunc_t add, void *arg"
#define ADDITIONALDATAARGS "rdata, add, arg"
#define ADDITIONALDATACLASS "rdata->rdclass"
#define ADDITIONALDATATYPE "rdata->type"
#define ADDITIONALDATADEF "use_default = ISC_TRUE"
#define DIGESTDECL \
"dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg"
#define DIGESTARGS "rdata, digest, arg"
#define DIGESTCLASS "rdata->rdclass"
#define DIGESTTYPE "rdata->type"
#define DIGESTDEF "use_default = ISC_TRUE"
char copyright[] =
"/*\n\
* Copyright (C) 1998%s Internet Software Consortium.\n\
*\n\
* Permission to use, copy, modify, and distribute this software for any\n\
* purpose with or without fee is hereby granted, provided that the above\n\
* copyright notice and this permission notice appear in all copies.\n\
*\n\
* THE SOFTWARE IS PROVIDED \"AS IS\" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\n\
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\n\
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\n\
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\n\
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\n\
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n\
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\n\
* SOFTWARE.\n\
*/\n\
\n\
/* THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT */\n\
\n";
struct cc {
int rdclass;
char classname[11];
} *classes;
struct tt {
int rdclass;
int type;
char classname[11];
char typename[11];
} *types;
struct ttnam {
char typename[11];
char macroname[11];
char attr[256];
unsigned int sorted;
} typenames[256];
char * upper(char *);
char * funname(char *, char *);
void doswitch(char *, char *, char *, char *, char *, char *);
void dodecl(char *, char *, char *);
void add(int, char *, int, char *, char *);
void sd(int, char *, char *, char);
void insert_into_typenames(int, char *, char *);
/*
* If you use more than 10 of these in, say, a printf(), you'll have problems.
*/
char *
upper(char *s) {
static int buf_to_use = 0;
char *b;
int c;
buf_to_use++;
if (buf_to_use > 9)
buf_to_use = 0;
b = buf[buf_to_use];
memset(b, 0, 256);
while ((c = (*s++) & 0xff))
*b = '\0';
return (buf[buf_to_use]);
}
char *
char *b = buf;
char c;
while ((c = *s++)) {
*b++ = (c == '-') ? '_' : c;
}
*b = '\0';
return (buf);
}
void
{
int first = 1;
int lasttype = 0;
int subswitch = 0;
char *result = " result =";
result = "";
if (first) {
first = 0;
}
else
"\t\tdefault: %s; break; \\\n", res);
subswitch = 0;
}
subswitch = 1;
}
"\tcase %d:%s %s_%s(%s); break;",
else
"\t\tcase %d:%s %s_%s_%s(%s); break;",
}
if (subswitch) {
else
}
if (first) {
else
} else {
else
}
}
void
"static inline %s %s_%s_%s(%s);\n",
else
"static inline %s %s_%s(%s);\n",
}
void
{
int c;
char tmp[256];
typename);
exit(1);
}
exit(1);
}
while (c > 0) {
c--;
}
}
exit(1);
}
exit(1);
}
}
void
exit(1);
}
}
exit(1);
}
exit(1);
else
/* do a class switch for this type */
if (rdclass == 0)
return;
}
return;
}
else
}
void
char buf[sizeof "0123456789_65535.h"];
int type;
char typename[11];
return;
continue;
continue;
continue;
}
end_directory(&dir);
}
static unsigned int
{
unsigned int n;
unsigned char a, b;
return ((a + n) * b) % 256;
}
int
int rdclass;
char classname[11];
unsigned int hash;
char year[11];
int lasttype;
int code = 1;
int class_enum = 0;
int type_enum = 0;
int structs = 0;
int c, i, j;
char buf1[11];
char filetype = 'c';
for (i = 0 ; i <= 255 ; i++)
switch (c) {
case 'c':
code = 0;
type_enum = 0;
class_enum = 1;
filetype = 'c';
structs = 0;
break;
case 't':
code = 0;
class_enum = 0;
type_enum = 1;
filetype = 'c';
structs = 0;
break;
case 'i':
code = 0;
class_enum = 0;
type_enum = 0;
structs = 1;
filetype = 'h';
break;
case 's':
break;
case 'P':
break;
case 'S':
break;
case '?':
exit(1);
}
exit(1);
continue;
continue;
continue;
}
end_directory(&dir);
else
year[0] = 0;
} else
year[0] = 0;
if (code) {
/*
* From here down, we are processing the rdata names and
* attributes.
*/
#define METANOTQUESTION "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION"
#define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_QUESTIONONLY"
#define RESERVED "DNS_RDATATYPEATTR_RESERVED"
/*
* sort them without special cases.
*/
printf("\ntypedef struct {\n");
printf("\tchar *name;\n");
printf("\tunsigned int flags;\n");
printf("} typeattr_t;\n");
printf("static typeattr_t typeattr[] = {\n");
for (i = 0 ; i <= 255 ; i++) {
printf("\t{ \"RRTYPE%d\", "
"DNS_RDATATYPEATTR_UNKNOWN"
"}%s\n", i, PRINT_COMMA(i));
} else {
printf("\t{ \"%s\", %s }%s\n",
PRINT_COMMA(i));
}
}
printf("};\n");
/*
* Run through the list of types and pre-mark the unused
* ones as "sorted" so we simply ignore them below.
*/
for (i = 0 ; i <= 255 ; i++) {
}
/*
* Spit out a quick and dirty hash function. Here,
* we walk through the list of type names, and calculate
* a hash. This isn't perfect, but it will generate "pretty
* good" estimates. Lowercase the characters before
* computing in all cases.
*
* Here, walk the list from top to bottom, calculating
* the hash (mod 256) for each name.
*/
printf("#define RDATATYPE_FROMTEXT_SW(_hash,_typename,_typep) \\\n");
printf("\tswitch (_hash) { \\\n");
for (i = 0 ; i <= 255 ; i++) {
/*
* Skip entries we already processed.
*/
continue;
/*
* Find all other entries that happen to match
* this hash.
*/
for (j = i ; j <= 255 ; j++) {
printf("\t\t\tif (strcasecmp(\"%s\", (_typename)) == 0) { \\\n"
"\t\t\t\tif ((typeattr[%u].flags & DNS_RDATATYPEATTR_RESERVED) != 0) \\\n"
"\t\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n"
"\t\t\t\t*(_typep) = %u; \\\n"
"\t\t\t\treturn (ISC_R_SUCCESS); \\\n"
"\t\t\t} \\\n",
}
}
printf("\t\t\tbreak; \\\n");
}
printf("\t}\n");
/*
* Dump the class names.
*/
} else if (type_enum) {
lasttype = 0;
} else if (class_enum) {
} else if (structs) {
}
}
}
}
}
}
}
exit(1);
return (0);
}