1M4(1)                       General Commands Manual                      M4(1)
2
3
4

NAME

6       m4 - macro processor
7

SYNOPSIS

9       m4 [ files ]
10

DESCRIPTION

12       M4  is  a  macro  processor  intended as a front end for Ratfor, C, and
13       other languages.  Each of the argument files is processed in order;  if
14       there are no arguments, or if an argument is `-', the standard input is
15       read.  The processed text is written on the standard output.
16
17       Macro calls have the form
18
19            name(arg1,arg2, . . . , argn)
20
21       The `(' must immediately follow the name of the macro.   If  a  defined
22       macro name is not followed by a `(', it is deemed to have no arguments.
23       Leading unquoted blanks, tabs, and newlines are ignored while  collect‐
24       ing  arguments.   Potential  macro names consist of alphabetic letters,
25       digits, and underscore `_', where the first character is not a digit.
26
27       Left and right single quotes (`´) are used to quote strings.  The value
28       of a quoted string is the string stripped of the quotes.
29
30       When a macro name is recognized, its arguments are collected by search‐
31       ing for a matching right parenthesis.  Macro evaluation  proceeds  nor‐
32       mally  during  the collection of the arguments, and any commas or right
33       parentheses which happen to turn up within the value of a  nested  call
34       are  as  effective as those in the original input text.  After argument
35       collection, the value of the macro is pushed back onto the input stream
36       and rescanned.
37
38       M4  makes  available  the following built-in macros.  They may be rede‐
39       fined, but once this is done the original meaning is lost.  Their  val‐
40       ues are null unless otherwise stated.
41
42       define    The  second  argument  is installed as the value of the macro
43                 whose name is the first argument.  Each occurrence of  $n  in
44                 the  replacement text, where n is a digit, is replaced by the
45                 n-th argument.  Argument 0 is the name of the macro;  missing
46                 arguments are replaced by the null string.
47
48       undefine  removes the definition of the macro named in its argument.
49
50       ifdef     If  the  first  argument  is defined, the value is the second
51                 argument, otherwise the third.  If there is  no  third  argu‐
52                 ment, the value is null.  The word unix is predefined on UNIX
53                 versions of m4.
54
55       changequote
56                 Change quote characters to the first  and  second  arguments.
57                 Changequote  without  arguments  restores the original values
58                 (i.e., `´).
59
60       divert    M4 maintains 10 output streams, numbered 0-9.  The final out‐
61                 put  is  the concatenation of the streams in numerical order;
62                 initially stream 0 is the current stream.  The  divert  macro
63                 changes the current output stream to its (digit-string) argu‐
64                 ment.  Output diverted to a stream other than 0 through 9  is
65                 discarded.
66
67       undivert  causes  immediate  output  of  text  from diversions named as
68                 arguments, or all diversions if no  argument.   Text  may  be
69                 undiverted  into another diversion.  Undiverting discards the
70                 diverted text.
71
72       divnum    returns the value of the current output stream.
73
74       dnl       reads and discards characters up to and  including  the  next
75                 newline.
76
77       ifelse    has  three  or  more arguments.  If the first argument is the
78                 same string as the second, then the value is the third  argu‐
79                 ment.  If not, and if there are more than four arguments, the
80                 process is repeated with arguments 4, 5, 6 and 7.  Otherwise,
81                 the  value  is  either  the  fourth  string, or, if it is not
82                 present, null.
83
84       incr      returns the value of its  argument  incremented  by  1.   The
85                 value  of  the argument is calculated by interpreting an ini‐
86                 tial digit-string as a decimal number.
87
88       eval      evaluates its argument as  an  arithmetic  expression,  using
89                 32-bit arithmetic.  Operators include +, -, ∗, /, %, ^ (expo‐
90                 nentiation); relationals; parentheses.
91
92       len       returns the number of characters in its argument.
93
94       index     returns the position in its first argument where  the  second
95                 argument  begins  (zero origin), or -1 if the second argument
96                 does not occur.
97
98       substr    returns a substring of its first argument.  The second  argu‐
99                 ment  is  a zero origin number selecting the first character;
100                 the third argument indicates the length of the substring.   A
101                 missing  third argument is taken to be large enough to extend
102                 to the end of the first string.
103
104       translit  transliterates the characters in its first argument from  the
105                 set  given  by  the  second  argument to the set given by the
106                 third.  No abbreviations are permitted.
107
108       include   returns the contents of the file named in the argument.
109
110       sinclude  is identical to include, except that it says nothing  if  the
111                 file is inaccessible.
112
113       syscmd    executes  the  UNIX  command given in the first argument.  No
114                 value is returned.
115
116       maketemp  fills in a string of XXXXX in its argument with  the  current
117                 process id.
118
119       errprint  prints its argument on the diagnostic output file.
120
121       dumpdef   prints current names and definitions, for the named items, or
122                 for all if no arguments are given.
123

SEE ALSO

125       B. W. Kernighan and D. M. Ritchie, The M4 Macro Processor
126
127
128
129                                                                         M4(1)
Impressum