Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ m4.bsd(1) — Domain/IX SR9.2.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

M4(1)

NAME

m4 − macro processor

USAGE

m4 [ files ]

DESCRIPTION

M4 is a macro processor intended as a front end for RATFOR, C, and other languages.  It processes each of the files in order.  If there are no arguments, or if an argument is specified as a dash (−), m4 reads the standard input.  It writes the processed text on the standard output. 

Macro calls have the form

name(arg1,arg2, . . . , argn)

You must place a left parenthesis immediately after the name of the macro to specify arguments.  Processing ignores leading unquoted blanks, tabs, and newlines while collecting arguments.  Potential macro names consist of alphabetic letters, digits, and underscore characters, where the first character is not a digit. 

To quote strings, use left and right single quotes (`´). The value of a quoted string is the string stripped of the quotes.

When m4 recognizes a macro name, it collects the macro’s arguments by searching for a matching right parenthesis.  Macro evaluation proceeds normally during the collection of the arguments, and any commas or right parentheses that appear within the value of a nested call are as effective as those in the original input text.  After argument collection, m4 pushes back the value of the macro onto the input stream and scans it again. 

BUILT-IN MACROS

M4 uses the built-in macros described below.  You may redefine them, but once you have done this, the original meaning is lost.  Their values are null unless otherwise stated. 

define Install the second argument as the value of the macro whose name is the first argument.  Each occurrence of $n in the replacement text, where n is a digit, is replaced by the nth argument.  Argument 0 is the name of the macro; the null string replaces missing arguments.

undefine Remove the definition of the macro named in its argument. 

ifdef If the first argument is defined, the value is the second argument; otherwise, the value is the third.  If there is no third argument, the value is null.  The word unix is predefined on UNIX versions of m4. 

changequote
Change quote characters to the first and second arguments. Changequote without arguments restores the original values (i.e., `´).

divert Change the current output stream to its digit-string argument.  Discard output diverted to a stream other than 0 through 9.  M4 maintains 10 output streams, numbered 0 through 9.  The final output is the concatenation of the streams in numerical order; initially, stream 0 is the current stream. 

undivert Produce immediate output of text from diversions named as arguments, or all diversions if no argument is present.  You may undivert text into another diversion.  Undiverting discards the diverted text. 

divnum Return the value of the current output stream. 

dnl Read and discard characters up to and including the next newline. 

ifelse When three or more arguments are present, and the first argument is the same string as the second, use the value is the third argument.  If this is not the case, and there are more than four arguments, repeat the process with arguments 4, 5, 6, and 7.  Otherwise, the value is either the fourth string (if present) or null. 

incr Return the value of its argument incremented by one.  Calculate the value of the argument by interpreting an initial digit-string as a decimal number. 

eval Evaluate the argument as an arithmetic expression, using 32-bit arithmetic.  Operators include +, −, ∗, /, %, and ^ (exponentiation); relationals; and parentheses. 

len Return the number of characters in the argument. 

index Return the position in the first argument where the second argument begins (zero origin), or −1 if the second argument does not occur. 

substr Return a substring of the first argument.  The second argument is a zero origin number selecting the first character.  The third argument indicates the length of the substring.  A missing third argument is assumed to be large enough to extend to the end of the first string. 

translit Transliterate the characters in the first argument from the set given by the second argument to the set given by the third.  You cannot use abbreviations. 

include Return the contents of the file named in the argument. 

sinclude Perform the same function as include, but say nothing if the file is inaccessible. 

syscmd Execute the UNIX command given in the first argument.  Return no value. 

maketemp
Fill in a string of XXXXX in its argument with the current process ID.

errprint Print the argument on the diagnostic output file. 

dumpdef Print current names and definitions for the named items, or for all items if no arguments are given. 

RELATED INFORMATION

ratfor (1). 

DOMAIN/IX User’s Guide (for paper on “The M4 Macro Processor” by B.W. Kernighan and D. M. Ritchie). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026