Previous: Command Aliases, Up: Configuration [Contents][Index]
Before parsing its configuration file, dicod
preprocesses
it. The built-in preprocessor handles only file inclusion
and #line
statements (see Pragmatic Comments), while the
rest of traditional preprocessing facilities, such as macro expansion,
is supported via m4
, which is used as an external preprocessor.
The detailed description of m4
facilities lies far beyond
the scope of this document. You will find a complete user manual in
http://www.gnu.org/software/m4/manual.
For the rest of this subsection we assume the reader is sufficiently
acquainted with m4
macro processor.
The external preprocessor is invoked with -s flag, instructing it to include line synchronization information in its output. This information is then used by the parser to display meaningful diagnostic. An initial set of macro definitions is supplied by the pp-setup file, located in $prefix/share/dico/version/include directory (where version means the version of GNU Dico package).
The default pp-setup file changes quote characters to ‘[’
and ‘]’, and renames all m4
built-in macros so they all
start with the prefix ‘m4_’. The latter has an effect similar
to GNU m4
--prefix-builtin option, but has an
advantage that it works with non-GNU m4
implementations as well.
As an example of how the use of preprocessor may improve
dicod
configuration, consider the following fragment taken
from one of the installations of GNU Dico. This installation offers quite
a few Freedict dictionaries. The database definition for each of them
is almost the same, except for the dictionary name and eventual
description entry for several databases that miss it. To avoid
repeating the same text over again, we define the following macro:
# defdb(NAME[, DESCR]) # Produce a standard definition for a database NAME. # If DESCR is given, use it as a description. m4_define([defdb], [ database { name "$1"; handler "dictorg database=$1";m4_dnl m4_ifelse([$2],,,[ description "$2";]) } ])
It takes two arguments. The first one, NAME, defines the dictionary
name visible in the output of SHOW DB
command. Optional second
argument may be used to supply a description string for the databases
that miss it.
Given this macro, the database definitions look like:
defdb(eng-swa) defdb(swa-eng) defdb(afr-eng, Afrikaans-English Dictionary) defdb(eng-afr, English-Afrikaans Dictionary)
Previous: Command Aliases, Up: Configuration [Contents][Index]