This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
M4(1) Cosmopolitan General Commands Manual -*-text-*-
๐๐๐๐
๐บ๐ฐ โ macro language processor
๐๐๐๐๐๐๐๐
๐บ๐ฐ [-๐๐ด๐๐] [-๐nฬฒaฬฒmฬฒeฬฒ[=vฬฒaฬฒlฬฒuฬฒeฬฒ]] [-๐ฑ fฬฒlฬฒaฬฒgฬฒsฬฒ] [-๐ dฬฒiฬฒrฬฒnฬฒaฬฒmฬฒeฬฒ] [-๐ผ fฬฒiฬฒlฬฒeฬฒnฬฒaฬฒmฬฒeฬฒ]
[-๐ mฬฒaฬฒcฬฒrฬฒoฬฒ] [-๐nฬฒaฬฒmฬฒeฬฒ] [fฬฒiฬฒlฬฒeฬฒ .ฬฒ.ฬฒ.ฬฒ]
๐๐๐๐๐๐๐๐๐๐๐
The ๐บ๐ฐ utility is a macro processor that can be used as a front end
to any language (e.g., C, ratfor, fortran, lex, and yacc). If no
input files are given, ๐บ๐ฐ reads from the standard input, otherwise
files specified on the command line are processed in the given
order. Input files can be regular files, files in the m4 include
paths, or a single dash (โ-โ), denoting standard input. ๐บ๐ฐ writes
the processed text to the standard output, unless told otherwise.
Macro calls have the form name(argument1[, argument2, ..., arguโ
mentN]).
There cannot be any space following the macro name and the open
parenthesis (โ(โ). If the macro name is not followed by an open
parenthesis it is processed with no arguments.
Macro names consist of a leading alphabetic or underscore possibly
followed by alphanumeric or underscore characters, e.g., valid
macro names match the pattern โ[a-zA-Z_][a-zA-Z0-9_]*โ.
In arguments to macros, leading unquoted space, tab, and newline
(โ\nโ) characters are ignored. To quote strings, use left and
right single quotes (e.g., โ this is a string with a leading
spaceโ). You can change the quote characters with the ๐ฐ๐ต๐ฎ๐ป๐ด๐ฒ๐พ๐๐ผ๐๐ฒ
built-in macro.
Most built-ins don't make any sense without arguments, and hence
are not recognized as special when not followed by an open parenโ
thesis.
The options are as follows:
-๐nฬฒaฬฒmฬฒeฬฒ[=vฬฒaฬฒlฬฒuฬฒeฬฒ]
Define the symbol nฬฒaฬฒmฬฒeฬฒ to have some value (or NULL).
-๐ฑ fฬฒlฬฒaฬฒgฬฒsฬฒ
Set trace flags. fฬฒlฬฒaฬฒgฬฒsฬฒ may hold the following:
aฬฒ print macro arguments.
cฬฒ print macro expansion over several lines.
eฬฒ print result of macro expansion.
fฬฒ print filename location.
lฬฒ print line number.
qฬฒ quote arguments and expansion with the current
quotes.
tฬฒ start with all macros traced.
xฬฒ number macro expansions.
Vฬฒ turn on all options.
By default, trace is set to "eq".
-๐ Set warnings to be fatal. When a single -๐ flag is speciโ
fied, if warnings are issued, execution continues but ๐บ๐ฐ
will exit with a non-zero exit status. When multiple -๐
flags are specified, execution will halt upon issuing the
first warning and ๐บ๐ฐ will exit with a non-zero exit status.
This behaviour matches GNU-m4 1.4.9 and later.
-๐ด Activate GNU-m4 compatibility mode. In this mode, translit
handles simple character ranges (e.g., a-z), regular
expressions mimic emacs behavior, multiple m4wrap calls are
handled as a stack, the number of diversions is unlimited,
empty names for macro definitions are allowed, and eval
understands โ0rbase:valueโ numbers.
-๐ dฬฒiฬฒrฬฒnฬฒaฬฒmฬฒeฬฒ
Add directory dฬฒiฬฒrฬฒnฬฒaฬฒmฬฒeฬฒ to the include path.
-๐ผ fฬฒiฬฒlฬฒeฬฒnฬฒaฬฒmฬฒeฬฒ
Send trace output to fฬฒiฬฒlฬฒeฬฒnฬฒaฬฒmฬฒeฬฒ.
-๐ Prefix all built-in macros with โm4_โ. For example,
instead of writing ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ, use ๐บ๐ฐ_๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ.
-๐ Output line synchronization directives, suitable for
cpp(1).
-๐ mฬฒaฬฒcฬฒrฬฒoฬฒ
Turn tracing on for mฬฒaฬฒcฬฒrฬฒoฬฒ.
-๐nฬฒaฬฒmฬฒeฬฒ Undefine the symbol nฬฒaฬฒmฬฒeฬฒ.
๐๐๐๐๐๐
๐บ๐ฐ provides the following built-in macros. They may be redefined,
losing their original meaning. Return values are null unless othโ
erwise stated.
๐ฏ๐๐ถ๐น๐๐ถ๐ป(nฬฒaฬฒmฬฒeฬฒ)
Calls a built-in by its nฬฒaฬฒmฬฒeฬฒ, overriding possible
redefinitions.
๐ฐ๐ต๐ฎ๐ป๐ด๐ฒ๐ฐ๐ผ๐บ(sฬฒtฬฒaฬฒrฬฒtฬฒcฬฒoฬฒmฬฒmฬฒeฬฒnฬฒtฬฒ, eฬฒnฬฒdฬฒcฬฒoฬฒmฬฒmฬฒeฬฒnฬฒtฬฒ)
Changes the start comment and end comment sequences.
Comment sequences may be up to five characters long.
The default values are the hash sign and the newline
character.
# This is a comment
With no arguments, comments are turned off. With one
single argument, the end comment sequence is set to
the newline character.
๐ฐ๐ต๐ฎ๐ป๐ด๐ฒ๐พ๐๐ผ๐๐ฒ(bฬฒeฬฒgฬฒiฬฒnฬฒqฬฒuฬฒoฬฒtฬฒeฬฒ, eฬฒnฬฒdฬฒqฬฒuฬฒoฬฒtฬฒeฬฒ)
Defines the open quote and close quote sequences.
Quote sequences may be up to five characters long.
The default values are the backquote character and the
quote character.
`Here is a quoted string'
With no arguments, the default quotes are restored.
With one single argument, the close quote sequence is
set to the newline character.
๐ฑ๐ฒ๐ฐ๐ฟ(aฬฒrฬฒgฬฒ) Decrements the argument aฬฒrฬฒgฬฒ by 1. The argument aฬฒrฬฒgฬฒ
must be a valid numeric string.
๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ(nฬฒaฬฒmฬฒeฬฒ, vฬฒaฬฒlฬฒuฬฒeฬฒ)
Define a new macro named by the first argument nฬฒaฬฒmฬฒeฬฒ to
have the value of the second argument vฬฒaฬฒlฬฒuฬฒeฬฒ. Each
occurrence of โ$nโ (where nฬฒ is 0 through 9) is
replaced by the nฬฒ'th argument. โ$0โ is the name of
the calling macro. Undefined arguments are replaced
by a null string. โ$#โ is replaced by the number of
arguments; โ$*โ is replaced by all arguments comma
separated; โ$@โ is the same as โ$*โ but all arguments
are quoted against further expansion.
๐ฑ๐ฒ๐ณ๐ป(nฬฒaฬฒmฬฒeฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Returns the quoted definition for each argument. This
can be used to rename macro definitions (even for
built-in macros).
๐ฑ๐ถ๐๐ฒ๐ฟ๐(nฬฒuฬฒmฬฒ) There are 10 output queues (numbered 0-9). At the end
of processing ๐บ๐ฐ concatenates all the queues in numerโ
ical order to produce the final output. Initially the
output queue is 0. The divert macro allows you to
select a new output queue (an invalid argument passed
to divert causes output to be discarded).
๐ฑ๐ถ๐๐ป๐๐บ Returns the current output queue number.
๐ฑ๐ป๐น Discard input characters up to and including the next
newline.
๐ฑ๐๐บ๐ฝ๐ฑ๐ฒ๐ณ(nฬฒaฬฒmฬฒeฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Prints the names and definitions for the named items,
or for everything if no arguments are passed.
๐ฒ๐ฟ๐ฟ๐ฝ๐ฟ๐ถ๐ป๐(mฬฒsฬฒgฬฒ)
Prints the first argument on the standard error output
stream.
๐ฒ๐๐๐๐ฐ๐บ๐ฑ(cฬฒmฬฒdฬฒ)
Passes its first argument to a shell and returns the
shell's standard output. Note that the shell shares
its standard input and standard error with ๐บ๐ฐ.
๐ฒ๐๐ฎ๐น(eฬฒxฬฒpฬฒrฬฒ[ฬฒ,ฬฒrฬฒaฬฒdฬฒiฬฒxฬฒ[ฬฒ,ฬฒmฬฒiฬฒnฬฒiฬฒmฬฒuฬฒmฬฒ]ฬฒ]ฬฒ)
Computes the first argument as an arithmetic expresโ
sion using 32-bit arithmetic. Operators are the stanโ
dard C ternary, arithmetic, logical, shift, relaโ
tional, bitwise, and parentheses operators. You can
specify octal, decimal, and hexadecimal numbers as in
C. The optional second argument rฬฒaฬฒdฬฒiฬฒxฬฒ specifies the
radix for the result and the optional third argument
mฬฒiฬฒnฬฒiฬฒmฬฒuฬฒmฬฒ specifies the minimum number of digits in the
result.
๐ฒ๐ ๐ฝ๐ฟ(eฬฒxฬฒpฬฒrฬฒ) This is an alias for ๐ฒ๐๐ฎ๐น.
๐ณ๐ผ๐ฟ๐บ๐ฎ๐(fฬฒoฬฒrฬฒmฬฒaฬฒtฬฒsฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, aฬฒrฬฒgฬฒ1ฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Returns fฬฒoฬฒrฬฒmฬฒaฬฒtฬฒsฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ with escape sequences substituted
with aฬฒrฬฒgฬฒ1ฬฒ and following arguments, in a way similar to
printf(3). This built-in is only available in GNU-m4
compatibility mode, and the only parameters impleโ
mented are there for autoconf compatibility: left-padโ
ding flag, an optional field width, a maximum field
width, *-specified field widths, and the %s and %c
data type.
๐ถ๐ณ๐ฑ๐ฒ๐ณ(nฬฒaฬฒmฬฒeฬฒ, yฬฒeฬฒsฬฒ, nฬฒoฬฒ)
If the macro named by the first argument is defined
then return the second argument, otherwise the third.
If there is no third argument, the value is NULL. The
word "unix" is predefined.
๐ถ๐ณ๐ฒ๐น๐๐ฒ(aฬฒ, bฬฒ, yฬฒeฬฒsฬฒ, .ฬฒ.ฬฒ.ฬฒ)
If the first argument aฬฒ matches the second argument bฬฒ
then ๐ถ๐ณ๐ฒ๐น๐๐ฒ() returns the third argument yฬฒeฬฒsฬฒ. If the
match fails the three arguments are discarded and the
next three arguments are used until there is zero or
one arguments left, either this last argument or NULL
is returned if no other matches were found.
๐ถ๐ป๐ฐ๐น๐๐ฑ๐ฒ(nฬฒaฬฒmฬฒeฬฒ)
Returns the contents of the file specified in the
first argument. If the file is not found as is, look
through the include path: first the directories speciโ
fied with -๐ on the command line, then the environment
variable M4PATH, as a colon-separated list of directoโ
ries. Include aborts with an error message if the
file cannot be included.
๐ถ๐ป๐ฐ๐ฟ(aฬฒrฬฒgฬฒ) Increments the argument by 1. The argument must be a
valid numeric string.
๐ถ๐ป๐ฑ๐ฒ๐ (sฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, sฬฒuฬฒbฬฒsฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ)
Returns the index of the second argument in the first
argument (e.g., ๐ถ๐ป๐ฑ๐ฒ๐ (๐๐ต๐ฒ๐พ๐๐ถ๐ฐ๐ธ๐ฏ๐ฟ๐ผ๐๐ป๐ณ๐ผ๐ ๐ท๐๐บ๐ฝ๐ฒ๐ฑ, ๐ณ๐ผ๐ )
returns 16). If the second argument is not found
index returns -1.
๐ถ๐ป๐ฑ๐ถ๐ฟ(mฬฒaฬฒcฬฒrฬฒoฬฒ, aฬฒrฬฒgฬฒ1ฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Indirectly calls the macro whose name is passed as the
first argument, with the remaining arguments passed as
first, ... arguments.
๐น๐ฒ๐ป(aฬฒrฬฒgฬฒ) Returns the number of characters in the first arguโ
ment. Extra arguments are ignored.
๐บ๐ฐ๐ฒ๐ ๐ถ๐(cฬฒoฬฒdฬฒeฬฒ)
Immediately exits with the return value specified by
the first argument, 0 if none.
๐บ๐ฐ๐๐ฟ๐ฎ๐ฝ(tฬฒoฬฒdฬฒoฬฒ)
Allows you to define what happens at the final EOF,
usually for cleanup purposes (e.g.,
๐บ๐ฐ๐๐ฟ๐ฎ๐ฝ("๐ฐ๐น๐ฒ๐ฎ๐ป๐๐ฝ(๐๐ฒ๐บ๐ฝ๐ณ๐ถ๐น๐ฒ)") causes the macro cleanup
to be invoked after all other processing is done).
Multiple calls to ๐บ๐ฐ๐๐ฟ๐ฎ๐ฝ() get inserted in sequence at
the final EOF.
๐บ๐ฎ๐ธ๐ฒ๐๐ฒ๐บ๐ฝ(tฬฒeฬฒmฬฒpฬฒlฬฒaฬฒtฬฒeฬฒ)
Like ๐บ๐ธ๐๐๐ฒ๐บ๐ฝ.
๐บ๐ธ๐๐๐ฒ๐บ๐ฝ(tฬฒeฬฒmฬฒpฬฒlฬฒaฬฒtฬฒeฬฒ)
Invokes mkstemp(3) on the first argument, and returns
the modified string. This can be used to create
unique temporary file names.
๐ฝ๐ฎ๐๐๐ฒ(fฬฒiฬฒlฬฒeฬฒ) Includes the contents of the file specified by the
first argument without any macro processing. Aborts
with an error message if the file cannot be included.
๐ฝ๐ฎ๐๐๐๐ฏ๐๐(sฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, rฬฒeฬฒgฬฒeฬฒxฬฒpฬฒ, rฬฒeฬฒpฬฒlฬฒaฬฒcฬฒeฬฒmฬฒeฬฒnฬฒtฬฒ)
Substitutes a regular expression in a string with a
replacement string. Usual substitution patterns
apply: an ampersand (โ&โ) is replaced by the string
matching the regular expression. The string โ\#โ,
where โ#โ is a digit, is replaced by the corresponding
back-reference.
๐ฝ๐ผ๐ฝ๐ฑ๐ฒ๐ณ(aฬฒrฬฒgฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Restores the ๐ฝ๐๐๐ต๐ฑ๐ฒ๐ณed definition for each argument.
๐ฝ๐๐๐ต๐ฑ๐ฒ๐ณ(mฬฒaฬฒcฬฒrฬฒoฬฒ, dฬฒeฬฒfฬฒ)
Takes the same arguments as ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ, but it saves the
definition on a stack for later retrieval by ๐ฝ๐ผ๐ฝ๐ฑ๐ฒ๐ณ().
๐ฟ๐ฒ๐ด๐ฒ๐ ๐ฝ(sฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, rฬฒeฬฒgฬฒeฬฒxฬฒpฬฒ, rฬฒeฬฒpฬฒlฬฒaฬฒcฬฒeฬฒmฬฒeฬฒnฬฒtฬฒ)
Finds a regular expression in a string. If no further
arguments are given, it returns the first match posiโ
tion or -1 if no match. If a third argument is proโ
vided, it returns the replacement string, with sub-
patterns replaced.
๐๐ต๐ถ๐ณ๐(aฬฒrฬฒgฬฒ1ฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Returns all but the first argument, the remaining
arguments are quoted and pushed back with commas in
between. The quoting nullifies the effect of the
extra scan that will subsequently be performed.
๐๐ถ๐ป๐ฐ๐น๐๐ฑ๐ฒ(fฬฒiฬฒlฬฒeฬฒ)
Similar to ๐ถ๐ป๐ฐ๐น๐๐ฑ๐ฒ, except it ignores any errors.
๐๐ฝ๐ฎ๐๐๐ฒ(fฬฒiฬฒlฬฒeฬฒ)
Similar to ๐ฝ๐ฎ๐๐๐ฒ(), except it ignores any errors.
๐๐๐ฏ๐๐๐ฟ(sฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, oฬฒfฬฒfฬฒsฬฒeฬฒtฬฒ, lฬฒeฬฒnฬฒgฬฒtฬฒhฬฒ)
Returns a substring of the first argument starting at
the offset specified by the second argument and the
length specified by the third argument. If no third
argument is present it returns the rest of the string.
๐๐๐๐ฐ๐บ๐ฑ(cฬฒmฬฒdฬฒ) Passes the first argument to the shell. Nothing is
returned.
๐๐๐๐๐ฎ๐น Returns the return value from the last ๐๐๐๐ฐ๐บ๐ฑ.
๐๐ฟ๐ฎ๐ฐ๐ฒ๐ผ๐ป(aฬฒrฬฒgฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Enables tracing of macro expansions for the given
arguments, or for all macros if no argument is given.
๐๐ฟ๐ฎ๐ฐ๐ฒ๐ผ๐ณ๐ณ(aฬฒrฬฒgฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Disables tracing of macro expansions for the given
arguments, or for all macros if no argument is given.
๐๐ฟ๐ฎ๐ป๐๐น๐ถ๐(sฬฒtฬฒrฬฒiฬฒnฬฒgฬฒ, mฬฒaฬฒpฬฒfฬฒrฬฒoฬฒmฬฒ, mฬฒaฬฒpฬฒtฬฒoฬฒ)
Transliterate the characters in the first argument
from the set given by the second argument to the set
given by the third. You cannot use tr(1) style abbreโ
viations.
๐๐ป๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ(nฬฒaฬฒmฬฒeฬฒ1ฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Removes the definition for the macros specified by its
arguments.
๐๐ป๐ฑ๐ถ๐๐ฒ๐ฟ๐(aฬฒrฬฒgฬฒ, .ฬฒ.ฬฒ.ฬฒ)
Flushes the named output queues (or all queues if no
arguments).
๐๐ป๐ถ๐ A pre-defined macro for testing the OS platform.
__๐น๐ถ๐ป๐ฒ__ Returns the current file's line number.
__๐ณ๐ถ๐น๐ฒ__ Returns the current file's name.
๐๐๐๐๐๐๐๐๐๐
The ๐บ๐ฐ utility exits 0 on success, and >0 if an error occurs.
But note that the ๐บ๐ฐ๐ฒ๐ ๐ถ๐ macro can modify the exit status, as can
the -๐ flag.
๐๐๐๐๐๐๐๐๐
The ๐บ๐ฐ utility is compliant with the IEEE Std 1003.1-2008
(โPOSIX.1โ) specification.
The flags [-๐ฑ๐๐ด๐๐๐ผ๐] and the macros ๐ฏ๐๐ถ๐น๐๐ถ๐ป, ๐ฒ๐๐๐๐ฐ๐บ๐ฑ, ๐ฒ๐ ๐ฝ๐ฟ, ๐ณ๐ผ๐ฟ๐บ๐ฎ๐,
๐ถ๐ป๐ฑ๐ถ๐ฟ, ๐ฝ๐ฎ๐๐๐ฒ, ๐ฝ๐ฎ๐๐๐๐ฏ๐๐, ๐ฟ๐ฒ๐ด๐ฒ๐ ๐ฝ, ๐๐ฝ๐ฎ๐๐๐ฒ, ๐๐ป๐ถ๐ , __๐น๐ถ๐ป๐ฒ__, and
__๐ณ๐ถ๐น๐ฒ__ are extensions to that specification.
๐บ๐ฎ๐ธ๐ฒ๐๐ฒ๐บ๐ฝ is not supposed to be a synonym for ๐บ๐ธ๐๐๐ฒ๐บ๐ฝ, but instead
to be an insecure temporary file name creation function. It is
marked by IEEE Std 1003.1-2008 (โPOSIX.1โ) as being obsolescent and
should not be used if portability is a concern.
The output format of ๐๐ฟ๐ฎ๐ฐ๐ฒ๐ผ๐ป and ๐ฑ๐๐บ๐ฝ๐ฑ๐ฒ๐ณ are not specified in any
standard, are likely to change and should not be relied upon. The
current format of tracing is closely modelled on ๐ด๐ป๐-๐บ๐ฐ, to allow
๐ฎ๐๐๐ผ๐ฐ๐ผ๐ป๐ณ to work.
The built-ins ๐ฝ๐๐๐ต๐ฑ๐ฒ๐ณ and ๐ฝ๐ผ๐ฝ๐ฑ๐ฒ๐ณ handle macro definitions as a
stack. However, ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ interacts with the stack in an undefined
way. In this implementation, ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ replaces the top-most definiโ
tion only. Other implementations may erase all definitions on the
stack instead.
All built-ins do expand without arguments in many other ๐บ๐ฐ.
Many other ๐บ๐ฐ have dire size limitations with respect to buffer
sizes.
๐๐๐๐๐๐๐
Ozan Yigit <oฬฒzฬฒ@ฬฒsฬฒiฬฒsฬฒ.ฬฒyฬฒoฬฒrฬฒkฬฒuฬฒ.ฬฒcฬฒaฬฒ> and Richard A. O'Keefe
<oฬฒkฬฒ@ฬฒgฬฒoฬฒaฬฒnฬฒnฬฒaฬฒ.ฬฒcฬฒsฬฒ.ฬฒrฬฒmฬฒiฬฒtฬฒ.ฬฒOฬฒZฬฒ.ฬฒAฬฒUฬฒ>.
GNU-m4 compatibility extensions by Marc Espie
<eฬฒsฬฒpฬฒiฬฒeฬฒ@ฬฒcฬฒvฬฒsฬฒ.ฬฒoฬฒpฬฒeฬฒnฬฒbฬฒsฬฒdฬฒ.ฬฒoฬฒrฬฒgฬฒ>.
COSMOPOLITAN June 15, 2017 BSD