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