Next: M4exit, Previous: Errprint, Up: Miscellaneous
To make it possible to specify the location of an error, three utility builtins exist:
Expand to the quoted name of the current input file, the current input line number in that file, and the quoted name of the current invocation of
m4
.
errprint(__program__:__file__:__line__: `input error ') error-->m4:stdin:1: input error =>
Line numbers start at 1 for each file. If the file was found due to the
-I option or M4PATH environment variable, that is
reflected in the file name. The syncline option (-s,
see Invoking m4), and the
`f' and `l' flags of debugmode
(see Debug Levels),
also use this notion of current file and line. Redefining the three
location macros has no effect on syncline, debug, or warning message
output. Assume this example is run in the
m4-1.4.8/checks directory of the GNU M4
package, using `--include=../examples' in the command line to find
the file incl.m4 mentioned earlier:
define(`foo', ``$0' called at __file__:__line__') => foo =>foo called at stdin:2 include(`incl.m4') =>Include file start =>foo called at ../examples/incl.m4:2 =>Include file end =>
The location of macros invoked during the rescanning of macro expansion
text corresponds to the location in the file where the expansion was
triggered, regardless of how many newline characters the expansion text
contains. As of GNU M4 1.4.8, the location of text wrapped
with m4wrap
(see M4wrap) is the point at which the
m4wrap
was invoked. Previous versions, however, behaved as
though wrapped text came from line 0 of the file “”.
define(`echo', `$@') => define(`foo', `echo(__line__ __line__)') => echo(__line__ __line__) =>4 =>5 m4wrap(`foo ') => foo(errprint(__line__ __line__ )) error-->8 error-->9 =>8 =>8 __line__ =>11 ^D =>6 =>6
The __program__
macro behaves like `$0' in shell
terminology. If you invoke m4
through an absolute path or a link
with a different spelling, rather than by relying on a PATH search
for plain `m4', it will affect how __program__
expands.
The intent is that you can use it to produce error messages with the
same formatting that m4
produces internally. It can also be used
within syscmd
(see Syscmd) to pick the same version of
m4
that is currently running, rather than whatever version of
m4
happens to be first in PATH. It was first introduced in
GNU M4 1.4.6.