Debian Codegraph @

scripts/makedbh

raw
1 #!/bin/csh -f
2 #
3 # makes the "database.h" (1st argument, $1) file from "database.h.in"
4 # (2nd argument, $2), setting various mask operation definitions
5 # according to the number of words implied by the value of TT_MAXTYPES
6
7 # The following mess grabs the value of TT_MAXTYPES from database.h.in
8 #
9 set maxtypes=`sed -n -e '/^#define[[:space:]]*TT_MAXTYPES/s/#define[[:space:]]*TT_MAXTYPES[[:space:]]*//p' < $1 | sed -e 's/\/\*[[:print:]]*\*\/[[:space:]]*//g' `
10 #
11 # Alternative method works with outdated versions of sed/ed.
12 #
13 if ($maxtypes == "") then
14 set maxtypes=`sed -n -e '/^#define[ ]*TT_MAXTYPES/s/#define[ ]*TT_MAXTYPES[ ]*//p' < $1 | sed -e 's/\/\*.*\*\/[ ]*//g' `
15 endif
16 #
17 # If we can't generate database.h correctly, nothing is going to compile.
18 #
19 if ($maxtypes == "") then
20 echo "Bad sed script in scripts/makedbh: Cannot generate database/database.h!"
21 exit
22 endif
23
24 # Find derived values from bits per word
25 # Note that bits-per-word should be determined from the compiler, but
26 # 32 bits per word has always been hardwired into magic.
27 #
28 set bpw = 32
29
30 # @ wordmask=$bpw - 1
31 # set wordshift=`echo "c=l($bpw); d=l(2); scale=0; c/d" | bc -l`
32 # @ maskwords=$maxtypes + $bpw - 1
33 # @ maskwords/=$bpw
34
35 @ maskwords=$maxtypes + $bpw - 1
36 @ maskwords/=$bpw
37
38
39 # Generate the main part of the database.h file from database.h.in
40 cat $1 > $2
41
42 # Generate a list of integers from 0 to the value of "maskwords" - 1
43 set count=""
44 @ maskwords--
45 while (${maskwords} >= 0)
46 set count=`echo ${count} ${maskwords}`
47 @ maskwords--
48 end
49
50 # Definitions
51
52 echo "#define TTMaskZero(m) ( \" >> $2
53 foreach i (${count})
54 echo -n " (m)->tt_words[$i] = 0" >> $2
55 if ($i == 0) then
56 echo ")" >> $2
57 echo "" >> $2
58 else
59 echo ", \" >> $2
60 endif
61 end
62
63 echo "#define TTMaskIsZero(m) ( \" >> $2
64 foreach i (${count})
65 echo -n " (m)->tt_words[$i] == 0" >> $2
66 if ($i == 0) then
67 echo ")" >> $2
68 echo "" >> $2
69 else
70 echo " && \" >> $2
71 endif
72 end
73
74 echo "#define TTMaskEqual(m, n) ( \" >> $2
75 foreach i (${count})
76 echo -n " (m)->tt_words[$i] == (n)->tt_words[$i]" >> $2
77 if ($i == 0) then
78 echo ")" >> $2
79 echo "" >> $2
80 else
81 echo " && \" >> $2
82 endif
83 end
84
85 echo "#define TTMaskIntersect(m, n) ( \" >> $2
86 foreach i (${count})
87 echo -n " ((m)->tt_words[$i] & (n)->tt_words[$i])" >> $2
88 if ($i == 0) then
89 echo ")" >> $2
90 echo "" >> $2
91 else
92 echo " || \" >> $2
93 endif
94 end
95
96 echo "#define TTMaskCom(m) ( \" >> $2
97 foreach i (${count})
98 echo -n " ((m)->tt_words[$i] = ~(m)->tt_words[$i])" >> $2
99 if ($i == 0) then
100 echo ")" >> $2
101 echo "" >> $2
102 else
103 echo ", \" >> $2
104 endif
105 end
106
107 echo "#define TTMaskCom2(m, n) ( \" >> $2
108 foreach i (${count})
109 echo -n " ((m)->tt_words[$i] = ~(n)->tt_words[$i])" >> $2
110 if ($i == 0) then
111 echo ")" >> $2
112 echo "" >> $2
113 else
114 echo ", \" >> $2
115 endif
116 end
117
118 echo "#define TTMaskSetMask(m, n) ( \" >> $2
119 foreach i (${count})
120 echo -n " ((m)->tt_words[$i] |= (n)->tt_words[$i])" >> $2
121 if ($i == 0) then
122 echo ")" >> $2
123 echo "" >> $2
124 else
125 echo ", \" >> $2
126 endif
127 end
128
129 echo "#define TTMaskSetMask3(m, n, o) ( \" >> $2
130 foreach i (${count})
131 echo -n " ((m)->tt_words[$i] |= (n)->tt_words[$i] | (o)->tt_words[$i])" \
132 >> $2
133 if ($i == 0) then
134 echo ")" >> $2
135 echo "" >> $2
136 else
137 echo ", \" >> $2
138 endif
139 end
140
141 echo "#define TTMaskAndMask(m, n) ( \" >> $2
142 foreach i (${count})
143 echo -n " ((m)->tt_words[$i] &= (n)->tt_words[$i])" >> $2
144 if ($i == 0) then
145 echo ")" >> $2
146 echo "" >> $2
147 else
148 echo ", \" >> $2
149 endif
150 end
151
152 echo "#define TTMaskAndMask3(m, n, o) ( \" >> $2
153 foreach i (${count})
154 echo -n " ((m)->tt_words[$i] = (n)->tt_words[$i] & (o)->tt_words[$i])" \
155 >> $2
156 if ($i == 0) then
157 echo ")" >> $2
158 echo "" >> $2
159 else
160 echo ", \" >> $2
161 endif
162 end
163
164 echo "#define TTMaskClearMask(m, n) ( \" >> $2
165 foreach i (${count})
166 echo -n " ((m)->tt_words[$i] &= ~(n)->tt_words[$i])" >> $2
167 if ($i == 0) then
168 echo ")" >> $2
169 echo "" >> $2
170 else
171 echo ", \" >> $2
172 endif
173 end
174
175 echo "#define TTMaskClearMask3(m, n, o) ( \" >> $2
176 foreach i (${count})
177 echo -n " ((m)->tt_words[$i] = (n)->tt_words[$i] & ~(o)->tt_words[$i])" \
178 >> $2
179 if ($i == 0) then
180 echo ")" >> $2
181 else
182 echo ", \" >> $2
183 endif
184 end
185
186 echo "" >> $2
187 echo "#endif /* _DATABASE_H */" >> $2