-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathm4.cat1
More file actions
351 lines (260 loc) · 17.3 KB
/
m4.cat1
File metadata and controls
351 lines (260 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
M4(1) BSD General Commands Manual M4(1)
NNAAMMEE
mm44 — macro language processor
SSYYNNOOPPSSIISS
mm44 [--ggPPss] [--DD_n_a_m_e[=_v_a_l_u_e]] [--dd _f_l_a_g_s] [--II _d_i_r_n_a_m_e] [--oo _f_i_l_e_n_a_m_e]
[--tt _m_a_c_r_o] [--UU_n_a_m_e] [_f_i_l_e _._._.]
DDEESSCCRRIIPPTTIIOONN
The mm44 utility is a macro processor that can be used as a front end to
any language (e.g., C, ratfor, fortran, lex, and yacc). If no input
files are given, mm44 reads from the standard input, otherwise files speci‐
fied on the command line are processed in the given order. Input files
can be regular files, files in the m4 include paths, or a single dash
(‘-’), denoting standard input. mm44 writes the processed text to the
standard output, unless told otherwise.
Macro calls have the form name(argument1[, argument2, ..., argumentN]).
There cannot be any space following the macro name and the open parenthe‐
sis (‘(’). If the macro name is not followed by an open parenthesis it
is processed with no arguments.
Macro names consist of a leading alphabetic or underscore possibly fol‐
lowed by alphanumeric or underscore characters, e.g., valid macro names
match the pattern “[a-zA-Z_][a-zA-Z0-9_]*”.
In arguments to macros, leading unquoted space, tab, and newline (‘\n’)
characters are ignored. To quote strings, use left and right single
quotes (e.g., ‘ this is a string with a leading space’). You can change
the quote characters with the cchhaannggeeqquuoottee built-in macro.
Most built-ins don't make any sense without arguments, and hence are not
recognized as special when not followed by an open parenthesis.
The options are as follows:
--DD_n_a_m_e[=_v_a_l_u_e]
Define the symbol _n_a_m_e to have some value (or NULL).
--dd _f_l_a_g_s
Set trace flags. _f_l_a_g_s may hold the following:
_a print macro arguments.
_c print macro expansion over several lines.
_e print result of macro expansion.
_f print filename location.
_l print line number.
_q quote arguments and expansion with the current quotes.
_t start with all macros traced.
_x number macro expansions.
_V turn on all options.
By default, trace is set to "eq".
--gg Activate GNU-m4 compatibility mode. In this mode, translit han‐
dles simple character ranges (e.g., a-z), regular expressions
mimic emacs behavior, multiple m4wrap calls are handled as a
stack, the number of diversions is unlimited, empty names for
macro definitions are allowed, and eval understands
‘0rbase:value’ numbers.
--II _d_i_r_n_a_m_e
Add directory _d_i_r_n_a_m_e to the include path.
--oo _f_i_l_e_n_a_m_e
Send trace output to _f_i_l_e_n_a_m_e.
--PP Prefix all built-in macros with ‘m4_’. For example, instead of
writing ddeeffiinnee, use mm44__ddeeffiinnee.
--ss Output line synchronization directives, suitable for cpp(1).
--tt _m_a_c_r_o
Turn tracing on for _m_a_c_r_o.
--UU_n_a_m_e Undefine the symbol _n_a_m_e.
SSYYNNTTAAXX
mm44 provides the following built-in macros. They may be redefined, losing
their original meaning. Return values are null unless otherwise stated.
bbuuiillttiinn(_n_a_m_e)
Calls a built-in by its _n_a_m_e, overriding possible redefini‐
tions.
cchhaannggeeccoomm(_s_t_a_r_t_c_o_m_m_e_n_t, _e_n_d_c_o_m_m_e_n_t)
Changes the start comment and end comment sequences. Com‐
ment sequences may be up to five characters long. The
default values are the hash sign and the newline character.
# This is a comment
With no arguments, comments are turned off. With one single
argument, the end comment sequence is set to the newline
character.
cchhaannggeeqquuoottee(_b_e_g_i_n_q_u_o_t_e, _e_n_d_q_u_o_t_e)
Defines the open quote and close quote sequences. Quote
sequences may be up to five characters long. The default
values are the backquote character and the quote character.
`Here is a quoted string'
With no arguments, the default quotes are restored. With
one single argument, the close quote sequence is set to the
newline character.
ddeeccrr(_a_r_g) Decrements the argument _a_r_g by 1. The argument _a_r_g must be
a valid numeric string.
ddeeffiinnee(_n_a_m_e, _v_a_l_u_e)
Define a new macro named by the first argument _n_a_m_e to have
the value of the second argument _v_a_l_u_e. Each occurrence of
‘$n’ (where _n is 0 through 9) is replaced by the _n'th argu‐
ment. ‘$0’ is the name of the calling macro. Undefined
arguments are replaced by a null string. ‘$#’ is replaced
by the number of arguments; ‘$*’ is replaced by all argu‐
ments comma separated; ‘$@’ is the same as ‘$*’ but all
arguments are quoted against further expansion.
ddeeffnn(_n_a_m_e, _._._.)
Returns the quoted definition for each argument. This can
be used to rename macro definitions (even for built-in
macros).
ddiivveerrtt(_n_u_m) There are 10 output queues (numbered 0-9). At the end of
processing mm44 concatenates all the queues in numerical order
to produce the final output. Initially the output queue is
0. The divert macro allows you to select a new output queue
(an invalid argument passed to divert causes output to be
discarded).
ddiivvnnuumm Returns the current output queue number.
ddnnll Discard input characters up to and including the next new‐
line.
dduummppddeeff(_n_a_m_e, _._._.)
Prints the names and definitions for the named items, or for
everything if no arguments are passed.
eerrrrpprriinntt(_m_s_g)
Prints the first argument on the standard error output
stream.
eessyyssccmmdd(_c_m_d)
Passes its first argument to a shell and returns the shell's
standard output. Note that the shell shares its standard
input and standard error with mm44.
eevvaall(_e_x_p_r) Computes the first argument as an arithmetic expression
using 32-bit arithmetic. Operators are the standard C
ternary, arithmetic, logical, shift, relational, bitwise,
and parentheses operators. You can specify octal, decimal,
and hexadecimal numbers as in C. The second argument (if
any) specifies the radix for the result and the third argu‐
ment (if any) specifies the minimum number of digits in the
result.
eexxpprr(_e_x_p_r) This is an alias for eevvaall.
ffoorrmmaatt(_f_o_r_m_a_t_s_t_r_i_n_g, _a_r_g_1, _._._.)
Returns _f_o_r_m_a_t_s_t_r_i_n_g with escape sequences substituted with
_a_r_g_1 and following arguments, in a way similar to printf(3).
This built-in is only available in GNU-m4 compatibility
mode, and the only parameters implemented are there for
autoconf compatibility: left-padding flag, an optional field
width, a maximum field width, *-specified field widths, and
the %s and %c data type.
iiffddeeff(_n_a_m_e, _y_e_s, _n_o)
If the macro named by the first argument is defined then
return the second argument, otherwise the third. If there
is no third argument, the value is NULL. The word "unix" is
predefined.
iiffeellssee(_a, _b, _y_e_s, _._._.)
If the first argument _a matches the second argument _b then
iiffeellssee() returns the third argument _y_e_s. If the match fails
the three arguments are discarded and the next three argu‐
ments are used until there is zero or one arguments left,
either this last argument or NULL is returned if no other
matches were found.
iinncclluuddee(_n_a_m_e)
Returns the contents of the file specified in the first
argument. If the file is not found as is, look through the
include path: first the directories specified with --II on the
command line, then the environment variable M4PATH, as a
colon-separated list of directories. Include aborts with an
error message if the file cannot be included.
iinnccrr(_a_r_g) Increments the argument by 1. The argument must be a valid
numeric string.
iinnddeexx(_s_t_r_i_n_g, _s_u_b_s_t_r_i_n_g)
Returns the index of the second argument in the first argu‐
ment (e.g., iinnddeexx((tthhee qquuiicckk bbrroowwnn ffooxx jjuummppeedd,, ffooxx)) returns
16). If the second argument is not found index returns -1.
iinnddiirr(_m_a_c_r_o, _a_r_g_1, _._._.)
Indirectly calls the macro whose name is passed as the first
argument, with the remaining arguments passed as first, ...
arguments.
lleenn(_a_r_g) Returns the number of characters in the first argument.
Extra arguments are ignored.
mm44eexxiitt(_c_o_d_e)
Immediately exits with the return value specified by the
first argument, 0 if none.
mm44wwrraapp(_t_o_d_o)
Allows you to define what happens at the final EOF, usually
for cleanup purposes (e.g., mm44wwrraapp((""cclleeaannuupp((tteemmppffiillee))""))
causes the macro cleanup to be invoked after all other pro‐
cessing is done).
Multiple calls to mm44wwrraapp() get inserted in sequence at the
final EOF.
mmaakkeetteemmpp(_t_e_m_p_l_a_t_e)
Like mmkksstteemmpp.
mmkksstteemmpp(_t_e_m_p_l_a_t_e)
Invokes mkstemp(3) on the first argument, and returns the
modified string. This can be used to create unique tempo‐
rary file names.
ppaassttee(_f_i_l_e) Includes the contents of the file specified by the first
argument without any macro processing. Aborts with an error
message if the file cannot be included.
ppaattssuubbsstt(_s_t_r_i_n_g, _r_e_g_e_x_p, _r_e_p_l_a_c_e_m_e_n_t)
Substitutes a regular expression in a string with a replace‐
ment string. Usual substitution patterns apply: an amper‐
sand (‘&’) is replaced by the string matching the regular
expression. The string ‘\#’, where ‘#’ is a digit, is
replaced by the corresponding back-reference.
ppooppddeeff(_a_r_g, _._._.)
Restores the ppuusshhddeeffed definition for each argument.
ppuusshhddeeff(_m_a_c_r_o, _d_e_f)
Takes the same arguments as ddeeffiinnee, but it saves the defini‐
tion on a stack for later retrieval by ppooppddeeff().
rreeggeexxpp(_s_t_r_i_n_g, _r_e_g_e_x_p, _r_e_p_l_a_c_e_m_e_n_t)
Finds a regular expression in a string. If no further argu‐
ments are given, it returns the first match position or -1
if no match. If a third argument is provided, it returns
the replacement string, with sub-patterns replaced.
sshhiifftt(_a_r_g_1, _._._.)
Returns all but the first argument, the remaining arguments
are quoted and pushed back with commas in between. The
quoting nullifies the effect of the extra scan that will
subsequently be performed.
ssiinncclluuddee(_f_i_l_e)
Similar to iinncclluuddee, except it ignores any errors.
ssppaassttee(_f_i_l_e)
Similar to ppaassttee(), except it ignores any errors.
ssuubbssttrr(_s_t_r_i_n_g, _o_f_f_s_e_t, _l_e_n_g_t_h)
Returns a substring of the first argument starting at the
offset specified by the second argument and the length spec‐
ified by the third argument. If no third argument is
present it returns the rest of the string.
ssyyssccmmdd(_c_m_d) Passes the first argument to the shell. Nothing is
returned.
ssyyssvvaall Returns the return value from the last ssyyssccmmdd.
ttrraacceeoonn(_a_r_g, _._._.)
Enables tracing of macro expansions for the given arguments,
or for all macros if no argument is given.
ttrraacceeooffff(_a_r_g, _._._.)
Disables tracing of macro expansions for the given argu‐
ments, or for all macros if no argument is given.
ttrraannsslliitt(_s_t_r_i_n_g, _m_a_p_f_r_o_m, _m_a_p_t_o)
Transliterate the characters in the first argument from the
set given by the second argument to the set given by the
third. You cannot use tr(1) style abbreviations.
uunnddeeffiinnee(_n_a_m_e_1, _._._.)
Removes the definition for the macros specified by its argu‐
ments.
uunnddiivveerrtt(_a_r_g, _._._.)
Flushes the named output queues (or all queues if no argu‐
ments).
uunniixx A pre-defined macro for testing the OS platform.
____lliinnee____ Returns the current file's line number.
____ffiillee____ Returns the current file's name.
EEXXIITT SSTTAATTUUSS
The mm44 utility exits 0 on success, and >0 if an error occurs.
But note that the mm44eexxiitt macro can modify the exit status.
SSTTAANNDDAARRDDSS
The mm44 utility is mostly compliant with the IEEE Std 1003.1-2008
(“POSIX.1”) specification.
The flags [--ddggIIoott] and the macros bbuuiillttiinn, eessyyssccmmdd, eexxpprr, ffoorrmmaatt, iinnddiirr,
ppaassttee, ppaattssuubbsstt, rreeggeexxpp, ssppaassttee, uunniixx, ____lliinnee____, and ____ffiillee____ are exten‐
sions to that specification.
mmaakkeetteemmpp is not supposed to be a synonym for mmkksstteemmpp, but instead to be
an insecure temporary file name creation function. The change causes no
known compatibility issues.
The output format of tracing and of dduummppddeeff are not specified in any
standard, are likely to change and should not be relied upon. The cur‐
rent format of tracing is closely modelled on ggnnuu--mm44, to allow aauuttooccoonnff
to work.
The built-ins ppuusshhddeeff and ppooppddeeff handle macro definitions as a stack.
However, ddeeffiinnee interacts with the stack in an undefined way. In this
implementation, ddeeffiinnee replaces the top-most definition only. Other
implementations may erase all definitions on the stack instead.
All built-ins do expand without arguments in many other mm44.
Many other mm44 have dire size limitations with respect to buffer sizes.
AAUUTTHHOORRSS
Ozan Yigit ⟨oz@sis.yorku.ca⟩ and Richard A. O'Keefe
⟨ok@goanna.cs.rmit.OZ.AU⟩.
GNU-m4 compatibility extensions by Marc Espie ⟨espie@cvs.openbsd.org⟩.
BSD August 8, 2012 BSD