gen.c revision 69fe9aaafdd6a141610e86a777d325db75422070
/*
* Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1998-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.75 2005/04/29 00:22:46 marka Exp $ */
/*! \file */
#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 FROMTEXTARGS "rdclass, type, lexer, origin, options, target, callbacks"
#define FROMTEXTCLASS "rdclass"
#define FROMTEXTTYPE "type"
#define FROMTEXTDEF "result = DNS_R_UNKNOWN"
#define TOTEXTARGS "rdata, tctx, target"
#define TOTEXTCLASS "rdata->rdclass"
#define TOTEXTTYPE "rdata->type"
#define TOTEXTDEF "use_default = ISC_TRUE"
#define FROMWIREARGS "rdclass, type, source, dctx, options, target"
#define FROMWIRECLASS "rdclass"
#define FROMWIRETYPE "type"
#define FROMWIREDEF "use_default = ISC_TRUE"
#define TOWIREARGS "rdata, cctx, target"
#define TOWIRECLASS "rdata->rdclass"
#define TOWIRETYPE "rdata->type"
#define TOWIREDEF "use_default = ISC_TRUE"
#define FROMSTRUCTARGS "rdclass, type, source, target"
#define FROMSTRUCTCLASS "rdclass"
#define FROMSTRUCTTYPE "type"
#define FROMSTRUCTDEF "use_default = ISC_TRUE"
#define TOSTRUCTARGS "rdata, target, mctx"
#define TOSTRUCTCLASS "rdata->rdclass"
#define TOSTRUCTTYPE "rdata->type"
#define TOSTRUCTDEF "use_default = ISC_TRUE"
#define FREESTRUCTARGS "source"
#define FREESTRUCTCLASS "common->rdclass"
#define FREESTRUCTTYPE "common->rdtype"
#define FREESTRUCTDEF NULL
#define COMPAREARGS "rdata1, rdata2"
#define COMPARECLASS "rdata1->rdclass"
#define COMPARETYPE "rdata1->type"
#define COMPAREDEF "use_default = ISC_TRUE"
#define ADDITIONALDATAARGS "rdata, add, arg"
#define ADDITIONALDATACLASS "rdata->rdclass"
#define ADDITIONALDATATYPE "rdata->type"
#define ADDITIONALDATADEF "use_default = ISC_TRUE"
#define DIGESTARGS "rdata, digest, arg"
#define DIGESTCLASS "rdata->rdclass"
#define DIGESTTYPE "rdata->type"
#define DIGESTDEF "use_default = ISC_TRUE"
#define CHECKOWNERARGS "name, rdclass, type, wildcard"
#define CHECKOWNERCLASS "rdclass"
#define CHECKOWNERTYPE "type"
#define CHECKOWNERDEF "result = ISC_TRUE"
#define CHECKNAMESARGS "rdata, owner, bad"
#define CHECKNAMESCLASS "rdata->rdclass"
#define CHECKNAMESTYPE "rdata->type"
#define CHECKNAMESDEF "result = ISC_TRUE"
const char copyright[] =
"/*\n"
" * Copyright (C) 2004%s Internet Systems Consortium, Inc. (\"ISC\")\n"
" * Copyright (C) 1998-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH\n"
" * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
" * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
" * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
" * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE\n"
" * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
" * PERFORMANCE OF THIS SOFTWARE.\n"
" */\n"
"\n"
"/***************\n"
" ***************\n"
" *************** THIS FILE IS AUTOMATICALLY GENERATED BY gen.c.\n"
" *************** DO NOT EDIT!\n"
" ***************\n"
" ***************/\n"
"\n"
"/*! \\file */\n"
"\n";
#define TYPENAMES 256
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;
int type;
int maxtype = -1;
char *
upper(char *);
char *
funname(const char *, char *);
void
doswitch(const char *, const char *, const char *, const char *,
const char *, const char *);
void
dodecl(char *, char *, char *);
void
add(int, const char *, int, const char *, const char *);
void
sd(int, const char *, const char *, char);
void
insert_into_typenames(int, const char *, const 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;
const 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",
}
static struct ttnam *
find_typename(int type) {
int i;
for (i = 0; i < TYPENAMES; i++) {
return (&typenames[i]);
}
return (NULL);
}
void
int c, i;
char tmp[256];
for (i = 0; i < TYPENAMES; i++) {
"Error: type %d has two names: %s, %s\n",
exit(1);
}
}
exit(1);
}
typename);
exit(1);
}
while (c > 0) {
c--;
}
}
exit(1);
}
exit(1);
}
}
void
const char *dirname)
{
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;
if (n == 0) {
exit(1);
}
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 depend = 0;
int c, i, j;
char buf1[11];
char filetype = 'c';
for (i = 0; i < TYPENAMES; i++)
switch (c) {
case 'c':
code = 0;
depend = 0;
type_enum = 0;
class_enum = 1;
filetype = 'c';
structs = 0;
break;
case 'd':
code = 0;
depend = 1;
class_enum = 0;
type_enum = 0;
structs = 0;
filetype = 'h';
break;
case 't':
code = 0;
depend = 0;
class_enum = 0;
type_enum = 1;
filetype = 'c';
structs = 0;
break;
case 'i':
code = 0;
depend = 0;
class_enum = 0;
type_enum = 0;
structs = 1;
filetype = 'h';
break;
case 's':
break;
case 'F':
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.
*/
/*
* 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.
*/
"\t\t strncasecmp(_s,(_tn),"
"(sizeof(_s) - 1)) == 0) { \\\n");
"DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
"_typename,_length,_typep) \\\n");
for (i = 0; i <= maxtype; i++) {
ttn = find_typename(i);
continue;
/*
* Skip entries we already processed.
*/
continue;
/*
* Find all other entries that happen to match
* this hash.
*/
for (j = 0; j <= maxtype; j++) {
ttn2 = find_typename(j);
continue;
"(\"%s\", %u, "
"_typename, _length, _typep); \\\n",
}
}
}
for (i = 0; i <= maxtype; i++) {
ttn = find_typename(i);
continue;
}
for (i = 0; i <= maxtype; i++) {
ttn = find_typename(i);
continue;
"(str_totext(\"%s\", target)); \\\n",
}
} else if (type_enum) {
char *s;
lasttype = 0;
"\tdns_rdatatype_%s = %d,\n",
"((dns_rdatatype_t)dns_rdatatype_none)\n");
"#define dns_rdatatype_%s\t%s"
"((dns_rdatatype_t)dns_rdatatype_%s)"
"\n",
}
"((dns_rdatatype_t)dns_rdatatype_ixfr)\n");
"((dns_rdatatype_t)dns_rdatatype_axfr)\n");
"((dns_rdatatype_t)dns_rdatatype_mailb)\n");
"((dns_rdatatype_t)dns_rdatatype_maila)\n");
"((dns_rdatatype_t)dns_rdatatype_any)\n");
} else if (class_enum) {
char *s;
int classnum;
"((dns_rdataclass_t)dns_rdataclass_reserved0)\n");
do { \
"((dns_rdataclass_t)dns_rdataclass_%s)\n", s, s); \
} while (0)
}
}
} else if (structs) {
}
}
}
}
}
}
} else if (depend) {
}
exit(1);
return (0);
}