You can use m4's internal macro look-up table to hold your own tables. Here's a table with three entries, strcmp, struct tm and uint32_t, and each is associated with a description, an availability, some flags, and some file names:
define(`LIB_strcmp', ```Compare strings'', ``'', ``F'', ``string.h''')dnl define(`LIB_struct tm', ```Time type'', ``'', ``T'', ``time.h''')dnl define(`LIB_uint32_t', ```Fixed-width integer type'', ``C99-'', ``T'', ``stdint.h'', ``inttypes.h''')dnl
Some fields are empty. Note that the labels can have characters not normally allowed in macro names.
You can use access this table firstly by using indir, and then by using its result as the
arguments to a macro of yours which formats them:
define(`LIBFMT', ``The 'ifelse($4,`T',``type'', $4,`F',``function'', ``identifier'')` defined in <'$5`> is 'ifelse($3,,``always available'',``available in '$3')`.'')dnl define(`LIB', `LIBFMT(`$1',indir(`LIB_'$1))')dnl
Creating the table is a little tiresome and error-prone. The following form might be more convenient:
strcmp|Compare strings||F|string.h struct tm|Time type||T|time.h uint32_t|Fixed-width integer type|C99-|T|stdint.h|inttypes.h
Place such data in, for example, src/tables/identifiers.tab. The Makefile knows how to convert this to m4 if you also give it an awk script in src/scripts/identifiers.awk:
BEGIN { FS="|" }
{ print "define(`LIB_" $1 "',```" $2 "'', ``" $3 "'', \
``" $4 "'', ``" $5 "''')dnl" }
You need this rule in your global Makefile, include/buildwww.mk:
var/tables/%.m4: src/tables/%.tab src/scripts/%.awk @mkdir -p var/tables @echo Compiling "$*" to m4 @awk -f "src/scripts/$*.awk" < "src/tables/$*.tab" > "$@"
A file var/tables/identifiers.m4 will be created, which your pages can include, either directly, or through etc/site.m4 (which I recommend). You should explicitly specify any dependencies that your other files have on this, for example:
$(SITE_HTML) $(SITE_SVG) $(SITE_CSS): \ var/tables/identifiers.m4
If you use a large number of macros to hold table entries, you may want to increase the size of the hash table used by m4 with the -H, in order to speed up processing. However, I'm not sure how effective this is.
Updated: 2007-May-11 16:56 GMT
Contact
Steven Simpson
Ĉi tiu paĝo disponeblas ĉi-lingve, laŭ via krozila agordo.