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