Debian Codegraph @

src/process_atoms

raw
1 #! /bin/sh
2
3 help() {
4 echo commands: help header gperf filter table
5 }
6
7 header() {
8 echo '/* Automatically generated by process_atoms,'
9 echo ' * ' `date`
10 echo ' * Do not edit! */'
11 echo
12 }
13
14 atom_id=0
15
16 getatom() {
17 atom=''
18 while [ "x$atom" = x ]; do
19 read atom ignored
20 if [ x$? != x0 ] ; then
21 return 1
22 fi
23 case "$atom" in
24 \#*)
25 atom=''
26 ;;
27 esac ;
28 done
29 atom_id=`expr $atom_id + 1`
30 }
31
32 atom2define () {
33 printf "%s" "`echo ATOM_$1 | tr [a-z]- [A-Z]_ \
34 | sed -e 's/\*/STAR/' -e 's/@.*$/_LOCAL/'`"
35 }
36
37 if [ x$# != x1 ]; then
38 help
39 exit 1
40 fi
41
42 case $1 in
43 filter)
44 while getatom; do
45 echo "$atom" $atom_id
46 done
47 ;;
48 header)
49 header
50 while getatom; do
51 printf "%s" '#define '
52 atom2define "$atom"
53 echo ' ' $atom_id
54 done
55 echo '#define NUMBER_OF_ATOMS' `expr $atom_id + 1`
56 ;;
57 gperf)
58 echo '%{'
59 header
60 echo '%}'
61
62 echo 'struct atom_assoc { const char *name; int id; };'
63 echo '%%'
64
65 while getatom; do
66 printf "%s" "$atom, "
67 atom2define "$atom"
68 echo
69 done
70 ;;
71 table)
72 header
73 printf "%s" '{ { "UNKNOWN", 7 },'
74 while getatom; do
75 printf ' {"%s", %s},\n' "$atom" "`expr "$atom" : '.*'`"
76 done
77 echo ' }'
78 ;;
79 help)
80 help
81 exit 0
82 ;;
83 *)
84 help
85 exit 1
86 ;;
87 esac