[BACK]Return to m4.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / m4

Annotation of src/usr.bin/m4/m4.1, Revision 1.18

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