home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / gnu / info / m4.info-2 (.txt) < prev    next >
GNU Info File  |  1994-11-17  |  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]*\)')
  185.      =>@a
  186.    In the TeX example, the first line defines a macro `a' to print the
  187. message `Hello'.  The second line defines @ to be usable instead of \
  188. as an escape character.  The third line defines \ to be a normal
  189. printing character, not an escape.  The fourth line invokes the macro
  190. `a'.  So, when TeX is run on this file, it displays the message `Hello'.
  191.    When the `m4' example is passed through `m4', it outputs
  192. `errprint(Hello)'.  The reason for this is that TeX does lexical
  193. analysis of macro definition when the macro is *defined*.  `m4' just
  194. stores the text, postponing the lexical analysis until the macro is
  195. *used*.
  196.    You should note that using `changeword' will slow `m4' down by a
  197. factor of about seven.
  198. File: m4.info,  Node: M4wrap,  Prev: Changeword,  Up: Input Control
  199. Saving input
  200. ============
  201.    It is possible to `save' some text until the end of the normal input
  202. has been seen.  Text can be saved, to be read again by `m4' when the
  203. normal input has been exhausted.  This feature is normally used to
  204. initiate cleanup actions before normal exit, e.g., deleting temporary
  205. files.
  206.    To save input text, use the builtin `m4wrap':
  207.      m4wrap(STRING, ...)
  208. which stores STRING and the rest of the arguments in a safe place, to
  209. be reread when end of input is reached.
  210.      define(`cleanup', `This is the `cleanup' actions.
  211.      ')
  212.      =>
  213.      m4wrap(`cleanup')
  214.      =>
  215.      This is the first and last normal input line.
  216.      =>This is the first and last normal input line.
  217.      ^D
  218.      =>This is the cleanup actions.
  219.    The saved input is only reread when the end of normal input is seen,
  220. and not if `m4exit' is used to exit `m4'.
  221.    It is safe to call `m4wrap' from saved text, but then the order in
  222. which the saved text is reread is undefined.  If `m4wrap' is not used
  223. recursively, the saved pieces of text are reread in the opposite order
  224. in which they were saved (LIFO--last in, first out).
  225. File: m4.info,  Node: File Inclusion,  Next: Diversions,  Prev: Input Control,  Up: Top
  226. File inclusion
  227. **************
  228.    `m4' allows you to include named files at any point in the input.
  229. * Menu:
  230. * Include::                     Including named files
  231. * Search Path::                 Searching for include files
  232. File: m4.info,  Node: Include,  Next: Search Path,  Prev: File Inclusion,  Up: File Inclusion
  233. Including named files
  234. =====================
  235.    There are two builtin macros in `m4' for including files:
  236.      include(FILENAME)
  237.      sinclude(FILENAME)
  238. both of which cause the file named FILENAME to be read by `m4'.  When
  239. the end of the file is reached, input is resumed from the previous
  240. input file.
  241.    The expansion of `include' and `sinclude' is therefore the contents
  242. of FILENAME.
  243.    It is an error for an `include'd file not to exist.  If you do not
  244. want error messages about non-existent files, `sinclude' can be used to
  245. include a file, if it exists, expanding to nothing if it does not.
  246.      include(`no-such-file')
  247.      =>
  248.      error-->30.include:2: m4: Cannot open no-such-file: No such file or directory
  249.      sinclude(`no-such-file')
  250.      =>
  251.    Assume in the following that the file `incl.m4' contains the lines:
  252.      Include file start
  253.      foo
  254.      Include file end
  255. Normally file inclusion is used to insert the contents of a file into
  256. the input stream.  The contents of the file will be read by `m4' and
  257. macro calls in the file will be expanded:
  258.      define(`foo', `FOO')
  259.      =>
  260.      include(`incl.m4')
  261.      =>Include file start
  262.      =>FOO
  263.      =>Include file end
  264.      =>
  265.    The fact that `include' and `sinclude' expand to the contents of the
  266. file can be used to define macros that operate on entire files.  Here
  267. is an example, which defines `bar' to expand to the contents of
  268. `incl.m4':
  269.      define(`bar', include(`incl.m4'))
  270.      =>
  271.      This is `bar':  >>>bar<<<
  272.      =>This is bar:  >>>Include file start
  273.      =>foo
  274.      =>Include file end
  275.      =><<<
  276.    This use of `include' is not trivial, though, as files can contain
  277. quotes, commas and parentheses, which can interfere with the way the
  278. `m4' parser works.
  279.    The builtin macros `include' and `sinclude' are recognized only when
  280. given arguments.
  281. File: m4.info,  Node: Search Path,  Prev: Include,  Up: File Inclusion
  282. Searching for include files
  283. ===========================
  284.    GNU `m4' allows included files to be found in other directories than
  285. the current working directory.
  286.    If a file is not found in the current working directory, and the file
  287. name is not absolute, the file will be looked for in a specified search
  288. path.  First, the directories specified with the `-I' option will be
  289. searched, in the order found on the command line.  Second, if the
  290. `M4PATH' environment variable is set, it is expected to contain a
  291. colon-separated list of directories, which will be searched in order.
  292.    If the automatic search for include-files causes trouble, the `p'
  293. debug flag (*note Debug Levels::.) can help isolate the problem.
  294. File: m4.info,  Node: Diversions,  Next: Text handling,  Prev: File Inclusion,  Up: Top
  295. Diverting and undiverting output
  296. ********************************
  297.    Diversions are a way of temporarily saving output.  The output of
  298. `m4' can at any time be diverted to a temporary file, and be reinserted
  299. into the output stream, "undiverted", again at a later time.
  300.    Numbered diversions are counted from 0 upwards, diversion number 0
  301. being the normal output stream.  The number of simultaneous diversions
  302. is limited mainly by the memory used to describe them, because GNU `m4'
  303. tries to keep diversions in memory.  However, there is a limit to the
  304. overall memory usable by all diversions taken altogether (512K,
  305. currently).  When this maximum is about to be exceeded, a temporary
  306. file is opened to receive the contents of the biggest diversion still
  307. in memory, freeing this memory for other diversions.  So, it is
  308. theoretically possible that the number of diversions be limited by the
  309. number of available file descriptors.
  310. * Menu:
  311. * Divert::                      Diverting output
  312. * Undivert::                    Undiverting output
  313. * Divnum::                      Diversion numbers
  314. * Cleardiv::                    Discarding diverted text
  315. File: m4.info,  Node: Divert,  Next: Undivert,  Prev: Diversions,  Up: Diversions
  316. Diverting output
  317. ================
  318.    Output is diverted using `divert':
  319.      divert(opt NUMBER)
  320. where NUMBER is the diversion to be used.  If NUMBER is left out, it is
  321. assumed to be zero.
  322.    The expansion of `divert' is void.
  323.    When all the `m4' input will have been processed, all existing
  324. diversions are automatically undiverted, in numerical order.
  325.      divert(1)
  326.      This text is diverted.
  327.      divert
  328.      =>
  329.      This text is not diverted.
  330.      =>This text is not diverted.
  331.      ^D
  332.      =>
  333.      =>This text is diverted.
  334.    Several calls of `divert' with the same argument do not overwrite
  335. the previous diverted text, but append to it.
  336.    If output is diverted to a non-existent diversion, it is simply
  337. discarded.  This can be used to suppress unwanted output.  A common
  338. example of unwanted output is the trailing newlines after macro
  339. definitions.  Here is how to avoid them.
  340.      divert(-1)
  341.      define(`foo', `Macro `foo'.')
  342.      define(`bar', `Macro `bar'.')
  343.      divert
  344.      =>
  345.    This is a common programming idiom in `m4'.
  346. File: m4.info,  Node: Undivert,  Next: Divnum,  Prev: Divert,  Up: Diversions
  347. Undiverting output
  348. ==================
  349.    Diverted text can be undiverted explicitly using the builtin
  350. `undivert':
  351.      undivert(opt NUMBER, ...)
  352. which undiverts the diversions given by the arguments, in the order
  353. given.  If no arguments are supplied, all diversions are undiverted, in
  354. numerical order.
  355.    The expansion of `undivert' is void.
  356.      divert(1)
  357.      This text is diverted.
  358.      divert
  359.      =>
  360.      This text is not diverted.
  361.      =>This text is not diverted.
  362.      undivert(1)
  363.      =>
  364.      =>This text is diverted.
  365.      =>
  366.    Notice the last two blank lines.  One of them comes from the newline
  367. following `undivert', the other from the newline that followed the
  368. `divert'!  A diversion often starts with a blank line like this.
  369.    When diverted text is undiverted, it is *not* reread by `m4', but
  370. rather copied directly to the current output, and it is therefore not
  371. an error to undivert into a diversion.
  372.    When a diversion has been undiverted, the diverted text is discarded,
  373. and it is not possible to bring back diverted text more than once.
  374.      divert(1)
  375.      This text is diverted first.
  376.      divert(0)undivert(1)dnl
  377.      =>
  378.      =>This text is diverted first.
  379.      undivert(1)
  380.      =>
  381.      divert(1)
  382.      This text is also diverted but not appended.
  383.      divert(0)undivert(1)dnl
  384.      =>
  385.      =>This text is also diverted but not appended.
  386.    Attempts to undivert the current diversion are silently ignored.
  387.    GNU `m4' allows named files to be undiverted.  Given a non-numeric
  388. argument, the contents of the file named will be copied, uninterpreted,
  389. to the current output.  This complements the builtin `include' (*note
  390. Include::.).  To illustrate the difference, assume the file `foo'
  391. contains the word `bar':
  392.      define(`bar', `BAR')
  393.      =>
  394.      undivert(`foo')
  395.      =>bar
  396.      =>
  397.      include(`foo')
  398.      =>BAR
  399.      =>
  400. File: m4.info,  Node: Divnum,  Next: Cleardiv,  Prev: Undivert,  Up: Diversions
  401. Diversion numbers
  402. =================
  403.    The builtin `divnum':
  404.      divnum
  405. expands to the number of the current diversion.
  406.      Initial divnum
  407.      =>Initial 0
  408.      divert(1)
  409.      Diversion one: divnum
  410.      divert(2)
  411.      Diversion two: divnum
  412.      divert
  413.      =>
  414.      ^D
  415.      =>
  416.      =>Diversion one: 1
  417.      =>
  418.      =>Diversion two: 2
  419.    The last call of `divert' without argument is necessary, since the
  420. undiverted text would otherwise be diverted itself.
  421. File: m4.info,  Node: Cleardiv,  Prev: Divnum,  Up: Diversions
  422. Discarding diverted text
  423. ========================
  424.    Often it is not known, when output is diverted, whether the diverted
  425. text is actually needed.  Since all non-empty diversion are brought back
  426. on the main output stream when the end of input is seen, a method of
  427. discarding a diversion is needed.  If all diversions should be
  428. discarded, the easiest is to end the input to `m4' with `divert(-1)'
  429. followed by an explicit `undivert':
  430.      divert(1)
  431.      Diversion one: divnum
  432.      divert(2)
  433.      Diversion two: divnum
  434.      divert(-1)
  435.      undivert
  436.      ^D
  437. No output is produced at all.
  438.    Clearing selected diversions can be done with the following macro:
  439.      define(`cleardivert',
  440.      `pushdef(`_num', divnum)divert(-1)undivert($@)divert(_num)popdef(`_num')')
  441.      =>
  442.    It is called just like `undivert', but the effect is to clear the
  443. diversions, given by the arguments.  (This macro has a nasty bug!  You
  444. should try to see if you can find it and correct it.)
  445. File: m4.info,  Node: Text handling,  Next: Arithmetic,  Prev: Diversions,  Up: Top
  446. Macros for text handling
  447. ************************
  448.    There are a number of builtins in `m4' for manipulating text in
  449. various ways, extracting substrings, searching, substituting, and so on.
  450. * Menu:
  451. * Len::                         Calculating length of strings
  452. * Index::                       Searching for substrings
  453. * Regexp::                      Searching for regular expressions
  454. * Substr::                      Extracting substrings
  455. * Translit::                    Translating characters
  456. * Patsubst::                    Substituting text by regular expression
  457. * Format::                      Formatting strings (printf-like)
  458. File: m4.info,  Node: Len,  Next: Index,  Prev: Text handling,  Up: Text handling
  459. Calculating length of strings
  460. =============================
  461.    The length of a string can be calculated by `len':
  462.      len(STRING)
  463. which expands to the length of STRING, as a decimal number.
  464.      len()
  465.      =>0
  466.      len(`abcdef')
  467.      =>6
  468.    The builtin macro `len' is recognized only when given arguments.
  469. File: m4.info,  Node: Index,  Next: Regexp,  Prev: Len,  Up: Text handling
  470. Searching for substrings
  471. ========================
  472.    Searching for substrings is done with `index':
  473.      index(STRING, SUBSTRING)
  474. which expands to the index of the first occurrence of SUBSTRING in
  475. STRING.  The first character in STRING has index 0.  If SUBSTRING does
  476. not occur in STRING, `index' expands to `-1'.
  477.      index(`gnus, gnats, and armadillos', `nat')
  478.      =>7
  479.      index(`gnus, gnats, and armadillos', `dag')
  480.      =>-1
  481.    The builtin macro `index' is recognized only when given arguments.
  482. File: m4.info,  Node: Regexp,  Next: Substr,  Prev: Index,  Up: Text handling
  483. Searching for regular expressions
  484. =================================
  485.    Searching for regular expressions is done with the builtin `regexp':
  486.      regexp(STRING, REGEXP, opt REPLACEMENT)
  487. which searches for REGEXP in STRING.  The syntax for regular
  488. expressions is the same as in GNU Emacs.  *Note Syntax of Regular
  489. Expressions: (emacs)Regexps.
  490.    If REPLACEMENT is omitted, `regexp' expands to the index of the
  491. first match of REGEXP in STRING.  If REGEXP does not match anywhere in
  492. STRING, it expands to -1.
  493.      regexp(`GNUs not Unix', `\<[a-z]\w+')
  494.      =>5
  495.      regexp(`GNUs not Unix', `\<Q\w*')
  496.      =>-1
  497.    If REPLACEMENT is supplied, `regexp' changes the expansion to this
  498. argument, with `\N' substituted by the text matched by the Nth
  499. parenthesized sub-expression of REGEXP, `\&' being the text the entire
  500. regular expression matched.
  501.      regexp(`GNUs not Unix', `\w\(\w+\)$', `*** \& *** \1 ***')
  502.      =>*** Unix *** nix ***
  503.    The builtin macro `regexp' is recognized only when given arguments.
  504. File: m4.info,  Node: Substr,  Next: Translit,  Prev: Regexp,  Up: Text handling
  505. Extracting substrings
  506. =====================
  507.    Substrings are extracted with `substr':
  508.      substr(STRING, FROM, opt LENGTH)
  509. which expands to the substring of STRING, which starts at index FROM,
  510. and extends for LENGTH characters, or to the end of STRING, if LENGTH
  511. is omitted.  The starting index of a string is always 0.
  512.      substr(`gnus, gnats, and armadillos', 6)
  513.      =>gnats, and armadillos
  514.      substr(`gnus, gnats, and armadillos', 6, 5)
  515.      =>gnats
  516.    The builtin macro `substr' is recognized only when given arguments.
  517. File: m4.info,  Node: Translit,  Next: Patsubst,  Prev: Substr,  Up: Text handling
  518. Translating characters
  519. ======================
  520.    Character translation is done with `translit':
  521.      translit(STRING, CHARS, REPLACEMENT)
  522. which expands to STRING, with each character that occurs in CHARS
  523. translated into the character from REPLACEMENT with the same index.
  524.    If REPLACEMENT is shorter than CHARS, the excess characters are
  525. deleted from the expansion.  If REPLACEMENT is omitted, all characters
  526. in STRING, that are present in CHARS are deleted from the expansion.
  527.    Both CHARS and REPLACEMENT can contain character-ranges, e.g., `a-z'
  528. (meaning all lowercase letters) or `0-9' (meaning all digits).  To
  529. include a dash `-' in CHARS or REPLACEMENT, place it first or last.
  530.    It is not an error for the last character in the range to be `larger'
  531. than the first.  In that case, the range runs backwards, i.e., `9-0'
  532. means the string `9876543210'.
  533.      translit(`GNUs not Unix', `A-Z')
  534.      =>s not nix
  535.      translit(`GNUs not Unix', `a-z', `A-Z')
  536.      =>GNUS NOT UNIX
  537.      translit(`GNUs not Unix', `A-Z', `z-a')
  538.      =>tmfs not fnix
  539.    The first example deletes all uppercase letters, the second converts
  540. lowercase to uppercase, and the third `mirrors' all uppercase letters,
  541. while converting them to lowercase.  The two first cases are by far the
  542. most common.
  543.    The builtin macro `translit' is recognized only when given arguments.
  544. File: m4.info,  Node: Patsubst,  Next: Format,  Prev: Translit,  Up: Text handling
  545. Substituting text by regular expression
  546. =======================================
  547.    Global substitution in a string is done by `patsubst':
  548.      patsubst(STRING, REGEXP, opt REPLACEMENT)
  549. which searches STRING for matches of REGEXP, and substitutes
  550. REPLACEMENT for each match.  The syntax for regular expressions is the
  551. same as in GNU Emacs.
  552.    The parts of STRING that are not covered by any match of REGEXP are
  553. copied to the expansion.  Whenever a match is found, the search
  554. proceeds from the end of the match, so a character from STRING will
  555. never be substituted twice.  If REGEXP matches a string of zero length,
  556. the start position for the search is incremented, to avoid infinite
  557. loops.
  558.    When a replacement is to be made, REPLACEMENT is inserted into the
  559. expansion, with `\N' substituted by the text matched by the Nth
  560. parenthesized sub-expression of REGEXP, `\&' being the text the entire
  561. regular expression matched.
  562.    The REPLACEMENT argument can be omitted, in which case the text
  563. matched by REGEXP is deleted.
  564.      patsubst(`GNUs not Unix', `^', `OBS: ')
  565.      =>OBS: GNUs not Unix
  566.      patsubst(`GNUs not Unix', `\<', `OBS: ')
  567.      =>OBS: GNUs OBS: not OBS: Unix
  568.      patsubst(`GNUs not Unix', `\w*', `(\&)')
  569.      =>(GNUs)() (not)() (Unix)
  570.      patsubst(`GNUs not Unix', `\w+', `(\&)')
  571.      =>(GNUs) (not) (Unix)
  572.      patsubst(`GNUs not Unix', `[A-Z][a-z]+')
  573.      =>GN not
  574.    Here is a slightly more realistic example, which capitalizes
  575. individual word or whole sentences, by substituting calls of the macros
  576. `upcase' and `downcase' into the strings.
  577.      define(`upcase', `translit(`$*', `a-z', `A-Z')')dnl
  578.      define(`downcase', `translit(`$*', `A-Z', `a-z')')dnl
  579.      define(`capitalize1',
  580.           `regexp(`$1', `^\(\w\)\(\w*\)', `upcase(`\1')`'downcase(`\2')')')dnl
  581.      define(`capitalize',
  582.           `patsubst(`$1', `\w+', `capitalize1(`\&')')')dnl
  583.      capitalize(`GNUs not Unix')
  584.      =>Gnus Not Unix
  585.    The builtin macro `patsubst' is recognized only when given arguments.
  586. File: m4.info,  Node: Format,  Prev: Patsubst,  Up: Text handling
  587. Formatted output
  588. ================
  589.    Formatted output can be made with `format':
  590.      format(FORMAT-STRING, ...)
  591. which works much like the C function `printf'.  The first argument is a
  592. format string, which can contain `%' specifications, and the expansion
  593. of `format' is the formatted string.
  594.    Its use is best described by a few examples:
  595.      define(`foo', `The brown fox jumped over the lazy dog')
  596.      =>
  597.      format(`The string "%s" is %d characters long', foo, len(foo))
  598.      =>The string "The brown fox jumped over the lazy dog" is 38 characters long
  599.    Using the `forloop' macro defined in *Note Loops::, this example
  600. shows how `format' can be used to produce tabular output.
  601.      forloop(`i', 1, 10, `format(`%6d squared is %10d
  602.      ', i, eval(i**2))')
  603.      =>     1 squared is        1
  604.      =>     2 squared is        4
  605.      =>     3 squared is        9
  606.      =>     4 squared is       16
  607.      =>     5 squared is       25
  608.      =>     6 squared is       36
  609.      =>     7 squared is       49
  610.      =>     8 squared is       64
  611.      =>     9 squared is       81
  612.      =>    10 squared is      100
  613.    The builtin `format' is modeled after the ANSI C `printf' function,
  614. and supports the normal `%' specifiers: `c', `s', `d', `o', `x', `X',
  615. `u', `e', `E' and `f'; it supports field widths and precisions, and the
  616. modifiers `+', `-', ` ', `0', `#', `h' and `l'.  For more details on
  617. the functioning of `printf', see the C Library Manual.
  618. File: m4.info,  Node: Arithmetic,  Next: UNIX commands,  Prev: Text handling,  Up: Top
  619. Macros for doing arithmetic
  620. ***************************
  621.    Integer arithmetic is included in `m4', with a C-like syntax.  As
  622. convenient shorthands, there are builtins for simple increment and
  623. decrement operations.
  624. * Menu:
  625. * Incr::                        Decrement and increment operators
  626. * Eval::                        Evaluating integer expressions
  627. File: m4.info,  Node: Incr,  Next: Eval,  Prev: Arithmetic,  Up: Arithmetic
  628. Decrement and increment operators
  629. =================================
  630.    Increment and decrement of integers are supported using the builtins
  631. `incr' and `decr':
  632.      incr(NUMBER)
  633.      decr(NUMBER)
  634. which expand to the numerical value of NUMBER, incremented, or
  635. decremented, respectively, by one.
  636.      incr(4)
  637.      =>5
  638.      decr(7)
  639.      =>6
  640.    The builtin macros `incr' and `decr' are recognized only when given
  641. arguments.
  642. File: m4.info,  Node: Eval,  Prev: Incr,  Up: Arithmetic
  643. Evaluating integer expressions
  644. ==============================
  645.    Integer expressions are evaluated with `eval':
  646.      eval(EXPRESSION, opt RADIX, opt WIDTH)
  647. which expands to the value of EXPRESSION.
  648.    Expressions can contain the following operators, listed in order of
  649. decreasing precedence.
  650.      Unary minus
  651.      Exponentiation
  652. `*  /  %'
  653.      Multiplication, division and modulo
  654. `+  -'
  655.      Addition and subtraction
  656. `<<  >>'
  657.      Shift left or right
  658. `==  !=  >  >=  <  <='
  659.      Relational operators
  660.      Logical negation
  661.      Bitwise negation
  662.      Bitwise and
  663.      Bitwise exclusive-or
  664.      Bitwise or
  665.      Logical and
  666.      Logical or
  667.    All operators, except exponentiation, are left associative.
  668.    Note that many `m4' implementations use `^' as an alternate operator
  669. for the exponentiation, while many others use `^' for the bitwise
  670. exclusive-or.  GNU `m4' changed its behavior: it used to exponentiate
  671. for `^', it now computes the bitwise exclusive-or.
  672.    Numbers without special prefix are given decimal.  A simple `0'
  673. prefix introduces an octal number.  `0x' introduces an hexadecimal
  674. number.  `0b' introduces a binary number.  `0r' introduces a number
  675. expressed in any radix between 1 and 36: the prefix should be
  676. immediately followed by the decimal expression of the radix, a colon,
  677. then the digits making the number.  For any radix, the digits are `0',
  678. `1', `2', ....  Beyond `9', the digits are `a', `b' ... up to `z'.
  679. Lower and upper case letters can be used interchangeably in numbers
  680. prefixes and as number digits.
  681.    Parentheses may be used to group subexpressions whenever needed.
  682. For the relational operators, a true relation returns `1', and a false
  683. relation return `0'.
  684.    Here are a few examples of use of `eval'.
  685.      eval(-3 * 5)
  686.      =>-15
  687.      eval(index(`Hello world', `llo') >= 0)
  688.      =>1
  689.      define(`square', `eval(($1)**2)')
  690.      =>
  691.      square(9)
  692.      =>81
  693.      square(square(5)+1)
  694.      =>676
  695.      define(`foo', `666')
  696.      =>
  697.      eval(`foo'/6)
  698.      error-->51.eval:14: m4: Bad expression in eval: foo/6
  699.      =>
  700.      eval(foo/6)
  701.      =>111
  702.    As the second to last example shows, `eval' does not handle macro
  703. names, even if they expand to a valid expression (or part of a valid
  704. expression).  Therefore all macros must be expanded before they are
  705. passed to `eval'.
  706.    If RADIX is specified, it specifies the radix to be used in the
  707. expansion.  The default radix is 10.  The result of `eval' is always
  708. taken to be signed.  The WIDTH argument specifies a minimum output
  709. width.  The result is zero-padded to extend the expansion to the
  710. requested width.
  711.      eval(666, 10)
  712.      =>666
  713.      eval(666, 11)
  714.      =>556
  715.      eval(666, 6)
  716.      =>3030
  717.      eval(666, 6, 10)
  718.      =>0000003030
  719.      eval(-666, 6, 10)
  720.      =>-000003030
  721.    Take note that RADIX cannot be larger than 36.
  722.    The builtin macro `eval' is recognized only when given arguments.
  723. File: m4.info,  Node: UNIX commands,  Next: Miscellaneous,  Prev: Arithmetic,  Up: Top
  724. Running UNIX commands
  725. *********************
  726.    There are a few builtin macros in `m4' that allow you to run UNIX
  727. commands from within `m4'.
  728. * Menu:
  729. * Syscmd::                      Executing simple commands
  730. * Esyscmd::                     Reading the output of commands
  731. * Sysval::                      Exit codes
  732. * Maketemp::                    Making names for temporary files
  733. File: m4.info,  Node: Syscmd,  Next: Esyscmd,  Prev: UNIX commands,  Up: UNIX commands
  734. Executing simple commands
  735. =========================
  736.    Any shell command can be executed, using `syscmd':
  737.      syscmd(SHELL-COMMAND)
  738. which executes SHELL-COMMAND as a shell command.
  739.    The expansion of `syscmd' is void, *not* the output from
  740. SHELL-COMMAND!  Output or error messages from SHELL-COMMAND are not
  741. read by `m4'.  *Note Esyscmd:: if you need to process the command
  742. output.
  743.    Prior to executing the command, `m4' flushes its output buffers.
  744. The default standard input, output and error of SHELL-COMMAND are the
  745. same as those of `m4'.
  746.    The builtin macro `syscmd' is recognized only when given arguments.
  747. File: m4.info,  Node: Esyscmd,  Next: Sysval,  Prev: Syscmd,  Up: UNIX commands
  748. Reading the output of commands
  749. ==============================
  750.    If you want `m4' to read the output of a UNIX command, use `esyscmd':
  751.      esyscmd(SHELL-COMMAND)
  752. which expands to the standard output of the shell command SHELL-COMMAND.
  753.    Prior to executing the command, `m4' flushes its output buffers.
  754. The default standard input and error output of SHELL-COMMAND are the
  755. same as those of `m4'.  The error output of SHELL-COMMAND is not a part
  756. of the expansion: it will appear along with the error output of `m4'.
  757.    Assume you are positioned into the `checks' directory of GNU `m4'
  758. distribution, then:
  759.      define(`vice', `esyscmd(grep Vice ../COPYING)')
  760.      =>
  761.      vice
  762.      =>  Ty Coon, President of Vice
  763.      =>
  764.    Note how the expansion of `esyscmd' has a trailing newline.
  765.    The builtin macro `esyscmd' is recognized only when given arguments.
  766. File: m4.info,  Node: Sysval,  Next: Maketemp,  Prev: Esyscmd,  Up: UNIX commands
  767. Exit codes
  768. ==========
  769.    To see whether a shell command succeeded, use `sysval':
  770.      sysval
  771. which expands to the exit status of the last shell command run with
  772. `syscmd' or `esyscmd'.
  773.      syscmd(`false')
  774.      =>
  775.      ifelse(sysval, 0, zero, non-zero)
  776.      =>non-zero
  777.      syscmd(`true')
  778.      =>
  779.      sysval
  780.      =>0
  781. File: m4.info,  Node: Maketemp,  Prev: Sysval,  Up: UNIX commands
  782. Making names for temporary files
  783. ================================
  784.    Commands specified to `syscmd' or `esyscmd' might need a temporary
  785. file, for output or for some other purpose.  There is a builtin macro,
  786. `maketemp', for making temporary file names:
  787.      maketemp(TEMPLATE)
  788. which expands to a name of a non-existent file, made from the string
  789. TEMPLATE, which should end with the string `XXXXXX'.  The six `X''s are
  790. then replaced, usually with something that includes the process id of
  791. the `m4' process, in order to make the filename unique.
  792.      maketemp(`/tmp/fooXXXXXX')
  793.      =>/tmp/fooa07346
  794.      maketemp(`/tmp/fooXXXXXX')
  795.      =>/tmp/fooa07346
  796.    As seen in the example, several calls of `maketemp' might expand to
  797. the same string, since the selection criteria is whether the file exists
  798. or not.  If a file has not been created before the next call, the two
  799. macro calls might expand to the same name.
  800.    The builtin macro `maketemp' is recognized only when given arguments.
  801. File: m4.info,  Node: Miscellaneous,  Next: Frozen files,  Prev: UNIX commands,  Up: Top
  802. Miscellaneous builtin macros
  803. ****************************
  804.    This chapter describes various builtins, that do not really belong in
  805. any of the previous chapters.
  806. * Menu:
  807. * Errprint::                    Printing error messages
  808. * M4exit::                      Exiting from m4
  809. File: m4.info,  Node: Errprint,  Next: M4exit,  Prev: Miscellaneous,  Up: Miscellaneous
  810. Printing error messages
  811. =======================
  812.    You can print error messages using `errprint':
  813.      errprint(MESSAGE, ...)
  814. which simply prints MESSAGE and the rest of the arguments on the
  815. standard error output.
  816.    The expansion of `errprint' is void.
  817.      errprint(`Illegal arguments to forloop
  818.      ')
  819.      error-->Illegal arguments to forloop
  820.      =>
  821.    A trailing newline is *not* printed automatically, so it must be
  822. supplied as part of the argument, as in the example.  (BSD flavored
  823. `m4''s do append a trailing newline on each `errprint' call).
  824.    To make it possible to specify the location of the error, two
  825. utility builtins exist:
  826.      __file__
  827.      __line__
  828. which expands to the quoted name of the current input file, and the
  829. current input line number in that file.
  830.      errprint(`m4:'__file__:__line__: `Input error
  831.      ')
  832.      error-->m4:56.errprint:2: Input error
  833.      =>
  834. File: m4.info,  Node: M4exit,  Prev: Errprint,  Up: Miscellaneous
  835. Exiting from `m4'
  836. =================
  837.    If you need to exit from `m4' before the entire input has been read,
  838. you can use `m4exit':
  839.      m4exit(opt CODE)
  840. which causes `m4' to exit, with exit code CODE.  If CODE is left out,
  841. the exit code is zero.
  842.      define(`fatal_error', `errprint(`m4: '__file__: __line__`: fatal error: $*
  843.      ')m4exit(1)')
  844.      =>
  845.      fatal_error(`This is a BAD one, buster')
  846.      error-->m4: 57.m4exit: 5: fatal error: This is a BAD one, buster
  847.    After this macro call, `m4' will exit with exit code 1.  This macro
  848. is only intended for error exits, since the normal exit procedures are
  849. not followed, e.g., diverted text is not undiverted, and saved text
  850. (*note M4wrap::.) is not reread.
  851. File: m4.info,  Node: Frozen files,  Next: Compatibility,  Prev: Miscellaneous,  Up: Top
  852. Fast loading of frozen states
  853. *****************************
  854.    Some bigger `m4' applications may be built over a common base
  855. containing hundreds of definitions and other costly initializations.
  856. Usually, the common base is kept in one or more declarative files,
  857. which files are listed on each `m4' invocation prior to the user's
  858. input file, or else, `include''d from this input file.
  859.    Reading the common base of a big application, over and over again,
  860. may be time consuming.  GNU `m4' offers some machinery to speed up the
  861. start of an application using lengthy common bases.  Presume the user
  862. repeatedly uses:
  863.      m4 base.m4 input.m4
  864. with a varying contents of `input.m4', but a rather fixed contents for
  865. `base.m4'.  Then, the user might rather execute:
  866.      m4 -F base.m4f base.m4
  867. once, and further execute, as often as needed:
  868.      m4 -R base.m4f input.m4
  869. with the varying input.  The first call, containing the `-F' option,
  870. only reads and executes file `base.m4', so defining various application
  871. macros and computing other initializations.  Only once the input file
  872. `base.m4' has been completely processed, GNU `m4' produces on
  873. `base.m4f' a "frozen" file, that is, a file which contains a kind of
  874. snapshot of the `m4' internal state.
  875.    Later calls, containing the `-R' option, are able to reload the
  876. internal state of `m4''s memory, from `base.m4f', *prior* to reading
  877. any other input files.  By this mean, instead of starting with a virgin
  878. copy of `m4', input will be read after having effectively recovered the
  879. effect of a prior run.  In our example, the effect is the same as if
  880. file `base.m4' has been read anew.  However, this effect is achieved a
  881. lot faster.
  882.    Only one frozen file may be created or read in any one `m4'
  883. invocation.  It is not possible to recover two frozen files at once.
  884. However, frozen files may be updated incrementally, through using `-R'
  885. and `-F' options simultaneously.  For example, if some care is taken,
  886. the command:
  887.      m4 file1.m4 file2.m4 file3.m4 file4.m4
  888. could be broken down in the following sequence, accumulating the same
  889. output:
  890.      m4 -F file1.m4f file1.m4
  891.      m4 -R file1.m4f -F file2.m4f file2.m4
  892.      m4 -R file2.m4f -F file3.m4f file3.m4
  893.      m4 -R file3.m4f file4.m4
  894.    Some care is necessary because not every effort has been made for
  895. this to work in all cases.  In particular, the trace attribute of
  896. macros is not handled, nor the current setting of `changeword'.  Also,
  897. interactions for some options of `m4' being used in one call and not
  898. for the next, have not been fully analyzed yet.  On the other end, you
  899. may be confident that stacks of `pushdef''ed definitions are handled
  900. correctly, so are `undefine''d or renamed builtins, changed strings for
  901. quotes or comments.
  902.    When an `m4' run is to be frozen, the automatic undiversion which
  903. takes place at end of execution is inhibited.  Instead, all positively
  904. numbered diversions are saved into the frozen file.  The active
  905. diversion number is also transmitted.
  906.    A frozen file to be reloaded need not reside in the current
  907. directory.  It is looked up the same way as an `include' file (*note
  908. Search Path::.).
  909.    Frozen files are sharable across architectures.  It is safe to write
  910. a frozen file one one machine and read it on another, given that the
  911. second machine uses the same, or a newer version of GNU `m4'.  These
  912. are simple (editable) text files, made up of directives, each starting
  913. with a capital letter and ending with a newline (NL).  Wherever a
  914. directive is expected, the character `#' introduces a comment line,
  915. empty lines are also ignored.  In the following descriptions, LENGTHs
  916. always refer to corresponding STRINGs.  Numbers are always expressed in
  917. decimal.  The directives are:
  918. `V NUMBER NL'
  919.      Confirms the format of the file.  NUMBER should be 1.
  920. `C LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  921.      Uses STRING1 and STRING2 as the beginning comment and end comment
  922.      strings.
  923. `Q LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  924.      Uses STRING1 and STRING2 as the beginning quote and end quote
  925.      strings.
  926. `F LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  927.      Defines, through `pushdef', a definition for STRING1 expanding to
  928.      the function whose builtin name is STRING2.
  929. `T LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  930.      Defines, though `pushdef', a definition for STRING1 expanding to
  931.      the text given by STRING2.
  932. `D NUMBER, LENGTH NL STRING NL'
  933.      Selects diversion NUMBER, making it current, then copy STRING in
  934.      the current diversion.  NUMBER may be a negative number for a
  935.      non-existing diversion.  To merely specify an active selection,
  936.      use this command with an empty STRING.  With 0 as the diversion
  937.      NUMBER, STRING will be issued on standard output at reload time,
  938.      however this may not be produced from within `m4'.
  939. File: m4.info,  Node: Compatibility,  Next: Concept index,  Prev: Frozen files,  Up: Top
  940. Compatibility with other versions of `m4'
  941. *****************************************
  942.    This chapter describes the differences between this implementation of
  943. `m4', and the implementation found under UNIX, notably System V,
  944. Release 3.
  945.    There are also differences in BSD flavors of `m4'.  No attempt is
  946. made to summarize these here.
  947. * Menu:
  948. * Extensions::                  Extensions in GNU m4
  949. * Incompatibilities::           Facilities in System V m4 not in GNU m4
  950. * Other Incompat::              Other incompatibilities
  951. File: m4.info,  Node: Extensions,  Next: Incompatibilities,  Prev: Compatibility,  Up: Compatibility
  952. Extensions in GNU `m4'
  953. ======================
  954.    This version of `m4' contains a few facilities, that do not exist in
  955. System V `m4'.  These extra facilities are all suppressed by using the
  956. `-G' command line option, unless overridden by other command line
  957. options.
  958.    * In the `$'N notation for macro arguments, N can contain several
  959.      digits, while the System V `m4' only accepts one digit.  This
  960.      allows macros in GNU `m4' to take any number of arguments, and not
  961.      only nine (*note Arguments::.).
  962.    * Files included with `include' and `sinclude' are sought in a user
  963.      specified search path, if they are not found in the working
  964.      directory.  The search path is specified by the `-I' option and the
  965.      `M4PATH' environment variable (*note Search Path::.).
  966.    * Arguments to `undivert' can be non-numeric, in which case the named
  967.      file will be included uninterpreted in the output (*note
  968.      Undivert::.).
  969.    * Formatted output is supported through the `format' builtin, which
  970.      is modeled after the C library function `printf' (*note Format::.).
  971.    * Searches and text substitution through regular expressions are
  972.      supported by the `regexp' (*note Regexp::.) and `patsubst' (*note
  973.      Patsubst::.) builtins.
  974.    * The output of shell commands can be read into `m4' with `esyscmd'
  975.      (*note Esyscmd::.).
  976.    * There is indirect access to any builtin macro with `builtin'
  977.      (*note Builtin::.).
  978.    * Macros can be called indirectly through `indir' (*note Indir::.).
  979.    * The name of the current input file and the current input line
  980.      number are accessible through the builtins `__file__' and
  981.      `__line__' (*note Errprint::.).
  982.    * The format of the output from `dumpdef' and macro tracing can be
  983.      controlled with `debugmode' (*note Debug Levels::.).
  984.    * The destination of trace and debug output can be controlled with
  985.      `debugfile' (*note Debug Output::.).
  986.    In addition to the above extensions, GNU `m4' implements the
  987. following command line options: `-F', `-G', `-I', `-L', `-R', `-V',
  988. `-W', `-d', `-l', `-o' and `-t'.  *Note Invoking m4::, for a
  989. description of these options.
  990.    Also, the debugging and tracing facilities in GNU `m4' are much more
  991. extensive than in most other versions of `m4'.
  992. File: m4.info,  Node: Incompatibilities,  Next: Other Incompat,  Prev: Extensions,  Up: Compatibility
  993. Facilities in System V `m4' not in GNU `m4'
  994. ===========================================
  995.    The version of `m4' from System V contains a few facilities that
  996. have not been implemented in GNU `m4' yet.
  997.    * System V `m4' supports multiple arguments to `defn'.  This is not
  998.      implemented in GNU `m4'.  Its usefulness is unclear to me.
  999. File: m4.info,  Node: Other Incompat,  Prev: Incompatibilities,  Up: Compatibility
  1000. Other incompatibilities
  1001. =======================
  1002.    There are a few other incompatibilities between this implementation
  1003. of `m4', and the System V version.
  1004.    * GNU `m4' implements sync lines differently from System V `m4',
  1005.      when text is being diverted.  GNU `m4' outputs the sync lines when
  1006.      the text is being diverted, and System V `m4' when the diverted
  1007.      text is being brought back.
  1008.      The problem is which lines and filenames should be attached to
  1009.      text that is being, or has been, diverted.  System V `m4' regards
  1010.      all the diverted text as being generated by the source line
  1011.      containing the `undivert' call, whereas GNU `m4' regards the
  1012.      diverted text as being generated at the time it is diverted.
  1013.      I expect the sync line option to be used mostly when using `m4' as
  1014.      a front end to a compiler.  If a diverted line causes a compiler
  1015.      error, the error messages should most probably refer to the place
  1016.      where the diversion were made, and not where it was inserted again.
  1017.    * GNU `m4' makes no attempt at prohiting autoreferential definitions
  1018.      like:
  1019.           define(`x', `x')
  1020.           define(`x', `x ')
  1021.      There is nothing inherently wrong with defining `x' to return `x'.
  1022.      The wrong thing is to expand `x' unquoted.  In `m4', one might
  1023.      use macros to hold strings, as we do for variables in other
  1024.      programming languages, further checking them with:
  1025.           ifelse(defn(`HOLDER'), `VALUE', ...)
  1026.      In cases like this one, an interdiction for a macro to hold its own
  1027.      name would be a useless limitation.  Of course, this leave more
  1028.      rope for the GNU `m4' user to hang himself!  Rescanning hangs may
  1029.      be avoided through careful programming, a little like for endless
  1030.      loops in traditional programming languages.
  1031.    * GNU `m4' without `-G' option will define the macro `__gnu__' to
  1032.      expand to the empty string.
  1033.      On UNIX systems, GNU `m4' without the `-G' option will define the
  1034.      macro `__unix__', otherwise the macro `unix'.  Both will expand to
  1035.      the empty string.
  1036.