2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
47 .TH M4 1 "Oct 25, 2017"
53 \fB/usr/bin/m4\fR [\fB-e\fR] [\fB-s\fR] [\fB-B\fR \fIint\fR] [\fB-H\fR \fIint\fR] [\fB-S\fR \fIint\fR]
54 [\fB-T\fR \fIint\fR] [\fB-D\fR\fIname\fR [...\fI=val\fR]] [\fB-U\fR \fIname\fR] ... [\fIfile\fR]...
60 The \fBm4\fR utility is a macro processor intended as a front end for C,
61 assembler, and other languages. Each of the argument files is processed in
62 order. If there are no files, or if a file is \fB\(mi\fR, the standard input is
63 read. The processed text is written on the standard output. \fBNote:\fR
64 \fBm4\fR cannot include more than nine nested files and writes a diagnostic
65 message if that number is exceeded.
69 Macro calls have the form:
73 \fIname\fR(\fIarg1\fR,\fIarg2\fR, ..., \fIargn\fR)
80 The open parenthesis character, \fB(\fR, must immediately follow the name of
81 the macro. If the name of a defined macro is not followed by a \fB(\fR, it is
82 deemed to be a call of that macro with no arguments. Potential macro names
83 consist of alphanumeric characters and underscore (\fB_\fR), where the first
84 character is not a digit.
87 Leading unquoted blanks, TABs, and \fBNEWLINE\fRs are ignored while collecting
88 arguments. Left and right single quotes are used to quote strings. The value of
89 a quoted string is the string stripped of the quotes.
90 .SS "Macro Processing"
93 When a macro name is recognized, its arguments are collected by searching for a
94 matching right parenthesis. If fewer arguments are supplied than are in the
95 macro definition, the trailing arguments are taken to be \fINULL\fR. Macro
96 evaluation proceeds normally during the collection of the arguments, and any
97 commas or right parentheses that happen to turn up within the value of a nested
98 call are as effective as those in the original input text. After argument
99 collection, the value of the macro is pushed back onto the input stream and
104 The options and their effects are as follows:
108 \fB\fB-B\fR\fIint\fR\fR
111 Changes the size of the push-back and argument collection buffers from the
112 default of \fB4,096\fR.
121 Operates interactively. Interrupts are ignored and the output is unbuffered.
127 \fB\fB-H\fR\fIint\fR\fR
130 Changes the size of the symbol table hash array from the default of \fB199\fR.
131 The size should be prime.
140 Enables line sync output for the C preprocessor (\fB#\fRline .\|.\|.\|)
146 \fB\fB-S\fR\fIint\fR\fR
149 Changes the size of the call stack from the default of \fB100\fRslots. Macros
150 take three slots, and non-macro arguments take one.
156 \fB\fB-T\fR\fIint\fR\fR
159 Changes the size of the token buffer from the default of \fB512\fRbytes.
164 To be effective, the above flags must appear before any file names and before
165 any \fB-D\fR or \fB-U\fR flags:
169 \fB\fB-D\fR \fIname\fR[\fB=\fR\fBval\fR]\fR
172 Defines \fIname\fR to \fBval\fR or to \fINULL\fR in \fBval\fR's absence.
178 \fB\fB-U\fR\fIname\fR\fR
181 Undefines \fIname\fR.
187 The following operand is supported:
194 A path name of a text file to be processed. If no \fIfile\fR is given, or if it
195 is \(mi, the standard input is read.
201 The \fBm4\fR utility makes available the following built-in macros. These
202 macros can be redefined, but once this is done the original meaning is lost.
203 Their values are \fINULL\fR unless otherwise stated.
207 \fB\fBchangequote\fR\fR
210 Change quote symbols to the first and second arguments. The symbols can be up
211 to five characters long. \fBchangequote\fR without arguments restores the
212 original values (that is, \fB`\|'\fR).
218 \fB\fBchangecom\fR\fR
221 Change left and right comment markers from the default \fB#\fR and
222 \fBNEWLINE\fR. With no arguments, the comment mechanism is effectively
223 disabled. With one argument, the left marker becomes the argument and the right
224 marker becomes \fBNEWLINE\fR. With two arguments, both markers are affected.
225 Comment markers can be up to five characters long.
234 Returns the value of its argument decremented by 1.
243 The second argument is installed as the value of the macro whose name is the
244 first argument. Each occurrence of \fB$\fR\fIn\fR in the replacement text,
245 where \fIn\fR is a digit, is replaced by the \fIn\fR-th argument. Argument 0 is
246 the name of the macro; missing arguments are replaced by the null string;
247 \fB$#\fR is replaced by the number of arguments; \fB$*\fR is replaced by a list
248 of all the arguments separated by commas; \fB$@\fR is like \fB$*\fR, but each
249 argument is quoted (with the current quotes).
258 Returns the quoted definition of its argument(s). It is useful for renaming
259 macros, especially built-ins.
268 \fBm4\fR maintains 10 output streams, numbered 0-9. The final output is the
269 concatenation of the streams in numerical order. Initially stream 0 is the
270 current stream. The \fBdivert\fR macro changes the current output stream to its
271 (digit-string) argument. Output diverted to a stream other than 0 through 9 is
281 Returns the value of the current output stream.
290 Reads and discards characters up to and including the next \fBNEWLINE\fR.
299 Prints current names and definitions, for the named items, or for all if no
309 Prints its argument on the diagnostic output file.
318 If the first argument is defined, the value is the second argument, otherwise
319 the third. If there is no third argument, the value is \fINULL\fR. The word
320 \fBunix\fR is predefined.
329 This macro has three or more arguments. If the first argument is the same
330 string as the second, then the value is the third argument. If not, and if
331 there are more than four arguments, the process is repeated with arguments 4,
332 5, 6 and 7. Otherwise, the value is either the fourth string, or, if it is not
342 Returns the contents of the file named in the argument.
351 Returns the value of its argument incremented by 1. The value of the argument
352 is calculated by interpreting an initial digit-string as a decimal number.
361 Returns the position in its first argument where the second argument begins
362 (zero origin), or \(mi1 if the second argument does not occur.
371 Returns the number of characters in its argument.
380 This macro causes immediate exit from \fBm4\fR. Argument 1, if given, is the
381 exit code; the default is \fB0\fR.
390 Argument 1 is pushed back at final \fBEOF\fR. Example:
391 \fBm4wrap(`cleanup(\|)')\fR
400 Fills in a string of "\fBX\fR" characters in its argument with the current
410 Removes current definition of its argument(s), exposing the previous one, if
420 Like \fBdefine\fR, but saves any previous definition.
429 Returns all but its first argument. The other arguments are quoted and pushed
430 back with commas in between. The quoting nullifies the effect of the extra scan
431 that is subsequently be performed.
440 This macro is identical to \fBinclude\fR, except that it says nothing if the
441 file is inaccessible.
450 Returns a substring of its first argument. The second argument is a zero origin
451 number selecting the first character; the third argument indicates the length
452 of the substring. A missing third argument is taken to be large enough to
453 extend to the end of the first string.
462 This macro executes the command given in the first argument. No value is
472 This macro is the return code from the last call to \fBsyscmd\fR.
481 Transliterates the characters in its first argument from the set given by the
482 second argument to the set given by the third. No abbreviations are permitted.
491 This macro with no arguments, turns on tracing for all macros (including
492 built-ins). Otherwise, turns on tracing for named macros.
501 Turns off trace globally and for any macros specified.
510 Removes the definition of the macro named in its argument.
519 This macro causes immediate output of text from diversions named as arguments,
520 or all diversions if no argument. Text can be undiverted into another
521 diversion. Undiverting discards the diverted text.
530 Evaluates its argument as an arithmetic expression, using 32-bit
531 signed-integer arithmetic. The following operators are supported: parentheses,
532 unary -, unary +, !, ~, *, /, %, +, -, <<, >>, relationals, bitwise &, |, &&,
533 and ||. Precedence and associativity are as in C. Octal and hex numbers can
534 also be specified as in C. The second argument specifies the radix for the
535 result; the default is 10. The third argument can be used to specify the
536 minimum number of digits in the result.
541 \fBExample 1 \fRExamples of m4 files
544 If the file \fBm4src\fR contains the lines:
549 The value of `VER' is "VER".
550 ifdef(`VER', ``VER'' is defined to be VER., VER is not defined.)
551 ifelse(VER, 1, ``VER'' is `VER'.)
552 ifelse(VER, 2, ``VER'' is `VER'., ``VER'' is not 2.)
577 \fBm4 -U VER m4src\fR
589 The value of VER is "VER".
605 \fBm4 -D VER m4src\fR
617 The value of VER is "".
618 VER is defined to be .
633 \fBm4 -D VER=1 m4src\fR
645 The value of VER is "1".
646 VER is defined to be 1.
661 \fBm4 -D VER=2 m4src\fR
673 The value of VER is "2".
674 VER is defined to be 2.
682 .SH ENVIRONMENT VARIABLES
685 See \fBenviron\fR(5) for descriptions of the following environment variables
686 that affect the execution of \fBm4\fR: \fBLANG\fR, \fBLC_ALL\fR,
687 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
691 The following exit values are returned:
698 Successful completion.
712 If the \fBm4exit\fR macro is used, the exit value can be specified by the input
718 See \fBattributes\fR(5) for descriptions of the following attributes:
719 .SS "\fB/usr/bin/m4\fR"
727 ATTRIBUTE TYPE ATTRIBUTE VALUE
729 Interface Stability Standard
735 \fBas\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)