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