3
# $0 ../function_defs.list OUTDIR
5
# Generates output files with various defs and lookup arrays.
10
if [ -z "${infile}" -o ! -r "${infile}" ]; then
15
if [ -z "${outdir}" -o ! -d "${outdir}" ]; then
24
echo " * AUTOGENERATED FILE -- DO NOT EDIT"
25
echo " * This file is generated automatically by $0"
26
echo " * from '${infile}'"
27
echo " * during the build process."
33
# Getting one section out of the input file
35
# We presume we always want to clear out the comments and blank lines
36
# anyway, so stick that in here. And I think we always end up
37
# sorting too, so do that as well.
38
sed -e "1,/^# START($1)/d" -e "/^# END($1)/,\$d" \
39
-e 's/#.*//' -e '/^[[:space:]]*$/d' \
46
# First off, creating the F_ defines.
48
gf="${outdir}/functions_defs.h"
52
#ifndef _CTWM_FUNCTIONS_DEFS_H
53
#define _CTWM_FUNCTIONS_DEFS_H
55
/* Definitions for functions */
57
#define F_NOP 0 /* Hardcoded magic value */
63
echo "/* Standard functions */"
64
while read func ctype ifdef
66
# f.nop is special cased to always be 0, so skip it when we
67
# encounter it in here.
68
if [ "X${func}" = "XNOP" ]; then
73
# Output #define, possible guarded by #ifdef's, with a comment to
74
# note the ones that take string args.
75
if [ "X${ifdef}" != "X-" ]; then
76
echo "#ifdef ${ifdef}"
80
if [ "X${ctype}" = "XS" ]; then
83
if [ "X${cmt}" = "X //" ]; then
87
printf "#define F_%-21s %3d${cmt}\n" "${func}" "${counter}"
89
if [ "X${ifdef}" != "X-" ]; then
92
counter=$((counter+1))
95
| awk '{printf "%s %s %s\n", toupper($1), $2, $4;}')
99
echo "/* Synthetic functions */"
102
printf "#define F_%-21s %3d\n" "${func}" "${counter}"
103
counter=$((counter+1))
105
$(getsect synthetic \
106
| awk '{printf "%s\n", toupper($1)}')
111
#endif // _CTWM_FUNCTIONS_DEFS_H
115
#echo "Generated ${gf}"
120
# Next, setup the deferral lookup struct for function execution
122
gf="${outdir}/functions_deferral.h"
127
#ifndef _CTWM_FUNCTIONS_DEFERRAL_H
128
#define _CTWM_FUNCTIONS_DEFERRAL_H
130
/* Functions deferral lookup */
136
} _fdef_table_cursor;
138
static const _fdef_table_cursor fdef_table[] = {
143
if [ "X${func}" = "X" ]; then
144
echo "Got no function!"
149
if [ "X${curs}" = "XCS" ]; then scurs="DC_SELECT"; fi
150
if [ "X${curs}" = "XCM" ]; then scurs="DC_MOVE"; fi
151
if [ "X${curs}" = "XCD" ]; then scurs="DC_DESTROY"; fi
153
if [ "X${scurs}" = "X" ]; then
154
echo "Invalid: unexpected cursor '${curs}' for '${func}'!"
158
printf "\t%-23s = %s,\n" "[F_${func}]" "${scurs}"
161
| awk '{ if ($3 != "-") {printf "%s %s\n", toupper($1), $3;} }')
167
static const size_t fdef_table_max = (sizeof(fdef_table) / sizeof(fdef_table[0]));
169
#endif // _CTWM_FUNCTIONS_DEFERRAL_H
173
#echo "Generated ${gf}"
178
# Now the keyword table for the config file parser. This is somewhat
179
# more involved because it needs the entries from the main as well as
180
# alias sections, but it needs to have them together in a single
183
gf="${outdir}/functions_parse_table.h"
185
# So we better start by pulling the main section, and stashing up
187
while read func ctype ifdef fdef
189
eval _STASH_${func}_ctype=\"$ctype\"
190
eval _STASH_${func}_ifdef=\"$ifdef\"
191
eval _STASH_${func}_fdef=\"$fdef\"
194
| awk '{ printf "%s %s %s %s\n", $1, $2, $4, toupper($1) }')
196
# Adding and stashing the extra toupper() there instead of calling
197
# tr(1) in the loop below saves more than a quarter of a second
198
# (which is ~quintuple the runtime without it).
201
# Now run 'em both together and output
204
#ifndef _CTWM_FUNCTIONS_PARSE_TABLE_H
205
#define _CTWM_FUNCTIONS_PARSE_TABLE_H
207
/* Parser table for functions */
208
static const TwmKeyword funckeytable[] = {
211
while read func alias
216
if [ "X${alias}" != "X" ]; then
218
cmt=" // -> f.${alias}"
221
eval _ctype=\$_STASH_${luf}_ctype
222
eval ifdef=\$_STASH_${luf}_ifdef
223
eval fdef=\$_STASH_${luf}_fdef
226
if [ "X${_ctype}" = "XS" ]; then
232
if [ "X${ifdef}" != "X-" ]; then
233
echo "#ifdef ${ifdef}"
236
printf "\t{ %-24s %10s %s },%s\n" "\"f.${func}\"," "${ctype}," \
239
if [ "X${ifdef}" != "X-" ]; then
243
$( ( getsect main | awk '{printf "%s\n", $1}' ;
244
getsect aliases | awk '{printf "%s %s\n", $1, $2}'
251
static const size_t numfunckeywords = (sizeof(funckeytable) / sizeof(funckeytable[0]));
253
#endif // _CTWM_FUNCTIONS_PARSE_TABLE_H
257
#echo "Generated ${gf}"
262
# And finally, the dispatch table for executing functions.
264
gf="${outdir}/functions_dispatch_execution.h"
266
# Everything we need for this is in the main section.
267
# Now run 'em both together and output
270
#ifndef _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
271
#define _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
273
/* Dispatcher table for executing functions */
274
static ExFunc * const func_dispatch[] = {
277
while read func lcfunc ifdef
279
if [ "X${ifdef}" != "X-" ]; then
280
echo "#ifdef ${ifdef}"
283
printf "\t%-23s = %s,\n" "[F_${func}]" "f_${lcfunc}_impl"
285
if [ "X${ifdef}" != "X-" ]; then
290
| awk '{ if ($5 != "N") {printf "%s %s %s\n", toupper($1), $1, $4} }'
292
| awk '{ if ($2 != "N") {printf "%s %s -\n", toupper($1), $1} }'
299
static const size_t num_f_dis = (sizeof(func_dispatch) / sizeof(func_dispatch[0]));
301
#endif // _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
305
#echo "Generated ${gf}"