gen.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1998-2009, 2012-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#ifdef WIN32
/*
* Silence compiler warnings about using strcpy and friends.
*/
#define _CRT_SECURE_NO_DEPRECATE 1
/*
* We use snprintf which was defined late in Windows even it is in C99.
*/
#if _MSC_VER < 1900
#endif
#endif
#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
if (!(cond)) { \
abort(); \
}
#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"
static 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
#define ATTRIBUTESIZE 256
#define DIRNAMESIZE 256
static struct cc {
int rdclass;
char classname[TYPECLASSBUF];
} *classes;
static struct tt {
int rdclass;
int type;
char classname[TYPECLASSBUF];
char typename[TYPECLASSBUF];
} *types;
static struct ttnam {
char typename[TYPECLASSBUF];
char macroname[TYPECLASSBUF];
char attr[ATTRIBUTESIZE];
unsigned int sorted;
int type;
static int maxtype = -1;
static char *
upper(char *);
static char *
funname(const char *, char *);
static void
doswitch(const char *, const char *, const char *, const char *,
const char *, const char *);
static void
add(int, const char *, int, const char *, const char *);
static void
sd(int, const char *, const char *, char);
static 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.
*/
static 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]);
}
static char *
char *b = buf;
char c;
while ((c = *s++)) {
*b++ = (c == '-') ? '_' : c;
}
*b = '\0';
return (buf);
}
static 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
}
}
static struct ttnam *
find_typename(int type) {
int i;
for (i = 0; i < TYPENAMES; i++) {
return (&typenames[i]);
}
return (NULL);
}
static void
size_t c;
int i, n;
char tmp[256];
for (i = 0; i < TYPENAMES; i++) {
"Error: type %d has two names: %s, %s\n",
exit(1);
}
}
exit(1);
}
/* XXXMUKS: This is redundant due to the INSIST above. */
typename);
exit(1);
}
while (c > 0) {
c--;
}
}
exit(1);
}
exit(1);
}
}
static void
const char *dirname)
{
exit(1);
}
dirname += 2;
}
exit(1);
}
exit(1);
else
/*
* Do a class switch for this type.
*/
if (rdclass == 0)
return;
exit(1);
}
}
return;
}
else
}
static void
char typename[TYPECLASSBUF];
int type, n;
return;
continue;
continue;
continue;
}
end_directory(&dir);
}
static unsigned int
size_t n;
unsigned char a, b;
if (n == 0) {
exit(1);
}
return ((a + n) * b) % 256;
}
int
int rdclass;
char classname[TYPECLASSBUF];
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, n;
char buf1[TYPECLASSBUF];
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':
if (strlen(isc_commandline_argument) >
sizeof("/rdata/_65535_65535")) {
exit(1);
}
break;
case 'F':
break;
case 'P':
break;
case 'S':
break;
case '?':
exit(1);
}
exit(1);
&rdclass) != 2)
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\", %d, "
"_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;
/*
* Remove KEYDATA (65533) from the type to memonic
* translation as it is internal use only. This
* stops the tools from displaying KEYDATA instead
* of TYPE65533.
*/
if (i == 65533U)
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);
}