6001 strcat(9f) needs a manpage
[unleashed.git] / usr / src / man / man1 / m4.1
blobc7ae9e1bde03860d4d3964ec0626a6d8571443b9
1 '\" te
2 .\"  Copyright 1989 AT&T Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\"  This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH M4 1 "Jul 3, 2007"
11 .SH NAME
12 m4 \- macro processor
13 .SH SYNOPSIS
14 .LP
15 .nf
16 \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]
17      [\fB-T\fR \fIint\fR] [\fB-D\fR\fIname\fR [\fI=val\fR]] ... [\fB-U\fR \fIname\fR] ... [\fIfile\fR]...
18 .fi
20 .LP
21 .nf
22 \fB/usr/xpg4/bin/m4\fR [\fB-e\fR] [\fB-s\fR] [\fB-B\fR \fIint\fR] [\fB-H\fR \fIint\fR] [\fB-S\fR \fIint\fR]
23      [\fB-T\fR \fIint\fR] [\fB-D\fR\fIname\fR [...\fI=val\fR]] [\fB-U\fR \fIname\fR] ... [\fIfile\fR]...
24 .fi
26 .SH DESCRIPTION
27 .sp
28 .LP
29 The \fBm4\fR utility is a macro processor intended as a front end for C,
30 assembler, and other languages. Each of the argument files is processed in
31 order. If there are no files, or if a file is \fB\(mi\fR, the standard input is
32 read. The processed text is written on the standard output. \fBNote:\fR
33 \fBm4\fR cannot include more than nine nested files and writes a diagnostic
34 message if that number is exceeded.
35 .SS "Macro Syntax"
36 .sp
37 .LP
38 Macro calls have the form:
39 .sp
40 .in +2
41 .nf
42 \fIname\fR(\fIarg1\fR,\fIarg2\fR, ..., \fIargn\fR)
43 .fi
44 .in -2
45 .sp
47 .sp
48 .LP
49 The open parenthesis character, \fB(\fR, must immediately follow the name of
50 the macro. If the name of a defined macro is not followed by a \fB(\fR, it is
51 deemed to be a call of that macro with no arguments. Potential macro names
52 consist of alphanumeric characters and underscore (\fB_\fR), where the first
53 character is not a digit.
54 .sp
55 .LP
56 Leading unquoted blanks, TABs, and \fBNEWLINE\fRs are ignored while collecting
57 arguments. Left and right single quotes are used to quote strings. The value of
58 a quoted string is the string stripped of the quotes.
59 .SS "Macro Processing"
60 .sp
61 .LP
62 When a macro name is recognized, its arguments are collected by searching for a
63 matching right parenthesis. If fewer arguments are supplied than are in the
64 macro definition, the trailing arguments are taken to be \fINULL\fR. Macro
65 evaluation proceeds normally during the collection of the arguments, and any
66 commas or right parentheses that happen to turn up within the value of a nested
67 call are as effective as those in the original input text. After argument
68 collection, the value of the macro is pushed back onto the input stream and
69 rescanned.
70 .SH OPTIONS
71 .sp
72 .LP
73 The options and their effects are as follows:
74 .sp
75 .ne 2
76 .na
77 \fB\fB-B\fR\fIint\fR\fR
78 .ad
79 .RS 9n
80 Changes the size of the push-back and argument collection buffers from the
81 default of \fB4,096\fR.
82 .RE
84 .sp
85 .ne 2
86 .na
87 \fB\fB-e\fR\fR
88 .ad
89 .RS 9n
90 Operates interactively. Interrupts are ignored and the output is unbuffered.
91 .RE
93 .sp
94 .ne 2
95 .na
96 \fB\fB-H\fR\fIint\fR\fR
97 .ad
98 .RS 9n
99 Changes the size of the symbol table hash array from the default of \fB199\fR.
100 The size should be prime.
104 .ne 2
106 \fB\fB-s\fR\fR
108 .RS 9n
109 Enables line sync output for the C preprocessor (\fB#\fRline .\|.\|.\|)
113 .ne 2
115 \fB\fB-S\fR\fIint\fR\fR
117 .RS 9n
118 Changes the size of the call stack from the default of \fB100\fRslots. Macros
119 take three slots, and non-macro arguments take one.
123 .ne 2
125 \fB\fB-T\fR\fIint\fR\fR
127 .RS 9n
128 Changes the size of the token buffer from the default of \fB512\fRbytes.
133 To be effective, the above flags must appear before any file names and before
134 any \fB-D\fR or \fB-U\fR flags:
136 .ne 2
138 \fB\fB-D\fR \fIname\fR[\fB=\fR\fBval\fR]\fR
140 .RS 17n
141 Defines \fIname\fR to \fBval\fR or to \fINULL\fR in \fBval\fR's absence.
145 .ne 2
147 \fB\fB-U\fR\fIname\fR\fR
149 .RS 17n
150 Undefines \fIname\fR.
153 .SH OPERANDS
156 The following operand is supported:
158 .ne 2
160 \fB\fIfile\fR\fR
162 .RS 8n
163 A path name of a text file to be processed. If no \fIfile\fR is given, or if it
164 is \(mi, the standard input is read.
167 .SH USAGE
170 The \fBm4\fR utility makes available the following built-in macros. These
171 macros can be redefined, but once this is done the original meaning is lost.
172 Their values are \fINULL\fR unless otherwise stated.
174 .ne 2
176 \fB\fBchangequote\fR\fR
178 .RS 15n
179 Change quote symbols to the first and second arguments. The symbols can be up
180 to five characters long. \fBchangequote\fR without arguments restores the
181 original values (that is, \fB`\|'\fR).
185 .ne 2
187 \fB\fBchangecom\fR\fR
189 .RS 15n
190 Change left and right comment markers from the default \fB#\fR and
191 \fBNEWLINE\fR. With no arguments, the comment mechanism is effectively
192 disabled. With one argument, the left marker becomes the argument and the right
193 marker becomes \fBNEWLINE\fR. With two arguments, both markers are affected.
194 Comment markers can be up to five characters long.
198 .ne 2
200 \fB\fBdecr\fR\fR
202 .RS 15n
203 Returns the value of its argument decremented by 1.
207 .ne 2
209 \fB\fBdefine\fR\fR
211 .RS 15n
212 The second argument is installed as the value of the macro whose name is the
213 first argument. Each occurrence of \fB$\fR\fIn\fR in the replacement text,
214 where \fIn\fR is a digit, is replaced by the \fIn\fR-th argument. Argument 0 is
215 the name of the macro; missing arguments are replaced by the null string;
216 \fB$#\fR is replaced by the number of arguments; \fB$*\fR is replaced by a list
217 of all the arguments separated by commas; \fB$@\fR is like \fB$*\fR, but each
218 argument is quoted (with the current quotes).
222 .ne 2
224 \fB\fBdefn\fR\fR
226 .RS 15n
227 Returns the quoted definition of its argument(s). It is useful for renaming
228 macros, especially built-ins.
232 .ne 2
234 \fB\fBdivert\fR\fR
236 .RS 15n
237 \fBm4\fR maintains 10 output streams, numbered 0-9. The final output is the
238 concatenation of the streams in numerical order. Initially stream 0 is the
239 current stream. The \fBdivert\fR macro changes the current output stream to its
240 (digit-string) argument. Output diverted to a stream other than 0 through 9 is
241 discarded.
245 .ne 2
247 \fB\fBdivnum\fR\fR
249 .RS 15n
250 Returns the value of the current output stream.
254 .ne 2
256 \fB\fBdnl\fR\fR
258 .RS 15n
259 Reads and discards characters up to and including the next \fBNEWLINE\fR.
263 .ne 2
265 \fB\fBdumpdef\fR\fR
267 .RS 15n
268 Prints current names and definitions, for the named items, or for all if no
269 arguments are given.
273 .ne 2
275 \fB\fBerrprint\fR\fR
277 .RS 15n
278 Prints its argument on the diagnostic output file.
282 .ne 2
284 \fB\fBifdef\fR\fR
286 .RS 15n
287 If the first argument is defined, the value is the second argument, otherwise
288 the third. If there is no third argument, the value is \fINULL\fR. The word
289 \fBunix\fR is predefined.
293 .ne 2
295 \fB\fBifelse\fR\fR
297 .RS 15n
298 This macro has three or more arguments. If the first argument is the same
299 string as the second, then the value is the third argument. If not, and if
300 there are more than four arguments, the process is repeated with arguments 4,
301 5, 6 and 7. Otherwise, the value is either the fourth string, or, if it is not
302 present, \fINULL\fR.
306 .ne 2
308 \fB\fBinclude\fR\fR
310 .RS 15n
311 Returns the contents of the file named in the argument.
315 .ne 2
317 \fB\fBincr\fR\fR
319 .RS 15n
320 Returns the value of its argument incremented by 1. The value of the argument
321 is calculated by interpreting an initial digit-string as a decimal number.
325 .ne 2
327 \fB\fBindex\fR\fR
329 .RS 15n
330 Returns the position in its first argument where the second argument begins
331 (zero origin), or \(mi1 if the second argument does not occur.
335 .ne 2
337 \fB\fBlen\fR\fR
339 .RS 15n
340 Returns the number of characters in its argument.
344 .ne 2
346 \fB\fBm4exit\fR\fR
348 .RS 15n
349 This macro causes immediate exit from \fBm4\fR. Argument 1, if given, is the
350 exit code; the default is \fB0\fR.
354 .ne 2
356 \fB\fBm4wrap\fR\fR
358 .RS 15n
359 Argument 1 is pushed back at final \fBEOF\fR. Example:
360 \fBm4wrap(`cleanup(\|)')\fR
364 .ne 2
366 \fB\fBmaketemp\fR\fR
368 .RS 15n
369 Fills in a string of "\fBX\fR" characters in its argument with the current
370 process \fBID\fR.
374 .ne 2
376 \fB\fBpopdef\fR\fR
378 .RS 15n
379 Removes current definition of its argument(s), exposing the previous one, if
380 any.
384 .ne 2
386 \fB\fBpushdef\fR\fR
388 .RS 15n
389 Like \fBdefine\fR, but saves any previous definition.
393 .ne 2
395 \fB\fBshift\fR\fR
397 .RS 15n
398 Returns all but its first argument. The other arguments are quoted and pushed
399 back with commas in between. The quoting nullifies the effect of the extra scan
400 that is subsequently be performed.
404 .ne 2
406 \fB\fBsinclude\fR\fR
408 .RS 15n
409 This macro is identical to \fBinclude\fR, except that it says nothing if the
410 file is inaccessible.
414 .ne 2
416 \fB\fBsubstr\fR\fR
418 .RS 15n
419 Returns a substring of its first argument. The second argument is a zero origin
420 number selecting the first character; the third argument indicates the length
421 of the substring. A missing third argument is taken to be large enough to
422 extend to the end of the first string.
426 .ne 2
428 \fB\fBsyscmd\fR\fR
430 .RS 15n
431 This macro executes the command given in the first argument. No value is
432 returned.
436 .ne 2
438 \fB\fBsysval\fR\fR
440 .RS 15n
441 This macro is the return code from the last call to \fBsyscmd\fR.
445 .ne 2
447 \fB\fBtranslit\fR\fR
449 .RS 15n
450 Transliterates the characters in its first argument from the set given by the
451 second argument to the set given by the third. No abbreviations are permitted.
455 .ne 2
457 \fB\fBtraceon\fR\fR
459 .RS 15n
460 This macro with no arguments, turns on tracing for all macros (including
461 built-ins). Otherwise, turns on tracing for named macros.
465 .ne 2
467 \fB\fBtraceoff\fR\fR
469 .RS 15n
470 Turns off trace globally and for any macros specified.
474 .ne 2
476 \fB\fBundefine\fR\fR
478 .RS 15n
479 Removes the definition of the macro named in its argument.
483 .ne 2
485 \fB\fBundivert\fR\fR
487 .RS 15n
488 This macro causes immediate output of text from diversions named as arguments,
489 or all diversions if no argument. Text can be undiverted into another
490 diversion. Undiverting discards the diverted text.
493 .SS "/usr/bin/m4"
495 .ne 2
497 \fB\fBeval\fR\fR
499 .RS 8n
500 Evaluates its argument as an arithmetic expression, using 32-bit signed-integer
501 arithmetic. The following operators are supported: parentheses, unary -, unary
502 +, !, ~, *, /, %, +, -, relationals, bitwise &, |, &&, and ||. Octal and hex
503 numbers can be specified as in C. The second argument specifies the radix for
504 the result; the default is 10. The third argument  can be used to specify the
505 minimum number of digits in the result.
508 .SS "/usr/xpg4/bin/m4"
510 .ne 2
512 \fB\fBeval\fR\fR
514 .RS 8n
515 Evaluates its argument as an arithmetic expression,  using  32-bit
516 signed-integer arithmetic. The following operators are supported: parentheses,
517 unary -, unary +, !, ~, *, /, %, +, -, <<, >>, relationals, bitwise &, |, &&,
518 and ||. Precedence and associativity are as in C. Octal and hex numbers can
519 also be specified as in C. The second argument specifies the radix for the
520 result; the default is 10. The third argument can be used to specify the
521 minimum number of digits in the result.
524 .SH EXAMPLES
526 \fBExample 1 \fRExamples of m4 files
529 If the file \fBm4src\fR contains the lines:
532 .in +2
534 The value of `VER' is "VER".
535         ifdef(`VER', ``VER'' is defined to be VER., VER is not defined.)
536         ifelse(VER, 1, ``VER'' is `VER'.)
537         ifelse(VER, 2, ``VER'' is `VER'., ``VER'' is not 2.)
538         end
540 .in -2
545 then the command:
548 .in +2
550 \fBm4 m4src\fR
552 .in -2
557 or the command:
560 .in +2
562 \fBm4 -U VER m4src\fR
564 .in -2
569 produces the output:
572 .in +2
574 The value of VER is "VER".
575         VER is not defined.
577         VER is not 2.
578         end
580 .in -2
585 The command:
588 .in +2
590 \fBm4 -D VER m4src\fR
592 .in -2
597 produces the output:
600 .in +2
602 The value of VER is "".
603         VER is defined to be .
605         VER is not 2.
606         end
608 .in -2
613 The command:
616 .in +2
618 \fBm4 -D VER=1 m4src\fR
620 .in -2
625 produces the output:
628 .in +2
630 The value of VER is "1".
631        VER is defined to be 1.
632        VER is 1.
633        VER is not 2.
634        end
636 .in -2
641 The command:
644 .in +2
646 \fBm4 -D VER=2 m4src\fR
648 .in -2
653 produces the output:
656 .in +2
658 The value of VER is "2".
659         VER is defined to be 2.
661         VER is 2.
662         end
664 .in -2
667 .SH ENVIRONMENT VARIABLES
670 See \fBenviron\fR(5) for descriptions of the following environment variables
671 that affect the execution of \fBm4\fR: \fBLANG\fR, \fBLC_ALL\fR,
672 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
673 .SH EXIT STATUS
676 The following exit values are returned:
678 .ne 2
680 \fB\fB0\fR\fR
682 .RS 6n
683 Successful completion.
687 .ne 2
689 \fB\fB>0\fR\fR
691 .RS 6n
692 An error occurred
697 If the \fBm4exit\fR macro is used, the exit value can be specified by the input
698 file.
700 .SH ATTRIBUTES
703 See \fBattributes\fR(5) for descriptions of the following attributes:
704 .SS "\fB/usr/xpg4/bin/m4\fR"
709 box;
710 c | c
711 l | l .
712 ATTRIBUTE TYPE  ATTRIBUTE VALUE
714 Interface Stability     Standard
717 .SH SEE ALSO
720 \fBas\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)