BSD 3 development
[unix-history] / usr / man / man1 / m4.1
CommitLineData
e6817382
BJ
1.TH M4 1
2.SH NAME
3m4 \- macro processor
4.SH SYNOPSIS
5.B m4
6[ files ]
7.SH DESCRIPTION
8.I M4
9is a macro processor
10intended as a front end for Ratfor, C, and other languages.
11Each of the argument files is processed in order;
12if there are no arguments, or if an argument is `\-',
13the standard input is read.
14The processed text is written on the standard output.
15.PP
16Macro calls
17have the form
18.PP
19 name(arg1,arg2, . . . , argn)
20.br
21.PP
22The `(' must immediately follow the name of the macro.
23If a defined macro name is not followed by a `(',
24it is deemed to have no arguments.
25Leading unquoted blanks, tabs, and newlines are ignored while collecting arguments.
26Potential macro names consist of alphabetic letters,
27digits, and underscore `\_', where the first character is not a digit.
28.PP
29Left and right single quotes (\`\|\') are used to quote strings.
30The value of a quoted string is the string stripped of the quotes.
31.PP
32When a macro name is recognized,
33its arguments are collected by searching for a matching right
34parenthesis.
35Macro evaluation proceeds normally during the collection of the arguments,
36and any commas or right parentheses
37which happen to turn up within the value of a nested
38call are as effective as those in the original input text.
39After argument collection,
40the value of the macro is pushed back onto the input stream
41and rescanned.
42.PP
43.I M4
44makes available the following built-in macros.
45They may be redefined, but once this is done the original meaning is lost.
46Their values are null unless otherwise stated.
47.TP 10
48define
49The second argument is installed as the value of the macro
50whose name is the first argument.
51Each occurrence of $\fIn\fR in the replacement text,
52where
53.I n
54is a digit,
55is replaced by the
56.IR n -th
57argument.
58Argument 0 is the name of the macro;
59missing arguments are replaced by the null string.
60.TP
61undefine
62removes the definition of the macro named in its argument.
63.TP
64ifdef
65If the first argument is defined, the value is the second argument, otherwise the third.
66If there is no third argument, the value is null.
67The word
68.I unix
69is predefined on UNIX versions of
70.IR m4 .
71.TP
72changequote
73Change quote characters to the first and second arguments.
74.I Changequote
75without arguments restores the original values
76(i.e., \`\|\').
77.TP
78divert
79.I M4
80maintains 10 output streams,
81numbered 0-9.
82The final output is the concatenation of the streams
83in numerical order;
84initially stream 0 is the current stream.
85The
86.I divert
87macro changes the current output stream to its (digit-string)
88argument.
89Output diverted to a stream other than 0 through 9
90is discarded.
91.TP
92undivert
93causes immediate output of text from diversions named as
94arguments, or all diversions if no argument.
95Text may be undiverted into another diversion.
96Undiverting discards the diverted text.
97.TP
98divnum
99returns the value of the current output stream.
100.TP
101dnl
102reads and discards characters up to and including the next newline.
103.TP
104ifelse
105has three or more arguments.
106If the first argument is the same string as the second,
107then the value is the third argument.
108If not, and if there are more than four arguments, the process is repeated with arguments 4, 5, 6 and 7.
109Otherwise, the value is either the fourth string, or, if it is not present,
110null.
111.TP
112incr
113returns the value of its argument incremented by 1.
114The value of the argument is calculated
115by interpreting an initial digit-string as a decimal number.
116.TP
117eval
118evaluates its argument as an arithmetic expression, using 32-bit arithmetic.
119Operators include +, \-, \(**, /, %, ^ (exponentiation); relationals; parentheses.
120.TP
121len
122returns the number of characters in its argument.
123.TP
124index
125returns the position in its first argument where the second argument begins (zero origin),
126or \-1 if the second argument does not occur.
127.TP
128substr
129returns a substring of its first argument.
130The second argument is a zero origin
131number selecting the first character;
132the third argument indicates the length of the substring.
133A missing third argument is taken to be large enough to extend to
134the end of the first string.
135.TP
136translit
137transliterates the characters in its first argument
138from the set given by the second argument to the set given by the third.
139No abbreviations are permitted.
140.TP
141include
142returns the contents of the file named in the argument.
143.TP
144sinclude
145is identical to
146.I include,
147except that it
148says nothing if the file is inaccessible.
149.TP
150syscmd
151executes the UNIX command given in the first argument.
152No value is returned.
153.TP
154maketemp
155fills in a string of XXXXX in its argument with the current process id.
156.TP
157errprint
158prints its argument
159on the diagnostic output file.
160.TP
161dumpdef
162prints current names and definitions,
163for the named items, or for all if no arguments are given.
164.dt
165.SH "SEE ALSO"
166B. W. Kernighan and D. M. Ritchie,
167.I The M4 Macro Processor