home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d160 / m4.lha / M4 / M4.man < prev    next >
Text File  |  1988-10-02  |  15KB  |  463 lines

  1.  
  2.  
  3.  
  4. M4(local)           UNIX Programmer's Manual            M4(local)
  5.  
  6.  
  7.  
  8. NAME
  9.      pd m4 - macro processor
  10.  
  11. ORIGIN
  12.      MetaSystems
  13.  
  14. SYNOPSIS
  15.      m4[ _o_p_t_i_o_n_s ]
  16.  
  17. DESCRIPTION
  18.      _P_d _M_4 is a un*x M4 look-alike macro processor intended as a
  19.      front end for Ratfor, Pascal, and other languages that do
  20.      not have a built-in macro processing capability.  Pd M4
  21.      reads standard input, the processed text is written on the
  22.      standard output.
  23.  
  24.      The options and their effects are as follows:
  25.  
  26.      -D_n_a_m_e[=_v_a_l]
  27.           Defines _n_a_m_e to _v_a_l or to null in _v_a_l's absence.
  28.  
  29.      -U_n_a_m_e
  30.           undefines _n_a_m_e.
  31.  
  32.      Macro calls have the form:
  33.  
  34.           name(_a_r_g_1,_a_r_g_2, ..., _a_r_g_n)
  35.  
  36.      The ( must immediately follow the name of the macro.  If the
  37.      name of a defined macro is not followed by a (, it is taken
  38.      to be a call of that macro with no arguments, i.e. name().
  39.      Potential macro names consist of alphabetic letters and
  40.      digits.
  41.  
  42.      Leading unquoted blanks, tabs and newlines are ignored while
  43.      collecting arguments.  Left and right single quotes are used
  44.      to quote strings.  The value of a quoted string is the
  45.      string stripped of the quotes.
  46.  
  47.      When a macro name is recognized, its arguments are collected
  48.      by searching for a matching ).  If fewer arguments are sup-
  49.      plied than are in the macro definition, the trailing argu-
  50.      ments are taken to be null.  Macro evaluation proceeds nor-
  51.      mally during the collection of the arguments, and any commas
  52.      or right parentheses which happen to turn up within the
  53.      value of a nested call are as effective as those in the ori-
  54.      ginal input text. (This is typically referred as _i_n_s_i_d_e-_o_u_t
  55.      macro expansion.) After argument collection, the value of
  56.      the macro is pushed back onto the input stream and res-
  57.      canned.
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Printed 5/16/88            30 Aug 1987                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. M4(local)           UNIX Programmer's Manual            M4(local)
  71.  
  72.  
  73.  
  74.      _P_d _M_4 makes available the following built-in macros.  They
  75.      may be redefined, but once this is done the original meaning
  76.      is lost.  Their values are null unless otherwise stated.
  77.  
  78.      define        usage: _d_e_f_i_n_e(_n_a_m_e [, _v_a_l])
  79.                    the second argument is installed as the value
  80.                    of the macro whose name is the first argument.
  81.                    If there is no second argument, the value is
  82.                    null.  Each occurrence of $_n in the replace-
  83.                    ment text, where _n is a digit, is replaced by
  84.                    the _n-th argument.  Argument 0 is the name of
  85.                    the macro; missing arguments are replaced by
  86.                    the null string.
  87.  
  88.      defn          usage: _d_e_f_n(_n_a_m_e [, _n_a_m_e ...])
  89.                    returns the quoted definition of its
  90.                    argument(s). Useful in renaming macros.
  91.  
  92.      undefine      usage: _u_n_d_e_f_i_n_e(_n_a_m_e [, _n_a_m_e ...])
  93.                    removes the definition of the macro(s) named.
  94.                    If there is more than one definition for the
  95.                    named macro, (due to previous use of _p_u_s_h_d_e_f)
  96.                    all definitions are removed.
  97.  
  98.      pushdef       usage: _p_u_s_h_d_e_f(_n_a_m_e [, _v_a_l])
  99.                    like _d_e_f_i_n_e, but saves any previous definition
  100.                    by stacking the current definition.
  101.  
  102.      popdef        usage: _p_o_p_d_e_f(_n_a_m_e [, _n_a_m_e ...])
  103.                    removes current definition of its argument(s),
  104.                    exposing the previous one if any.
  105.  
  106.      ifdef         usage: _i_f_d_e_f(_n_a_m_e, _i_f-_d_e_f [, _i_f_n_o_t-_d_e_f])
  107.                    if the first argument is defined, the value is
  108.                    the second argument, otherwise the third.  If
  109.                    there is no third argument, the value is null.
  110.                    A word indicating the current operating system
  111.                    is predefined.  (e.g.  _u_n_i_x or _v_m_s)
  112.  
  113.      shift         usage: _s_h_i_f_t(_a_r_g, _a_r_g, _a_r_g, ...)
  114.                    returns all but its first argument.  The other
  115.                    arguments are quoted and pushed back with com-
  116.                    mas in between.  The quoting nullifies the
  117.                    effect of the extra scan that will subse-
  118.                    quently be performed.
  119.  
  120.      changequote   usage: _c_h_a_n_g_e_q_u_o_t_e(_l_q_c_h_a_r, _r_q_c_h_a_r)
  121.                    change quote symbols to the first and second
  122.                    arguments.  With no arguments, the quotes are
  123.                    reset back to the default characters. (i.e.,
  124.                    ).
  125.  
  126.  
  127.  
  128.  
  129. Printed 5/16/88            30 Aug 1987                          2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. M4(local)           UNIX Programmer's Manual            M4(local)
  137.  
  138.  
  139.  
  140.      changecom     usage: _c_h_a_n_g_e_c_o_m(_l_c_c_h_a_r, _r_c_c_h_a_r)
  141.                    change left and right comment markers from the
  142.                    default # and newline.  With no arguments, the
  143.                    comment mechanism is reset back to the default
  144.                    characters.  With one argument, the left
  145.                    marker becomes the argument and the right
  146.                    marker becomes newline.  With two arguments,
  147.                    both markers are affected.
  148.  
  149.      divert        usage: _d_i_v_e_r_t(_d_i_v_n_u_m)
  150.                    _m_4 maintains 10 output streams, numbered 0-9.
  151.                    initially stream 0 is the current stream. The
  152.                    _d_i_v_e_r_t macro changes the current output stream
  153.                    to its (digit-string) argument.  Output
  154.                    diverted to a stream other than 0 through 9
  155.                    disappears into bitbucket.
  156.  
  157.      undivert      usage: _u_n_d_i_v_e_r_t([_d_i_v_n_u_m [, _d_i_v_n_u_m ...]])
  158.                    causes immediate output of text from diver-
  159.                    sions named as argument(s), or all diversions
  160.                    if no argument.  Text may be undiverted into
  161.                    another diversion.  Undiverting discards the
  162.                    diverted text. At the end of input processing,
  163.                    _M_4 forces an automatic _u_n_d_i_v_e_r_t, unless _m_4_w_r_a_p
  164.                    is defined.
  165.  
  166.      divnum        usage: _d_i_v_n_u_m()
  167.                    returns the value of the current output
  168.                    stream.
  169.  
  170.      dnl           usage: _d_n_l()
  171.                    reads and discards characters up to and
  172.                    including the next newline.
  173.  
  174.      ifelse        usage: _i_f_e_l_s_e(_a_r_g, _a_r_g, _i_f-_s_a_m_e [, _i_f_n_o_t-_s_a_m_e
  175.                    | _a_r_g, _a_r_g ...])
  176.                    has three or more arguments.  If the first
  177.                    argument is the same string as the second,
  178.                    then the value is the third argument.  If not,
  179.                    and if there are more than four arguments, the
  180.                    process is repeated with arguments 4, 5, 6 and
  181.                    7.  Otherwise, the value is either the fourth
  182.                    string, or, if it is not present, null.
  183.  
  184.      incr          usage: _i_n_c_r(_n_u_m)
  185.                    returns the value of its argument incremented
  186.                    by 1.  The value of the argument is calculated
  187.                    by interpreting an initial digit-string as a
  188.                    decimal number.
  189.  
  190.      decr          usage: _d_e_c_r(_n_u_m)
  191.                    returns the value of its argument decremented
  192.  
  193.  
  194.  
  195. Printed 5/16/88            30 Aug 1987                          3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. M4(local)           UNIX Programmer's Manual            M4(local)
  203.  
  204.  
  205.  
  206.                    by 1.
  207.  
  208.      eval          usage: _e_v_a_l(_e_x_p_r_e_s_s_i_o_n)
  209.                    evaluates its argument as a constant expres-
  210.                    sion, using integer arithmetic.  The evalua-
  211.                    tion mechanism is very similar to that of _c_p_p
  212.                    (#if expression). The expression can involve
  213.                    only integer constants and character con-
  214.                    stants, possibly connected by the binary
  215.                    operators
  216.  
  217.                    *    /    %    +    -    >>   <<   <    >
  218.                    <=   >=   ==   !=   &    ^    |    &&   ||
  219.  
  220.                    or the unary operators - ~ !  or by the ter-
  221.                    nary operator  ? : .  Parentheses may be used
  222.                    for grouping. Octal numbers may be specified
  223.                    as in C.
  224.  
  225.      len           usage: _l_e_n(_s_t_r_i_n_g)
  226.                    returns the number of characters in its argu-
  227.                    ment.
  228.  
  229.      index         usage: _i_n_d_e_x(_s_e_a_r_c_h-_s_t_r_i_n_g, _s_t_r_i_n_g)
  230.                    returns the position in its first argument
  231.                    where the second argument begins (zero ori-
  232.                    gin), or -1 if the second argument does not
  233.                    occur.
  234.  
  235.      substr        usage: _s_u_b_s_t_r(_s_t_r_i_n_g, _i_n_d_e_x [, _l_e_n_g_t_h])
  236.                    returns a substring of its first argument.
  237.                    The second argument is a zero origin number
  238.                    selecting the first character (internally
  239.                    treated as an expression); the third argument
  240.                    indicates the length of the substring.  A
  241.                    missing third argument is taken to be large
  242.                    enough to extend to the end of the first
  243.                    string.
  244.  
  245.      translit      usage: _t_r_a_n_s_l_i_t(_s_o_u_r_c_e, _f_r_o_m [, _t_o])
  246.                    transliterates the characters in its first
  247.                    argument from the set given by the second
  248.                    argument to the set given by the third.  If
  249.                    the third argument is shorter than the second,
  250.                    all extra characters in the second argument
  251.                    are deleted from the first argument. If the
  252.                    third argument is missing altogether, all
  253.                    characters in the second argument are deleted
  254.                    from the first argument.
  255.  
  256.      include       usage: _i_n_c_l_u_d_e(_f_i_l_e_n_a_m_e)
  257.                    returns the contents of the file named in the
  258.  
  259.  
  260.  
  261. Printed 5/16/88            30 Aug 1987                          4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. M4(local)           UNIX Programmer's Manual            M4(local)
  269.  
  270.  
  271.  
  272.                    argument.
  273.  
  274.      sinclude      usage: _s_i_n_c_l_u_d_e(_f_i_l_e_n_a_m_e)
  275.                    is identical to _i_n_c_l_u_d_e, except that it says
  276.                    nothing if the file is inaccessible.
  277.  
  278.      paste         usage: _p_a_s_t_e(_f_i_l_e_n_a_m_e)
  279.                    returns the contents of the file named in the
  280.                    argument without any processing, unlike
  281.                    _i_n_c_l_u_d_e.
  282.  
  283.      spaste        usage: _s_p_a_s_t_e(_f_i_l_e_n_a_m_e)
  284.                    is identical to _p_a_s_t_e, except that it says
  285.                    nothing if the file is inaccessible.
  286.  
  287.      syscmd        usage: _s_y_s_c_m_d(_c_o_m_m_a_n_d)
  288.                    executes the UNIX command given in the first
  289.                    argument.  No value is returned.
  290.  
  291.      sysval        usage: _s_y_s_v_a_l()
  292.                    is the return code from the last call to
  293.                    _s_y_s_c_m_d.
  294.  
  295.      maketemp      usage: _m_a_k_e_t_e_m_p(_s_t_r_i_n_g)
  296.                    fills in a string of XXXXXX in its argument
  297.                    with the current process ID.
  298.  
  299.      m4exit        usage: _m_4_e_x_i_t([_e_x_i_t_c_o_d_e])
  300.                    causes immediate exit from _m_4.  Argument 1, if
  301.                    given, is the exit code; the default is 0.
  302.  
  303.      m4wrap        usage: _m_4_w_r_a_p(_m_4-_m_a_c_r_o-_o_r-_b_u_i_l_t-_i_n)
  304.                    argument 1 will be pushed back at final EOF;
  305.                    example: m4wrap(`dumptable()').
  306.  
  307.      errprint      usage: _e_r_r_p_r_i_n_t(_s_t_r [, _s_t_r, _s_t_r, ...])
  308.                    prints its argument(s) on stderr. If there is
  309.                    more than one argument, each argument is
  310.                    separated by a space during the output.
  311.  
  312.      dumpdef       usage: _d_u_m_p_d_e_f([_n_a_m_e, _n_a_m_e, ...])
  313.                    prints current names and definitions, for the
  314.                    named items, or for all if no arguments are
  315.                    given.
  316.  
  317. AUTHOR
  318.      Ozan S. Yigit (oz)
  319.  
  320. BUGS
  321.      Pd M4 is distributed at the source level, and does not
  322.      require an expensive license agreement.
  323.  
  324.  
  325.  
  326.  
  327. Printed 5/16/88            30 Aug 1987                          5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. M4(local)           UNIX Programmer's Manual            M4(local)
  335.  
  336.  
  337.  
  338.      A sufficiently complex M4 macro set is about as readable as
  339.      APL.
  340.  
  341.      All complex uses of M4 require the ability to program in
  342.      deep recursion.  Previous lisp experience is recommended.
  343.  
  344.      Pd M4 is slower than V7 M4.
  345.  
  346. EXAMPLES
  347.      The following macro program illustrates the type of things
  348.      that can be done with M4.
  349.  
  350.           changequote(<,>) define(HASHVAL,99) dnl
  351.           define(hash,<expr(str(substr($1,1),0)%HASHVAL)>) dnl
  352.           define(str,
  353.                <ifelse($1,",$2,
  354.                     <str(substr(<$1>,1),<expr($2+'substr($1,0,1)')>)>)
  355.                >) dnl
  356.           define(KEYWORD,<$1,hash($1),>) dnl
  357.           define(TSTART,
  358.           <struct prehash {
  359.                char *keyword;
  360.                int   hashval;
  361.           } keytab[] = {>) dnl
  362.           define(TEND,<  "",0
  363.           };>) dnl
  364.  
  365.      Thus a keyword table containing the keyword string and its
  366.      pre-calculated hash value may be generated thus:
  367.  
  368.           TSTART
  369.                KEYWORD("foo")
  370.                KEYWORD("bar")
  371.                KEYWORD("baz")
  372.           TEND
  373.  
  374.      which will expand into:
  375.           struct prehash {
  376.                char *keyword;
  377.                int   hashval;
  378.           } keytab[] = {
  379.                "foo",27,
  380.                "bar",12,
  381.                "baz",20,
  382.                "",0
  383.           };
  384.  
  385.      Presumably, such a table would speed up the installation of
  386.      the keywords into a dynamic hash table. (Note that the above
  387.      macro cannot be used with _M_4, since eval does not handle
  388.      character constants.)
  389.  
  390.  
  391.  
  392.  
  393. Printed 5/16/88            30 Aug 1987                          6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. M4(local)           UNIX Programmer's Manual            M4(local)
  401.  
  402.  
  403.  
  404. SEE ALSO
  405.      cc(1), m4(1), cpp(1).  _T_h_e _M_4 _M_a_c_r_o _P_r_o_c_e_s_s_o_r by B. W. Ker-
  406.      nighan and D. M. Ritchie.
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459. Printed 5/16/88            30 Aug 1987                          7
  460.  
  461.  
  462.  
  463.