home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / m4.info-2 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  48KB  |  1,036 lines

  1. This is Info file m4.info, produced by Makeinfo-1.55 from the input
  2. file m4.texinfo.
  3. START-INFO-DIR-ENTRY
  4. * m4: (m4).            A powerful macro processor.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU `m4' utility.
  7.    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: m4.info,  Node: Debug Output,  Prev: Debug Levels,  Up: Debugging
  21. Saving debugging output
  22. =======================
  23.    Debug and tracing output can be redirected to files using either the
  24. `-o' option to `m4', or with the builtin macro `debugfile':
  25.      debugfile(opt FILENAME)
  26. will send all further debug and trace output to FILENAME.  If FILENAME
  27. is empty, debug and trace output are discarded and if `debugfile' is
  28. called without any arguments, debug and trace output are sent to the
  29. standard error output.
  30. File: m4.info,  Node: Input Control,  Next: File Inclusion,  Prev: Debugging,  Up: Top
  31. Input control
  32. *************
  33.    This chapter describes various builtin macros for controlling the
  34. input to `m4'.
  35. * Menu:
  36. * Dnl::                         Deleting whitespace in input
  37. * Changequote::                 Changing the quote characters
  38. * Changecom::                   Changing the comment delimiters
  39. * Changeword::                  Changing the lexical structure of words
  40. * M4wrap::                      Saving input until end of input
  41. File: m4.info,  Node: Dnl,  Next: Changequote,  Prev: Input Control,  Up: Input Control
  42. Deleting whitespace in input
  43. ============================
  44.    The builtin `dnl' reads and discards all characters, up to and
  45. including the first newline:
  46.      dnl
  47. and it is often used in connection with `define', to remove the newline
  48. that follow the call to `define'.  Thus
  49.      define(`foo', `Macro `foo'.')dnl A very simple macro, indeed.
  50.      foo
  51.      =>Macro foo.
  52.    The input up to and including the next newline is discarded, as
  53. opposed to the way comments are treated (*note Comments::.).
  54.    Usually, `dnl' is immediately followed by an end of line or some
  55. other whitespace.  GNU `m4' will produce a warning diagnostic if `dnl'
  56. is followed by an open parenthesis.  In this case, `dnl' will collect
  57. and process all arguments, looking for a matching close parenthesis.
  58. All predictable side effects resulting from this collection will take
  59. place.  `dnl' will return no output.  The input following the matching
  60. close parenthesis up to and including the next newline, on whatever
  61. line containing it, will still be discarded.
  62. File: m4.info,  Node: Changequote,  Next: Changecom,  Prev: Dnl,  Up: Input Control
  63. Changing the quote characters
  64. =============================
  65.    The default quote delimiters can be changed with the builtin
  66. `changequote':
  67.      changequote(opt START, opt END)
  68. where START is the new start-quote delimiter and END is the new
  69. end-quote delimiter.  If any of the arguments are missing, the default
  70. quotes (``' and `'') are used instead of the void arguments.
  71.    The expansion of `changequote' is void.
  72.      changequote([, ])
  73.      =>
  74.      define([foo], [Macro [foo].])
  75.      =>
  76.      foo
  77.      =>Macro foo.
  78.    If no single character is appropriate, START and END can be of any
  79. length.
  80.      changequote([[, ]])
  81.      =>
  82.      define([[foo]], [[Macro [[[foo]]].]])
  83.      =>
  84.      foo
  85.      =>Macro [foo].
  86.    Changing the quotes to the empty strings will effectively disable the
  87. quoting mechanism, leaving no way to quote text.
  88.      define(`foo', `Macro `FOO'.')
  89.      =>
  90.      changequote(, )
  91.      =>
  92.      foo
  93.      =>Macro `FOO'.
  94.      `foo'
  95.      =>`Macro `FOO'.'
  96.    There is no way in `m4' to quote a string containing an unmatched
  97. left quote, except using `changequote' to change the current quotes.
  98.    Neither quote string should start with a letter or `_' (underscore),
  99. as they will be confused with names in the input.  Doing so disables
  100. the quoting mechanism.
  101. File: m4.info,  Node: Changecom,  Next: Changeword,  Prev: Changequote,  Up: Input Control
  102. Changing comment delimiters
  103. ===========================
  104.    The default comment delimiters can be changed with the builtin macro
  105. `changecom':
  106.      changecom(opt START, opt END)
  107. where START is the new start-comment delimiter and END is the new
  108. end-comment delimiter.  If any of the arguments are void, the default
  109. comment delimiters (`#' and newline) are used instead of the void
  110. arguments.  The comment delimiters can be of any length.
  111.    The expansion of `changecom' is void.
  112.      define(`comment', `COMMENT')
  113.      =>
  114.      # A normal comment
  115.      =># A normal comment
  116.      changecom(`/*', `*/')
  117.      =>
  118.      # Not a comment anymore
  119.      =># Not a COMMENT anymore
  120.      But: /* this is a comment now */ while this is not a comment
  121.      =>But: /* this is a comment now */ while this is not a COMMENT
  122.    Note how comments are copied to the output, much as if they were
  123. quoted strings.  If you want the text inside a comment expanded, quote
  124. the start comment delimiter.
  125.    Calling `changecom' without any arguments disables the commenting
  126. mechanism completely.
  127.      define(`comment', `COMMENT')
  128.      =>
  129.      changecom
  130.      =>
  131.      # Not a comment anymore
  132.      =># Not a COMMENT anymore
  133. File: m4.info,  Node: Changeword,  Next: M4wrap,  Prev: Changecom,  Up: Input Control
  134. Changing the lexical structure of words
  135. =======================================
  136.      The macro `changeword' and all associated functionnality is
  137.      experimental.  It is only available if the `--enable-changeword'
  138.      option was given to `configure', at GNU `m4' installation time.
  139.      The functionnality might change or even go away in the future.
  140.      *Do not rely on it*.  Please direct your comments about it the
  141.      same way you would do for bugs.
  142.    A file being processed by `m4' is split into quoted strings, words
  143. (potential macro names) and simple tokens (any other single character).
  144. Initially a word is defined by the following regular expression:
  145.      [_a-zA-Z][_a-zA-Z0-9]*
  146.    Using `changeword', you can change this regular expression.  Relaxing
  147. `m4''s lexical rules might be useful (for example) if you wanted to
  148. apply translations to a file of numbers:
  149.      changeword(`[_a-zA-Z0-9]+')
  150.      define(1, 0)
  151.      =>1
  152.    Tightening the lexical rules is less useful, because it will
  153. generally make some of the builtins unavailable.  You could use it to
  154. prevent accidental call of builtins, for example:
  155.      define(`_indir', defn(`indir'))
  156.      changeword(`_[_a-zA-Z0-9]*')
  157.      esyscmd(foo)
  158.      _indir(`esyscmd', `ls')
  159.    Because `m4' constructs its words a character at a time, there is a
  160. restriction on the regular expressions that may be passed to
  161. `changeword'.  This is that if your regular expression accepts `foo',
  162. it must also accept `f' and `fo'.
  163.    `changeword' has another function.  If the regular expression
  164. supplied contains any bracketed subexpressions, then text outside the
  165. first of these is discarded before symbol lookup.  So:
  166.      changecom(`/*', `*/')
  167.      changeword(`#\([_a-zA-Z0-9]*\)')
  168.      #esyscmd(ls)
  169.    `m4' now requires a `#' mark at the beginning of every macro
  170. invocation, so one can use `m4' to preprocess shell scripts without
  171. getting `shift' commands swallowed, and plain text without losing
  172. various common words.
  173.    `m4''s macro substitution is based on text, while TeX's is based on
  174. tokens.  `changeword' can throw this difference into relief.  For
  175. example, here is the same idea represented in TeX and `m4'.  First, the
  176. TeX version:
  177.      \def\a{\message{Hello}}
  178.      \catcode`\@=0
  179.      \catcode`\\=12
  180.      =>@a
  181.      =>@bye
  182. Then, the `m4' version:
  183.      define(a, `errprint(`Hello')')
  184.      changeword(`@\([_a-zA-Z0-9]*\)')