m4: Extensions
1
1 16.1 Extensions in GNU M4
1 =========================
1
1 This version of 'm4' contains a few facilities that do not exist in
1 System V 'm4'. These extra facilities are all suppressed by using the
1 '-G' command line option (⇒Invoking m4 Limits control.), unless
1 overridden by other command line options.
1
1 * In the '$N' notation for macro arguments, N can contain several
1 digits, while the System V 'm4' only accepts one digit. This
1 allows macros in GNU 'm4' to take any number of arguments, and not
1 only nine (⇒Arguments).
1
1 This means that 'define(`foo', `$11')' is ambiguous between
1 implementations. To portably choose between grabbing the first
1 parameter and appending 1 to the expansion, or grabbing the
1 eleventh parameter, you can do the following:
1
1 define(`a1', `A1')
1 =>
1 dnl First argument, concatenated with 1
1 define(`_1', `$1')define(`first1', `_1($@)1')
1 =>
1 dnl Eleventh argument, portable
1 define(`_9', `$9')define(`eleventh', `_9(shift(shift($@)))')
1 =>
1 dnl Eleventh argument, GNU style
1 define(`Eleventh', `$11')
1 =>
1 first1(`a', `b', `c', `d', `e', `f', `g', `h', `i', `j', `k')
1 =>A1
1 eleventh(`a', `b', `c', `d', `e', `f', `g', `h', `i', `j', `k')
1 =>k
1 Eleventh(`a', `b', `c', `d', `e', `f', `g', `h', `i', `j', `k')
1 =>k
1
1 Also see the 'argn' macro (⇒Shift).
1
1 * The 'divert' (⇒Divert) macro can manage more than 9
1 diversions. GNU 'm4' treats all positive numbers as valid
1 diversions, rather than discarding diversions greater than 9.
1
1 * Files included with 'include' and 'sinclude' are sought in a user
1 specified search path, if they are not found in the working
1 directory. The search path is specified by the '-I' option and the
1 'M4PATH' environment variable (⇒Search Path).
1
1 * Arguments to 'undivert' can be non-numeric, in which case the named
11 file will be included uninterpreted in the output (⇒
Undivert).
1
1 * Formatted output is supported through the 'format' builtin, which
1 is modeled after the C library function 'printf' (⇒Format).
1
1 * Searches and text substitution through basic regular expressions
1 are supported by the 'regexp' (⇒Regexp) and 'patsubst'
1 (⇒Patsubst) builtins. Some BSD implementations use extended
1 regular expressions instead.
1
1 * The output of shell commands can be read into 'm4' with 'esyscmd'
1 (⇒Esyscmd).
1
11 * There is indirect access to any builtin macro with 'builtin' (⇒
Builtin).
1
1 * Macros can be called indirectly through 'indir' (⇒Indir).
1
1 * The name of the program, the current input file, and the current
1 input line number are accessible through the builtins
1 '__program__', '__file__', and '__line__' (⇒Location).
1
1 * The format of the output from 'dumpdef' and macro tracing can be
1 controlled with 'debugmode' (⇒Debug Levels).
1
1 * The destination of trace and debug output can be controlled with
1 'debugfile' (⇒Debug Output).
1
1 * The 'maketemp' (⇒Mkstemp) macro behaves like 'mkstemp',
1 creating a new file with a unique name on every invocation, rather
1 than following the insecure behavior of replacing the trailing 'X'
1 characters with the 'm4' process id.
1
1 * POSIX only requires support for the command line options '-s',
1 '-D', and '-U', so all other options accepted by GNU M4 are
1 extensions. ⇒Invoking m4, for a description of these
1 options.
1
1 The debugging and tracing facilities in GNU 'm4' are much more
1 extensive than in most other versions of 'm4'.
1