aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in17
-rw-r--r--enums/msg_type.in6
-rw-r--r--enums/op.in23
-rw-r--r--enums/query_field.in28
-rw-r--r--enums/query_type.in9
-rw-r--r--enums/res.in4
-rw-r--r--enums/sev.in6
-rwxr-xr-xmaketables210
-rw-r--r--pseudo.h89
-rw-r--r--pseudo_client.c2
-rw-r--r--pseudo_client.h2
-rw-r--r--pseudo_db.c2
-rw-r--r--pseudo_db.h12
-rw-r--r--pseudo_ipc.h16
-rw-r--r--pseudo_table.c250
-rw-r--r--table_templates/pseudo_tables.c43
-rw-r--r--table_templates/pseudo_tables.h23
17 files changed, 377 insertions, 365 deletions
diff --git a/Makefile.in b/Makefile.in
index e931faa..a0609a2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -47,7 +47,7 @@ GUTS=$(filter-out "$(GLOB_PATTERN)",$(wildcard $(GLOB_PATTERN)))
DBLDFLAGS=-lsqlite3
USE_64=wrapfuncs64.in
-SHOBJS=pseudo_table.o pseudo_util.o
+SHOBJS=pseudo_tables.o pseudo_util.o
DBOBJS=pseudo_db.o -ldl -lpthread
WRAPOBJS=pseudo_wrappers.o
@@ -57,6 +57,7 @@ PSEUDOLOG=$(BIN)/pseudolog
LIBPSEUDO=$(LIB)/libpseudo.so
TEMPLATES=templates/guts templates/wrapfuncs.c templates/wrapfuncs.h templates/wrapper_table
+TABLES=table_templates/pseudo_tables.c table_templates/pseudo_tables.h
all: $(LIBPSEUDO) $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG)
@@ -115,15 +116,23 @@ pseudo_client.o: pseudo_client.h
pseudo_server.o: pseudo_server.h
+tables: enums/*.in maketables templatefile.py $(TABLES)
+ ./maketables enums/*.in
+
wrappers: wrapfuncs.in $(USE_64) makewrappers templatefile.py $(TEMPLATES)
./makewrappers wrapfuncs.in $(USE_64)
-.SECONDARY: wrappers
+.SECONDARY: tables wrappers
pseudo_wrapfuncs.c pseudo_wrapfuncs.h: wrappers
+pseudo_tables.c pseudo_tables.h: tables
+
+pseudo_tables.o: pseudo_tables.c
+ $(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -c -o pseudo_tables.o pseudo_tables.c
+
# no-strict-aliasing is needed for the function pointer trickery.
-pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c pseudo_wrapfuncs.c pseudo_wrapfuncs.h
+pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c pseudo_wrapfuncs.c pseudo_wrapfuncs.h pseudo_tables.h
$(CC) -fno-strict-aliasing $(CFLAGS) $(CFLAGS_PSEUDO) -D_GNU_SOURCE -c -o pseudo_wrappers.o pseudo_wrappers.c
offsets32:
@@ -136,7 +145,7 @@ clean:
rm -f *.o *.so $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG) \
pseudo_wrapfuncs.h pseudo_wrapfuncs.c \
pseudo_wrapper_table.c \
- pseudo_wrapfuncs.c.old pseudo_wrapfuncs.h.old \
+ pseudo_tables.c pseudo_tables.h \
offsets32 offsets64
distclean: clean
diff --git a/enums/msg_type.in b/enums/msg_type.in
new file mode 100644
index 0000000..0313073
--- /dev/null
+++ b/enums/msg_type.in
@@ -0,0 +1,6 @@
+msg_type: PSEUDO_MSG
+ping
+shutdown
+op
+ack
+nak
diff --git a/enums/op.in b/enums/op.in
new file mode 100644
index 0000000..65eb73c
--- /dev/null
+++ b/enums/op.in
@@ -0,0 +1,23 @@
+op: OP
+chdir
+chmod
+chown
+chroot
+close
+creat
+dup
+fchmod
+fchown
+fstat
+link
+mkdir
+mknod
+open
+rename
+stat
+unlink
+symlink
+exec
+may-unlink
+did-unlink
+cancel-unlink
diff --git a/enums/query_field.in b/enums/query_field.in
new file mode 100644
index 0000000..5124c5d
--- /dev/null
+++ b/enums/query_field.in
@@ -0,0 +1,28 @@
+query_field: PSQF
+# Note: These are later used as bitwise masks into a value,
+# currently an unsigned long; if the number of these gets up
+# near 32, that may take rethinking. The first thing to
+# go would probably be something special to do for FTYPE and
+# PERM because they aren't "real" database fields -- both
+# of them actually imply MODE.
+access
+client
+dev
+fd
+ftype
+gid
+id
+inode
+mode
+op
+order
+path
+perm
+program
+result
+severity
+stamp
+tag
+text
+type
+uid
diff --git a/enums/query_type.in b/enums/query_type.in
new file mode 100644
index 0000000..5bfc741
--- /dev/null
+++ b/enums/query_type.in
@@ -0,0 +1,9 @@
+query_type: PSQT; sql = LITTLE BOBBY TABLES
+exact, =
+less, <
+greater, >
+bitand, &
+notequal, !=
+like, LIKE
+notlike, NOT LIKE
+sqlpat, LIKE
diff --git a/enums/res.in b/enums/res.in
new file mode 100644
index 0000000..435338f
--- /dev/null
+++ b/enums/res.in
@@ -0,0 +1,4 @@
+res: RESULT
+succeed
+fail
+error
diff --git a/enums/sev.in b/enums/sev.in
new file mode 100644
index 0000000..24c2c6e
--- /dev/null
+++ b/enums/sev.in
@@ -0,0 +1,6 @@
+sev: SEVERITY
+debug
+info
+warn
+error
+critical
diff --git a/maketables b/maketables
new file mode 100755
index 0000000..4e7d6ea
--- /dev/null
+++ b/maketables
@@ -0,0 +1,210 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2008-2010 Wind River Systems, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the Lesser GNU General Public License version 2.1 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the Lesser GNU General Public License for more details.
+#
+# You should have received a copy of the Lesser GNU General Public License
+# version 2.1 along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""convert tables.in files to enums, tables, and support code.
+
+Inputs are a type name, prefix, and a list of columns, followed by a list of
+names with optional "= value" suffixes, plus optional additional columns.
+The names are used to create enums and a table of strings, as well as
+to/from lookups between the ids and names. If additional columns are
+defined, each column (separated by ", ") is used to create an additional
+table of the given name, and a lookup function from ids. Example:
+ foo: FFF; bar = GOZINTA
+ hello, yah
+ world, nope
+produces:
+ typedef enum {
+ FFF_UNKNOWN = -1,
+ FFF_MIN = 0,
+ FFF_NONE = 0,
+ FFF_HELLO,
+ FFF_WORLD,
+ FFF_MAX
+ } foo_id_t;
+ extern const char *foo_name(foo_id_t id);
+ extern foo_id_t foo_id(const char *name);
+ extern const char *foo_bar(foo_id_t id);
+
+such that foo_name(1) => "hello" and foo_bar(1) => "yah". If there
+is an assigned value for a column description, missing column values
+yield that value, otherwise they yield "unknown".
+
+Values out of range yield "unknown", and unrecognized names yield the
+value -1. Note that the "MAX" value is one more than the highest defined
+value. (This is for consistency with C array bounds.)
+"""
+
+import glob
+import sys
+import re
+import datetime
+import string
+from templatefile import TemplateFile
+
+class DataType:
+ """a set of related DataItem objects"""
+
+ def __init__(self, path):
+ """read the first line of path, then make tuples of the rest"""
+ source = file(path)
+ definition = source.readline().rstrip()
+ self.name, qualifiers = string.split(definition, ': ', 2)
+ if '; ' in qualifiers:
+ self.prefix, columns = string.split(qualifiers, '; ')
+ else:
+ self.prefix = qualifiers
+ columns = []
+ if len(columns):
+ self.columns = []
+ columns = string.split(columns, ', ')
+ for col in columns:
+ if "=" in col:
+ name, default = string.split(col, ' = ')
+ else:
+ name, default = col, ""
+ self.columns.append({"name":name, "value":default})
+ else:
+ self.columns = []
+ self.data = []
+ self.comments = []
+ for line in source.readlines():
+ item = {}
+ if line.startswith('#'):
+ self.comments.append(line.rstrip().replace('#', ''))
+ continue
+ # first entry on the line is the "real" name/id, following hunks
+ # are additional columns
+ cols = string.split(line.rstrip(), ', ')
+ item["name"] = cols.pop(0)
+ item["upper"] = item["name"].replace('-', '_').upper()
+ column_list = []
+ for col in self.columns:
+ if len(cols) > 0:
+ column_list.append({"name":col["name"], "value":cols.pop(0)})
+ else:
+ column_list.append({"name":col["name"], "value":col["default"]})
+ item["cols"] = column_list
+ self.data.append(item)
+
+ def __getitem__(self, key):
+ """Make this object look like a dict for Templates to use"""
+ attr = getattr(self, key)
+
+ if callable(attr):
+ return attr()
+ else:
+ return attr
+
+ def __repr__(self):
+ str = ""
+ str += "type: %s_t" % self.name
+ str += " %s_ENUM\n" % self.prefix
+ for col in self.columns:
+ str += "\tcol: %s (%s)\n" % (col["name"], col["value"])
+ for item in self.data:
+ str += "item: %s\n" % item["name"]
+ for col in item["cols"]:
+ str += "\t%s(%s)\n" % (col["name"], col["value"])
+ return str
+
+ def comment(self):
+ if len(self.comments):
+ return '/*' + '\n *'.join(self.comments) + ' */\n'
+ else:
+ return ''
+
+ def names(self):
+ return ',\n\t'.join('"%s"' % x["name"] for x in self.data)
+
+ def enums(self):
+ return ',\n\t'.join('%s_%s' % (self.prefix, x["upper"]) for x in self.data)
+
+ def column_names(self):
+ decl_lines = []
+ column = 0
+ for col in self.columns:
+ decl_lines.append("static const char *%s_id_to_%s[] = {" % (self.name, col["name"]))
+ decl_lines.append('\t"%s",' % col["value"])
+ for item in self.data:
+ decl_lines.append('\t"%s",' % item["cols"][column]["value"])
+ decl_lines.append('\tNULL')
+ decl_lines.append("};")
+ column = column + 1
+ return '\n'.join(decl_lines)
+
+ def column_funcs(self):
+ decl_lines = []
+ for col in self.columns:
+ decl_lines.append('extern const char *')
+ decl_lines.append('pseudo_%s_%s(pseudo_%s_t id) {' %
+ (self.name, col["name"], self.name))
+ decl_lines.append('\tif (id < 0 || id >= %s_MAX)' % (self.prefix))
+ decl_lines.append('\t\treturn "%s";' % col["value"])
+ decl_lines.append('\treturn %s_id_to_%s[id];' %
+ (self.name, col["name"]))
+ decl_lines.append('}')
+ return '\n'.join(decl_lines)
+
+ def column_protos(self):
+ decl_lines = []
+ for col in self.columns:
+ decl_lines.append('extern const char *pseudo_%s_%s(pseudo_%s_t id);' %
+ (self.name, col["name"], self.name))
+ return '\n'.join(decl_lines)
+
+def main():
+ """Read in function defintions, write out files based on templates."""
+ datatypes = []
+ templates = []
+
+ # error checking helpfully provided by the exception handler
+ copyright_file = open('guts/COPYRIGHT')
+ TemplateFile.copyright = copyright_file.read()
+ copyright_file.close()
+
+ for path in glob.glob('table_templates/*'):
+ try:
+ template_file = TemplateFile(path)
+ template_file.emit('copyright')
+ template_file.emit('header')
+ templates.append(template_file)
+ except IOError:
+ print "Invalid or malformed template %s. Aborting." % path
+ exit(1)
+
+ for filename in sys.argv[1:]:
+ # read in the datatype
+ sys.stdout.write("%s: " % filename)
+ datatype = DataType(filename)
+ datatypes.append(datatype)
+ print datatype.__repr__()
+ print ""
+
+ print "Writing datatypes...",
+ for datatype in datatypes:
+ # populate various tables and files with each datatype
+ for template_file in templates:
+ template_file.emit('body', datatype)
+ print "done. Cleaning up."
+
+ for template_file in templates:
+ # clean up files
+ template_file.emit('footer')
+ template_file.close()
+
+if __name__ == '__main__':
+ main()
diff --git a/pseudo.h b/pseudo.h
index a568bca..9b06651 100644
--- a/pseudo.h
+++ b/pseudo.h
@@ -26,94 +26,7 @@ void pseudo_dump_env(char **envp);
int pseudo_set_value(const char * key, const char * value);
char * pseudo_get_value(const char * key);
-typedef enum {
- OP_UNKNOWN = -1,
- OP_NONE = 0,
- OP_CHDIR,
- OP_CHMOD,
- OP_CHOWN,
- OP_CHROOT,
- OP_CLOSE,
- OP_CREAT,
- OP_DUP,
- OP_FCHMOD,
- OP_FCHOWN,
- OP_FSTAT,
- OP_LINK,
- OP_MKDIR,
- OP_MKNOD,
- OP_OPEN,
- OP_RENAME,
- OP_STAT,
- OP_UNLINK,
- /* added after the original release, so they have to go out of order
- * to avoid breaking the operation numbers in old logs.
- */
- OP_SYMLINK,
- OP_EXEC,
- OP_MAY_UNLINK,
- OP_DID_UNLINK,
- OP_CANCEL_UNLINK,
- OP_MAX
-} op_id_t;
-extern char *pseudo_op_name(op_id_t id);
-extern op_id_t pseudo_op_id(char *name);
-
-typedef enum {
- RESULT_UNKNOWN = -1,
- RESULT_NONE = 0,
- RESULT_SUCCEED,
- RESULT_FAIL,
- RESULT_ERROR,
- RESULT_MAX
-} res_id_t;
-extern char *pseudo_res_name(res_id_t id);
-extern res_id_t pseudo_res_id(char *name);
-
-typedef enum {
- SEVERITY_UNKNOWN = -1,
- SEVERITY_NONE = 0,
- SEVERITY_DEBUG,
- SEVERITY_INFO,
- SEVERITY_WARN,
- SEVERITY_ERROR,
- SEVERITY_CRITICAL,
- SEVERITY_MAX
-} sev_id_t;
-extern char *pseudo_sev_name(sev_id_t id);
-extern sev_id_t pseudo_sev_id(char *name);
-
-typedef enum pseudo_query_type {
- PSQT_UNKNOWN = -1,
- PSQT_NONE,
- PSQT_EXACT, PSQT_LESS, PSQT_GREATER, PSQT_BITAND,
- PSQT_NOTEQUAL, PSQT_LIKE, PSQT_NOTLIKE, PSQT_SQLPAT,
- PSQT_MAX
-} pseudo_query_type_t;
-extern char *pseudo_query_type_name(pseudo_query_type_t id);
-extern char *pseudo_query_type_sql(pseudo_query_type_t id);
-extern pseudo_query_type_t pseudo_query_type_id(char *name);
-
-/* Note: These are later used as bitwise masks into a value,
- * currently an unsigned long; if the number of these gets up
- * near 32, that may take rethinking. The first thing to
- * go would probably be something special to do for FTYPE and
- * PERM because they aren't "real" database fields -- both
- * of them actually imply MODE.
- */
-typedef enum pseudo_query_field {
- PSQF_UNKNOWN = -1,
- PSQF_NONE, /* so that these are always non-zero */
- PSQF_ACCESS,
- PSQF_CLIENT, PSQF_DEV, PSQF_FD, PSQF_FTYPE,
- PSQF_GID, PSQF_ID, PSQF_INODE, PSQF_MODE,
- PSQF_OP, PSQF_ORDER, PSQF_PATH, PSQF_PERM,
- PSQF_PROGRAM, PSQF_RESULT, PSQF_SEVERITY, PSQF_STAMP,
- PSQF_TAG, PSQF_TEXT, PSQF_TYPE, PSQF_UID,
- PSQF_MAX
-} pseudo_query_field_t;
-extern char *pseudo_query_field_name(pseudo_query_field_t id);
-extern pseudo_query_field_t pseudo_query_field_id(char *name);
+#include "pseudo_tables.h"
extern void pseudo_debug_verbose(void);
extern void pseudo_debug_terse(void);
diff --git a/pseudo_client.c b/pseudo_client.c
index a599da4..b169259 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -792,7 +792,7 @@ base_path(int dirfd, const char *path, int leave_last) {
}
pseudo_msg_t *
-pseudo_client_op(op_id_t op, int access, int fd, int dirfd, const char *path, const struct stat64 *buf, ...) {
+pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path, const struct stat64 *buf, ...) {
pseudo_msg_t *result = 0;
pseudo_msg_t msg = { .type = PSEUDO_MSG_OP };
size_t pathlen = -1;
diff --git a/pseudo_client.h b/pseudo_client.h
index 6bb334e..7eac3c8 100644
--- a/pseudo_client.h
+++ b/pseudo_client.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-extern pseudo_msg_t *pseudo_client_op(op_id_t op, int access, int fd, int dirfd, const char *path, const struct stat64 *buf, ...);
+extern pseudo_msg_t *pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path, const struct stat64 *buf, ...);
extern void pseudo_antimagic(void);
extern void pseudo_magic(void);
extern void pseudo_client_reset(void);
diff --git a/pseudo_db.c b/pseudo_db.c
index 245f4e6..27891aa 100644
--- a/pseudo_db.c
+++ b/pseudo_db.c
@@ -747,7 +747,7 @@ pdb_log_entry(log_entry *e) {
}
/* create a log from a given message, with tag and text */
int
-pdb_log_msg(sev_id_t severity, pseudo_msg_t *msg, const char *program, const char *tag, const char *text, ...) {
+pdb_log_msg(pseudo_sev_t severity, pseudo_msg_t *msg, const char *program, const char *tag, const char *text, ...) {
char *sql = "INSERT INTO logs "
"(stamp, op, access, client, dev, gid, ino, mode, path, result, uid, severity, text, program, tag, type)"
" VALUES "
diff --git a/pseudo_db.h b/pseudo_db.h
index bd09c89..fe2fb12 100644
--- a/pseudo_db.h
+++ b/pseudo_db.h
@@ -20,7 +20,7 @@
typedef struct {
time_t stamp;
pseudo_msg_type_t type;
- op_id_t op;
+ pseudo_op_t op;
int access;
unsigned long client;
unsigned long fd;
@@ -30,8 +30,8 @@ typedef struct {
unsigned long gid;
unsigned long uid;
char *path;
- res_id_t result;
- sev_id_t severity;
+ pseudo_res_t result;
+ pseudo_sev_t severity;
char *text;
char *tag;
char *program;
@@ -65,14 +65,14 @@ union pseudo_query_data {
};
typedef struct pseudo_query {
- enum pseudo_query_type type;
- enum pseudo_query_field field;
+ pseudo_query_type_t type;
+ pseudo_query_field_t field;
union pseudo_query_data data;
struct pseudo_query *next;
} pseudo_query_t;
extern int pdb_log_entry(log_entry *e);
-extern int pdb_log_msg(sev_id_t severity, pseudo_msg_t *msg, const char *program, const char *tag, const char *text, ...);
+extern int pdb_log_msg(pseudo_sev_t severity, pseudo_msg_t *msg, const char *program, const char *tag, const char *text, ...);
extern int pdb_log_traits(pseudo_query_t *traits);
struct pdb_file_list;
diff --git a/pseudo_ipc.h b/pseudo_ipc.h
index 40953a8..b65c7fb 100644
--- a/pseudo_ipc.h
+++ b/pseudo_ipc.h
@@ -17,26 +17,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-typedef enum {
- PSEUDO_MSG_UNKNOWN = -1,
- PSEUDO_MSG_NONE,
- PSEUDO_MSG_PING,
- PSEUDO_MSG_SHUTDOWN,
- PSEUDO_MSG_OP,
- PSEUDO_MSG_ACK,
- PSEUDO_MSG_NAK,
- PSEUDO_MSG_MAX
-} pseudo_msg_type_t;
-extern char *pseudo_msg_type_name(pseudo_msg_type_t id);
-extern pseudo_msg_type_t pseudo_msg_type_id(char *name);
/* The [] item at the end of the struct is a C99 feature, replacing the
* old (and unportable) "struct hack".
*/
typedef struct {
pseudo_msg_type_t type;
- op_id_t op;
- res_id_t result;
+ pseudo_op_t op;
+ pseudo_res_t result;
int access;
int client;
int fd;
diff --git a/pseudo_table.c b/pseudo_table.c
deleted file mode 100644
index c890adc..0000000
--- a/pseudo_table.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * pseudo_table.c, data definitions and related utilities
- *
- * Copyright (c) 2008-2010 Wind River Systems, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the Lesser GNU General Public License version 2.1 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Lesser GNU General Public License for more details.
- *
- * You should have received a copy of the Lesser GNU General Public License
- * version 2.1 along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include "pseudo.h"
-#include "pseudo_ipc.h"
-
-/* just a bunch of handy lookups for pretty-printing stuff */
-
-static char *operation_names[] = {
- "none",
- "chdir",
- "chmod",
- "chown",
- "chroot",
- "close",
- "creat",
- "dup",
- "fchmod",
- "fchown",
- "fstat",
- "link",
- "mkdir",
- "mknod",
- "open",
- "rename",
- "stat",
- "unlink",
- "symlink",
- "exec",
- "may-unlink",
- "did-unlink",
- "cancel-unlink",
- NULL
-};
-
-static char *result_names[] = {
- "none",
- "succeed",
- "fail",
- "error",
- NULL
-};
-
-static char *severity_names[] = {
- "none",
- "debug",
- "info",
- "warn",
- "error",
- "critical",
- NULL
-};
-
-static char *query_type_names[] = {
- "none",
- "exact",
- "less",
- "greater",
- "bitand",
- "notequal",
- "like",
- "notlike",
- "sqlpat",
- NULL
-};
-
-static char *query_type_sql[] = {
- "LITTLE BOBBY TABLES",
- "=",
- "<",
- ">",
- "&",
- "!=",
- "LIKE",
- "NOT LIKE",
- "LIKE",
- NULL
-};
-
-static char *query_field_names[] = {
- "zero",
- "access",
- "client",
- "dev",
- "fd",
- "ftype",
- "gid",
- "id",
- "ino",
- "mode",
- "op",
- "order",
- "path",
- "perm",
- "program",
- "result",
- "severity",
- "stamp",
- "tag",
- "text",
- "type",
- "uid",
- NULL
-};
-
-static char *pseudo_msg_type_names[] = {
- "none",
- "ping",
- "halt",
- "op",
- "ack",
- "nak",
- NULL
-};
-
-char *
-pseudo_op_name(op_id_t id) {
- if (id >= OP_NONE && id < OP_MAX) {
- return operation_names[id];
- }
- return "unknown";
-}
-
-char *
-pseudo_res_name(res_id_t id) {
- if (id >= RESULT_NONE && id < RESULT_MAX) {
- return result_names[id];
- }
- return "unknown";
-}
-
-char *
-pseudo_sev_name(sev_id_t id) {
- if (id >= SEVERITY_NONE && id < SEVERITY_MAX) {
- return severity_names[id];
- }
- return "unknown";
-}
-
-char *
-pseudo_query_type_name(pseudo_query_type_t id) {
- if (id >= PSQT_NONE && id < PSQT_MAX) {
- return query_type_names[id];
- }
- return "unknown";
-}
-
-char *
-pseudo_query_type_sql(pseudo_query_type_t id) {
- if (id >= PSQT_NONE && id < PSQT_MAX) {
- return query_type_sql[id];
- }
- return "LITTLE BOBBY TABLES";
-}
-
-char *
-pseudo_query_field_name(pseudo_query_field_t id) {
- if (id >= PSQF_NONE && id < PSQF_MAX) {
- return query_field_names[id];
- }
- return "unknown";
-}
-
-char *
-pseudo_msg_type_name(pseudo_msg_type_t id) {
- if (id >= PSEUDO_MSG_NONE && id < PSEUDO_MSG_MAX) {
- return pseudo_msg_type_names[id];
- }
- return "????";
-}
-
-op_id_t
-pseudo_op_id(char *name) {
- int id;
- for (id = OP_NONE; id < OP_MAX; ++id) {
- if (!strcmp(name, operation_names[id]))
- return id;
- }
- return OP_UNKNOWN;
-}
-
-res_id_t
-pseudo_res_id(char *name) {
- int id;
- for (id = RESULT_NONE; id < RESULT_MAX; ++id) {
- if (!strcmp(name, result_names[id]))
- return id;
- }
- return RESULT_UNKNOWN;
-}
-
-sev_id_t
-pseudo_sev_id(char *name) {
- int id;
- for (id = SEVERITY_NONE; id < SEVERITY_MAX; ++id) {
- if (!strcmp(name, severity_names[id]))
- return id;
- }
- return SEVERITY_UNKNOWN;
-}
-
-pseudo_query_type_t
-pseudo_query_type(char *name) {
- int id;
- for (id = PSQT_NONE; id < PSQT_MAX; ++id) {
- if (!strcmp(name, query_type_names[id]))
- return id;
- }
- return PSQT_UNKNOWN;
-}
-
-pseudo_query_field_t
-pseudo_query_field(char *name) {
- int id;
- for (id = PSQF_NONE; id < PSQF_MAX; ++id) {
- if (!strcmp(name, query_field_names[id]))
- return id;
- }
- return PSQF_UNKNOWN;
-}
-
-pseudo_msg_type_t
-pseudo_msg_type_id(char *name) {
- int id;
- for (id = PSEUDO_MSG_NONE; id < PSEUDO_MSG_MAX; ++id) {
- if (!strcmp(name, pseudo_msg_type_names[id]))
- return id;
- }
- return PSEUDO_MSG_NONE;;
-}
diff --git a/table_templates/pseudo_tables.c b/table_templates/pseudo_tables.c
new file mode 100644
index 0000000..f802187
--- /dev/null
+++ b/table_templates/pseudo_tables.c
@@ -0,0 +1,43 @@
+@name pseudo_tables.c
+@header
+/* Tables matching enums to strings */
+
+/* This file is generated and should not be modified. See the maketables
+ * script if you want to modify this. */
+
+#include "pseudo_tables.h"
+
+@body
+/* tables for ${name} */
+
+static const char *${name}_id_to_name[] = {
+ "none",
+ ${names},
+ NULL
+};
+${column_names}
+
+/* functions for ${name} */
+extern const char *
+pseudo_${name}_name(pseudo_${name}_t id) {
+ if (id < 0 || id >= ${prefix}_MAX)
+ return "unknown";
+ return ${name}_id_to_name[id];
+}
+
+extern pseudo_${name}_t
+pseudo_${name}_id(const char *name) {
+ int id;
+
+ if (!name)
+ return -1;
+
+ for (id = 0; id < ${prefix}_MAX; ++id)
+ if (!strcmp(${name}_id_to_name[id], name))
+ return id;
+
+ return -1;
+}
+${column_funcs}
+
+@footer
diff --git a/table_templates/pseudo_tables.h b/table_templates/pseudo_tables.h
new file mode 100644
index 0000000..7323658
--- /dev/null
+++ b/table_templates/pseudo_tables.h
@@ -0,0 +1,23 @@
+@name pseudo_tables.h
+@header
+/* standard ranges/values/keys */
+
+/* This file is generated and should not be modified. See the maketables
+ * script if you want to modify this. */
+
+/* NULL, strcmp */
+#include <string.h>
+@body
+/* tables for ${name} */
+${comment}
+typedef enum {
+ ${prefix}_UNKNOWN = -1,
+ ${prefix}_NONE = 0,
+ ${enums},
+ ${prefix}_MAX
+} pseudo_${name}_t;
+extern const char *pseudo_${name}_name(pseudo_${name}_t);
+extern pseudo_${name}_t pseudo_${name}_id(const char *);
+${column_protos}
+
+@footer