Make tables of standard encryption schemes etc.
[u/mdw/catacomb] / gengctab
diff --git a/gengctab b/gengctab
new file mode 100755 (executable)
index 0000000..3211b42
--- /dev/null
+++ b/gengctab
@@ -0,0 +1,46 @@
+#! /bin/sh
+
+set -e
+type=$1
+include=$2
+list=$3
+
+cat <<EOF
+/* -*-c-*-
+ *
+ * ${include}tab.c [generated]
+ */
+
+#include <string.h>
+
+#include "$2.h"
+
+EOF
+for i in $list; do
+  echo "#include \"$i.h\""
+done
+
+cat <<EOF
+
+const $type *const ${include}tab[] = {
+EOF
+for i in $list; do
+  c=`echo $i | sed 's/[^A-Za-z0-9_][^A-Za-z0-9_]*/_/g'`
+  echo "  &$c,"
+done
+cat <<EOF
+  0
+};
+
+const $type *${include}_byname(const char *p)
+{
+  const $type *const *c;
+
+  for (c = ${include}tab; *c; c++) {
+    if (strcmp(p, (*c)->name) == 0)
+      return (*c);
+  }
+  return (0);
+}
+
+EOF