Make tables of standard encryption schemes etc.
[u/mdw/catacomb] / gengctab
1 #! /bin/sh
2
3 set -e
4 type=$1
5 include=$2
6 list=$3
7
8 cat <<EOF
9 /* -*-c-*-
10 *
11 * ${include}tab.c [generated]
12 */
13
14 #include <string.h>
15
16 #include "$2.h"
17
18 EOF
19 for i in $list; do
20 echo "#include \"$i.h\""
21 done
22
23 cat <<EOF
24
25 const $type *const ${include}tab[] = {
26 EOF
27 for i in $list; do
28 c=`echo $i | sed 's/[^A-Za-z0-9_][^A-Za-z0-9_]*/_/g'`
29 echo " &$c,"
30 done
31 cat <<EOF
32 0
33 };
34
35 const $type *${include}_byname(const char *p)
36 {
37 const $type *const *c;
38
39 for (c = ${include}tab; *c; c++) {
40 if (strcmp(p, (*c)->name) == 0)
41 return (*c);
42 }
43 return (0);
44 }
45
46 EOF