Index: vendor/1.14/gensnmptree/gensnmptree.1 =================================================================== --- vendor/1.14/gensnmptree/gensnmptree.1 (revision 359491) +++ vendor/1.14/gensnmptree/gensnmptree.1 (nonexistent) @@ -1,252 +0,0 @@ -.\" -.\" Copyright (c) 2001-2005 -.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). -.\" All rights reserved. -.\" Copyright (c) 2006,2018 -.\" Hartmut Brandt -.\" All rights reserved. -.\" -.\" Author: Harti Brandt -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Begemot: gensnmptree.1 383 2006-05-30 07:40:49Z brandt_h $ -.\" -.Dd April 2, 2019 -.Dt GENSNMPTREE 1 -.Os -.Sh NAME -.Nm gensnmptree -.Nd "generate C and header files from a MIB description file" -.Sh SYNOPSIS -.Nm -.Op Fl dEeFfhlt -.Op Fl I Ar directory -.Op Fl i Ar infile -.Op Fl p Ar prefix -.Op Ar name Ar ... -.Sh DESCRIPTION -The -.Nm -utility is used to either generate C language tables and header files from -a MIB description or to numeric OIDs from MIB descriptions. -The first form is used only for maintaining the -.Xr bsnmpd 1 -daemon or for module writers. -The second form may be used by SNMP client program writers. -.Pp -If none of the options -.Fl e , -.Fl E -or -.Fl t -are used -.Nm -reads a MIB description from its standard input and creates two files: a -C-file -.Ar prefix Ns tree.c -containing a table used by -.Xr bsnmpd 1 -during PDU processing -and a header file -.Ar prefix Ns tree.h -containing appropriate declarations of the callback functions used in this -table, the table itself and definitions for all enums. -.Pp -The following options are available: -.Bl -tag -width ".Fl E" -.It Fl d -Switch on debugging. -.It Fl E -Extract enumerations and bit constructs. -In this mode the tool emits -a header file that contains for each type given on the command line a -C-enum definition and a preprocessor define that may be used to map -values to strings. -.It Fl e -.Nm -expects MIB variable names (only the last component) on its command line. -It reads a MIB specification from standard input and for each MIB variable -name emits three C preprocessor defines on its standard output: -.Bl -tag -width ".Va OIDLEN_ Ns Ar Name" -.It Va OIDX_ Ns Ar name -This define can be used to initialize a -.Va struct asn_oid -in the following way: -.Pp -.Dl const struct asn_oid oid_sysDescr = OIDX_sysDescr; -.It Va OIDLEN_ Ns Ar name -is the length of the OID. -.It Va OID_ Ns Ar name -is the last component of the OID. -.El -.It Fl F -emit definitions for C-functions includeable in a C-file that do some basic -stuff on enums like value checking and conversion between value and strings. -.It Fl f -emit definitions for inline C-functions that do some basic -stuff on enums like value checking and conversion between value and strings. -.It Fl h -Print a short help page. -.It Fl I Ar directory -Add the named directory to the include path just before the standard include -directories. -.It Fl i Ar infile -Read from the named file instead of standard input. -.It Fl l -Generate local preprocessor includes. -This is used for bootstrapping -.Xr bsnmpd 1 . -.It Fl t -Instead of normal output print the resulting tree. -.It Fl p Ar prefix -Prefix the file names and the table name with -.Ar prefix . -.El -.Sh MIBS -The syntax of the MIB description file can formally be specified as follows: -.Bd -unfilled -offset indent - file := top | top file - - top := tree | typedef | include - - tree := head elements ')' - - entry := head ':' index STRING elements ')' - - leaf := head type STRING ACCESS ')' - - column := head type ACCESS ')' - - type := BASETYPE | BASETYPE '|' subtype | enum | bits - - subtype := STRING - - enum := ENUM '(' value ')' - - bits := BITS '(' value ')' - - value := INT STRING | INT STRING value - - head := '(' INT STRING - - elements := EMPTY | elements element - - element := tree | leaf | column - - index := type | index type - - typedef := 'typedef' STRING type - - include := 'include' filespec - - filespec := '"' STRING '"' | '<' STRING '>' -.Ed -.Pp -.Ar BASETYPE -specifies a SNMP data type and may be one of -.Bl -bullet -offset indent -compact -.It -NULL -.It -INTEGER -.It -INTEGER32 (same as INTEGER) -.It -UNSIGNED32 (same as GAUGE) -.It -OCTETSTRING -.It -IPADDRESS -.It -OID -.It -TIMETICKS -.It -COUNTER -.It -GAUGE -.It -COUNTER64 -.El -.Pp -.Ar ACCESS -specifies the accessibility of the MIB variable (which operation can be -performed) and is one of -.Bl -bullet -offset indent -compact -.It -GET -.It -SET -.El -.Pp -.Ar INT -is a decimal integer and -.Ar STRING -is any string starting with a letter or underscore and consisting of -letters, digits, underscores and minuses, that is not one of the keywords. -.Pp -The -.Ar typedef -directive associates a type with a single name. -.Pp -The -.Ar include -directive is replaced by the contents of the named file. -.Sh EXAMPLES -The following MIB description describes the system group: -.Bd -literal -offset indent -include "tc.def" - -typedef AdminStatus ENUM ( - 1 up - 2 down -) - -(1 internet - (2 mgmt - (1 mibII - (1 system - (1 sysDescr OCTETSTRING op_system_group GET) - (2 sysObjectId OID op_system_group GET) - (3 sysUpTime TIMETICKS op_system_group GET) - (4 sysContact OCTETSTRING op_system_group GET SET) - (5 sysName OCTETSTRING op_system_group GET SET) - (6 sysLocation OCTETSTRING op_system_group GET SET) - (7 sysServices INTEGER op_system_group GET) - (8 sysORLastChange TIMETICKS op_system_group GET) - (9 sysORTable - (1 sysOREntry : INTEGER op_or_table - (1 sysORIndex INTEGER) - (2 sysORID OID GET) - (3 sysORDescr OCTETSTRING GET) - (4 sysORUpTime TIMETICKS GET) - )) - ) - ) - ) -) -.Ed -.Sh SEE ALSO -.Xr bsnmpd 1 -.Sh AUTHORS -.An Hartmut Brandt Aq harti@FreeBSD.org Property changes on: vendor/1.14/gensnmptree/gensnmptree.1 ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Index: vendor/1.14/gensnmptree/gensnmptree.c =================================================================== --- vendor/1.14/gensnmptree/gensnmptree.c (revision 359491) +++ vendor/1.14/gensnmptree/gensnmptree.c (nonexistent) @@ -1,1818 +0,0 @@ -/* - * Copyright (c) 2001-2003 - * Fraunhofer Institute for Open Communication Systems (FhG Fokus). - * All rights reserved. - * - * Copyright (c) 2004-2006,2018 - * Hartmut Brandt. - * All rights reserved. - * - * Author: Harti Brandt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Begemot: gensnmptree.c 383 2006-05-30 07:40:49Z brandt_h $ - * - * Generate OID table from table description. - * - * Syntax is: - * --------- - * file := top | top file - * - * top := tree | typedef | include - * - * tree := head elements ')' - * - * entry := head ':' index STRING elements ')' - * - * leaf := head type STRING ACCESS ')' - * - * column := head type ACCESS ')' - * - * type := BASETYPE | BASETYPE '|' subtype | enum | bits - * - * subtype := STRING - * - * enum := ENUM '(' value ')' - * - * bits := BITS '(' value ')' - * - * value := optminus INT STRING | optminus INT STRING value - * - * optminus := '-' | EMPTY - * - * head := '(' INT STRING - * - * elements := EMPTY | elements element - * - * element := tree | leaf | column - * - * index := type | index type - * - * typedef := 'typedef' STRING type - * - * include := 'include' filespec - * - * filespec := '"' STRING '"' | '<' STRING '>' - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_ERR_H -#include -#endif -#include -#include "support.h" -#include "asn1.h" -#include "snmp.h" -#include "snmpagent.h" - -/* - * Constant prefix for all OIDs - */ -static const asn_subid_t prefix[] = { 1, 3, 6 }; -#define PREFIX_LEN (sizeof(prefix) / sizeof(prefix[0])) - -u_int tree_size; -static const char *file_prefix = ""; - -/* if true generate local include paths */ -static int localincs = 0; - -/* if true print tokens */ -static int debug; - -static const char usgtxt[] = "\ -Generate SNMP tables.\n\ -usage: gensnmptree [-dEeFfhlt] [-I directory] [-i infile] [-p prefix]\n\ - [name]...\n\ -options:\n\ - -d debug mode\n\ - -E extract the named or all enums and bits only\n\ - -e extract the named oids or enums\n\ - -F generate functions for -E into a .c file\n\ - -f generate functions for -E into the header\n\ - -h print this info\n\ - -I directory add directory to include path\n\ - -i ifile read from the named file instead of stdin\n\ - -l generate local include directives\n\ - -p prefix prepend prefix to file and variable names\n\ - -t generate a .def file\n\ -"; - -/** - * Program operation. - */ -enum op { - /** generate the tree */ - OP_GEN, - - /** extract OIDs */ - OP_EXTRACT, - - /** print the parsed tree */ - OP_TREE, - - /** extract enums */ - OP_ENUMS, -}; - -/** - * Which functions to create. - */ -enum gen_funcs { - /** none */ - GEN_FUNCS_NONE, - - /** functions for header files */ - GEN_FUNCS_H, - - /** functions for C files */ - GEN_FUNCS_C, -}; - -/* - * A node in the OID tree - */ -enum ntype { - NODE_LEAF = 1, - NODE_TREE, - NODE_ENTRY, - NODE_COLUMN -}; - -enum { - FL_GET = 0x01, - FL_SET = 0x02, -}; - -struct node; -TAILQ_HEAD(node_list, node); - -struct node { - enum ntype type; - asn_subid_t id; /* last element of OID */ - char *name; /* name of node */ - TAILQ_ENTRY(node) link; - u_int lno; /* starting line number */ - u_int flags; /* allowed operations */ - - union { - struct tree { - struct node_list subs; - } tree; - - struct entry { - uint32_t index; /* index for table entry */ - char *func; /* function for tables */ - struct node_list subs; - char *subtypes[SNMP_INDEXES_MAX]; - } entry; - - struct leaf { - enum snmp_syntax syntax; /* syntax for this leaf */ - char *func; /* function name */ - char *subtype; /* subtype */ - } leaf; - - struct column { - enum snmp_syntax syntax; /* syntax for this column */ - char *subtype; /* subtype */ - } column; - } u; -}; - -struct func { - const char *name; - LIST_ENTRY(func) link; -}; - -static LIST_HEAD(, func) funcs = LIST_HEAD_INITIALIZER(funcs); - -struct enums { - const char *name; - long value; - TAILQ_ENTRY(enums) link; -}; - -struct type { - const char *name; - const char *from_fname; - u_int from_lno; - u_int syntax; - int is_enum; - int is_bits; - TAILQ_HEAD(, enums) enums; - LIST_ENTRY(type) link; -}; - -static LIST_HEAD(, type) types = LIST_HEAD_INITIALIZER(types); - -static void report(const char *, ...) __dead2 __printflike(1, 2); -static void report_node(const struct node *, const char *, ...) - __dead2 __printflike(2, 3); - -/************************************************************ - * - * Allocate memory and panic just in the case... - */ -static void * -xalloc(size_t size) -{ - void *ptr; - - if ((ptr = calloc(1, size)) == NULL) - err(1, "allocing %zu bytes", size); - - return (ptr); -} - -static char * -savestr(const char *s) -{ - - if (s == NULL) - return (NULL); - return (strcpy(xalloc(strlen(s) + 1), s)); -} - -/************************************************************ - * - * Input stack - */ -struct input { - FILE *fp; - u_int lno; - char *fname; - char *path; - LIST_ENTRY(input) link; -}; -static LIST_HEAD(, input) inputs = LIST_HEAD_INITIALIZER(inputs); -static struct input *input = NULL; - -#define MAX_PATHS 100 -static u_int npaths = 2; -static u_int stdpaths = 2; -static const char *paths[MAX_PATHS + 1] = { - "/usr/share/snmp/defs", - "/usr/local/share/snmp/defs", - NULL -}; - -static int pbchar = -1; - -static void -path_new(const char *path) -{ - if (npaths >= MAX_PATHS) - report("too many -I directives"); - memmove(&paths[npaths - stdpaths + 1], &paths[npaths - stdpaths], - sizeof(path[0]) * stdpaths); - paths[npaths - stdpaths] = savestr(path); - npaths++; -} - -static void -input_new(FILE *fp, const char *path, const char *fname) -{ - struct input *ip; - - ip = xalloc(sizeof(*ip)); - ip->fp = fp; - ip->lno = 1; - ip->fname = savestr(fname); - ip->path = savestr(path); - LIST_INSERT_HEAD(&inputs, ip, link); - - input = ip; -} - -static void -input_close(void) -{ - - if (input == NULL) - return; - fclose(input->fp); - free(input->fname); - free(input->path); - LIST_REMOVE(input, link); - free(input); - - input = LIST_FIRST(&inputs); -} - -static FILE * -tryopen(const char *path, const char *fname) -{ - char *fn; - FILE *fp; - - if (path == NULL) - fn = savestr(fname); - else { - fn = xalloc(strlen(path) + strlen(fname) + 2); - sprintf(fn, "%s/%s", path, fname); - } - fp = fopen(fn, "r"); - free(fn); - return (fp); -} - -static void -input_fopen(const char *fname, int loc) -{ - FILE *fp; - char *path; - u_int p; - - if (fname[0] == '/') { - if ((fp = tryopen(NULL, fname)) != NULL) { - input_new(fp, NULL, fname); - return; - } - - } else { - if (loc) { - if (input == NULL) - path = NULL; - else - path = input->path; - - if ((fp = tryopen(path, fname)) != NULL) { - input_new(fp, NULL, fname); - return; - } - } - - for (p = 0; paths[p] != NULL; p++) - if ((fp = tryopen(paths[p], fname)) != NULL) { - input_new(fp, paths[p], fname); - return; - } - } - report("cannot open '%s'", fname); -} - -static int -tgetc(void) -{ - int c; - - if (pbchar != -1) { - c = pbchar; - pbchar = -1; - return (c); - } - - for (;;) { - if (input == NULL) - return (EOF); - - if ((c = getc(input->fp)) != EOF) - return (c); - - input_close(); - } -} - -static void -tungetc(int c) -{ - - if (pbchar != -1) - abort(); - pbchar = c; -} - -/************************************************************ - * - * Parsing input - */ -enum tok { - TOK_EOF = 0200, /* end-of-file seen */ - TOK_NUM, /* number */ - TOK_STR, /* string */ - TOK_ACCESS, /* access operator */ - TOK_TYPE, /* type operator */ - TOK_ENUM, /* enum token (kind of a type) */ - TOK_TYPEDEF, /* typedef directive */ - TOK_DEFTYPE, /* defined type */ - TOK_INCLUDE, /* include directive */ - TOK_FILENAME, /* filename ("foo.bar" or ) */ - TOK_BITS, /* bits token (kind of a type) */ -}; - -static const struct { - const char *str; - enum tok tok; - u_int val; -} keywords[] = { - { "GET", TOK_ACCESS, FL_GET }, - { "SET", TOK_ACCESS, FL_SET }, - { "NULL", TOK_TYPE, SNMP_SYNTAX_NULL }, - { "INTEGER", TOK_TYPE, SNMP_SYNTAX_INTEGER }, - { "INTEGER32", TOK_TYPE, SNMP_SYNTAX_INTEGER }, - { "UNSIGNED32", TOK_TYPE, SNMP_SYNTAX_GAUGE }, - { "OCTETSTRING", TOK_TYPE, SNMP_SYNTAX_OCTETSTRING }, - { "IPADDRESS", TOK_TYPE, SNMP_SYNTAX_IPADDRESS }, - { "OID", TOK_TYPE, SNMP_SYNTAX_OID }, - { "TIMETICKS", TOK_TYPE, SNMP_SYNTAX_TIMETICKS }, - { "COUNTER", TOK_TYPE, SNMP_SYNTAX_COUNTER }, - { "GAUGE", TOK_TYPE, SNMP_SYNTAX_GAUGE }, - { "COUNTER64", TOK_TYPE, SNMP_SYNTAX_COUNTER64 }, - { "ENUM", TOK_ENUM, SNMP_SYNTAX_INTEGER }, - { "BITS", TOK_BITS, SNMP_SYNTAX_OCTETSTRING }, - { "typedef", TOK_TYPEDEF, 0 }, - { "include", TOK_INCLUDE, 0 }, - { NULL, 0, 0 } -}; - -/* arbitrary upper limit on node names and function names */ -#define MAXSTR 1000 -static char str[MAXSTR]; -static u_long val; /* integer values */ -static int saved_token = -1; - -/* - * Report an error and exit. - */ -static void -report(const char *fmt, ...) -{ - va_list ap; - int c; - - va_start(ap, fmt); - fprintf(stderr, "line %u: ", input->lno); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - fprintf(stderr, "context: \""); - while ((c = tgetc()) != EOF && c != '\n') - fprintf(stderr, "%c", c); - fprintf(stderr, "\n"); - va_end(ap); - exit(1); -} -static void -report_node(const struct node *np, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - fprintf(stderr, "line %u, node %s: ", np->lno, np->name); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - va_end(ap); - exit(1); -} - -/* - * Return a fresh copy of the string constituting the current token. - */ -static char * -savetok(void) -{ - return (savestr(str)); -} - -/* - * Get the next token from input. - */ -static int -gettoken_internal(void) -{ - int c; - struct type *t; - - if (saved_token != -1) { - c = saved_token; - saved_token = -1; - return (c); - } - - again: - /* - * Skip any whitespace before the next token - */ - while ((c = tgetc()) != EOF) { - if (c == '\n') - input->lno++; - if (!isspace(c)) - break; - } - if (c == EOF) - return (TOK_EOF); - if (!isascii(c)) - report("unexpected character %#2x", (u_int)c); - - /* - * Skip comments - */ - if (c == '#') { - while ((c = tgetc()) != EOF) { - if (c == '\n') { - input->lno++; - goto again; - } - } - report("unexpected EOF in comment"); - } - - /* - * Single character tokens - */ - if (strchr("():|-", c) != NULL) - return (c); - - if (c == '"' || c == '<') { - int end = c; - size_t n = 0; - - val = 1; - if (c == '<') { - val = 0; - end = '>'; - } - - while ((c = tgetc()) != EOF) { - if (c == end) - break; - if (n == sizeof(str) - 1) { - str[n++] = '\0'; - report("filename too long '%s...'", str); - } - str[n++] = c; - } - str[n++] = '\0'; - return (TOK_FILENAME); - } - - /* - * Sort out numbers - */ - if (isdigit(c)) { - size_t n = 0; - str[n++] = c; - while ((c = tgetc()) != EOF) { - if (!isdigit(c)) { - tungetc(c); - break; - } - if (n == sizeof(str) - 1) { - str[n++] = '\0'; - report("number too long '%s...'", str); - } - str[n++] = c; - } - str[n++] = '\0'; - sscanf(str, "%lu", &val); - return (TOK_NUM); - } - - /* - * So that has to be a string. - */ - if (isalpha(c) || c == '_') { - size_t n = 0; - str[n++] = c; - while ((c = tgetc()) != EOF) { - if (!isalnum(c) && c != '_' && c != '-') { - tungetc(c); - break; - } - if (n == sizeof(str) - 1) { - str[n++] = '\0'; - report("string too long '%s...'", str); - } - str[n++] = c; - } - str[n++] = '\0'; - - /* - * Keywords - */ - for (c = 0; keywords[c].str != NULL; c++) - if (strcmp(keywords[c].str, str) == 0) { - val = keywords[c].val; - return (keywords[c].tok); - } - - LIST_FOREACH(t, &types, link) { - if (strcmp(t->name, str) == 0) { - val = t->syntax; - return (TOK_DEFTYPE); - } - } - return (TOK_STR); - } - if (isprint(c)) - errx(1, "%u: unexpected character '%c'", input->lno, c); - else - errx(1, "%u: unexpected character 0x%02x", input->lno, - (u_int)c); -} -static int -gettoken(void) -{ - int tok = gettoken_internal(); - - if (debug) { - switch (tok) { - - case TOK_EOF: - fprintf(stderr, "EOF "); - break; - - case TOK_NUM: - fprintf(stderr, "NUM(%lu) ", val); - break; - - case TOK_STR: - fprintf(stderr, "STR(%s) ", str); - break; - - case TOK_ACCESS: - fprintf(stderr, "ACCESS(%lu) ", val); - break; - - case TOK_TYPE: - fprintf(stderr, "TYPE(%lu) ", val); - break; - - case TOK_ENUM: - fprintf(stderr, "ENUM "); - break; - - case TOK_BITS: - fprintf(stderr, "BITS "); - break; - - case TOK_TYPEDEF: - fprintf(stderr, "TYPEDEF "); - break; - - case TOK_DEFTYPE: - fprintf(stderr, "DEFTYPE(%s,%lu) ", str, val); - break; - - case TOK_INCLUDE: - fprintf(stderr, "INCLUDE "); - break; - - case TOK_FILENAME: - fprintf(stderr, "FILENAME "); - break; - - default: - if (tok < TOK_EOF) { - if (isprint(tok)) - fprintf(stderr, "'%c' ", tok); - else if (tok == '\n') - fprintf(stderr, "\n"); - else - fprintf(stderr, "%02x ", tok); - } else - abort(); - break; - } - } - return (tok); -} - -/** - * Pushback a token - */ -static void -pushback(enum tok tok) -{ - - if (saved_token != -1) - abort(); - saved_token = tok; -} - -/* - * Create a new type - */ -static struct type * -make_type(const char *s) -{ - struct type *t; - - t = xalloc(sizeof(*t)); - t->name = savestr(s); - t->is_enum = 0; - t->syntax = SNMP_SYNTAX_NULL; - t->from_fname = savestr(input->fname); - t->from_lno = input->lno; - TAILQ_INIT(&t->enums); - LIST_INSERT_HEAD(&types, t, link); - - return (t); -} - -/* - * Parse a type. We've seen the ENUM or type keyword already. Leave next - * token. - */ -static u_int -parse_type(enum tok *tok, struct type *t, const char *vname, char **subtype) -{ - u_int syntax; - struct enums *e; - - syntax = val; - if (subtype != NULL) - *subtype = NULL; - - if (*tok == TOK_ENUM || *tok == TOK_BITS) { - if (t == NULL && vname != NULL) { - t = make_type(vname); - t->is_enum = (*tok == TOK_ENUM); - t->is_bits = (*tok == TOK_BITS); - t->syntax = syntax; - } - if (gettoken() != '(') - report("'(' expected after ENUM"); - - if ((*tok = gettoken()) == TOK_EOF) - report("unexpected EOF in ENUM"); - do { - e = NULL; - if (t != NULL) { - e = xalloc(sizeof(*e)); - } - if (*tok == '-') { - if ((*tok = gettoken()) == TOK_EOF) - report("unexpected EOF in ENUM"); - e->value = -(long)val; - } else - e->value = val; - - if (*tok != TOK_NUM) - report("need value for ENUM/BITS"); - if (gettoken() != TOK_STR) - report("need string in ENUM/BITS"); - e->name = savetok(); - TAILQ_INSERT_TAIL(&t->enums, e, link); - if ((*tok = gettoken()) == TOK_EOF) - report("unexpected EOF in ENUM/BITS"); - } while (*tok != ')'); - *tok = gettoken(); - - } else if (*tok == TOK_DEFTYPE) { - *tok = gettoken(); - - } else { - if ((*tok = gettoken()) == '|') { - if (gettoken() != TOK_STR) - report("subtype expected after '|'"); - if (subtype != NULL) - *subtype = savetok(); - *tok = gettoken(); - } - } - - return (syntax); -} - -/* - * Parse the next node (complete with all subnodes) - */ -static struct node * -parse(enum tok tok) -{ - struct node *node; - struct node *sub; - u_int index_count; - - node = xalloc(sizeof(struct node)); - node->lno = input->lno; - node->flags = 0; - - if (tok != '(') - report("'(' expected at begin of node"); - if (gettoken() != TOK_NUM) - report("node id expected after opening '('"); - if (val > ASN_MAXID) - report("subid too large '%lu'", val); - node->id = (asn_subid_t)val; - if (gettoken() != TOK_STR) - report("node name expected after '(' ID"); - node->name = savetok(); - - if ((tok = gettoken()) == TOK_TYPE || tok == TOK_DEFTYPE || - tok == TOK_ENUM || tok == TOK_BITS) { - /* LEAF or COLUM */ - char *subtype; - u_int syntax = parse_type(&tok, NULL, node->name, &subtype); - - if (tok == TOK_STR) { - /* LEAF */ - node->type = NODE_LEAF; - node->u.leaf.func = savetok(); - node->u.leaf.syntax = syntax; - node->u.leaf.subtype = subtype; - tok = gettoken(); - } else { - /* COLUMN */ - node->type = NODE_COLUMN; - node->u.column.syntax = syntax; - node->u.column.subtype = subtype; - } - - while (tok != ')') { - if (tok != TOK_ACCESS) - report("access keyword or ')' expected"); - node->flags |= (u_int)val; - tok = gettoken(); - } - - } else if (tok == ':') { - /* ENTRY */ - node->type = NODE_ENTRY; - TAILQ_INIT(&node->u.entry.subs); - - index_count = 0; - node->u.entry.index = 0; - tok = gettoken(); - while (tok == TOK_TYPE || tok == TOK_DEFTYPE || - tok == TOK_ENUM || tok == TOK_BITS) { - char *subtype; - u_int syntax = parse_type(&tok, NULL, node->name, - &subtype); - if (index_count == SNMP_INDEXES_MAX) - report("too many table indexes"); - node->u.entry.subtypes[index_count++] = subtype; - node->u.entry.index |= - syntax << (SNMP_INDEX_SHIFT * index_count); - } - node->u.entry.index |= index_count; - if (index_count == 0) - report("need at least one index"); - if (tok != TOK_STR) - report("function name expected"); - - node->u.entry.func = savetok(); - - tok = gettoken(); - - while (tok != ')') { - sub = parse(tok); - TAILQ_INSERT_TAIL(&node->u.entry.subs, sub, link); - tok = gettoken(); - } - - } else { - /* subtree */ - node->type = NODE_TREE; - TAILQ_INIT(&node->u.tree.subs); - - while (tok != ')') { - sub = parse(tok); - TAILQ_INSERT_TAIL(&node->u.tree.subs, sub, link); - tok = gettoken(); - } - } - return (node); -} - -/* - * Parse a top level element. Return the tree if it was a tree, NULL - * otherwise. - */ -static struct node * -parse_top(enum tok tok) -{ - struct type *t; - - if (tok == '(') - return (parse(tok)); - - if (tok == TOK_TYPEDEF) { - if (gettoken() != TOK_STR) - report("type name expected after typedef"); - - t = make_type(str); - - tok = gettoken(); - t->is_enum = (tok == TOK_ENUM); - t->is_bits = (tok == TOK_BITS); - - t->syntax = parse_type(&tok, t, NULL, NULL); - pushback(tok); - - return (NULL); - } - - if (tok == TOK_INCLUDE) { - if (gettoken() != TOK_FILENAME) - report("filename expected in include directive"); - - input_fopen(str, val); - return (NULL); - } - - report("'(' or 'typedef' expected"); -} - -/* - * Generate the C-code table part for one node. - */ -static void -gen_node(FILE *fp, const struct node *np, struct asn_oid *oid, u_int idx, - const char *func) -{ - u_int n; - struct node *sub; - u_int syntax; - - if (oid->len == ASN_MAXOIDLEN) - report_node(np, "OID too long"); - oid->subs[oid->len++] = np->id; - - if (np->type == NODE_TREE) { - TAILQ_FOREACH(sub, &np->u.tree.subs, link) - gen_node(fp, sub, oid, 0, NULL); - oid->len--; - return; - } - if (np->type == NODE_ENTRY) { - TAILQ_FOREACH(sub, &np->u.entry.subs, link) - gen_node(fp, sub, oid, np->u.entry.index, - np->u.entry.func); - oid->len--; - return; - } - - /* leaf or column */ - if ((np->flags & (FL_GET|FL_SET)) == 0) { - oid->len--; - return; - } - - fprintf(fp, " {{ %u, {", oid->len); - for (n = 0; n < oid->len; n++) - fprintf(fp, " %u,", oid->subs[n]); - fprintf(fp, " }}, \"%s\", ", np->name); - - if (np->type == NODE_COLUMN) { - syntax = np->u.column.syntax; - fprintf(fp, "SNMP_NODE_COLUMN, "); - } else { - syntax = np->u.leaf.syntax; - fprintf(fp, "SNMP_NODE_LEAF, "); - } - - switch (syntax) { - - case SNMP_SYNTAX_NULL: - fprintf(fp, "SNMP_SYNTAX_NULL, "); - break; - - case SNMP_SYNTAX_INTEGER: - fprintf(fp, "SNMP_SYNTAX_INTEGER, "); - break; - - case SNMP_SYNTAX_OCTETSTRING: - fprintf(fp, "SNMP_SYNTAX_OCTETSTRING, "); - break; - - case SNMP_SYNTAX_IPADDRESS: - fprintf(fp, "SNMP_SYNTAX_IPADDRESS, "); - break; - - case SNMP_SYNTAX_OID: - fprintf(fp, "SNMP_SYNTAX_OID, "); - break; - - case SNMP_SYNTAX_TIMETICKS: - fprintf(fp, "SNMP_SYNTAX_TIMETICKS, "); - break; - - case SNMP_SYNTAX_COUNTER: - fprintf(fp, "SNMP_SYNTAX_COUNTER, "); - break; - - case SNMP_SYNTAX_GAUGE: - fprintf(fp, "SNMP_SYNTAX_GAUGE, "); - break; - - case SNMP_SYNTAX_COUNTER64: - fprintf(fp, "SNMP_SYNTAX_COUNTER64, "); - break; - - case SNMP_SYNTAX_NOSUCHOBJECT: - case SNMP_SYNTAX_NOSUCHINSTANCE: - case SNMP_SYNTAX_ENDOFMIBVIEW: - abort(); - } - - if (np->type == NODE_COLUMN) - fprintf(fp, "%s, ", func); - else - fprintf(fp, "%s, ", np->u.leaf.func); - - fprintf(fp, "0"); - if (np->flags & FL_SET) - fprintf(fp, "|SNMP_NODE_CANSET"); - fprintf(fp, ", %#x, NULL, NULL },\n", idx); - oid->len--; - return; -} - -/* - * Generate the header file with the function declarations. - */ -static void -gen_header(FILE *fp, const struct node *np, u_int oidlen, const char *func) -{ - char f[MAXSTR + 4]; - struct node *sub; - struct func *ptr; - - oidlen++; - if (np->type == NODE_TREE) { - TAILQ_FOREACH(sub, &np->u.tree.subs, link) - gen_header(fp, sub, oidlen, NULL); - return; - } - if (np->type == NODE_ENTRY) { - TAILQ_FOREACH(sub, &np->u.entry.subs, link) - gen_header(fp, sub, oidlen, np->u.entry.func); - return; - } - - if((np->flags & (FL_GET|FL_SET)) == 0) - return; - - if (np->type == NODE_COLUMN) { - if (func == NULL) - errx(1, "column without function (%s) - probably " - "outside of a table", np->name); - sprintf(f, "%s", func); - } else - sprintf(f, "%s", np->u.leaf.func); - - LIST_FOREACH(ptr, &funcs, link) - if (strcmp(ptr->name, f) == 0) - break; - - if (ptr == NULL) { - ptr = xalloc(sizeof(*ptr)); - ptr->name = savestr(f); - LIST_INSERT_HEAD(&funcs, ptr, link); - - fprintf(fp, "int %s(struct snmp_context *, " - "struct snmp_value *, u_int, u_int, " - "enum snmp_op);\n", f); - } - - fprintf(fp, "# define LEAF_%s %u\n", np->name, np->id); -} - -/* - * Generate the OID table. - */ -static void -gen_table(FILE *fp, const struct node *node) -{ - struct asn_oid oid; - - fprintf(fp, "#include \n"); - fprintf(fp, "#include \n"); -#ifdef HAVE_STDINT_H - fprintf(fp, "#include \n"); -#endif - if (localincs) { - fprintf(fp, "#include \"asn1.h\"\n"); - fprintf(fp, "#include \"snmp.h\"\n"); - fprintf(fp, "#include \"snmpagent.h\"\n"); - } else { - fprintf(fp, "#include \n"); - fprintf(fp, "#include \n"); - fprintf(fp, "#include \n"); - } - fprintf(fp, "#include \"%stree.h\"\n", file_prefix); - fprintf(fp, "\n"); - - fprintf(fp, "const struct snmp_node %sctree[] = {\n", file_prefix); - - oid.len = PREFIX_LEN; - memcpy(oid.subs, prefix, sizeof(prefix)); - gen_node(fp, node, &oid, 0, NULL); - - fprintf(fp, "};\n\n"); -} - -static void -print_syntax(u_int syntax) -{ - u_int i; - - for (i = 0; keywords[i].str != NULL; i++) - if (keywords[i].tok == TOK_TYPE && - keywords[i].val == syntax) { - printf(" %s", keywords[i].str); - return; - } - abort(); -} - -/* - * Generate a tree definition file - */ -static void -gen_tree(const struct node *np, int level) -{ - const struct node *sp; - u_int i; - - printf("%*s(%u %s", 2 * level, "", np->id, np->name); - - switch (np->type) { - - case NODE_LEAF: - print_syntax(np->u.leaf.syntax); - if (np->u.leaf.subtype != NULL) - printf(" | %s", np->u.leaf.subtype); - printf(" %s%s%s)\n", np->u.leaf.func, - (np->flags & FL_GET) ? " GET" : "", - (np->flags & FL_SET) ? " SET" : ""); - break; - - case NODE_TREE: - if (TAILQ_EMPTY(&np->u.tree.subs)) { - printf(")\n"); - } else { - printf("\n"); - TAILQ_FOREACH(sp, &np->u.tree.subs, link) - gen_tree(sp, level + 1); - printf("%*s)\n", 2 * level, ""); - } - break; - - case NODE_ENTRY: - printf(" :"); - - for (i = 0; i < SNMP_INDEX_COUNT(np->u.entry.index); i++) { - print_syntax(SNMP_INDEX(np->u.entry.index, i)); - if (np->u.entry.subtypes[i] != NULL) - printf(" | %s", np->u.entry.subtypes[i]); - } - printf(" %s\n", np->u.entry.func); - TAILQ_FOREACH(sp, &np->u.entry.subs, link) - gen_tree(sp, level + 1); - printf("%*s)\n", 2 * level, ""); - break; - - case NODE_COLUMN: - print_syntax(np->u.column.syntax); - if (np->u.column.subtype != NULL) - printf(" | %s", np->u.column.subtype); - printf("%s%s)\n", (np->flags & FL_GET) ? " GET" : "", - (np->flags & FL_SET) ? " SET" : ""); - break; - } -} - -static int -extract(FILE *fp, const struct node *np, struct asn_oid *oid, const char *obj, - const struct asn_oid *idx, const char *iname) -{ - struct node *sub; - u_long n; - - if (oid->len == ASN_MAXOIDLEN) - report_node(np, "OID too long"); - oid->subs[oid->len++] = np->id; - - if (strcmp(obj, np->name) == 0) { - if (oid->len + idx->len >= ASN_MAXOIDLEN) - report_node(np, "OID too long"); - fprintf(fp, "#define OID_%s%s\t%u\n", np->name, - iname ? iname : "", np->id); - fprintf(fp, "#define OIDLEN_%s%s\t%u\n", np->name, - iname ? iname : "", oid->len + idx->len); - fprintf(fp, "#define OIDX_%s%s\t{ %u, {", np->name, - iname ? iname : "", oid->len + idx->len); - for (n = 0; n < oid->len; n++) - fprintf(fp, " %u,", oid->subs[n]); - for (n = 0; n < idx->len; n++) - fprintf(fp, " %u,", idx->subs[n]); - fprintf(fp, " } }\n"); - return (0); - } - - if (np->type == NODE_TREE) { - TAILQ_FOREACH(sub, &np->u.tree.subs, link) - if (!extract(fp, sub, oid, obj, idx, iname)) - return (0); - } else if (np->type == NODE_ENTRY) { - TAILQ_FOREACH(sub, &np->u.entry.subs, link) - if (!extract(fp, sub, oid, obj, idx, iname)) - return (0); - } - oid->len--; - return (1); -} - -static int -gen_extract(FILE *fp, const struct node *root, char *object) -{ - struct asn_oid oid; - struct asn_oid idx; - char *s, *e, *end, *iname; - u_long ul; - int ret; - - /* look whether the object to extract has an index part */ - idx.len = 0; - iname = NULL; - s = strchr(object, '.'); - if (s != NULL) { - iname = malloc(strlen(s) + 1); - if (iname == NULL) - err(1, "cannot allocated index"); - - strcpy(iname, s); - for (e = iname; *e != '\0'; e++) - if (*e == '.') - *e = '_'; - - *s++ = '\0'; - while (s != NULL) { - if (*s == '\0') - errx(1, "bad index syntax"); - if ((e = strchr(s, '.')) != NULL) - *e++ = '\0'; - - errno = 0; - ul = strtoul(s, &end, 0); - if (*end != '\0') - errx(1, "bad index syntax '%s'", end); - if (errno != 0) - err(1, "bad index syntax"); - - if (idx.len == ASN_MAXOIDLEN) - errx(1, "index oid too large"); - idx.subs[idx.len++] = ul; - - s = e; - } - } - - oid.len = PREFIX_LEN; - memcpy(oid.subs, prefix, sizeof(prefix)); - ret = extract(fp, root, &oid, object, &idx, iname); - if (iname != NULL) - free(iname); - - return (ret); -} - - -static void -check_sub_order(const struct node *np, const struct node_list *subs) -{ - int first; - const struct node *sub; - asn_subid_t maxid = 0; - - /* ensure, that subids are ordered */ - first = 1; - TAILQ_FOREACH(sub, subs, link) { - if (!first && sub->id <= maxid) - report_node(np, "subids not ordered at %s", sub->name); - maxid = sub->id; - first = 0; - } -} - -/* - * Do some sanity checks on the tree definition and do some computations. - */ -static void -check_tree(struct node *np) -{ - struct node *sub; - - if (np->type == NODE_LEAF || np->type == NODE_COLUMN) { - if ((np->flags & (FL_GET|FL_SET)) != 0) - tree_size++; - return; - } - - if (np->type == NODE_ENTRY) { - check_sub_order(np, &np->u.entry.subs); - - /* ensure all subnodes are columns */ - TAILQ_FOREACH(sub, &np->u.entry.subs, link) { - if (sub->type != NODE_COLUMN) - report_node(np, "entry subnode '%s' is not " - "a column", sub->name); - check_tree(sub); - } - } else { - check_sub_order(np, &np->u.tree.subs); - - TAILQ_FOREACH(sub, &np->u.tree.subs, link) - check_tree(sub); - } -} - -static void -merge_subs(struct node_list *s1, struct node_list *s2) -{ - struct node *n1, *n2; - - while (!TAILQ_EMPTY(s2)) { - n2 = TAILQ_FIRST(s2); - TAILQ_REMOVE(s2, n2, link); - - TAILQ_FOREACH(n1, s1, link) - if (n1->id >= n2->id) - break; - if (n1 == NULL) - TAILQ_INSERT_TAIL(s1, n2, link); - else if (n1->id > n2->id) - TAILQ_INSERT_BEFORE(n1, n2, link); - else { - if (n1->type == NODE_TREE && n2->type == NODE_TREE) { - if (strcmp(n1->name, n2->name) != 0) - errx(1, "trees to merge must have " - "same name '%s' '%s'", n1->name, - n2->name); - merge_subs(&n1->u.tree.subs, &n2->u.tree.subs); - free(n2); - } else if (n1->type == NODE_ENTRY && - n2->type == NODE_ENTRY) { - if (strcmp(n1->name, n2->name) != 0) - errx(1, "entries to merge must have " - "same name '%s' '%s'", n1->name, - n2->name); - if (n1->u.entry.index != n2->u.entry.index) - errx(1, "entries to merge must have " - "same index '%s'", n1->name); - if (strcmp(n1->u.entry.func, - n2->u.entry.func) != 0) - errx(1, "entries to merge must have " - "same op '%s'", n1->name); - merge_subs(&n1->u.entry.subs, - &n2->u.entry.subs); - free(n2); - } else - errx(1, "entities to merge must be both " - "trees or both entries: %s, %s", - n1->name, n2->name); - } - } -} - -static void -merge(struct node **root, struct node *t) -{ - - if (*root == NULL) { - *root = t; - return; - } - if (t == NULL) - return; - - /* both must be trees */ - if ((*root)->type != NODE_TREE) - errx(1, "root is not a tree"); - if (t->type != NODE_TREE) - errx(1, "can merge only with tree"); - if ((*root)->id != t->id) - errx(1, "trees to merge must have same id"); - - merge_subs(&(*root)->u.tree.subs, &t->u.tree.subs); -} - -static void -unminus(FILE *fp, const char *s) -{ - - while (*s != '\0') { - if (*s == '-') - fprintf(fp, "_"); - else - fprintf(fp, "%c", *s); - s++; - } -} - -/** - * Generate helper functions for an enum. - * - * We always generate a switch statement for the isok function. The compiler - * optimizes this into range checks if possible. - * - * \param fp file to write to - * \param t type - * \param ccode generate externally visible non-inline functions - */ -static void -gen_enum_funcs(FILE *fp, const struct type *t, int ccode) -{ - fprintf(fp, "\n"); - - if (!ccode) - fprintf(fp, "static inline "); - fprintf(fp, "int\n"); - fprintf(fp, "isok_%s(enum %s s)\n", t->name, t->name); - fprintf(fp, "{\n"); - fprintf(fp, " switch (s) {\n"); - - const struct enums *e; - TAILQ_FOREACH(e, &t->enums, link) { - fprintf(fp, "\t case %s_", t->name); - unminus(fp, e->name); - fprintf(fp, ":\n"); - } - - fprintf(fp, " return (1);\n"); - fprintf(fp, " }\n"); - fprintf(fp, " return (0);\n"); - fprintf(fp, "}\n\n"); - - if (!ccode) - fprintf(fp, "static inline "); - fprintf(fp, "const char *\n"); - fprintf(fp, "tostr_%s(enum %s s)\n", t->name, t->name); - fprintf(fp, "{\n"); - fprintf(fp, " static const char *vals[] = { STRING_%s };\n", t->name); - fprintf(fp, "\n"); - fprintf(fp, " if (isok_%s(s))\n", t->name); - fprintf(fp, " return (vals[(int)s - STROFF_%s]);\n", t->name); - fprintf(fp, " return (\"%s???\");\n", t->name); - fprintf(fp, "}\n\n"); - - if (!ccode) - fprintf(fp, "static inline "); - fprintf(fp, "int\n"); - fprintf(fp, "fromstr_%s(const char *str, enum %s *s)\n", - t->name, t->name); - fprintf(fp, "{\n"); - fprintf(fp, " static const char *vals[] = { STRING_%s };\n", t->name); - fprintf(fp, "\n"); - fprintf(fp, " for (size_t i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) {\n"); - fprintf(fp, " if (vals[i] != NULL && strcmp(vals[i], str) == 0) {\n"); - fprintf(fp, " *s = i + STROFF_%s;\n", t->name); - fprintf(fp, " return (1);\n"); - fprintf(fp, " }\n"); - fprintf(fp, " }\n"); - fprintf(fp, " return (0);\n"); - fprintf(fp, "}\n"); -} - -/** - * Generate a definition for the enum packed into a guard against multiple - * definitions. - * - * \param fp file to write definition to - * \param t type - * \param dof generate functions too - */ -static void -gen_enum(FILE *fp, const struct type *t, int dof) -{ - const struct enums *e; - long min = LONG_MAX; - - fprintf(fp, "\n"); - fprintf(fp, "#ifndef %s_defined__\n", t->name); - fprintf(fp, "#define %s_defined__\n", t->name); - fprintf(fp, "/*\n"); - fprintf(fp, " * From %s:%u\n", t->from_fname, t->from_lno); - fprintf(fp, " */\n"); - fprintf(fp, "enum %s {\n", t->name); - TAILQ_FOREACH(e, &t->enums, link) { - fprintf(fp, "\t%s_", t->name); - unminus(fp, e->name); - fprintf(fp, " = %ld,\n", e->value); - if (e->value < min) - min = e->value; - } - fprintf(fp, "};\n"); - fprintf(fp, "#define STROFF_%s %ld\n", t->name, min); - fprintf(fp, "#define STRING_%s \\\n", t->name); - TAILQ_FOREACH(e, &t->enums, link) { - fprintf(fp, "\t[%ld] = \"%s_", e->value - min, t->name); - unminus(fp, e->name); - fprintf(fp, "\",\\\n"); - } - fprintf(fp, "\n"); - if (dof) { - fprintf(fp, "#ifdef SNMPENUM_FUNCS\n"); - fprintf(fp, "\n"); - gen_enum_funcs(fp, t, 0); - fprintf(fp, "\n"); - fprintf(fp, "#endif\n"); - fprintf(fp, "\n"); - } - fprintf(fp, "#endif /* %s_defined__ */\n", t->name); -} - -/** - * Generate helper functions for an enum. This generates code for a c file. - * - * \param fp file to write to - * \param name enum name - */ -static int -gen_enum_funcs_str(FILE *fp, const char *name) -{ - const struct type *t; - - LIST_FOREACH(t, &types, link) - if ((t->is_enum || t->is_bits) && strcmp(t->name, name) == 0) { - gen_enum_funcs(fp, t, 1); - return (0); - } - - return (-1); -} - -/** - * Generate helper functions for all enums. - * - * \param fp file to write to - * \param ccode generate externally visible non-inline functions - */ -static void -gen_all_enum_funcs(FILE *fp, int ccode) -{ - const struct type *t; - - LIST_FOREACH(t, &types, link) - if (t->is_enum || t->is_bits) - gen_enum_funcs(fp, t, ccode); -} - -static void -gen_enums(FILE *fp, int dof) -{ - const struct type *t; - - LIST_FOREACH(t, &types, link) - if (t->is_enum || t->is_bits) - gen_enum(fp, t, dof); -} - -/** - * Extract a given enum to the specified file and optionally generate static - * inline helper functions for them. - * - * \param fp file to print on - * \param name name of the enum - * \param gen_funcs generate the functions too - * - * \return 0 if found, -1 otherwise - */ -static int -extract_enum(FILE *fp, const char *name, int gen_funcs) -{ - const struct type *t; - - LIST_FOREACH(t, &types, link) - if ((t->is_enum || t->is_bits) && strcmp(t->name, name) == 0) { - gen_enum(fp, t, gen_funcs); - return (0); - } - return (-1); -} - -/** - * Extract all enums to the given file and optionally generate static inline - * helper functions for them. - * - * \param fp file to print on - * \param gen_funcs generate the functions too - */ -static void -extract_all_enums(FILE *fp, int gen_funcs) -{ - const struct type *t; - - LIST_FOREACH(t, &types, link) - if (t->is_enum || t->is_bits) - gen_enum(fp, t, gen_funcs); -} - -/** - * Extract enums and optionally generate some helper functions for them. - * - * \param argc number of arguments - * \param argv arguments (enum names) - * \param gen_funcs which functions to generate - */ -static void -make_enums(int argc, char *argv[], enum gen_funcs gen_funcs) -{ - if (gen_funcs == GEN_FUNCS_C) { - if (argc == 0) - gen_all_enum_funcs(stdout, 1); - else { - for (int i = 0; i < argc; i++) - if (gen_enum_funcs_str(stdout, argv[i])) - errx(1, "enum not found: %s", argv[i]); - } - } else { - if (argc == 0) - extract_all_enums(stdout, gen_funcs == GEN_FUNCS_H); - else { - for (int i = 0; i < argc; i++) - if (extract_enum(stdout, argv[i], - gen_funcs == GEN_FUNCS_H)) - errx(1, "enum not found: %s", argv[i]); - } - } -} - -/** - * Produce the operation tables for the daemon or a module. - * - * \param root tree root - * \param gen_funcs generate enum funcs - */ -static void -make_table(const struct node *root, int gen_funcs) -{ - FILE *fp; - - char fname[MAXPATHLEN + 1]; - sprintf(fname, "%stree.h", file_prefix); - if ((fp = fopen(fname, "w")) == NULL) - err(1, "%s: ", fname); - gen_header(fp, root, PREFIX_LEN, NULL); - - fprintf(fp, "\n#ifdef SNMPTREE_TYPES\n"); - gen_enums(fp, gen_funcs); - fprintf(fp, "\n#endif /* SNMPTREE_TYPES */\n\n"); - - fprintf(fp, "#define %sCTREE_SIZE %u\n", file_prefix, tree_size); - fprintf(fp, "extern const struct snmp_node %sctree[];\n", file_prefix); - - fclose(fp); - - sprintf(fname, "%stree.c", file_prefix); - if ((fp = fopen(fname, "w")) == NULL) - err(1, "%s: ", fname); - gen_table(fp, root); - fclose(fp); -} - -int -main(int argc, char *argv[]) -{ - enum op op = OP_GEN; - enum gen_funcs gen_funcs = GEN_FUNCS_NONE; - - char *infile = NULL; - - int opt; - while ((opt = getopt(argc, argv, "dEeFfhI:i:lp:t")) != EOF) - switch (opt) { - - case 'd': - debug = 1; - break; - - case 'E': - if (op != OP_GEN && op != OP_ENUMS) - errx(1, "-E conflicts with earlier options"); - op = OP_ENUMS; - break; - - case 'e': - if (op != OP_GEN && op != OP_EXTRACT) - errx(1, "-e conflicts with earlier options"); - op = OP_EXTRACT; - break; - - case 'F': - if (gen_funcs != GEN_FUNCS_NONE && - gen_funcs != GEN_FUNCS_C) - errx(1, "-F conflicts with -f"); - gen_funcs = GEN_FUNCS_C; - break; - - case 'f': - if (gen_funcs != GEN_FUNCS_NONE && - gen_funcs != GEN_FUNCS_H) - errx(1, "-f conflicts with -F"); - gen_funcs = GEN_FUNCS_H; - break; - - case 'h': - fprintf(stderr, "%s", usgtxt); - exit(0); - - case 'I': - path_new(optarg); - break; - - case 'i': - infile = optarg; - break; - - case 'l': - localincs = 1; - break; - - case 'p': - file_prefix = optarg; - if (strlen(file_prefix) + strlen("tree.c") > - MAXPATHLEN) - errx(1, "prefix too long"); - break; - - case 't': - if (op != OP_GEN && op != OP_TREE) - errx(1, "-t conflicts with earlier options"); - op = OP_TREE; - break; - } - - argc -= optind; - argv += optind; - - /* open input */ - if (infile == NULL) { - input_new(stdin, NULL, ""); - } else { - FILE *fp; - if ((fp = fopen(infile, "r")) == NULL) - err(1, "%s", infile); - input_new(fp, NULL, infile); - } - - /* parse and check input */ - struct node *root = parse_top(gettoken()); - - int tok; - while ((tok = gettoken()) != TOK_EOF) - merge(&root, parse_top(tok)); - - if (root) - check_tree(root); - - /* do what the user has requested */ - switch (op) { - - case OP_EXTRACT: - if (argc == 0) - errx(1, "-e requires arguments"); - - for (int i = 0; i < argc; i++) - if (gen_extract(stdout, root, argv[i])) - errx(1, "object not found: %s", argv[i]); - return (0); - - case OP_ENUMS: - make_enums(argc, argv, gen_funcs); - return (0); - - case OP_TREE: - if (argc != 0) - errx(1, "-t allows no arguments"); - gen_tree(root, 0); - return (0); - - case OP_GEN: - if (argc != 0) - errx(1, "tree generation allows no arguments"); - make_table(root, gen_funcs == GEN_FUNCS_H); - return (0); - } -} Property changes on: vendor/1.14/gensnmptree/gensnmptree.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Index: vendor/1.14/tests/main.cc =================================================================== --- vendor/1.14/tests/main.cc (revision 359491) +++ vendor/1.14/tests/main.cc (nonexistent) @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "catch.hpp" Property changes on: vendor/1.14/tests/main.cc ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: vendor/1.14/tests/catch.hpp =================================================================== --- vendor/1.14/tests/catch.hpp (revision 359491) +++ vendor/1.14/tests/catch.hpp (nonexistent) @@ -1,17597 +0,0 @@ -/* - * Catch v2.11.0 - * Generated: 2019-11-15 15:01:56.628356 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2019 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -// start catch.hpp - - -#define CATCH_VERSION_MAJOR 2 -#define CATCH_VERSION_MINOR 11 -#define CATCH_VERSION_PATCH 0 - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// start catch_suppress_warnings.h - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wswitch-enum" -# pragma clang diagnostic ignored "-Wcovered-switch-default" -# endif -#elif defined __GNUC__ - // Because REQUIREs trigger GCC's -Wparentheses, and because still - // supported version of g++ have only buggy support for _Pragmas, - // Wparentheses have to be suppressed globally. -# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details - -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wpadded" -#endif -// end catch_suppress_warnings.h -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -# define CATCH_CONFIG_ALL_PARTS -#endif - -// In the impl file, we want to have access to all parts of the headers -// Can also be used to sanely support PCHs -#if defined(CATCH_CONFIG_ALL_PARTS) -# define CATCH_CONFIG_EXTERNAL_INTERFACES -# if defined(CATCH_CONFIG_DISABLE_MATCHERS) -# undef CATCH_CONFIG_DISABLE_MATCHERS -# endif -# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -# endif -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) -// start catch_platform.h - -#ifdef __APPLE__ -# include -# if TARGET_OS_OSX == 1 -# define CATCH_PLATFORM_MAC -# elif TARGET_OS_IPHONE == 1 -# define CATCH_PLATFORM_IPHONE -# endif - -#elif defined(linux) || defined(__linux) || defined(__linux__) -# define CATCH_PLATFORM_LINUX - -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) -# define CATCH_PLATFORM_WINDOWS -#endif - -// end catch_platform.h - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// start catch_user_interfaces.h - -namespace Catch { - unsigned int rngSeed(); -} - -// end catch_user_interfaces.h -// start catch_tag_alias_autoregistrar.h - -// start catch_common.h - -// start catch_compiler_capabilities.h - -// Detect a number of compiler features - by compiler -// The following features are defined: -// -// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? -// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? -// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? -// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? -// **************** -// Note to maintainers: if new toggles are added please document them -// in configuration.md, too -// **************** - -// In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -#ifdef __cplusplus - -# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) -# define CATCH_CPP14_OR_GREATER -# endif - -# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) -# define CATCH_CPP17_OR_GREATER -# endif - -#endif - -#if defined(CATCH_CPP17_OR_GREATER) -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -// We have to avoid both ICC and Clang, because they try to mask themselves -// as gcc, and we want only GCC in this block -#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) -#endif - -#if defined(__clang__) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) - -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ - _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) - -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Assume that non-Windows platforms support posix signals by default -#if !defined(CATCH_PLATFORM_WINDOWS) - #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS -#endif - -//////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) - #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -#endif - -#ifdef __OS400__ -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# define CATCH_CONFIG_COLOUR_NONE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Android somehow still does not support std::to_string -#if defined(__ANDROID__) -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING -# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Not all Windows environments support SEH properly -#if defined(__MINGW32__) -# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH -#endif - -//////////////////////////////////////////////////////////////////////////////// -// PS4 -#if defined(__ORBIS__) -# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Cygwin -#ifdef __CYGWIN__ - -// Required for some versions of Cygwin to declare gettimeofday -// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin -# define _BSD_SOURCE -// some versions of cygwin (most) do not support std::to_string. Use the libstd check. -// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 -# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ - && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) - -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING - -# endif -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#if defined(_MSC_VER) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) - -# if _MSC_VER >= 1900 // Visual Studio 2015 or newer -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -# endif - -// Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define CATCH_CONFIG_COLOUR_NONE -# else -# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH -# endif - -// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ -// _MSVC_TRADITIONAL == 0 means new conformant preprocessor -// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor -# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) -# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -# endif -#endif // _MSC_VER - -#if defined(_REENTRANT) || defined(_MSC_VER) -// Enable async processing, as -pthread is specified or no additional linking is required -# define CATCH_INTERNAL_CONFIG_USE_ASYNC -#endif // _MSC_VER - -//////////////////////////////////////////////////////////////////////////////// -// Check if we are compiled with -fno-exceptions or equivalent -#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) -# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED -#endif - -//////////////////////////////////////////////////////////////////////////////// -// DJGPP -#ifdef __DJGPP__ -# define CATCH_INTERNAL_CONFIG_NO_WCHAR -#endif // __DJGPP__ - -//////////////////////////////////////////////////////////////////////////////// -// Embarcadero C++Build -#if defined(__BORLANDC__) - #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// Use of __COUNTER__ is suppressed during code analysis in -// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly -// handled by it. -// Otherwise all supported compilers support COUNTER macro, -// but user still might want to turn it off -#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) - #define CATCH_INTERNAL_CONFIG_COUNTER -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// RTX is a special version of Windows that is real time. -// This means that it is detected as Windows, but does not provide -// the same set of capabilities as real Windows does. -#if defined(UNDER_RTSS) || defined(RTX64_BUILD) - #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH - #define CATCH_INTERNAL_CONFIG_NO_ASYNC - #define CATCH_CONFIG_COLOUR_NONE -#endif - -#if defined(__UCLIBC__) -#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Various stdlib support checks that require __has_include -#if defined(__has_include) - // Check if string_view is available and usable - #if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW - #endif - - // Check if optional is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) - - // Check if byte is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_BYTE - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) - - // Check if variant is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # if defined(__clang__) && (__clang_major__ < 8) - // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 - // fix should be in clang 8, workaround in libstdc++ 8.2 - # include - # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # define CATCH_CONFIG_NO_CPP17_VARIANT - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__clang__) && (__clang_major__ < 8) - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) -#endif // defined(__has_include) - -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) -# define CATCH_CONFIG_COUNTER -#endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH -#endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS -#endif -// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. -#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) -# define CATCH_CONFIG_WCHAR -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) -# define CATCH_CONFIG_CPP11_TO_STRING -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) -# define CATCH_CONFIG_CPP17_OPTIONAL -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) -# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) -# define CATCH_CONFIG_CPP17_STRING_VIEW -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) -# define CATCH_CONFIG_CPP17_VARIANT -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) -# define CATCH_CONFIG_CPP17_BYTE -#endif - -#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) -# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) -# define CATCH_CONFIG_NEW_CAPTURE -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -# define CATCH_CONFIG_DISABLE_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) -# define CATCH_CONFIG_POLYFILL_ISNAN -#endif - -#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) -# define CATCH_CONFIG_USE_ASYNC -#endif - -#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) -# define CATCH_CONFIG_ANDROID_LOGWRITE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) -# define CATCH_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Even if we do not think the compiler has that warning, we still have -// to provide a macro that can be used by the code. -#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS -#endif - -#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#elif defined(__clang__) && (__clang_major__ < 5) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -#define CATCH_TRY if ((true)) -#define CATCH_CATCH_ALL if ((false)) -#define CATCH_CATCH_ANON(type) if ((false)) -#else -#define CATCH_TRY try -#define CATCH_CATCH_ALL catch (...) -#define CATCH_CATCH_ANON(type) catch (type) -#endif - -#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) -#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#endif - -// end catch_compiler_capabilities.h -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#ifdef CATCH_CONFIG_COUNTER -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) -#else -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) -#endif - -#include -#include -#include - -// We need a dummy global operator<< so we can bring it into Catch namespace later -struct Catch_global_namespace_dummy {}; -std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); - -namespace Catch { - - struct CaseSensitive { enum Choice { - Yes, - No - }; }; - - class NonCopyable { - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; - - protected: - NonCopyable(); - virtual ~NonCopyable(); - }; - - struct SourceLineInfo { - - SourceLineInfo() = delete; - SourceLineInfo( char const* _file, std::size_t _line ) noexcept - : file( _file ), - line( _line ) - {} - - SourceLineInfo( SourceLineInfo const& other ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo( SourceLineInfo&& ) noexcept = default; - SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - - bool empty() const noexcept { return file[0] == '\0'; } - bool operator == ( SourceLineInfo const& other ) const noexcept; - bool operator < ( SourceLineInfo const& other ) const noexcept; - - char const* file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // Bring in operator<< from global namespace into Catch namespace - // This is necessary because the overload of operator<< above makes - // lookup stop at namespace Catch - using ::operator<<; - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() const; - }; - template - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO \ - ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) - -// end catch_common.h -namespace Catch { - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -// end catch_tag_alias_autoregistrar.h -// start catch_test_registry.h - -// start catch_interfaces_testcase.h - -#include - -namespace Catch { - - class TestSpec; - - struct ITestInvoker { - virtual void invoke () const = 0; - virtual ~ITestInvoker(); - }; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; - }; - - bool isThrowSafe( TestCase const& testCase, IConfig const& config ); - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector const& getAllTestCasesSorted( IConfig const& config ); - -} - -// end catch_interfaces_testcase.h -// start catch_stringref.h - -#include -#include -#include -#include - -namespace Catch { - - /// A non-owning string class (similar to the forthcoming std::string_view) - /// Note that, because a StringRef may be a substring of another string, - /// it may not be null terminated. - class StringRef { - public: - using size_type = std::size_t; - using const_iterator = const char*; - - private: - static constexpr char const* const s_empty = ""; - - char const* m_start = s_empty; - size_type m_size = 0; - - public: // construction - constexpr StringRef() noexcept = default; - - StringRef( char const* rawChars ) noexcept; - - constexpr StringRef( char const* rawChars, size_type size ) noexcept - : m_start( rawChars ), - m_size( size ) - {} - - StringRef( std::string const& stdString ) noexcept - : m_start( stdString.c_str() ), - m_size( stdString.size() ) - {} - - explicit operator std::string() const { - return std::string(m_start, m_size); - } - - public: // operators - auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator != (StringRef const& other) const noexcept -> bool { - return !(*this == other); - } - - auto operator[] ( size_type index ) const noexcept -> char { - assert(index < m_size); - return m_start[index]; - } - - public: // named queries - constexpr auto empty() const noexcept -> bool { - return m_size == 0; - } - constexpr auto size() const noexcept -> size_type { - return m_size; - } - - // Returns the current start pointer. If the StringRef is not - // null-terminated, throws std::domain_exception - auto c_str() const -> char const*; - - public: // substrings and searches - // Returns a substring of [start, start + length). - // If start + length > size(), then the substring is [start, size()). - // If start > size(), then the substring is empty. - auto substr( size_type start, size_type length ) const noexcept -> StringRef; - - // Returns the current start pointer. May not be null-terminated. - auto data() const noexcept -> char const*; - - constexpr auto isNullTerminated() const noexcept -> bool { - return m_start[m_size] == '\0'; - } - - public: // iterators - constexpr const_iterator begin() const { return m_start; } - constexpr const_iterator end() const { return m_start + m_size; } - }; - - auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; - auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - - constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { - return StringRef( rawChars, size ); - } -} // namespace Catch - -constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { - return Catch::StringRef( rawChars, size ); -} - -// end catch_stringref.h -// start catch_preprocessor.hpp - - -#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ -#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) - -#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ -// MSVC needs more evaluations -#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) -#else -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) -#endif - -#define CATCH_REC_END(...) -#define CATCH_REC_OUT - -#define CATCH_EMPTY() -#define CATCH_DEFER(id) id CATCH_EMPTY() - -#define CATCH_REC_GET_END2() 0, CATCH_REC_END -#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 -#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 -#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT -#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) -#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) - -#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) - -#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) - -// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, -// and passes userdata as the first parameter to each invocation, -// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) -#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) -#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ -#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ -#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) -#else -// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) -#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) -#endif - -#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ -#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) - -#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) -#else -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) -#endif - -#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ - CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) - -#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) -#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) -#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) -#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) -#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) -#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) -#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _4, _5, _6) -#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) -#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) -#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) -#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) - -#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N - -#define INTERNAL_CATCH_TYPE_GEN\ - template struct TypeList {};\ - template\ - constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ - template class...> struct TemplateTypeList{};\ - template class...Cs>\ - constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ - template\ - struct append;\ - template\ - struct rewrap;\ - template class, typename...>\ - struct create;\ - template class, typename>\ - struct convert;\ - \ - template \ - struct append { using type = T; };\ - template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ - struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ - template< template class L1, typename...E1, typename...Rest>\ - struct append, TypeList, Rest...> { using type = L1; };\ - \ - template< template class Container, template class List, typename...elems>\ - struct rewrap, List> { using type = TypeList>; };\ - template< template class Container, template class List, class...Elems, typename...Elements>\ - struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ - \ - template