1 .\" @(#) $OpenBSD: m4.1,v 1.24 2002/04/18 18:57:23 espie Exp $
2 .\" $FreeBSD: src/usr.bin/m4/m4.1,v 1.10.2.9 2003/04/26 14:29:55 schweikh Exp $
3 .\" $DragonFly: src/usr.bin/m4/m4.1,v 1.2 2003/06/17 04:29:28 dillon Exp $
10 .Nd macro language processor
16 .Op Fl D Ar name Ns Op = Ns Ar value
23 utility is a macro processor that can be used as a front end to any
24 language (e.g., C, ratfor, fortran, lex, and yacc).
26 reads from the standard input and writes
27 the processed text to the standard output.
29 Macro calls have the form
30 .Ic name Ns Pq Ar argument1 Ns Op , Ar argument2 , ... , argumentN .
32 There cannot be any space following the macro name and the open
35 If the macro name is not followed by an open
36 parenthesis it is processed with no arguments.
38 Macro names consist of a leading alphabetic or underscore
39 possibly followed by alphanumeric or underscore characters, e.g.,
40 valid macro names match the pattern
41 .Dq Li [a-zA-Z_][a-zA-Z0-9_]* .
43 In arguments to macros, leading unquoted space, tab, and newline
45 characters are ignored.
46 To quote strings, use left and right single
48 .Sq "\ this is a string with a leading space" ) .
49 You can change the quote characters with the
53 Most built-ins do not make any sense without arguments, and hence are not
54 recognized as special when not followed by an open parenthesis.
56 The options are as follows:
57 .Bl -tag -width indent
63 .It Fl D Ar name Ns Op = Ns Ar value
66 to have some value (or
79 argument may hold the following:
81 .Bl -tag -width indent -compact
85 print macro expansion over several lines
87 print result of macro expansion
89 print filename location
93 quote arguments and expansion with the current quotes
95 start with all macros traced
97 number macro expansions
102 By default, trace is set to
108 Activate GNU-m4 compatibility mode.
111 with two empty parameters deactivates quotes,
113 handles simple character ranges (e.g.,
115 regular expressions mimic
118 and the number of diversions is unlimited.
123 utility provides the following built-in macros.
124 They may be redefined, losing their original meaning.
125 Return values are null unless otherwise stated.
126 .Bl -tag -width ".Ic changequote"
128 Calls a built-in by its name, overriding possible redefinitions.
130 Changes the start and end comment sequences.
131 The default is the pound sign
133 and the newline character.
134 With no arguments, the comment sequence is reset to the default,
137 mode, comments are turned off.
138 The maximum length for a comment marker is five characters.
140 Defines the quote symbols to be the first and second arguments.
141 The symbols may be up to five characters long.
143 given it restores the default open and close single quotes.
145 Decrements the argument by 1.
146 The argument must be a valid numeric string.
148 Define a new macro named by the first argument to have the
149 value of the second argument.
154 is 0 through 9) is replaced by the
158 is the name of the calling macro.
159 Undefined arguments are replaced by a null string.
161 is replaced by the number of arguments;
163 is replaced by all arguments comma separated;
167 but all arguments are quoted against further expansion.
169 Returns the quoted definition for each argument.
170 This can be used to rename
171 macro definitions (even for built-in macros).
173 There are 10 output queues (numbered 0-9).
174 At the end of processing
176 concatenates all the queues in numerical order to produce the
178 Initially the output queue is 0.
181 macro allows you to select a new output queue (an invalid argument
184 causes output to be discarded).
186 Returns the current output queue number.
188 Discards input characters up to and including the next newline.
190 Prints the names and definitions for the named items, or for everything
191 if no arguments are passed.
193 Prints the first argument on the standard error output stream.
195 Passes its first argument to a shell and returns the shell's standard output.
196 Note that the shell shares its standard input and standard error with
199 Computes the first argument as an arithmetic expression using 32-bit
201 Operators are the standard C ternary, arithmetic, logical,
202 shift, relational, bitwise, and parentheses operators.
204 octal, decimal, and hexadecimal numbers as in C.
205 The second argument (if any)
206 specifies the radix for the result, and the third argument (if any)
207 specifies the minimum number of digits in the result.
212 If the macro named by the first argument is defined then return the second
213 argument, otherwise the third.
214 If there is no third argument, the value is
220 If the first argument matches the second argument then
224 If the match fails, the three arguments are
225 discarded and the next three arguments are used until there is
226 zero or one arguments left, either this last argument or
228 is returned if no other matches were found.
230 Returns the contents of the file specified in the first argument.
231 If the file is not found as is, look through the include path:
232 first the directories specified with
234 on the command line, then the environment variable
236 as a colon-separated list of directories.
237 Aborts with an error message if the file cannot be included.
239 Increments the argument by 1.
240 The argument must be a valid numeric string.
242 Returns the index of the second argument in the first argument (e.g.,
243 .Fn index "the quick brown fox jumped" fox
246 argument is not found,
250 Indirectly calls the macro whose name is passed as the first arguments,
251 with the remaining arguments passed as first, etc. arguments.
253 Returns the number of characters in the first argument.
257 Immediately exits with the return value specified by the first argument,
260 Allows you to define what happens at the final
262 usually for cleanup purposes (e.g.,
263 .Fn m4wrap cleanup(tempfile)
267 invoked after all other processing is done).
269 Translates the string
271 in the first argument with the current process
272 ID leaving other characters alone.
273 This can be used to create unique
274 temporary file names.
276 Includes the contents of the file specified by the first argument without
277 any macro processing.
278 Aborts with an error message if the file cannot be
281 Substitutes a regular expression in a string with a replacement string.
282 Usual substitution patterns apply: an ampersand
284 is replaced by the string matching the regular expression.
289 is a digit, is replaced by the corresponding back-reference.
293 definition for each argument.
295 Takes the same arguments as
297 but it saves the definition on a
298 stack for later retrieval by
301 Finds a regular expression in a string.
302 If no further arguments are given,
303 it returns the first match position or \-1 if no match.
305 is provided, it returns the replacement string, with sub-patterns replaced.
307 Returns all but the first argument, the remaining arguments are
308 quoted and pushed back with commas in between.
310 nullifies the effect of the extra scan that will subsequently be
315 except it ignores any errors.
319 except it ignores any errors.
321 Returns a substring of the first argument starting at the offset specified
322 by the second argument and the length specified by the third argument.
323 If no third argument is present it returns the rest of the string.
325 Passes the first argument to the shell.
328 Returns the return value from the last
331 Enables tracing of macro expansions for the given arguments, or for all
332 macros if no argument is given.
334 Disables tracing of macro expansions for the given arguments, or for all
335 macros if no argument is given.
337 Transliterate the characters in the first argument from the set
338 given by the second argument to the set given by the third.
343 Removes the definition for the macros specified by its arguments.
345 Flushes the named output queues (or all queues if no arguments).
347 A pre-defined macro for testing the OS platform.
349 Returns the current file's line number.
351 Returns the current file's name.
358 macro may be used to change the exit status from the input file.
361 follows the Single Unix 2 specification, along with a few extensions taken
369 The output format of tracing and of
371 are not specified in any standard,
372 are likely to change and should not be relied upon.
373 The current format of tracing is closely modeled on GNU-m4,
378 For portability, one should not use the macros
392 All built-ins do expand without arguments in many other
398 implementations have dire size limitations with respect to buffer sizes.
408 command appeared in PWB UNIX.
411 .An Ozan Yigit Aq oz@sis.yorku.ca
413 .An Richard A. O'Keefe Aq ok@goanna.cs.rmit.OZ.AU .
414 GNU-m4 compatibility extensions by
415 .An Marc Espie Aq espie@cvs.openbsd.org .