18ce3644cSJung-uk Kim.\" $NetBSD: m4.1,v 1.23 2012/04/08 22:00:39 wiz Exp $ 2a841e1ebSBaptiste Daroussin.\" 3a841e1ebSBaptiste Daroussin.\" Copyright (c) 1989, 1993 4a841e1ebSBaptiste Daroussin.\" The Regents of the University of California. All rights reserved. 5a841e1ebSBaptiste Daroussin.\" 6a841e1ebSBaptiste Daroussin.\" This code is derived from software contributed to Berkeley by 7a841e1ebSBaptiste Daroussin.\" Ozan Yigit at York University. 8a841e1ebSBaptiste Daroussin.\" 9a841e1ebSBaptiste Daroussin.\" Redistribution and use in source and binary forms, with or without 10a841e1ebSBaptiste Daroussin.\" modification, are permitted provided that the following conditions 11a841e1ebSBaptiste Daroussin.\" are met: 12a841e1ebSBaptiste Daroussin.\" 1. Redistributions of source code must retain the above copyright 13a841e1ebSBaptiste Daroussin.\" notice, this list of conditions and the following disclaimer. 14a841e1ebSBaptiste Daroussin.\" 2. Redistributions in binary form must reproduce the above copyright 15a841e1ebSBaptiste Daroussin.\" notice, this list of conditions and the following disclaimer in the 16a841e1ebSBaptiste Daroussin.\" documentation and/or other materials provided with the distribution. 17a841e1ebSBaptiste Daroussin.\" 3. Neither the name of the University nor the names of its contributors 18a841e1ebSBaptiste Daroussin.\" may be used to endorse or promote products derived from this software 19a841e1ebSBaptiste Daroussin.\" without specific prior written permission. 20a841e1ebSBaptiste Daroussin.\" 21a841e1ebSBaptiste Daroussin.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22a841e1ebSBaptiste Daroussin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23a841e1ebSBaptiste Daroussin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24a841e1ebSBaptiste Daroussin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25a841e1ebSBaptiste Daroussin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26a841e1ebSBaptiste Daroussin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27a841e1ebSBaptiste Daroussin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28a841e1ebSBaptiste Daroussin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29a841e1ebSBaptiste Daroussin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30a841e1ebSBaptiste Daroussin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31a841e1ebSBaptiste Daroussin.\" SUCH DAMAGE. 32a841e1ebSBaptiste Daroussin.\" 3347b32f8fSDag-Erling Smørgrav.Dd June 21, 2023 34a4cab7d3SMike Pritchard.Dt M4 1 3597ad9755SJordan K. Hubbard.Os 3697ad9755SJordan K. Hubbard.Sh NAME 3797ad9755SJordan K. Hubbard.Nm m4 3897ad9755SJordan K. Hubbard.Nd macro language processor 3997ad9755SJordan K. Hubbard.Sh SYNOPSIS 408ce3644cSJung-uk Kim.Nm 416c9ed64cSDag-Erling Smørgrav.Op Fl EGgPs 42a841e1ebSBaptiste Daroussin.Oo 43a841e1ebSBaptiste Daroussin.Sm off 44a841e1ebSBaptiste Daroussin.Fl D Ar name Op No = Ar value 45a841e1ebSBaptiste Daroussin.Sm on 46a841e1ebSBaptiste Daroussin.Oc 4747b32f8fSDag-Erling Smørgrav.Op Fl d Oo Oo +- Oc Ns Ar flags Oc 4829fc00b3SJuli Mallett.Op Fl I Ar dirname 49a841e1ebSBaptiste Daroussin.Op Fl o Ar filename 50a841e1ebSBaptiste Daroussin.Op Fl t Ar macro 51a841e1ebSBaptiste Daroussin.Op Fl U Ns Ar name 5239a82b8cSRuslan Ermilov.Op Ar 5397ad9755SJordan K. Hubbard.Sh DESCRIPTION 5497ad9755SJordan K. HubbardThe 558ce3644cSJung-uk Kim.Nm 5697ad9755SJordan K. Hubbardutility is a macro processor that can be used as a front end to any 5797ad9755SJordan K. Hubbardlanguage (e.g., C, ratfor, fortran, lex, and yacc). 58a841e1ebSBaptiste DaroussinIf no input files are given, 598ce3644cSJung-uk Kim.Nm 60a841e1ebSBaptiste Daroussinreads from the standard input, 61a841e1ebSBaptiste Daroussinotherwise files specified on the command line are 62a841e1ebSBaptiste Daroussinprocessed in the given order. 63a841e1ebSBaptiste DaroussinInput files can be regular files, files in the m4 include paths, or a 64a841e1ebSBaptiste Daroussinsingle dash 65a841e1ebSBaptiste Daroussin.Pq Sq - , 66a841e1ebSBaptiste Daroussindenoting standard input. 678ce3644cSJung-uk Kim.Nm 68a841e1ebSBaptiste Daroussinwrites 69a841e1ebSBaptiste Daroussinthe processed text to the standard output, unless told otherwise. 7097ad9755SJordan K. Hubbard.Pp 71a841e1ebSBaptiste DaroussinMacro calls have the form name(argument1[, argument2, ..., argumentN]). 7297ad9755SJordan K. Hubbard.Pp 7397ad9755SJordan K. HubbardThere cannot be any space following the macro name and the open 7429fc00b3SJuli Mallettparenthesis 758ce3644cSJung-uk Kim.Pq Sq \&( . 7629fc00b3SJuli MallettIf the macro name is not followed by an open 7729fc00b3SJuli Mallettparenthesis it is processed with no arguments. 7897ad9755SJordan K. Hubbard.Pp 7997ad9755SJordan K. HubbardMacro names consist of a leading alphabetic or underscore 8029fc00b3SJuli Mallettpossibly followed by alphanumeric or underscore characters, e.g., 8129fc00b3SJuli Mallettvalid macro names match the pattern 82a841e1ebSBaptiste Daroussin.Dq [a-zA-Z_][a-zA-Z0-9_]* . 8397ad9755SJordan K. Hubbard.Pp 8429fc00b3SJuli MallettIn arguments to macros, leading unquoted space, tab, and newline 85a841e1ebSBaptiste Daroussin.Pq Sq \en 8629fc00b3SJuli Mallettcharacters are ignored. 87a841e1ebSBaptiste DaroussinTo quote strings, use left and right single quotes 8888497f0cSBaptiste Daroussin.Pq e.g., Sq \ \&this is a string with a leading space . 8929fc00b3SJuli MallettYou can change the quote characters with the 9029fc00b3SJuli Mallett.Ic changequote 9129fc00b3SJuli Mallettbuilt-in macro. 9229fc00b3SJuli Mallett.Pp 93aee53c33SJoel DahlMost built-ins do not make any sense without arguments, and hence are not 9429fc00b3SJuli Mallettrecognized as special when not followed by an open parenthesis. 9597ad9755SJordan K. Hubbard.Pp 9697ad9755SJordan K. HubbardThe options are as follows: 97a841e1ebSBaptiste Daroussin.Bl -tag -width Ds 9847b32f8fSDag-Erling Smørgrav.It Fl D Ns Ar name Ns Oo = Ns Ar value Oc , Fl -define Ns = Ns Ar name Ns Oo = Ns Ar value Oc 9997ad9755SJordan K. HubbardDefine the symbol 10097ad9755SJordan K. Hubbard.Ar name 10129fc00b3SJuli Mallettto have some value (or 10229fc00b3SJuli Mallett.Dv NULL ) . 10347b32f8fSDag-Erling Smørgrav.It Fl d Oo Oo +|- Oc Ns Ar flags Oc , Fl -debug Ns = Ns Oo Oo +|- Oc Ns Ar flags Oc 10447b32f8fSDag-Erling SmørgravSet or unset trace flags. 10547b32f8fSDag-Erling SmørgravThe trace flags are as follows: 106a841e1ebSBaptiste Daroussin.Bl -tag -width Ds 107a841e1ebSBaptiste Daroussin.It Ar a 108a841e1ebSBaptiste Daroussinprint macro arguments. 109a841e1ebSBaptiste Daroussin.It Ar c 110a841e1ebSBaptiste Daroussinprint macro expansion over several lines. 111a841e1ebSBaptiste Daroussin.It Ar e 112a841e1ebSBaptiste Daroussinprint result of macro expansion. 113a841e1ebSBaptiste Daroussin.It Ar f 114a841e1ebSBaptiste Daroussinprint filename location. 115a841e1ebSBaptiste Daroussin.It Ar l 116a841e1ebSBaptiste Daroussinprint line number. 117a841e1ebSBaptiste Daroussin.It Ar q 118a841e1ebSBaptiste Daroussinquote arguments and expansion with the current quotes. 119a841e1ebSBaptiste Daroussin.It Ar t 120a841e1ebSBaptiste Daroussinstart with all macros traced. 121a841e1ebSBaptiste Daroussin.It Ar x 122a841e1ebSBaptiste Daroussinnumber macro expansions. 123a841e1ebSBaptiste Daroussin.It Ar V 124a841e1ebSBaptiste Daroussinturn on all options. 12529fc00b3SJuli Mallett.El 12629fc00b3SJuli Mallett.Pp 12747b32f8fSDag-Erling SmørgravIf 12847b32f8fSDag-Erling Smørgrav.Qq + 12947b32f8fSDag-Erling Smørgravor 13047b32f8fSDag-Erling Smørgrav.Qq - 13147b32f8fSDag-Erling Smørgravis used, the specified flags are added to or removed from the set of 13247b32f8fSDag-Erling Smørgravactive trace flags, respectively; otherwise, the specified flags 13347b32f8fSDag-Erling Smørgravreplace the set of active trace flags. 13447b32f8fSDag-Erling Smørgrav.Pp 13547b32f8fSDag-Erling SmørgravSpecifying this option without an argument is equivalent to specifying 13647b32f8fSDag-Erling Smørgravit with the argument 13747b32f8fSDag-Erling Smørgrav.Qq aeq . 13847b32f8fSDag-Erling Smørgrav.Pp 13929fc00b3SJuli MallettBy default, trace is set to 140a841e1ebSBaptiste Daroussin.Qq eq . 14147b32f8fSDag-Erling Smørgrav.It Fl E , Fl -fatal-warnings 142c560b67cSBaptiste DaroussinSet warnings to be fatal. 143c560b67cSBaptiste DaroussinWhen a single 144c560b67cSBaptiste Daroussin.Fl E 145c560b67cSBaptiste Daroussinflag is specified, if warnings are issued, execution 146c560b67cSBaptiste Daroussincontinues but 147c560b67cSBaptiste Daroussin.Nm 148c560b67cSBaptiste Daroussinwill exit with a non-zero exit status. 149c560b67cSBaptiste DaroussinWhen multiple 150c560b67cSBaptiste Daroussin.Fl E 151c560b67cSBaptiste Daroussinflags are specified, execution will halt upon issuing the 152c560b67cSBaptiste Daroussinfirst warning and 153c560b67cSBaptiste Daroussin.Nm 154c560b67cSBaptiste Daroussinwill exit with a non-zero exit status. 155*764464afSBenedict ReuschlingThis behavior matches GNU m4 1.4.9 and later. 1566c9ed64cSDag-Erling Smørgrav.It Fl G , Fl -traditional 1576c9ed64cSDag-Erling SmørgravDisable GNU compatibility mode (see 1586c9ed64cSDag-Erling Smørgrav.Fl g 1596c9ed64cSDag-Erling Smørgravbelow). 16047b32f8fSDag-Erling Smørgrav.It Fl g , Fl -gnu 1616c9ed64cSDag-Erling SmørgravEnable GNU compatibility mode. 162db4c5b8aSDag-Erling SmørgravIn this mode, 163db4c5b8aSDag-Erling Smørgrav.Ic translit 164db4c5b8aSDag-Erling Smørgravhandles simple character ranges (e.g., 165db4c5b8aSDag-Erling Smørgrav.Sq a-z ) , 166db4c5b8aSDag-Erling Smørgravregular expressions mimic Emacs behavior, 167db4c5b8aSDag-Erling Smørgravmultiple 168db4c5b8aSDag-Erling Smørgrav.Ic m4wrap 169db4c5b8aSDag-Erling Smørgravcalls are handled as a stack, 170a841e1ebSBaptiste Daroussinthe number of diversions is unlimited, 171a841e1ebSBaptiste Daroussinempty names for macro definitions are allowed, 172db4c5b8aSDag-Erling Smørgrav.Ic undivert 173db4c5b8aSDag-Erling Smørgravcan be used to include files, 174db4c5b8aSDag-Erling Smørgravand 175db4c5b8aSDag-Erling Smørgrav.Ic eval 176db4c5b8aSDag-Erling Smørgravunderstands 177a841e1ebSBaptiste Daroussin.Sq 0rbase:value 178a841e1ebSBaptiste Daroussinnumbers. 17947b32f8fSDag-Erling Smørgrav.It Fl I Ar dirname , Fl -include Ns = Ns Ar dirname 180a841e1ebSBaptiste DaroussinAdd directory 181a841e1ebSBaptiste Daroussin.Ar dirname 182a841e1ebSBaptiste Daroussinto the include path. 18347b32f8fSDag-Erling Smørgrav.It Fl o Ar filename , Fl -error-output Ns = Ns Ar filename 184a841e1ebSBaptiste DaroussinSend trace output to 185a841e1ebSBaptiste Daroussin.Ar filename . 18647b32f8fSDag-Erling Smørgrav.It Fl P , Fl -prefix-builtins 187a841e1ebSBaptiste DaroussinPrefix all built-in macros with 188a841e1ebSBaptiste Daroussin.Sq m4_ . 189a841e1ebSBaptiste DaroussinFor example, instead of writing 190a841e1ebSBaptiste Daroussin.Ic define , 191a841e1ebSBaptiste Daroussinuse 192a841e1ebSBaptiste Daroussin.Ic m4_define . 19347b32f8fSDag-Erling Smørgrav.It Fl s , Fl -synclines 194a841e1ebSBaptiste DaroussinOutput line synchronization directives, suitable for 195a841e1ebSBaptiste Daroussin.Xr cpp 1 . 19647b32f8fSDag-Erling Smørgrav.It Fl t Ar macro , Fl -trace Ns = Ns Ar macro 19729fc00b3SJuli MallettTurn tracing on for 19829fc00b3SJuli Mallett.Ar macro . 19947b32f8fSDag-Erling Smørgrav.It Fl U Ns Ar name , Fl -undefine Ns = Ns Ar name 200a841e1ebSBaptiste DaroussinUndefine the symbol 201a841e1ebSBaptiste Daroussin.Ar name . 20297ad9755SJordan K. Hubbard.El 20397ad9755SJordan K. Hubbard.Sh SYNTAX 2048ce3644cSJung-uk Kim.Nm 205a841e1ebSBaptiste Daroussinprovides the following built-in macros. 20629fc00b3SJuli MallettThey may be redefined, losing their original meaning. 20729fc00b3SJuli MallettReturn values are null unless otherwise stated. 208a841e1ebSBaptiste Daroussin.Bl -tag -width changequote 209a841e1ebSBaptiste Daroussin.It Fn builtin name 210a841e1ebSBaptiste DaroussinCalls a built-in by its 211a841e1ebSBaptiste Daroussin.Fa name , 212a841e1ebSBaptiste Daroussinoverriding possible redefinitions. 213a841e1ebSBaptiste Daroussin.It Fn changecom startcomment endcomment 214a841e1ebSBaptiste DaroussinChanges the start comment and end comment sequences. 215a841e1ebSBaptiste DaroussinComment sequences may be up to five characters long. 216a841e1ebSBaptiste DaroussinThe default values are the hash sign 21729fc00b3SJuli Mallettand the newline character. 218a841e1ebSBaptiste Daroussin.Bd -literal -offset indent 219a841e1ebSBaptiste Daroussin# This is a comment 220a841e1ebSBaptiste Daroussin.Ed 221a841e1ebSBaptiste Daroussin.Pp 222a841e1ebSBaptiste DaroussinWith no arguments, comments are turned off. 223a841e1ebSBaptiste DaroussinWith one single argument, the end comment sequence is set 224a841e1ebSBaptiste Daroussinto the newline character. 225a841e1ebSBaptiste Daroussin.It Fn changequote beginquote endquote 226a841e1ebSBaptiste DaroussinDefines the open quote and close quote sequences. 227a841e1ebSBaptiste DaroussinQuote sequences may be up to five characters long. 228a841e1ebSBaptiste DaroussinThe default values are the backquote character and the quote 229a841e1ebSBaptiste Daroussincharacter. 230a841e1ebSBaptiste Daroussin.Bd -literal -offset indent 231a841e1ebSBaptiste Daroussin`Here is a quoted string' 232a841e1ebSBaptiste Daroussin.Ed 233a841e1ebSBaptiste Daroussin.Pp 234a841e1ebSBaptiste DaroussinWith no arguments, the default quotes are restored. 235a841e1ebSBaptiste DaroussinWith one single argument, the close quote sequence is set 236a841e1ebSBaptiste Daroussinto the newline character. 237a841e1ebSBaptiste Daroussin.It Fn decr arg 238a841e1ebSBaptiste DaroussinDecrements the argument 239a841e1ebSBaptiste Daroussin.Fa arg 240a841e1ebSBaptiste Daroussinby 1. 241a841e1ebSBaptiste DaroussinThe argument 242a841e1ebSBaptiste Daroussin.Fa arg 243a841e1ebSBaptiste Daroussinmust be a valid numeric string. 244a841e1ebSBaptiste Daroussin.It Fn define name value 245a841e1ebSBaptiste DaroussinDefine a new macro named by the first argument 246a841e1ebSBaptiste Daroussin.Fa name 247a841e1ebSBaptiste Daroussinto have the 248a841e1ebSBaptiste Daroussinvalue of the second argument 249a841e1ebSBaptiste Daroussin.Fa value . 25029fc00b3SJuli MallettEach occurrence of 251a841e1ebSBaptiste Daroussin.Sq $n 25229fc00b3SJuli Mallett(where 25329fc00b3SJuli Mallett.Ar n 25429fc00b3SJuli Mallettis 0 through 9) is replaced by the 25529fc00b3SJuli Mallett.Ar n Ns 'th 25629fc00b3SJuli Mallettargument. 257a841e1ebSBaptiste Daroussin.Sq $0 25829fc00b3SJuli Mallettis the name of the calling macro. 25929fc00b3SJuli MallettUndefined arguments are replaced by a null string. 260a841e1ebSBaptiste Daroussin.Sq $# 26129fc00b3SJuli Mallettis replaced by the number of arguments; 262a841e1ebSBaptiste Daroussin.Sq $* 26329fc00b3SJuli Mallettis replaced by all arguments comma separated; 264a841e1ebSBaptiste Daroussin.Sq $@ 26529fc00b3SJuli Mallettis the same as 266a841e1ebSBaptiste Daroussin.Sq $* 26729fc00b3SJuli Mallettbut all arguments are quoted against further expansion. 268a841e1ebSBaptiste Daroussin.It Fn defn name ... 26929fc00b3SJuli MallettReturns the quoted definition for each argument. 27029fc00b3SJuli MallettThis can be used to rename 27197ad9755SJordan K. Hubbardmacro definitions (even for built-in macros). 272a841e1ebSBaptiste Daroussin.It Fn divert num 27397ad9755SJordan K. HubbardThere are 10 output queues (numbered 0-9). 27497ad9755SJordan K. HubbardAt the end of processing 2758ce3644cSJung-uk Kim.Nm 27697ad9755SJordan K. Hubbardconcatenates all the queues in numerical order to produce the 27729fc00b3SJuli Mallettfinal output. 27829fc00b3SJuli MallettInitially the output queue is 0. 279a841e1ebSBaptiste DaroussinThe divert 28097ad9755SJordan K. Hubbardmacro allows you to select a new output queue (an invalid argument 281a841e1ebSBaptiste Daroussinpassed to divert causes output to be discarded). 28229fc00b3SJuli Mallett.It Ic divnum 28397ad9755SJordan K. HubbardReturns the current output queue number. 28429fc00b3SJuli Mallett.It Ic dnl 285a841e1ebSBaptiste DaroussinDiscard input characters up to and including the next newline. 286a841e1ebSBaptiste Daroussin.It Fn dumpdef name ... 28797ad9755SJordan K. HubbardPrints the names and definitions for the named items, or for everything 28897ad9755SJordan K. Hubbardif no arguments are passed. 289a841e1ebSBaptiste Daroussin.It Fn errprint msg 29097ad9755SJordan K. HubbardPrints the first argument on the standard error output stream. 291a841e1ebSBaptiste Daroussin.It Fn esyscmd cmd 29239a82b8cSRuslan ErmilovPasses its first argument to a shell and returns the shell's standard output. 29329fc00b3SJuli MallettNote that the shell shares its standard input and standard error with 2948ce3644cSJung-uk Kim.Nm . 29588497f0cSBaptiste Daroussin.It Fn eval expr[,radix[,minimum]] 29697ad9755SJordan K. HubbardComputes the first argument as an arithmetic expression using 32-bit 29729fc00b3SJuli Mallettarithmetic. 29829fc00b3SJuli MallettOperators are the standard C ternary, arithmetic, logical, 29929fc00b3SJuli Mallettshift, relational, bitwise, and parentheses operators. 30029fc00b3SJuli MallettYou can specify 30129fc00b3SJuli Mallettoctal, decimal, and hexadecimal numbers as in C. 30288497f0cSBaptiste DaroussinThe optional second argument 30388497f0cSBaptiste Daroussin.Fa radix 30488497f0cSBaptiste Daroussinspecifies the radix for the result and the optional third argument 30588497f0cSBaptiste Daroussin.Fa minimum 30629fc00b3SJuli Mallettspecifies the minimum number of digits in the result. 307a841e1ebSBaptiste Daroussin.It Fn expr expr 30829fc00b3SJuli MallettThis is an alias for 30929fc00b3SJuli Mallett.Ic eval . 310a841e1ebSBaptiste Daroussin.It Fn format formatstring arg1 ... 311a841e1ebSBaptiste DaroussinReturns 312a841e1ebSBaptiste Daroussin.Fa formatstring 313a841e1ebSBaptiste Daroussinwith escape sequences substituted with 314a841e1ebSBaptiste Daroussin.Fa arg1 315a841e1ebSBaptiste Daroussinand following arguments, in a way similar to 316a841e1ebSBaptiste Daroussin.Xr printf 3 . 317a841e1ebSBaptiste DaroussinThis built-in is only available in GNU-m4 compatibility mode, and the only 318a841e1ebSBaptiste Daroussinparameters implemented are there for autoconf compatibility: 319a841e1ebSBaptiste Daroussinleft-padding flag, an optional field width, a maximum field width, 320a841e1ebSBaptiste Daroussin*-specified field widths, and the %s and %c data type. 321a841e1ebSBaptiste Daroussin.It Fn ifdef name yes no 32297ad9755SJordan K. HubbardIf the macro named by the first argument is defined then return the second 32329fc00b3SJuli Mallettargument, otherwise the third. 32429fc00b3SJuli MallettIf there is no third argument, the value is 32529fc00b3SJuli Mallett.Dv NULL . 32629fc00b3SJuli MallettThe word 327a841e1ebSBaptiste Daroussin.Qq unix 32829fc00b3SJuli Mallettis predefined. 329a841e1ebSBaptiste Daroussin.It Fn ifelse a b yes ... 330a841e1ebSBaptiste DaroussinIf the first argument 331a841e1ebSBaptiste Daroussin.Fa a 332a841e1ebSBaptiste Daroussinmatches the second argument 333a841e1ebSBaptiste Daroussin.Fa b 334a841e1ebSBaptiste Daroussinthen 335a841e1ebSBaptiste Daroussin.Fn ifelse 33629fc00b3SJuli Mallettreturns 337a841e1ebSBaptiste Daroussinthe third argument 338a841e1ebSBaptiste Daroussin.Fa yes . 339a841e1ebSBaptiste DaroussinIf the match fails the three arguments are 34097ad9755SJordan K. Hubbarddiscarded and the next three arguments are used until there is 34129fc00b3SJuli Mallettzero or one arguments left, either this last argument or 34229fc00b3SJuli Mallett.Dv NULL 34329fc00b3SJuli Mallettis returned if no other matches were found. 344a841e1ebSBaptiste Daroussin.It Fn include name 34597ad9755SJordan K. HubbardReturns the contents of the file specified in the first argument. 34629fc00b3SJuli MallettIf the file is not found as is, look through the include path: 34729fc00b3SJuli Mallettfirst the directories specified with 34829fc00b3SJuli Mallett.Fl I 34929fc00b3SJuli Malletton the command line, then the environment variable 35029fc00b3SJuli Mallett.Ev M4PATH , 35129fc00b3SJuli Mallettas a colon-separated list of directories. 352a841e1ebSBaptiste DaroussinInclude aborts with an error message if the file cannot be included. 353a841e1ebSBaptiste Daroussin.It Fn incr arg 35429fc00b3SJuli MallettIncrements the argument by 1. 35529fc00b3SJuli MallettThe argument must be a valid numeric string. 356a841e1ebSBaptiste Daroussin.It Fn index string substring 35797ad9755SJordan K. HubbardReturns the index of the second argument in the first argument (e.g., 358a841e1ebSBaptiste Daroussin.Ic index(the quick brown fox jumped, fox) 35929fc00b3SJuli Mallettreturns 16). 36029fc00b3SJuli MallettIf the second 361a841e1ebSBaptiste Daroussinargument is not found index returns \-1. 362a841e1ebSBaptiste Daroussin.It Fn indir macro arg1 ... 363a841e1ebSBaptiste DaroussinIndirectly calls the macro whose name is passed as the first argument, 364a841e1ebSBaptiste Daroussinwith the remaining arguments passed as first, ... arguments. 365a841e1ebSBaptiste Daroussin.It Fn len arg 36629fc00b3SJuli MallettReturns the number of characters in the first argument. 36729fc00b3SJuli MallettExtra arguments 36897ad9755SJordan K. Hubbardare ignored. 369a841e1ebSBaptiste Daroussin.It Fn m4exit code 37097ad9755SJordan K. HubbardImmediately exits with the return value specified by the first argument, 37197ad9755SJordan K. Hubbard0 if none. 372a841e1ebSBaptiste Daroussin.It Fn m4wrap todo 37329fc00b3SJuli MallettAllows you to define what happens at the final 37429fc00b3SJuli Mallett.Dv EOF , 37529fc00b3SJuli Mallettusually for cleanup purposes (e.g., 376a841e1ebSBaptiste Daroussin.Ic m4wrap("cleanup(tempfile)") 377a841e1ebSBaptiste Daroussincauses the macro cleanup to be 37829fc00b3SJuli Mallettinvoked after all other processing is done). 379a841e1ebSBaptiste Daroussin.Pp 380a841e1ebSBaptiste DaroussinMultiple calls to 381a841e1ebSBaptiste Daroussin.Fn m4wrap 382a841e1ebSBaptiste Daroussinget inserted in sequence at the final 383a841e1ebSBaptiste Daroussin.Dv EOF . 384a841e1ebSBaptiste Daroussin.It Fn maketemp template 3858ce3644cSJung-uk KimLike 3868ce3644cSJung-uk Kim.Ic mkstemp . 3878ce3644cSJung-uk Kim.It Fn mkstemp template 388a841e1ebSBaptiste DaroussinInvokes 389a841e1ebSBaptiste Daroussin.Xr mkstemp 3 390a841e1ebSBaptiste Daroussinon the first argument, and returns the modified string. 39129fc00b3SJuli MallettThis can be used to create unique 39297ad9755SJordan K. Hubbardtemporary file names. 393a841e1ebSBaptiste Daroussin.It Fn paste file 39497ad9755SJordan K. HubbardIncludes the contents of the file specified by the first argument without 39529fc00b3SJuli Mallettany macro processing. 39629fc00b3SJuli MallettAborts with an error message if the file cannot be 39797ad9755SJordan K. Hubbardincluded. 398a841e1ebSBaptiste Daroussin.It Fn patsubst string regexp replacement 39929fc00b3SJuli MallettSubstitutes a regular expression in a string with a replacement string. 40029fc00b3SJuli MallettUsual substitution patterns apply: an ampersand 401a841e1ebSBaptiste Daroussin.Pq Sq \&& 40229fc00b3SJuli Mallettis replaced by the string matching the regular expression. 40329fc00b3SJuli MallettThe string 404a841e1ebSBaptiste Daroussin.Sq \e# , 40529fc00b3SJuli Mallettwhere 406a841e1ebSBaptiste Daroussin.Sq # 40729fc00b3SJuli Mallettis a digit, is replaced by the corresponding back-reference. 408a841e1ebSBaptiste Daroussin.It Fn popdef arg ... 40929fc00b3SJuli MallettRestores the 41029fc00b3SJuli Mallett.Ic pushdef Ns ed 41129fc00b3SJuli Mallettdefinition for each argument. 412a841e1ebSBaptiste Daroussin.It Fn pushdef macro def 41329fc00b3SJuli MallettTakes the same arguments as 41429fc00b3SJuli Mallett.Ic define , 41529fc00b3SJuli Mallettbut it saves the definition on a 41629fc00b3SJuli Mallettstack for later retrieval by 417a841e1ebSBaptiste Daroussin.Fn popdef . 418a841e1ebSBaptiste Daroussin.It Fn regexp string regexp replacement 41929fc00b3SJuli MallettFinds a regular expression in a string. 42029fc00b3SJuli MallettIf no further arguments are given, 42129fc00b3SJuli Mallettit returns the first match position or \-1 if no match. 42229fc00b3SJuli MallettIf a third argument 42329fc00b3SJuli Mallettis provided, it returns the replacement string, with sub-patterns replaced. 424a841e1ebSBaptiste Daroussin.It Fn shift arg1 ... 42597ad9755SJordan K. HubbardReturns all but the first argument, the remaining arguments are 42629fc00b3SJuli Mallettquoted and pushed back with commas in between. 42729fc00b3SJuli MallettThe quoting 42897ad9755SJordan K. Hubbardnullifies the effect of the extra scan that will subsequently be 42997ad9755SJordan K. Hubbardperformed. 430a841e1ebSBaptiste Daroussin.It Fn sinclude file 43129fc00b3SJuli MallettSimilar to 43229fc00b3SJuli Mallett.Ic include , 43329fc00b3SJuli Mallettexcept it ignores any errors. 434a841e1ebSBaptiste Daroussin.It Fn spaste file 43529fc00b3SJuli MallettSimilar to 436a841e1ebSBaptiste Daroussin.Fn paste , 43729fc00b3SJuli Mallettexcept it ignores any errors. 438a841e1ebSBaptiste Daroussin.It Fn substr string offset length 43997ad9755SJordan K. HubbardReturns a substring of the first argument starting at the offset specified 44097ad9755SJordan K. Hubbardby the second argument and the length specified by the third argument. 44197ad9755SJordan K. HubbardIf no third argument is present it returns the rest of the string. 442a841e1ebSBaptiste Daroussin.It Fn syscmd cmd 44329fc00b3SJuli MallettPasses the first argument to the shell. 44429fc00b3SJuli MallettNothing is returned. 44529fc00b3SJuli Mallett.It Ic sysval 44629fc00b3SJuli MallettReturns the return value from the last 44729fc00b3SJuli Mallett.Ic syscmd . 448a841e1ebSBaptiste Daroussin.It Fn traceon arg ... 44929fc00b3SJuli MallettEnables tracing of macro expansions for the given arguments, or for all 45029fc00b3SJuli Mallettmacros if no argument is given. 451a841e1ebSBaptiste Daroussin.It Fn traceoff arg ... 45229fc00b3SJuli MallettDisables tracing of macro expansions for the given arguments, or for all 45329fc00b3SJuli Mallettmacros if no argument is given. 454a841e1ebSBaptiste Daroussin.It Fn translit string mapfrom mapto 45597ad9755SJordan K. HubbardTransliterate the characters in the first argument from the set 45629fc00b3SJuli Mallettgiven by the second argument to the set given by the third. 45729fc00b3SJuli MallettYou cannot use 45897ad9755SJordan K. Hubbard.Xr tr 1 45997ad9755SJordan K. Hubbardstyle abbreviations. 460a841e1ebSBaptiste Daroussin.It Fn undefine name1 ... 46129fc00b3SJuli MallettRemoves the definition for the macros specified by its arguments. 462a841e1ebSBaptiste Daroussin.It Fn undivert arg ... 46397ad9755SJordan K. HubbardFlushes the named output queues (or all queues if no arguments). 46429fc00b3SJuli Mallett.It Ic unix 46597ad9755SJordan K. HubbardA pre-defined macro for testing the OS platform. 46629fc00b3SJuli Mallett.It Ic __line__ 46729fc00b3SJuli MallettReturns the current file's line number. 46829fc00b3SJuli Mallett.It Ic __file__ 46929fc00b3SJuli MallettReturns the current file's name. 47097ad9755SJordan K. Hubbard.El 4718ce3644cSJung-uk Kim.Sh EXIT STATUS 4728ce3644cSJung-uk Kim.Ex -std m4 4738ce3644cSJung-uk Kim.Pp 4748ce3644cSJung-uk KimBut note that the 4758ce3644cSJung-uk Kim.Ic m4exit 476c560b67cSBaptiste Daroussinmacro can modify the exit status, as can the 477c560b67cSBaptiste Daroussin.Fl E 478c560b67cSBaptiste Daroussinflag. 47997fa288aSGordon Bergling.Sh SEE ALSO 48097fa288aSGordon Bergling.Rs 48197fa288aSGordon Bergling.\" 4.4BSD PSD:17 48297fa288aSGordon Bergling.%A B. W. Kernighan 48397fa288aSGordon Bergling.%A D. M. Ritchie 48497fa288aSGordon Bergling.%I AT&T Bell Laboratories 48597fa288aSGordon Bergling.%T The M4 Macro Processor 48697fa288aSGordon Bergling.%R Computing Science Technical Report 48797fa288aSGordon Bergling.%N 59 48897fa288aSGordon Bergling.%D July 1977 48997fa288aSGordon Bergling.Re 490a841e1ebSBaptiste Daroussin.Sh STANDARDS 491bfd62d70SPhilippe CharnierThe 492b1ea3d46SJuli Mallett.Nm 49388497f0cSBaptiste Daroussinutility is compliant with the 494a841e1ebSBaptiste Daroussin.St -p1003.1-2008 495a841e1ebSBaptiste Daroussinspecification. 49629fc00b3SJuli Mallett.Pp 497a841e1ebSBaptiste DaroussinThe flags 4986c9ed64cSDag-Erling Smørgrav.Op Fl dEGgIPot 499a841e1ebSBaptiste Daroussinand the macros 50029fc00b3SJuli Mallett.Ic builtin , 501af16b40bSJens Schweikhardt.Ic esyscmd , 50229fc00b3SJuli Mallett.Ic expr , 503a841e1ebSBaptiste Daroussin.Ic format , 50429fc00b3SJuli Mallett.Ic indir , 50529fc00b3SJuli Mallett.Ic paste , 50629fc00b3SJuli Mallett.Ic patsubst , 50729fc00b3SJuli Mallett.Ic regexp , 50829fc00b3SJuli Mallett.Ic spaste , 50929fc00b3SJuli Mallett.Ic unix , 51029fc00b3SJuli Mallett.Ic __line__ , 51139a82b8cSRuslan Ermilovand 512a841e1ebSBaptiste Daroussin.Ic __file__ 513a841e1ebSBaptiste Daroussinare extensions to that specification. 514a841e1ebSBaptiste Daroussin.Pp 5158ce3644cSJung-uk Kim.Ic maketemp 5168ce3644cSJung-uk Kimis not supposed to be a synonym for 5178ce3644cSJung-uk Kim.Ic mkstemp , 5188ce3644cSJung-uk Kimbut instead to be an insecure temporary file name creation function. 51988497f0cSBaptiste DaroussinIt is marked by 52088497f0cSBaptiste Daroussin.St -p1003.1-2008 52188497f0cSBaptiste Daroussinas being obsolescent and should not be used if portability is a concern. 5228ce3644cSJung-uk Kim.Pp 52388497f0cSBaptiste DaroussinThe output format of 52488497f0cSBaptiste Daroussin.Ic traceon 52588497f0cSBaptiste Daroussinand 526a841e1ebSBaptiste Daroussin.Ic dumpdef 527a841e1ebSBaptiste Daroussinare not specified in any standard, 528a841e1ebSBaptiste Daroussinare likely to change and should not be relied upon. 529a841e1ebSBaptiste DaroussinThe current format of tracing is closely modelled on 530a841e1ebSBaptiste Daroussin.Nm gnu-m4 , 531a841e1ebSBaptiste Daroussinto allow 532a841e1ebSBaptiste Daroussin.Nm autoconf 533a841e1ebSBaptiste Daroussinto work. 534a841e1ebSBaptiste Daroussin.Pp 535a841e1ebSBaptiste DaroussinThe built-ins 536a841e1ebSBaptiste Daroussin.Ic pushdef 537a841e1ebSBaptiste Daroussinand 538a841e1ebSBaptiste Daroussin.Ic popdef 539a841e1ebSBaptiste Daroussinhandle macro definitions as a stack. 540a841e1ebSBaptiste DaroussinHowever, 541a841e1ebSBaptiste Daroussin.Ic define 542a841e1ebSBaptiste Daroussininteracts with the stack in an undefined way. 543a841e1ebSBaptiste DaroussinIn this implementation, 544a841e1ebSBaptiste Daroussin.Ic define 545a841e1ebSBaptiste Daroussinreplaces the top-most definition only. 546a841e1ebSBaptiste DaroussinOther implementations may erase all definitions on the stack instead. 54729fc00b3SJuli Mallett.Pp 54839a82b8cSRuslan ErmilovAll built-ins do expand without arguments in many other 5498ce3644cSJung-uk Kim.Nm . 55029fc00b3SJuli Mallett.Pp 55129fc00b3SJuli MallettMany other 55229fc00b3SJuli Mallett.Nm 553a841e1ebSBaptiste Daroussinhave dire size limitations with respect to buffer sizes. 554306005e7SPhilippe Charnier.Sh AUTHORS 55539a82b8cSRuslan Ermilov.An -nosplit 5562b7af31cSBaptiste Daroussin.An Ozan Yigit Aq Mt oz@sis.yorku.ca 55739a82b8cSRuslan Ermilovand 5582b7af31cSBaptiste Daroussin.An Richard A. O'Keefe Aq Mt ok@goanna.cs.rmit.OZ.AU . 559a841e1ebSBaptiste Daroussin.Pp 56039a82b8cSRuslan ErmilovGNU-m4 compatibility extensions by 5612b7af31cSBaptiste Daroussin.An Marc Espie Aq Mt espie@cvs.openbsd.org . 562