17.8 Solution for fatal_error
The fatal_error
macro (see section Exiting from m4
) is not robust to versions
of GNU M4 earlier than 1.4.8, where invoking
__file__
(see section Printing current location) inside m4wrap
would result
in an empty string, and __line__
resulted in ‘0’ even
though all files start at line 1. Furthermore, versions earlier than
1.4.6 did not support the __program__
macro. If you want
fatal_error
to work across the entire 1.4.x release series, a
better implementation would be:
| define(`fatal_error',
`errprint(ifdef(`__program__', `__program__', ``m4'')'dnl
`:ifelse(__line__, `0', `',
`__file__:__line__:')` fatal error: $*
')m4exit(`1')')
⇒
m4wrap(`divnum(`demo of internal message')
fatal_error(`inside wrapped text')')
⇒
^D
error-->m4:stdin:6: Warning: excess arguments to builtin `divnum' ignored
⇒0
error-->m4:stdin:6: fatal error: inside wrapped text
|