M4(1) | User Commands | M4(1) |
m4 - macro processor
/usr/bin/m4 [-e] [-s] [-B int] [-H int] [-S int]
[-T int] [-Dname [=val]] ... [-U name] ... [file]...
/usr/xpg4/bin/m4 [-e] [-s] [-B int] [-H int] [-S int]
[-T int] [-Dname [...=val]] [-U name] ... [file]...
The m4 utility is a macro processor intended as a front end for C, assembler, and other languages. Each of the argument files is processed in order. If there are no files, or if a file is −, the standard input is read. The processed text is written on the standard output. Note: m4 cannot include more than nine nested files and writes a diagnostic message if that number is exceeded.
Macro calls have the form:
name(arg1,arg2, ..., argn)
The open parenthesis character, (, must immediately follow the name of the macro. If the name of a defined macro is not followed by a (, it is deemed to be a call of that macro with no arguments. Potential macro names consist of alphanumeric characters and underscore (_), where the first character is not a digit.
Leading unquoted blanks, TABs, and NEWLINEs are ignored while collecting arguments. Left and right single quotes are used to quote strings. The value of a quoted string is the string stripped of the quotes.
When a macro name is recognized, its arguments are collected by searching for a matching right parenthesis. If fewer arguments are supplied than are in the macro definition, the trailing arguments are taken to be NULL. Macro evaluation proceeds normally during the collection of the arguments, and any commas or right parentheses that happen to turn up within the value of a nested call are as effective as those in the original input text. After argument collection, the value of the macro is pushed back onto the input stream and rescanned.
The options and their effects are as follows:
-Bint
-e
-Hint
-s
-Sint
-Tint
To be effective, the above flags must appear before any file names and before any -D or -U flags:
-D name[=val]
-Uname
The following operand is supported:
file
The m4 utility makes available the following built-in macros. These macros can be redefined, but once this is done the original meaning is lost. Their values are NULL unless otherwise stated.
changequote
changecom
decr
define
defn
divert
divnum
dnl
dumpdef
errprint
ifdef
ifelse
include
incr
index
len
m4exit
m4wrap
maketemp
popdef
pushdef
shift
sinclude
substr
syscmd
sysval
translit
traceon
traceoff
undefine
undivert
eval
eval
Example 1 Examples of m4 files
If the file m4src contains the lines:
The value of `VER' is "VER".
ifdef(`VER', ``VER'' is defined to be VER., VER is not defined.)
ifelse(VER, 1, ``VER'' is `VER'.)
ifelse(VER, 2, ``VER'' is `VER'., ``VER'' is not 2.)
end
then the command:
m4 m4src
or the command:
m4 -U VER m4src
produces the output:
The value of VER is "VER".
VER is not defined.
VER is not 2.
end
The command:
m4 -D VER m4src
produces the output:
The value of VER is "".
VER is defined to be .
VER is not 2.
end
The command:
m4 -D VER=1 m4src
produces the output:
The value of VER is "1".
VER is defined to be 1.
VER is 1.
VER is not 2.
end
The command:
m4 -D VER=2 m4src
produces the output:
The value of VER is "2".
VER is defined to be 2.
VER is 2.
end
See environ(7) for descriptions of the following environment variables that affect the execution of m4: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
The following exit values are returned:
0
>0
If the m4exit macro is used, the exit value can be specified by the input file.
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Standard |
July 3, 2007 | OmniOS |