

m4                           Command                           m4




Macro processor

mm44 [ffiillee ...]

The command m4 processes macros.  It allows you to define strings
for which m4  is to search, and strings to  replace them; m4 then
opens  file, reads  its contents,  replaces  each macro  with its
specified  replacement string,  and writes  the results  into the
standard output stream.

m4  can  also  perform  file manipulation,  conditional  decision
making, substring selection, and arithmetic.  The Introduction to
the m4 Macro Processor describes m4 in detail.

The files are read in the  order given; if no file is named, then
m4 reads the standard  input stream.  The file name `-' indicates
the standard input.

m4 copies  input to output  until it finds a  potential _m_a_c_r_o.  A
macro is  a string of  alphanumerics (letters, digits,  or under-
scores) that begins  with a non-digit character and is surrounded
by  non-alphanumerics.  If  m4 does not  recognize the  macro, it
simply copies  it to the output and  continues processing.  If m4
recognizes the macro and the next character is a left parenthesis
`(', an argument set follows:


        macro(arg1,..., argn)


The arguments are collected by processing them in the same manner
as other  text (thus, an arguments may  itself be another macro),
and resulting output text is diverted into storage.  m4 stores up
to nine arguments; any more  will be processed but not saved.  An
argument  set consists  of strings  of  text separated  by commas
(commas inside quotation marks or parentheses do not terminate an
argument), and must contain balanced parentheses that are free of
quotation marks  (i.e., that are unquoted).   m4 strips arguments
of unquoted leading space (blanks, tabs, newline characters).

m4 then removes the macro  and its optional argument set from the
input  stream, processes  them, and  replaces  them in  the input
stream  with the  resulting value.   The  value becomes  the next
piece of text to be read.

Quotation  marks, of  the form  ` ',  inhibit the  recognition of
macro.  m4  strips off one  level of quotation marks  when it en-
counters them  (quotation marks are nestable).   Thus, `_m_a_c_r_o' is
not processed, but is changed to macro and passed on.

m4 determines  the value  of a  user-defined macro by  taking the
text that  constitutes the  macro's definition and  replacing any
occurrence within that text of  `$_n' (where n is `0' through `9')
with the text  of the nth argument.  Argument 0  is the macro it-


COHERENT Lexicon                                           Page 1




m4                           Command                           m4



self.

m4 recognizes the following predefined macros:

cchhaannggeeqquuoottee[([_o_p_e_n_q_u_o_t_e],[_c_l_o_s_e_q_u_o_t_e])]
     Changes the quotation characters.  Missing arguments default
     to ` for open or ' for close.  Quotation characters will not
     nest if they are defined to be the same character.  Value is
     null.

ddeeccrr[(_n_u_m_b_e_r)]
     Decrement number  (default, 0) by one  and returns resulting
     value.

ddeeffiinnee(_m_a_c_r_o,_d_e_f_i_n_i_t_i_o_n)
     Define  or  redefine   macro.   If  a  predefined  macro  is
     redefined,  its original  definition is  irrecoverably lost.
     Value is null.

ddiivveerrtt[(_n)]
     Redirects  output to  output stream n  (default is  0).  The
     standard output is 0, and 1 through 9 are maintained as tem-
     porary files.   Any other n  results in output  being thrown
     away until the next divert macro.  Value is null.

ddiivvnnuumm
     Value is current output stream number.

ddnnll   Delete to  newline: removes all  characters from  the input
     stream up to and including the next newline.  Value is null.

dduummppddeeff[(_m_a_c_r_o_s)]
     Value  is quoted  definitions  of all  macros specified,  or
     names and definitions of all defined macros if no arguments.

eerrrrpprriinntt(_t_e_x_t)
     Print text on standard error file.  Value is null.

eevvaall(_e_x_p_r_e_s_s_i_o_n)
     Value is a number that is the value of evaluated expression.
     It  recognizes, in  order of  decreasing  precedence: paren-
     theses, **,  unary + -,  * / %,  binary + -,  relations, and
     logicals.  Arithmetic is performed in longs.

iiffddeeff(_m_a_c_r_o,_d_e_f_v_a_l_u_e,_u_n_d_e_f_v_a_l_u_e)
     Return defvalue if macro is defined, and undefvalue if not.

iiffeellssee(_a_r_g_1,_a_r_g_2,_a_r_g_3...)
     Compares arg1 and arg2.  If they are the same, returns arg3.
     If not, and arg4  is the last argument, return arg4.  Other-
     wise, the  process repeats, comparing arg4  and arg5, and so
     on.  Like other m4 macros,  this takes a maximum of nine ar-
     guments.




COHERENT Lexicon                                           Page 2




m4                           Command                           m4



iinncclluuddee(_f_i_l_e)
     Value is the entire  contents of the file argument.  If file
     is not accessible, a fatal error results.

iinnccrr[(_n_u_m_b_e_r)]
     Increments given  number (default, zero) by  one and returns
     resulting value.

iinnddeexx(_t_e_x_t,_p_a_t_t_e_r_n)
     Value is  a number corresponding  to position of  pattern in
     text.  If pattern does not occur in text, value is -1.

lleenn(_t_e_x_t)
     Value is a number that corresponds to length of text.

mmaakkeetteemmpp(_f_i_l_e_n_a_m_e_X_X_X_X_X_X)
     Value is filename  with last six characters, usually XXXXXX,
     replaced with current  process id and a single letter.  Same
     as system call mktemp.

ssiinncclluuddee(_f_i_l_e)
     Value is the entire contents of file.  If file is not acces-
     sible, return null and continue processing.

ssuubbssttrr(_t_e_x_t[,_s_t_a_r_t[,_c_o_u_n_t]])
     Value is  a substring of  text.  start may  be left-oriented
     (nonnegative) or right-oriented (negative).  count specifies
     how many  characters to  the right  (if positive) or  to the
     left (if  negative) to return.  If absent,  it is assumed to
     be  large  and of  the  same  sign as  start.   If start  is
     omitted, it  is assumed to  be zero if count  is positive or
     omitted, or -1 if count is negative.

ssyyssccmmdd(_c_o_m_m_a_n_d)
     Pass command to the  shell sh for execution.  Value is null.
     Same as system call system.

ttrraannsslliitt(_t_e_x_t,_c_h_a_r_a_c_t_e_r_s[,_r_e_p_l_a_c_e_m_e_n_t_s])
     Replaces characters  in text with  the corresponding charac-
     ters from  replacements.  If  the replacements is  absent or
     too short, replace  characters with a null character.  Value
     is text with specified replacements.

uunnddeeffiinnee(_m_a_c_r_o)
     Remove macro  definition.  Value  is null.  If  a predefined
     macro is redefined, its original definition is irrecoverably
     lost.

uunnddiivveerrtt[(_s_t_r_e_a_m[,...])]
     Dumps each specified  stream into the current output stream.
     With  no arguments,  undivert  dumps all  output streams  in
     numeric order.  m4 will  not dump any output stream into it-
     self.  At the  end of processing, m4 automatically dumps all
     diverted text to standard output in numeric order.  Value is
     null.


COHERENT Lexicon                                           Page 3




m4                           Command                           m4




***** See Also *****

commands, mktemp, system
_I_n_t_r_o_d_u_c_t_i_o_n _t_o _t_h_e _m_4 _M_a_c_r_o _P_r_o_c_e_s_s_o_r




















































COHERENT Lexicon                                           Page 4


