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.27 2005/01/17 07:44:22 ru Exp $
3 .\" $DragonFly: src/usr.bin/m4/m4.1,v 1.5 2007/07/30 22:11:33 swildner 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).
27 utility reads from the standard input and writes
28 the processed text to the standard output.
30 Macro calls have the form
31 .Ic name Ns Pq Ar argument1 Ns Op , Ar argument2 , ... , argumentN .
33 There cannot be any space following the macro name and the open
36 If the macro name is not followed by an open
37 parenthesis it is processed with no arguments.
39 Macro names consist of a leading alphabetic or underscore
40 possibly followed by alphanumeric or underscore characters, e.g.,
41 valid macro names match the pattern
42 .Dq Li [a-zA-Z_][a-zA-Z0-9_]* .
44 In arguments to macros, leading unquoted space, tab, and newline
46 characters are ignored.
47 To quote strings, use left and right single
49 .Sq "\ this is a string with a leading space" ) .
50 You can change the quote characters with the
54 Most built-ins do not make any sense without arguments, and hence are not
55 recognized as special when not followed by an open parenthesis.
57 The options are as follows:
58 .Bl -tag -width indent
64 .It Fl D Ar name Ns Op = Ns Ar value
67 to have some value (or
75 builtin macros with the string
77 This changes the macro names
93 argument may hold the following:
95 .Bl -tag -width indent -compact
99 print macro expansion over several lines
101 print result of macro expansion
103 print filename location
107 quote arguments and expansion with the current quotes
109 start with all macros traced
111 number macro expansions
116 By default, trace is set to
122 Activate GNU-m4 compatibility mode.
125 with two empty parameters deactivates quotes,
127 handles simple character ranges (e.g.,
129 regular expressions mimic
132 and the number of diversions is unlimited.
137 utility provides the following built-in macros.
138 They may be redefined, losing their original meaning.
139 Return values are null unless otherwise stated.
140 .Bl -tag -width ".Ic changequote"
142 Calls a built-in by its name, overriding possible redefinitions.
144 Changes the start and end comment sequences.
145 The default is the pound sign
147 and the newline character.
148 With no arguments, the comment sequence is reset to the default,
151 mode, comments are turned off.
152 The maximum length for a comment marker is five characters.
154 Defines the quote symbols to be the first and second arguments.
155 The symbols may be up to five characters long.
157 given it restores the default open and close single quotes.
159 Decrements the argument by 1.
160 The argument must be a valid numeric string.
162 Define a new macro named by the first argument to have the
163 value of the second argument.
168 is 0 through 9) is replaced by the
172 is the name of the calling macro.
173 Undefined arguments are replaced by a null string.
175 is replaced by the number of arguments;
177 is replaced by all arguments comma separated;
181 but all arguments are quoted against further expansion.
183 Returns the quoted definition for each argument.
184 This can be used to rename
185 macro definitions (even for built-in macros).
187 There are 10 output queues (numbered 0-9).
188 At the end of processing
190 concatenates all the queues in numerical order to produce the
192 Initially the output queue is 0.
195 macro allows you to select a new output queue (an invalid argument
198 causes output to be discarded).
200 Returns the current output queue number.
202 Discards input characters up to and including the next newline.
204 Prints the names and definitions for the named items, or for everything
205 if no arguments are passed.
207 Prints the first argument on the standard error output stream.
209 Passes its first argument to a shell and returns the shell's standard output.
210 Note that the shell shares its standard input and standard error with
213 Computes the first argument as an arithmetic expression using 32-bit
215 Operators are the standard C ternary, arithmetic, logical,
216 shift, relational, bitwise, and parentheses operators.
218 octal, decimal, and hexadecimal numbers as in C.
219 The second argument (if any)
220 specifies the radix for the result, and the third argument (if any)
221 specifies the minimum number of digits in the result.
226 If the macro named by the first argument is defined then return the second
227 argument, otherwise the third.
228 If there is no third argument, the value is
234 If the first argument matches the second argument then
238 If the match fails, the three arguments are
239 discarded and the next three arguments are used until there is
240 zero or one arguments left, either this last argument or
242 is returned if no other matches were found.
244 Returns the contents of the file specified in the first argument.
245 If the file is not found as is, look through the include path:
246 first the directories specified with
248 on the command line, then the environment variable
250 as a colon-separated list of directories.
251 Aborts with an error message if the file cannot be included.
253 Increments the argument by 1.
254 The argument must be a valid numeric string.
256 Returns the index of the second argument in the first argument (e.g.,
257 .Fn index "the quick brown fox jumped" fox
260 argument is not found,
264 Indirectly calls the macro whose name is passed as the first arguments,
265 with the remaining arguments passed as first, etc.\& arguments.
267 Returns the number of characters in the first argument.
271 Immediately exits with the return value specified by the first argument,
274 Allows you to define what happens at the final
276 usually for cleanup purposes (e.g.,
277 .Fn m4wrap cleanup(tempfile)
281 invoked after all other processing is done).
283 Translates the string
285 in the first argument with the current process
286 ID leaving other characters alone.
287 This can be used to create unique
288 temporary file names.
290 Includes the contents of the file specified by the first argument without
291 any macro processing.
292 Aborts with an error message if the file cannot be
295 Substitutes a regular expression in a string with a replacement string.
296 Usual substitution patterns apply: an ampersand
298 is replaced by the string matching the regular expression.
303 is a digit, is replaced by the corresponding back-reference.
307 definition for each argument.
309 Takes the same arguments as
311 but it saves the definition on a
312 stack for later retrieval by
315 Finds a regular expression in a string.
316 If no further arguments are given,
317 it returns the first match position or \-1 if no match.
319 is provided, it returns the replacement string, with sub-patterns replaced.
321 Returns all but the first argument, the remaining arguments are
322 quoted and pushed back with commas in between.
324 nullifies the effect of the extra scan that will subsequently be
329 except it ignores any errors.
333 except it ignores any errors.
335 Returns a substring of the first argument starting at the offset specified
336 by the second argument and the length specified by the third argument.
337 If no third argument is present it returns the rest of the string.
339 Passes the first argument to the shell.
342 Returns the return value from the last
345 Enables tracing of macro expansions for the given arguments, or for all
346 macros if no argument is given.
348 Disables tracing of macro expansions for the given arguments, or for all
349 macros if no argument is given.
351 Transliterate the characters in the first argument from the set
352 given by the second argument to the set given by the third.
357 Removes the definition for the macros specified by its arguments.
359 Flushes the named output queues (or all queues if no arguments).
361 A pre-defined macro for testing the OS platform.
363 Returns the current file's line number.
365 Returns the current file's name.
372 macro may be used to change the exit status from the input file.
378 along with a few extensions taken from GNU-m4.
385 The output format of tracing and of
387 are not specified in any standard,
388 are likely to change and should not be relied upon.
389 The current format of tracing is closely modeled on GNU-m4,
394 For portability, one should not use the macros
408 All built-ins do expand without arguments in many other
414 implementations have dire size limitations with respect to buffer sizes.
424 command appeared in PWB
428 .An Ozan Yigit Aq oz@sis.yorku.ca
430 .An Richard A. O'Keefe Aq ok@goanna.cs.rmit.OZ.AU .
431 GNU-m4 compatibility extensions by
432 .An Marc Espie Aq espie@cvs.openbsd.org .
436 utility does not recognize multibyte characters.