3 .CD "m4 \(en macro processor"
4 .SX "m4\fR [\fB\(enD \fIname\fR = \fIvalue\fR]\fR [\fB\(enU \fIname\fR]
5 .FL "\(enD" "Define a symbol"
6 .FL "\(enU" "Undefine a symbol"
7 .EY "m4 <m4test" "Run M4"
9 \fIM4\fR is a macro processor intended as a front end
10 for Ratfor, Pascal, and other languages that do not have a built-in macro
11 processing capability. M4 reads standard input, the processed text is
12 written on the standard output.
14 The options and their effects are as follows:
18 \(enD name[=val] Defines name to val, or to null in val's absence.
20 \(enU name Undefines name.
24 Macro calls have the form: name(arg1,arg2, ..., argn)
26 The \*(OQ(\*(CQ must immediately follow the name of the macro.
28 defined macro is not followed by a ( it is taken to be a call of that macro
29 with no arguments, i.e. name(). Potential macro names consist of alphabetic
32 Leading unquoted blanks, tabs and newlines are ignored while collecting
33 arguments. Left and right single quotes are used to quote strings. The value
34 of a quoted string is the string stripped of the quotes.
36 When a macro name is recognized, its arguments are collected by searching
37 for a matching ). If fewer arguments are supplied than are in the macro
38 definition, the trailing arguments are taken to be null. Macro evaluation
39 proceeds normally during the collection of the arguments, and any commas or
40 right parentheses which happen to turn up within the value of a nested call
41 are as effective as those in the original input text. (This is typically
42 referred as inside-out macro expansion.) After argument collection, the
43 value of the macro is pushed back onto the input stream and rescanned.
45 M4 makes available the following built-in macros. They may be
46 redefined, but once this is done the original meaning is lost. Their values
47 are null unless otherwise stated.
49 \fBdefine "(name [, val])"\fR the second argument is installed as the value of
50 the macro whose name is the first argument. If there is no second argument,
51 the value is null. Each occurrence of $ n in the replacement text, where n is
52 a digit, is replaced by the n -th argument. Argument 0 is the name of the
53 macro; missing arguments are replaced by the null string.
55 \fBdefn "(name [, name ...])"\fR returns the quoted definition of its
56 argument(s). Useful in renaming macros.
58 \fBundefine "(name [, name ...])"\fR removes the definition of the macro(s)
59 named. If there is more than one definition for the named macro, (due to
60 previous use of pushdef) all definitions are removed.
62 \fBpushdef "(name [, val])"\fR like define, but saves any previous definition
63 by stacking the current definition.
65 \fBpopdef "(name [, name ...])"\fR removes current definition of its
66 argument(s), exposing the previous one if any.
68 \fBifdef "(name, if-def [, ifnot-def])"\fR if the first argument is defined,
69 the value is the second argument, otherwise the third. If there is no third
70 argument, the value is null. A word indicating the current operating system
71 is predefined. (e.g. unix or vms).
73 \fBshift "(arg, arg, arg, ...)"\fR returns all but its first argument. The
74 other arguments are quoted and pushed back with commas in between. The
75 quoting nullifies the effect of the extra scan that will subsequently be
78 \fBchangequote "(lqchar, rqchar)"\fR change quote symbols to the first and
79 second arguments. With no arguments, the quotes are reset back to the default
80 characters. (i.e., `').
82 \fBchangecom "(lcchar, rcchar)"\fR change left and right comment markers from
83 the default # and newline. With no arguments, the comment mechanism is reset
84 back to the default characters. With one argument, the left marker becomes
85 the argument and the right marker becomes newline. With two arguments, both
88 \fBdivert "(divnum)"\fR maintains 10 output streams, numbered 0-9. Initially
89 stream 0 is the current stream. The divert macro changes the current output
90 stream to its (digit-string) argument. Output diverted to a stream other than
93 \fBundivert "([divnum [, divnum ...]])"\fR causes immediate output of text from
94 diversions named as argument(s), or all diversions if no argument. Text may
95 be undiverted into another diversion. Undiverting discards the diverted text.
96 At the end of input processing, M4 forces an automatic undivert unless is
99 \fBdivnum "()"\fR returns the value of the current output stream.
101 \fBdnl "()"\fR reads and discards characters up to and including the next
104 \fBifelse "(arg, arg, if-same [, ifnot-same | arg, arg ...])"\fR has three or
105 more arguments. If the first argument is the same string as the second, then
106 the value is the third argument. If not, and if there are more than four
107 arguments, the process is repeated with arguments 4, 5, 6 and 7. Otherwise,
108 the value is either the fourth string, or, if it is not present, null.
110 \fBincr "(num)"\fR returns the value of its argument incremented by 1. The
111 value of the argument is calculated by interpreting an initial digit-string as
114 \fBdecr "(num)"\fR returns the value of its argument decremented by 1.
116 \fBeval "(expression)"\fR evaluates its argument as a constant expression,
117 using integer arithmetic. The evaluation mechanism is very similar to that of
118 cpp (#if expression). The expression can involve only integer constants and
119 character constants, possibly connected by the binary operators
122 * / % + - >> << < > <= >= == != & ^ | && ||
125 or the unary operators - ! or tilde or by the ternary operator ? : .
126 Parentheses may be used for grouping. Octal numbers may be specified as in C.
128 \fBlen "(string)"\fR returns the number of characters in its argument.
130 \fBindex "(search-string, string)"\fR returns the position in its first
131 argument where the second argument begins (zero origin), or 1 if the second
132 argument does not occur.
134 \fBsubstr "(string, index [, length])"\fR returns a substring of its first
135 argument. The second argument is a zero origin number selecting the first
136 character (internally treated as an expression); the third argument indicates
137 the length of the substring. A missing third argument is taken to be large
138 enough to extend to the end of the first string.
140 \fBtranslit "(source, from [, to])"\fR transliterates the characters in its
141 first argument from the set given by the second argument to the set given by
142 the third. If the third argument is shorter than the second, all extra
143 characters in the second argument are deleted from the first argument. If the
144 third argument is missing altogether, all characters in the second argument
145 are deleted from the first argument.
147 \fBinclude "(filename)"\fR returns the contents of the file that is
148 named in the argument.
150 \fBsinclude "(filename)"\fRis identical to include, except that it says nothing
151 if the file is inaccessable.
153 \fBpaste "(filename)"\fR returns the contents of the file named in the argument
154 without any processing, unlike include.
156 \fBspaste "(filename)"\fR is identical to paste, except that it says nothing if
157 the file is inaccessibl[De.
159 \fBsyscmd "(command)"\fR executes the
161 command given in the first argument.
162 No value is returned.
164 \fBsysval "()"\fR is the return code from the last call to syscmd.
166 \fBmaketemp \*(OQ(string)"\fR fills in a string of XXXXXX in its argument with the
169 \fBm4exit "([exitcode])"\fR causes immediate exit from M4. Argument 1, if
170 given, is the exit code; the default is 0.
172 \fBm4wrap "(m4-macro-or-built-n)"\fR argument 1 will be pushed back at final
173 EOF; example: m4wrap(`dumptable()').
175 \fBerrprint "(str [, str, str, ...])"\fR prints its argument(s) on stderr. If
176 there is more than one argument, each argument is separated by a space during
177 the output. An arbitrary number of arguments may be supplied.
179 \fBdumpdef "([name, name, ...])"\fR prints current names and definitions, for
180 the named items, or for all if no arguments are given.
185 \fIM4\fR was written by Ozan S. Yigif.