Annotation of src/usr.bin/m4/m4.1, Revision 1.15
1.15 ! aaron 1: .\" @(#) $OpenBSD: m4.1,v 1.14 2000/03/23 21:39:54 aaron Exp $
1.1 deraadt 2: .\"
3: .\"
4: .Dd January 26, 1993
1.5 aaron 5: .Dt M4 1
1.1 deraadt 6: .Os
7: .Sh NAME
8: .Nm m4
9: .Nd macro language processor
10: .Sh SYNOPSIS
11: .Nm m4
1.12 espie 12: .Op Fl g
1.1 deraadt 13: .Oo
14: .Fl D Ns Ar name Ns Op Ar =value
15: .Oc
16: .Op Fl U Ns Ar name
1.7 espie 17: .Op Fl I Ar dirname
1.1 deraadt 18: .Sh DESCRIPTION
19: The
20: .Nm m4
21: utility is a macro processor that can be used as a front end to any
22: language (e.g., C, ratfor, fortran, lex, and yacc).
23: .Nm m4
24: reads from the standard input and writes
25: the processed text to the standard output.
26: .Pp
1.8 espie 27: Macro calls have the form name(argument1[, argument2, ..., argumentN]).
1.1 deraadt 28: .Pp
29: There cannot be any space following the macro name and the open
1.10 aaron 30: parenthesis
31: .Pq Ql ( .
32: If the macro name is not followed by an open
1.5 aaron 33: parenthesis it is processed with no arguments.
1.1 deraadt 34: .Pp
35: Macro names consist of a leading alphabetic or underscore
1.9 espie 36: possibly followed by alphanumeric or underscore characters, e.g.,
1.10 aaron 37: valid macro names match the pattern
38: .Dq [a-zA-Z_][a-zA-Z0-9_]* .
1.1 deraadt 39: .Pp
1.10 aaron 40: In arguments to macros, leading unquoted space, tab, and newline
41: .Pq Ql \en
42: characters are ignored.
43: To quote strings, use left and right single
44: quotes (e.g.,
45: .Sq \ this is a string with a leading space ) .
46: You can change the quote characters with the
1.5 aaron 47: .Ic changequote
48: built-in macro.
1.9 espie 49: .Pp
1.12 espie 50: Most built-ins don't make any sense without arguments, and hence are not
1.9 espie 51: recognized as special when not followed by an open parenthesis.
1.1 deraadt 52: .Pp
53: The options are as follows:
54: .Bl -tag -width "-Dname[=value]xxx"
55: .It Fl D Ns Ar name Ns Oo
56: .Ar =value
57: .Oc
58: Define the symbol
59: .Ar name
1.10 aaron 60: to have some value (or
61: .Dv NULL ) .
1.1 deraadt 62: .It Fl "U" Ns Ar "name"
63: Undefine the symbol
64: .Ar name .
1.7 espie 65: .It Fl I Ar "dirname"
1.15 ! aaron 66: Add directory
1.7 espie 67: .Ar dirname
68: to the include path.
1.12 espie 69: .It Fl g
1.13 aaron 70: Activate GNU-m4 compatibility mode.
1.15 ! aaron 71: In this mode, changequote with
1.12 espie 72: two empty parameters deactivates quotes, translit handles simple character
73: ranges (e.g., a-z) and regular expressions mimic emacs behavior.
1.1 deraadt 74: .Sh SYNTAX
75: .Nm m4
1.10 aaron 76: provides the following built-in macros.
77: They may be redefined, losing their original meaning.
78: Return values are null unless otherwise stated.
1.1 deraadt 79: .Bl -tag -width changequotexxx
1.11 espie 80: .It Ic builtin
81: Calls a built-in by its name, overriding possible redefinitions.
1.5 aaron 82: .It Ic changecom
1.10 aaron 83: Change the start and end comment sequences.
84: The default is the pound sign
85: .Pq Ql #
86: and the newline character.
87: With no arguments comments are turned off.
88: The maximum length for a comment marker is five characters.
1.5 aaron 89: .It Ic changequote
1.1 deraadt 90: Defines the quote symbols to be the first and second arguments.
1.10 aaron 91: The symbols may be up to five characters long.
92: If no arguments are
1.1 deraadt 93: given it restores the default open and close single quotes.
1.5 aaron 94: .It Ic decr
1.10 aaron 95: Decrements the argument by 1.
96: The argument must be a valid numeric string.
1.5 aaron 97: .It Ic define
1.1 deraadt 98: Define a new macro named by the first argument to have the
1.10 aaron 99: value of the second argument.
100: Each occurrence of
101: .Ql $n
102: (where
103: .Ar n
104: is 0 through 9) is replaced by the
105: .Ar n Ns 'th
106: argument.
107: .Ql $0
108: is the name of the calling macro.
109: Undefined arguments are replaced by a null string.
110: .Ql $#
111: is replaced by the number of arguments;
112: .Ql $*
113: is replaced by all arguments comma separated;
114: .Ql $@
115: is the same as
116: .Ql $*
117: but all arguments are quoted against further expansion.
1.5 aaron 118: .It Ic defn
1.10 aaron 119: Returns the quoted definition for each argument.
120: This can be used to rename
1.1 deraadt 121: macro definitions (even for built-in macros).
1.5 aaron 122: .It Ic divert
1.1 deraadt 123: There are 10 output queues (numbered 0-9).
124: At the end of processing
125: .Nm m4
126: concatenates all the queues in numerical order to produce the
1.10 aaron 127: final output.
128: Initially the output queue is 0.
129: The divert
1.1 deraadt 130: macro allows you to select a new output queue (an invalid argument
131: passed to divert causes output to be discarded).
1.5 aaron 132: .It Ic divnum
1.1 deraadt 133: Returns the current output queue number.
1.5 aaron 134: .It Ic dnl
1.1 deraadt 135: Discard input characters up to and including the next newline.
1.5 aaron 136: .It Ic dumpdef
1.1 deraadt 137: Prints the names and definitions for the named items, or for everything
138: if no arguments are passed.
1.5 aaron 139: .It Ic errprint
1.1 deraadt 140: Prints the first argument on the standard error output stream.
1.5 aaron 141: .It Ic eval
1.1 deraadt 142: Computes the first argument as an arithmetic expression using 32-bit
1.10 aaron 143: arithmetic.
144: Operators are the standard C ternary, arithmetic, logical,
145: shift, relational, bitwise, and parentheses operators.
146: You can specify
147: octal, decimal, and hexadecimal numbers as in C.
148: The second argument (if any)
149: specifies the radix for the result and the third argument (if any)
150: specifies the minimum number of digits in the result.
1.5 aaron 151: .It Ic expr
152: This is an alias for
153: .Ic eval .
154: .It Ic ifdef
1.1 deraadt 155: If the macro named by the first argument is defined then return the second
1.10 aaron 156: argument, otherwise the third.
157: If there is no third argument, the value is
158: .Dv NULL .
159: The word
160: .Qq unix
161: is predefined.
1.5 aaron 162: .It Ic ifelse
163: If the first argument matches the second argument then
164: .Ic ifelse
165: returns
1.10 aaron 166: the third argument.
167: If the match fails the three arguments are
1.1 deraadt 168: discarded and the next three arguments are used until there is
1.10 aaron 169: zero or one arguments left, either this last argument or
170: .Dv NULL
171: is returned if no other matches were found.
1.5 aaron 172: .It Ic include
1.1 deraadt 173: Returns the contents of the file specified in the first argument.
1.7 espie 174: If the file is not found as is, look through the include path:
175: first the directories specified with
176: .Fl I
177: on the command line, then the environment variable
1.10 aaron 178: .Ev M4PATH ,
1.7 espie 179: as a colon-separated list of directories.
1.1 deraadt 180: Include aborts with an error message if the file cannot be included.
1.5 aaron 181: .It Ic incr
1.10 aaron 182: Increments the argument by 1.
183: The argument must be a valid numeric string.
1.5 aaron 184: .It Ic index
1.1 deraadt 185: Returns the index of the second argument in the first argument (e.g.,
1.10 aaron 186: .Ic index(the quick brown fox jumped, fox)
187: returns 16).
188: If the second
189: argument is not found index returns \-1.
1.11 espie 190: .It Ic indir
191: Indirectly calls the macro whose name is passed as the first arguments,
192: with the remaining arguments passed as first, ... arguments.
1.5 aaron 193: .It Ic len
1.10 aaron 194: Returns the number of characters in the first argument.
195: Extra arguments
1.1 deraadt 196: are ignored.
1.5 aaron 197: .It Ic m4exit
1.1 deraadt 198: Immediately exits with the return value specified by the first argument,
199: 0 if none.
1.5 aaron 200: .It Ic m4wrap
1.10 aaron 201: Allows you to define what happens at the final
202: .Dv EOF ,
203: usually for cleanup purposes (e.g.,
204: .Ic m4wrap("cleanup(tempfile)")
205: causes the macro cleanup to be
1.1 deraadt 206: invoked after all other processing is done.)
1.5 aaron 207: .It Ic maketemp
1.10 aaron 208: Translates the string
1.15 ! aaron 209: .Dq XXXXX
1.10 aaron 210: in the first argument with the current process
211: ID leaving other characters alone.
212: This can be used to create unique
1.1 deraadt 213: temporary file names.
1.5 aaron 214: .It Ic paste
1.1 deraadt 215: Includes the contents of the file specified by the first argument without
1.10 aaron 216: any macro processing.
217: Aborts with an error message if the file cannot be
1.1 deraadt 218: included.
1.11 espie 219: .It Ic patsubst
220: Substitutes a regular expression in a string with a replacement string.
221: Usual substitution patterns apply: an ampersand
1.15 ! aaron 222: .Pq Ql &
1.11 espie 223: is replaced by the string matching the regular expression.
224: The string
225: .Ql \e# ,
226: where
227: .Ql #
228: is a digit, is replaced by the corresponding back-reference.
1.5 aaron 229: .It Ic popdef
230: Restores the
231: .Ic pushdef Ns ed
232: definition for each argument.
233: .It Ic pushdef
234: Takes the same arguments as
235: .Ic define ,
236: but it saves the definition on a
237: stack for later retrieval by
238: .Ic popdef .
1.11 espie 239: .It Ic regexp
1.13 aaron 240: Finds a regular expression in a string.
241: If no further arguments are given,
1.14 aaron 242: it returns the first match position or \-1 if no match.
243: If a third argument
1.11 espie 244: is provided, it returns the replacement string, with sub-patterns replaced.
1.5 aaron 245: .It Ic shift
1.1 deraadt 246: Returns all but the first argument, the remaining arguments are
1.10 aaron 247: quoted and pushed back with commas in between.
248: The quoting
1.1 deraadt 249: nullifies the effect of the extra scan that will subsequently be
250: performed.
1.5 aaron 251: .It Ic sinclude
252: Similar to
253: .Ic include ,
254: except it ignores any errors.
255: .It Ic spaste
256: Similar to
257: .Ic paste ,
258: except it ignores any errors.
259: .It Ic substr
1.1 deraadt 260: Returns a substring of the first argument starting at the offset specified
261: by the second argument and the length specified by the third argument.
262: If no third argument is present it returns the rest of the string.
1.5 aaron 263: .It Ic syscmd
1.10 aaron 264: Passes the first argument to the shell.
265: Nothing is returned.
1.5 aaron 266: .It Ic sysval
267: Returns the return value from the last
268: .Ic syscmd .
269: .It Ic translit
1.1 deraadt 270: Transliterate the characters in the first argument from the set
1.10 aaron 271: given by the second argument to the set given by the third.
272: You cannot
1.1 deraadt 273: use
274: .Xr tr 1
275: style abbreviations.
1.5 aaron 276: .It Ic undefine
1.1 deraadt 277: Removes the definition for the macro specified by the first argument.
1.5 aaron 278: .It Ic undivert
1.1 deraadt 279: Flushes the named output queues (or all queues if no arguments).
1.5 aaron 280: .It Ic unix
1.1 deraadt 281: A pre-defined macro for testing the OS platform.
1.11 espie 282: .It Ic __line__
283: Returns the current file's line number.
284: .It Ic __file__
285: Returns the current file's name.
1.1 deraadt 286: .El
287: .Sh AUTHOR
1.11 espie 288: Ozan Yigit <oz@sis.yorku.ca> and Richard A. O'Keefe (ok@goanna.cs.rmit.OZ.AU).
289: GNU-m4 compatibility extensions by Marc Espie <espie@cvs.openbsd.org>.