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