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

NAME

6       m4 - macro processor
7

SYNOPSIS

9       m4 [ -Dname[=value]] [-Uname] [files ...]
10

DESCRIPTION

12       m4 is a macro processor intended as a front end for any language (e.g.,
13       C, ratfor, fortran, lex, and yacc).  m4 reads from the  standard  input
14       and  writes  the  processed  text  to the standard output.  Each of the
15       optional argument files is processed in order.
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       -Dname[=value]
39                 Define the symbol name to have some value (or NULL).
40
41       -Uname    Undefine the symbol name.
42
43       m4  makes  available  the following built-in macros.  They may be rede‐
44       fined, but once this is done the original meaning is lost.  Their  val‐
45       ues are null unless otherwise stated.
46
47       define    The  second  argument  is installed as the value of the macro
48                 whose name is the first argument.  Each occurrence of  $n  in
49                 the  replacement text, where n is a digit, is replaced by the
50                 n-th argument.  Argument 0 is the name of the macro;  missing
51                 arguments are replaced by the null string.
52
53       undefine  removes the definition of the macro named in its argument.
54
55       ifdef     If  the  first  argument  is defined, the value is the second
56                 argument, otherwise the third.  If there is  no  third  argu‐
57                 ment, the value is null.
58
59       changecom Change  the  start and end comment sequences.  The default is
60                 the pound sign '#' and the newline character.  With no  argu‐
61                 ments comments are turned off.  The maximum legnth for a com‐
62                 ment marker is five characters.
63
64       changequote
65                 Change quote characters to the first  and  second  arguments.
66                 Changequote  without  arguments  restores the original values
67                 (i.e., `´).
68
69       decr      Decrements the argument by 1.  The argument must be  a  valid
70                 numeric string.
71
72       divert    m4 maintains 10 output streams, numbered 0-9.  The final out‐
73                 put is the concatenation of the streams in  numerical  order;
74                 initially  stream  0 is the current stream.  The divert macro
75                 changes the current output stream to its (digit-string) argu‐
76                 ment.   Output diverted to a stream other than 0 through 9 is
77                 discarded.
78
79       undivert  causes immediate output of  text  from  diversions  named  as
80                 arguments,  or  all  diversions  if no argument.  Text may be
81                 undiverted into another diversion.  Undiverting discards  the
82                 diverted text.
83
84       defn      Returns the quoted definition for each argument.  This can be
85                 used to rename macro definitions (even for builtin macros).
86
87       divnum    returns the value of the current output stream.
88
89       dnl       reads and discards characters up to and  including  the  next
90                 newline.
91
92       expr      This is an alias for eval.
93
94       ifelse    has  three  or  more arguments.  If the first argument is the
95                 same string as the second, then the value is the third  argu‐
96                 ment.  If not, and if there are more than four arguments, the
97                 process is repeated with arguments 4, 5, 6 and 7.  Otherwise,
98                 the  value  is  either  the  fourth  string, or, if it is not
99                 present, null.
100
101       incr      returns the value of its  argument  incremented  by  1.   The
102                 value  of  the argument is calculated by interpreting an ini‐
103                 tial digit-string as a decimal number.
104
105       eval      evaluates its argument as  an  arithmetic  expression,  using
106                 32-bit arithmetic.  Operators include +, -, ∗, /, %, ^ (expo‐
107                 nentiation); relationals; parentheses.
108
109       len       returns the number of characters in its argument.
110
111       m4exit    Immediately exits with the  return  value  specified  by  the
112                 first argument, 0 if none.
113
114       m4wrap    Allows  you  to define what happens at the final EOF, usually
115                 for  cleanup  purposes.   (e.g.,  m4wrap("cleanup(tempfile)")
116                 causes  the  macro cleanup to be invoked after all processing
117                 is done.)
118
119       index     returns the position in its first argument where  the  second
120                 argument  begins  (zero origin), or -1 if the second argument
121                 does not occur.
122
123       substr    returns a substring of its first argument.  The second  argu‐
124                 ment  is  a zero origin number selecting the first character;
125                 the third argument indicates the length of the substring.   A
126                 missing  third argument is taken to be large enough to extend
127                 to the end of the first string.
128
129       translit  transliterates the characters in its first argument from  the
130                 set  given  by  the  second  argument to the set given by the
131                 third.  No abbreviations are permitted.
132
133       include   returns the contents of the file named in the argument.
134
135       sinclude  is identical to include, except that it says nothing  if  the
136                 file is inaccessible.
137
138       syscmd    executes  the  UNIX  command given in the first argument.  No
139                 value is returned.
140
141       maketemp  fills in a string of XXXXX in its argument with  the  current
142                 process id.
143
144       paste     Includes  the  contents  of  the  file specified by the first
145                 argument without any macro processing.  Aborts with an  error
146                 message if the file cannot be included.
147
148       popdef    Restores the pushdef'd definition for each argument.
149
150       pushdef   Takes  the same arguments as define, but it saves the defini‐
151                 tion on a stack for later retrieval by popdef.
152
153       shift     Returns all but the first argument, the  remaining  arguments
154                 are quoted and pushed back with commas in between.  The quot‐
155                 ing nullifies the effect of the extra scan that  will  subse‐
156                 quently be performed.
157
158       spaste    Similar to paste, except it ignores any errors.
159
160       syscal    Returns the return value from the last syscmd.
161
162       errprint  prints its argument on the diagnostic output file.
163
164       dumpdef   prints current names and definitions, for the named items, or
165                 for all if no arguments are given.
166
167       unix      A pre-defined macro for testing the OS platform.
168

SEE ALSO

170       B. W. Kernighan and D. M. Ritchie, The m4 Macro Processor
171

HISTORY

173       An m4 command appeared in Version 6 AT&T UNIX.
174

AUTHOR

176       Ozan Yigit <oz@sis.yorku.ca>
177
178
179
1803rd Berkeley Distribution       April 14, 1994                           m4(1)
Impressum