home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / info / m4.info-2 < prev    next >
Encoding:
GNU Info File  |  1996-10-12  |  46.6 KB  |  1,469 lines

  1. This is Info file m4.info, produced by Makeinfo-1.63 from the input
  2. file m4.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * m4: (m4).            A powerful macro processor.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the GNU `m4' utility.
  9.  
  10.    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994 Free Software
  11. Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided that
  19. the entire resulting derived work is distributed under the terms of a
  20. permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions, except that this permission notice may be stated in a
  25. translation approved by the Foundation.
  26.  
  27. 
  28. File: m4.info,  Node: Debug Output,  Prev: Debug Levels,  Up: Debugging
  29.  
  30. Saving debugging output
  31. =======================
  32.  
  33.    Debug and tracing output can be redirected to files using either the
  34. `-o' option to `m4', or with the builtin macro `debugfile':
  35.  
  36.      debugfile(opt FILENAME)
  37.  
  38. will send all further debug and trace output to FILENAME.  If FILENAME
  39. is empty, debug and trace output are discarded and if `debugfile' is
  40. called without any arguments, debug and trace output are sent to the
  41. standard error output.
  42.  
  43. 
  44. File: m4.info,  Node: Input Control,  Next: File Inclusion,  Prev: Debugging,  Up: Top
  45.  
  46. Input control
  47. *************
  48.  
  49.    This chapter describes various builtin macros for controlling the
  50. input to `m4'.
  51.  
  52. * Menu:
  53.  
  54. * Dnl::                         Deleting whitespace in input
  55. * Changequote::                 Changing the quote characters
  56. * Changecom::                   Changing the comment delimiters
  57. * Changeword::                  Changing the lexical structure of words
  58. * M4wrap::                      Saving input until end of input
  59.  
  60. 
  61. File: m4.info,  Node: Dnl,  Next: Changequote,  Prev: Input Control,  Up: Input Control
  62.  
  63. Deleting whitespace in input
  64. ============================
  65.  
  66.    The builtin `dnl' reads and discards all characters, up to and
  67. including the first newline:
  68.  
  69.      dnl
  70.  
  71. and it is often used in connection with `define', to remove the newline
  72. that follow the call to `define'.  Thus
  73.  
  74.      define(`foo', `Macro `foo'.')dnl A very simple macro, indeed.
  75.      foo
  76.      =>Macro foo.
  77.  
  78.    The input up to and including the next newline is discarded, as
  79. opposed to the way comments are treated (*note Comments::.).
  80.  
  81.    Usually, `dnl' is immediately followed by an end of line or some
  82. other whitespace.  GNU `m4' will produce a warning diagnostic if `dnl'
  83. is followed by an open parenthesis.  In this case, `dnl' will collect
  84. and process all arguments, looking for a matching close parenthesis.
  85. All predictable side effects resulting from this collection will take
  86. place.  `dnl' will return no output.  The input following the matching
  87. close parenthesis up to and including the next newline, on whatever
  88. line containing it, will still be discarded.
  89.  
  90. 
  91. File: m4.info,  Node: Changequote,  Next: Changecom,  Prev: Dnl,  Up: Input Control
  92.  
  93. Changing the quote characters
  94. =============================
  95.  
  96.    The default quote delimiters can be changed with the builtin
  97. `changequote':
  98.  
  99.      changequote(opt START, opt END)
  100.  
  101. where START is the new start-quote delimiter and END is the new
  102. end-quote delimiter.  If any of the arguments are missing, the default
  103. quotes (``' and `'') are used instead of the void arguments.
  104.  
  105.    The expansion of `changequote' is void.
  106.  
  107.      changequote([, ])
  108.      =>
  109.      define([foo], [Macro [foo].])
  110.      =>
  111.      foo
  112.      =>Macro foo.
  113.  
  114.    If no single character is appropriate, START and END can be of any
  115. length.
  116.  
  117.      changequote([[, ]])
  118.      =>
  119.      define([[foo]], [[Macro [[[foo]]].]])
  120.      =>
  121.      foo
  122.      =>Macro [foo].
  123.  
  124.    Changing the quotes to the empty strings will effectively disable the
  125. quoting mechanism, leaving no way to quote text.
  126.  
  127.      define(`foo', `Macro `FOO'.')
  128.      =>
  129.      changequote(, )
  130.      =>
  131.      foo
  132.      =>Macro `FOO'.
  133.      `foo'
  134.      =>`Macro `FOO'.'
  135.  
  136.    There is no way in `m4' to quote a string containing an unmatched
  137. left quote, except using `changequote' to change the current quotes.
  138.  
  139.    Neither quote string should start with a letter or `_' (underscore),
  140. as they will be confused with names in the input.  Doing so disables
  141. the quoting mechanism.
  142.  
  143. 
  144. File: m4.info,  Node: Changecom,  Next: Changeword,  Prev: Changequote,  Up: Input Control
  145.  
  146. Changing comment delimiters
  147. ===========================
  148.  
  149.    The default comment delimiters can be changed with the builtin macro
  150. `changecom':
  151.  
  152.      changecom(opt START, opt END)
  153.  
  154. where START is the new start-comment delimiter and END is the new
  155. end-comment delimiter.  If any of the arguments are void, the default
  156. comment delimiters (`#' and newline) are used instead of the void
  157. arguments.  The comment delimiters can be of any length.
  158.  
  159.    The expansion of `changecom' is void.
  160.  
  161.      define(`comment', `COMMENT')
  162.      =>
  163.      # A normal comment
  164.      =># A normal comment
  165.      changecom(`/*', `*/')
  166.      =>
  167.      # Not a comment anymore
  168.      =># Not a COMMENT anymore
  169.      But: /* this is a comment now */ while this is not a comment
  170.      =>But: /* this is a comment now */ while this is not a COMMENT
  171.  
  172.    Note how comments are copied to the output, much as if they were
  173. quoted strings.  If you want the text inside a comment expanded, quote
  174. the start comment delimiter.
  175.  
  176.    Calling `changecom' without any arguments disables the commenting
  177. mechanism completely.
  178.  
  179.      define(`comment', `COMMENT')
  180.      =>
  181.      changecom
  182.      =>
  183.      # Not a comment anymore
  184.      =># Not a COMMENT anymore
  185.  
  186. 
  187. File: m4.info,  Node: Changeword,  Next: M4wrap,  Prev: Changecom,  Up: Input Control
  188.  
  189. Changing the lexical structure of words
  190. =======================================
  191.  
  192.      The macro `changeword' and all associated functionnality is
  193.      experimental.  It is only available if the `--enable-changeword'
  194.      option was given to `configure', at GNU `m4' installation time.
  195.      The functionnality might change or even go away in the future.
  196.      *Do not rely on it*.  Please direct your comments about it the
  197.      same way you would do for bugs.
  198.  
  199.    A file being processed by `m4' is split into quoted strings, words
  200. (potential macro names) and simple tokens (any other single character).
  201. Initially a word is defined by the following regular expression:
  202.  
  203.      [_a-zA-Z][_a-zA-Z0-9]*
  204.  
  205.    Using `changeword', you can change this regular expression.  Relaxing
  206. `m4''s lexical rules might be useful (for example) if you wanted to
  207. apply translations to a file of numbers:
  208.  
  209.      changeword(`[_a-zA-Z0-9]+')
  210.      define(1, 0)
  211.      =>1
  212.  
  213.    Tightening the lexical rules is less useful, because it will
  214. generally make some of the builtins unavailable.  You could use it to
  215. prevent accidental call of builtins, for example:
  216.  
  217.      define(`_indir', defn(`indir'))
  218.      changeword(`_[_a-zA-Z0-9]*')
  219.      esyscmd(foo)
  220.      _indir(`esyscmd', `ls')
  221.  
  222.    Because `m4' constructs its words a character at a time, there is a
  223. restriction on the regular expressions that may be passed to
  224. `changeword'.  This is that if your regular expression accepts `foo',
  225. it must also accept `f' and `fo'.
  226.  
  227.    `changeword' has another function.  If the regular expression
  228. supplied contains any bracketed subexpressions, then text outside the
  229. first of these is discarded before symbol lookup.  So:
  230.  
  231.      changecom(`/*', `*/')
  232.      changeword(`#\([_a-zA-Z0-9]*\)')
  233.      #esyscmd(ls)
  234.  
  235.    `m4' now requires a `#' mark at the beginning of every macro
  236. invocation, so one can use `m4' to preprocess shell scripts without
  237. getting `shift' commands swallowed, and plain text without losing
  238. various common words.
  239.  
  240.    `m4''s macro substitution is based on text, while TeX's is based on
  241. tokens.  `changeword' can throw this difference into relief.  For
  242. example, here is the same idea represented in TeX and `m4'.  First, the
  243. TeX version:
  244.  
  245.      \def\a{\message{Hello}}
  246.      \catcode`\@=0
  247.      \catcode`\\=12
  248.      =>@a
  249.      =>@bye
  250.  
  251. Then, the `m4' version:
  252.  
  253.      define(a, `errprint(`Hello')')
  254.      changeword(`@\([_a-zA-Z0-9]*\)')
  255.      =>@a
  256.  
  257.    In the TeX example, the first line defines a macro `a' to print the
  258. message `Hello'.  The second line defines @ to be usable instead of \
  259. as an escape character.  The third line defines \ to be a normal
  260. printing character, not an escape.  The fourth line invokes the macro
  261. `a'.  So, when TeX is run on this file, it displays the message `Hello'.
  262.  
  263.    When the `m4' example is passed through `m4', it outputs
  264. `errprint(Hello)'.  The reason for this is that TeX does lexical
  265. analysis of macro definition when the macro is *defined*.  `m4' just
  266. stores the text, postponing the lexical analysis until the macro is
  267. *used*.
  268.  
  269.    You should note that using `changeword' will slow `m4' down by a
  270. factor of about seven.
  271.  
  272. 
  273. File: m4.info,  Node: M4wrap,  Prev: Changeword,  Up: Input Control
  274.  
  275. Saving input
  276. ============
  277.  
  278.    It is possible to `save' some text until the end of the normal input
  279. has been seen.  Text can be saved, to be read again by `m4' when the
  280. normal input has been exhausted.  This feature is normally used to
  281. initiate cleanup actions before normal exit, e.g., deleting temporary
  282. files.
  283.  
  284.    To save input text, use the builtin `m4wrap':
  285.  
  286.      m4wrap(STRING, ...)
  287.  
  288. which stores STRING and the rest of the arguments in a safe place, to
  289. be reread when end of input is reached.
  290.  
  291.      define(`cleanup', `This is the `cleanup' actions.
  292.      ')
  293.      =>
  294.      m4wrap(`cleanup')
  295.      =>
  296.      This is the first and last normal input line.
  297.      =>This is the first and last normal input line.
  298.      ^D
  299.      =>This is the cleanup actions.
  300.  
  301.    The saved input is only reread when the end of normal input is seen,
  302. and not if `m4exit' is used to exit `m4'.
  303.  
  304.    It is safe to call `m4wrap' from saved text, but then the order in
  305. which the saved text is reread is undefined.  If `m4wrap' is not used
  306. recursively, the saved pieces of text are reread in the opposite order
  307. in which they were saved (LIFO--last in, first out).
  308.  
  309. 
  310. File: m4.info,  Node: File Inclusion,  Next: Diversions,  Prev: Input Control,  Up: Top
  311.  
  312. File inclusion
  313. **************
  314.  
  315.    `m4' allows you to include named files at any point in the input.
  316.  
  317. * Menu:
  318.  
  319. * Include::                     Including named files
  320. * Search Path::                 Searching for include files
  321.  
  322. 
  323. File: m4.info,  Node: Include,  Next: Search Path,  Prev: File Inclusion,  Up: File Inclusion
  324.  
  325. Including named files
  326. =====================
  327.  
  328.    There are two builtin macros in `m4' for including files:
  329.  
  330.      include(FILENAME)
  331.      sinclude(FILENAME)
  332.  
  333. both of which cause the file named FILENAME to be read by `m4'.  When
  334. the end of the file is reached, input is resumed from the previous
  335. input file.
  336.  
  337.    The expansion of `include' and `sinclude' is therefore the contents
  338. of FILENAME.
  339.  
  340.    It is an error for an `include'd file not to exist.  If you do not
  341. want error messages about non-existent files, `sinclude' can be used to
  342. include a file, if it exists, expanding to nothing if it does not.
  343.  
  344.      include(`no-such-file')
  345.      =>
  346.      error-->30.include:2: m4: Cannot open no-such-file: No such file or directory
  347.      sinclude(`no-such-file')
  348.      =>
  349.  
  350.    Assume in the following that the file `incl.m4' contains the lines:
  351.      Include file start
  352.      foo
  353.      Include file end
  354.  
  355. Normally file inclusion is used to insert the contents of a file into
  356. the input stream.  The contents of the file will be read by `m4' and
  357. macro calls in the file will be expanded:
  358.  
  359.      define(`foo', `FOO')
  360.      =>
  361.      include(`incl.m4')
  362.      =>Include file start
  363.      =>FOO
  364.      =>Include file end
  365.      =>
  366.  
  367.    The fact that `include' and `sinclude' expand to the contents of the
  368. file can be used to define macros that operate on entire files.  Here
  369. is an example, which defines `bar' to expand to the contents of
  370. `incl.m4':
  371.  
  372.      define(`bar', include(`incl.m4'))
  373.      =>
  374.      This is `bar':  >>>bar<<<
  375.      =>This is bar:  >>>Include file start
  376.      =>foo
  377.      =>Include file end
  378.      =><<<
  379.  
  380.    This use of `include' is not trivial, though, as files can contain
  381. quotes, commas and parentheses, which can interfere with the way the
  382. `m4' parser works.
  383.  
  384.    The builtin macros `include' and `sinclude' are recognized only when
  385. given arguments.
  386.  
  387. 
  388. File: m4.info,  Node: Search Path,  Prev: Include,  Up: File Inclusion
  389.  
  390. Searching for include files
  391. ===========================
  392.  
  393.    GNU `m4' allows included files to be found in other directories than
  394. the current working directory.
  395.  
  396.    If a file is not found in the current working directory, and the file
  397. name is not absolute, the file will be looked for in a specified search
  398. path.  First, the directories specified with the `-I' option will be
  399. searched, in the order found on the command line.  Second, if the
  400. `M4PATH' environment variable is set, it is expected to contain a
  401. colon-separated list of directories, which will be searched in order.
  402.  
  403.    If the automatic search for include-files causes trouble, the `p'
  404. debug flag (*note Debug Levels::.) can help isolate the problem.
  405.  
  406. 
  407. File: m4.info,  Node: Diversions,  Next: Text handling,  Prev: File Inclusion,  Up: Top
  408.  
  409. Diverting and undiverting output
  410. ********************************
  411.  
  412.    Diversions are a way of temporarily saving output.  The output of
  413. `m4' can at any time be diverted to a temporary file, and be reinserted
  414. into the output stream, "undiverted", again at a later time.
  415.  
  416.    Numbered diversions are counted from 0 upwards, diversion number 0
  417. being the normal output stream.  The number of simultaneous diversions
  418. is limited mainly by the memory used to describe them, because GNU `m4'
  419. tries to keep diversions in memory.  However, there is a limit to the
  420. overall memory usable by all diversions taken altogether (512K,
  421. currently).  When this maximum is about to be exceeded, a temporary
  422. file is opened to receive the contents of the biggest diversion still
  423. in memory, freeing this memory for other diversions.  So, it is
  424. theoretically possible that the number of diversions be limited by the
  425. number of available file descriptors.
  426.  
  427. * Menu:
  428.  
  429. * Divert::                      Diverting output
  430. * Undivert::                    Undiverting output
  431. * Divnum::                      Diversion numbers
  432. * Cleardiv::                    Discarding diverted text
  433.  
  434. 
  435. File: m4.info,  Node: Divert,  Next: Undivert,  Prev: Diversions,  Up: Diversions
  436.  
  437. Diverting output
  438. ================
  439.  
  440.    Output is diverted using `divert':
  441.  
  442.      divert(opt NUMBER)
  443.  
  444. where NUMBER is the diversion to be used.  If NUMBER is left out, it is
  445. assumed to be zero.
  446.  
  447.    The expansion of `divert' is void.
  448.  
  449.    When all the `m4' input will have been processed, all existing
  450. diversions are automatically undiverted, in numerical order.
  451.  
  452.      divert(1)
  453.      This text is diverted.
  454.      divert
  455.      =>
  456.      This text is not diverted.
  457.      =>This text is not diverted.
  458.      ^D
  459.      =>
  460.      =>This text is diverted.
  461.  
  462.    Several calls of `divert' with the same argument do not overwrite
  463. the previous diverted text, but append to it.
  464.  
  465.    If output is diverted to a non-existent diversion, it is simply
  466. discarded.  This can be used to suppress unwanted output.  A common
  467. example of unwanted output is the trailing newlines after macro
  468. definitions.  Here is how to avoid them.
  469.  
  470.      divert(-1)
  471.      define(`foo', `Macro `foo'.')
  472.      define(`bar', `Macro `bar'.')
  473.      divert
  474.      =>
  475.  
  476.    This is a common programming idiom in `m4'.
  477.  
  478. 
  479. File: m4.info,  Node: Undivert,  Next: Divnum,  Prev: Divert,  Up: Diversions
  480.  
  481. Undiverting output
  482. ==================
  483.  
  484.    Diverted text can be undiverted explicitly using the builtin
  485. `undivert':
  486.  
  487.      undivert(opt NUMBER, ...)
  488.  
  489. which undiverts the diversions given by the arguments, in the order
  490. given.  If no arguments are supplied, all diversions are undiverted, in
  491. numerical order.
  492.  
  493.    The expansion of `undivert' is void.
  494.  
  495.      divert(1)
  496.      This text is diverted.
  497.      divert
  498.      =>
  499.      This text is not diverted.
  500.      =>This text is not diverted.
  501.      undivert(1)
  502.      =>
  503.      =>This text is diverted.
  504.      =>
  505.  
  506.    Notice the last two blank lines.  One of them comes from the newline
  507. following `undivert', the other from the newline that followed the
  508. `divert'!  A diversion often starts with a blank line like this.
  509.  
  510.    When diverted text is undiverted, it is *not* reread by `m4', but
  511. rather copied directly to the current output, and it is therefore not
  512. an error to undivert into a diversion.
  513.  
  514.    When a diversion has been undiverted, the diverted text is discarded,
  515. and it is not possible to bring back diverted text more than once.
  516.  
  517.      divert(1)
  518.      This text is diverted first.
  519.      divert(0)undivert(1)dnl
  520.      =>
  521.      =>This text is diverted first.
  522.      undivert(1)
  523.      =>
  524.      divert(1)
  525.      This text is also diverted but not appended.
  526.      divert(0)undivert(1)dnl
  527.      =>
  528.      =>This text is also diverted but not appended.
  529.  
  530.    Attempts to undivert the current diversion are silently ignored.
  531.  
  532.    GNU `m4' allows named files to be undiverted.  Given a non-numeric
  533. argument, the contents of the file named will be copied, uninterpreted,
  534. to the current output.  This complements the builtin `include' (*note
  535. Include::.).  To illustrate the difference, assume the file `foo'
  536. contains the word `bar':
  537.  
  538.      define(`bar', `BAR')
  539.      =>
  540.      undivert(`foo')
  541.      =>bar
  542.      =>
  543.      include(`foo')
  544.      =>BAR
  545.      =>
  546.  
  547. 
  548. File: m4.info,  Node: Divnum,  Next: Cleardiv,  Prev: Undivert,  Up: Diversions
  549.  
  550. Diversion numbers
  551. =================
  552.  
  553.    The builtin `divnum':
  554.  
  555.      divnum
  556.  
  557. expands to the number of the current diversion.
  558.  
  559.      Initial divnum
  560.      =>Initial 0
  561.      divert(1)
  562.      Diversion one: divnum
  563.      divert(2)
  564.      Diversion two: divnum
  565.      divert
  566.      =>
  567.      ^D
  568.      =>
  569.      =>Diversion one: 1
  570.      =>
  571.      =>Diversion two: 2
  572.  
  573.    The last call of `divert' without argument is necessary, since the
  574. undiverted text would otherwise be diverted itself.
  575.  
  576. 
  577. File: m4.info,  Node: Cleardiv,  Prev: Divnum,  Up: Diversions
  578.  
  579. Discarding diverted text
  580. ========================
  581.  
  582.    Often it is not known, when output is diverted, whether the diverted
  583. text is actually needed.  Since all non-empty diversion are brought back
  584. on the main output stream when the end of input is seen, a method of
  585. discarding a diversion is needed.  If all diversions should be
  586. discarded, the easiest is to end the input to `m4' with `divert(-1)'
  587. followed by an explicit `undivert':
  588.  
  589.      divert(1)
  590.      Diversion one: divnum
  591.      divert(2)
  592.      Diversion two: divnum
  593.      divert(-1)
  594.      undivert
  595.      ^D
  596.  
  597. No output is produced at all.
  598.  
  599.    Clearing selected diversions can be done with the following macro:
  600.  
  601.      define(`cleardivert',
  602.      `pushdef(`_num', divnum)divert(-1)undivert($@)divert(_num)popdef(`_num')')
  603.      =>
  604.  
  605.    It is called just like `undivert', but the effect is to clear the
  606. diversions, given by the arguments.  (This macro has a nasty bug!  You
  607. should try to see if you can find it and correct it.)
  608.  
  609. 
  610. File: m4.info,  Node: Text handling,  Next: Arithmetic,  Prev: Diversions,  Up: Top
  611.  
  612. Macros for text handling
  613. ************************
  614.  
  615.    There are a number of builtins in `m4' for manipulating text in
  616. various ways, extracting substrings, searching, substituting, and so on.
  617.  
  618. * Menu:
  619.  
  620. * Len::                         Calculating length of strings
  621. * Index::                       Searching for substrings
  622. * Regexp::                      Searching for regular expressions
  623. * Substr::                      Extracting substrings
  624. * Translit::                    Translating characters
  625. * Patsubst::                    Substituting text by regular expression
  626. * Format::                      Formatting strings (printf-like)
  627.  
  628. 
  629. File: m4.info,  Node: Len,  Next: Index,  Prev: Text handling,  Up: Text handling
  630.  
  631. Calculating length of strings
  632. =============================
  633.  
  634.    The length of a string can be calculated by `len':
  635.  
  636.      len(STRING)
  637.  
  638. which expands to the length of STRING, as a decimal number.
  639.  
  640.      len()
  641.      =>0
  642.      len(`abcdef')
  643.      =>6
  644.  
  645.    The builtin macro `len' is recognized only when given arguments.
  646.  
  647. 
  648. File: m4.info,  Node: Index,  Next: Regexp,  Prev: Len,  Up: Text handling
  649.  
  650. Searching for substrings
  651. ========================
  652.  
  653.    Searching for substrings is done with `index':
  654.  
  655.      index(STRING, SUBSTRING)
  656.  
  657. which expands to the index of the first occurrence of SUBSTRING in
  658. STRING.  The first character in STRING has index 0.  If SUBSTRING does
  659. not occur in STRING, `index' expands to `-1'.
  660.  
  661.      index(`gnus, gnats, and armadillos', `nat')
  662.      =>7
  663.      index(`gnus, gnats, and armadillos', `dag')
  664.      =>-1
  665.  
  666.    The builtin macro `index' is recognized only when given arguments.
  667.  
  668. 
  669. File: m4.info,  Node: Regexp,  Next: Substr,  Prev: Index,  Up: Text handling
  670.  
  671. Searching for regular expressions
  672. =================================
  673.  
  674.    Searching for regular expressions is done with the builtin `regexp':
  675.  
  676.      regexp(STRING, REGEXP, opt REPLACEMENT)
  677.  
  678. which searches for REGEXP in STRING.  The syntax for regular
  679. expressions is the same as in GNU Emacs.  *Note Syntax of Regular
  680. Expressions: (emacs)Regexps.
  681.  
  682.    If REPLACEMENT is omitted, `regexp' expands to the index of the
  683. first match of REGEXP in STRING.  If REGEXP does not match anywhere in
  684. STRING, it expands to -1.
  685.  
  686.      regexp(`GNUs not Unix', `\<[a-z]\w+')
  687.      =>5
  688.      regexp(`GNUs not Unix', `\<Q\w*')
  689.      =>-1
  690.  
  691.    If REPLACEMENT is supplied, `regexp' changes the expansion to this
  692. argument, with `\N' substituted by the text matched by the Nth
  693. parenthesized sub-expression of REGEXP, `\&' being the text the entire
  694. regular expression matched.
  695.  
  696.      regexp(`GNUs not Unix', `\w\(\w+\)$', `*** \& *** \1 ***')
  697.      =>*** Unix *** nix ***
  698.  
  699.    The builtin macro `regexp' is recognized only when given arguments.
  700.  
  701. 
  702. File: m4.info,  Node: Substr,  Next: Translit,  Prev: Regexp,  Up: Text handling
  703.  
  704. Extracting substrings
  705. =====================
  706.  
  707.    Substrings are extracted with `substr':
  708.  
  709.      substr(STRING, FROM, opt LENGTH)
  710.  
  711. which expands to the substring of STRING, which starts at index FROM,
  712. and extends for LENGTH characters, or to the end of STRING, if LENGTH
  713. is omitted.  The starting index of a string is always 0.
  714.  
  715.      substr(`gnus, gnats, and armadillos', 6)
  716.      =>gnats, and armadillos
  717.      substr(`gnus, gnats, and armadillos', 6, 5)
  718.      =>gnats
  719.  
  720.    The builtin macro `substr' is recognized only when given arguments.
  721.  
  722. 
  723. File: m4.info,  Node: Translit,  Next: Patsubst,  Prev: Substr,  Up: Text handling
  724.  
  725. Translating characters
  726. ======================
  727.  
  728.    Character translation is done with `translit':
  729.  
  730.      translit(STRING, CHARS, REPLACEMENT)
  731.  
  732. which expands to STRING, with each character that occurs in CHARS
  733. translated into the character from REPLACEMENT with the same index.
  734.  
  735.    If REPLACEMENT is shorter than CHARS, the excess characters are
  736. deleted from the expansion.  If REPLACEMENT is omitted, all characters
  737. in STRING, that are present in CHARS are deleted from the expansion.
  738.  
  739.    Both CHARS and REPLACEMENT can contain character-ranges, e.g., `a-z'
  740. (meaning all lowercase letters) or `0-9' (meaning all digits).  To
  741. include a dash `-' in CHARS or REPLACEMENT, place it first or last.
  742.  
  743.    It is not an error for the last character in the range to be `larger'
  744. than the first.  In that case, the range runs backwards, i.e., `9-0'
  745. means the string `9876543210'.
  746.  
  747.      translit(`GNUs not Unix', `A-Z')
  748.      =>s not nix
  749.      translit(`GNUs not Unix', `a-z', `A-Z')
  750.      =>GNUS NOT UNIX
  751.      translit(`GNUs not Unix', `A-Z', `z-a')
  752.      =>tmfs not fnix
  753.  
  754.    The first example deletes all uppercase letters, the second converts
  755. lowercase to uppercase, and the third `mirrors' all uppercase letters,
  756. while converting them to lowercase.  The two first cases are by far the
  757. most common.
  758.  
  759.    The builtin macro `translit' is recognized only when given arguments.
  760.  
  761. 
  762. File: m4.info,  Node: Patsubst,  Next: Format,  Prev: Translit,  Up: Text handling
  763.  
  764. Substituting text by regular expression
  765. =======================================
  766.  
  767.    Global substitution in a string is done by `patsubst':
  768.  
  769.      patsubst(STRING, REGEXP, opt REPLACEMENT)
  770.  
  771. which searches STRING for matches of REGEXP, and substitutes
  772. REPLACEMENT for each match.  The syntax for regular expressions is the
  773. same as in GNU Emacs.
  774.  
  775.    The parts of STRING that are not covered by any match of REGEXP are
  776. copied to the expansion.  Whenever a match is found, the search
  777. proceeds from the end of the match, so a character from STRING will
  778. never be substituted twice.  If REGEXP matches a string of zero length,
  779. the start position for the search is incremented, to avoid infinite
  780. loops.
  781.  
  782.    When a replacement is to be made, REPLACEMENT is inserted into the
  783. expansion, with `\N' substituted by the text matched by the Nth
  784. parenthesized sub-expression of REGEXP, `\&' being the text the entire
  785. regular expression matched.
  786.  
  787.    The REPLACEMENT argument can be omitted, in which case the text
  788. matched by REGEXP is deleted.
  789.  
  790.      patsubst(`GNUs not Unix', `^', `OBS: ')
  791.      =>OBS: GNUs not Unix
  792.      patsubst(`GNUs not Unix', `\<', `OBS: ')
  793.      =>OBS: GNUs OBS: not OBS: Unix
  794.      patsubst(`GNUs not Unix', `\w*', `(\&)')
  795.      =>(GNUs)() (not)() (Unix)
  796.      patsubst(`GNUs not Unix', `\w+', `(\&)')
  797.      =>(GNUs) (not) (Unix)
  798.      patsubst(`GNUs not Unix', `[A-Z][a-z]+')
  799.      =>GN not
  800.  
  801.    Here is a slightly more realistic example, which capitalizes
  802. individual word or whole sentences, by substituting calls of the macros
  803. `upcase' and `downcase' into the strings.
  804.  
  805.      define(`upcase', `translit(`$*', `a-z', `A-Z')')dnl
  806.      define(`downcase', `translit(`$*', `A-Z', `a-z')')dnl
  807.      define(`capitalize1',
  808.           `regexp(`$1', `^\(\w\)\(\w*\)', `upcase(`\1')`'downcase(`\2')')')dnl
  809.      define(`capitalize',
  810.           `patsubst(`$1', `\w+', `capitalize1(`\&')')')dnl
  811.      capitalize(`GNUs not Unix')
  812.      =>Gnus Not Unix
  813.  
  814.    The builtin macro `patsubst' is recognized only when given arguments.
  815.  
  816. 
  817. File: m4.info,  Node: Format,  Prev: Patsubst,  Up: Text handling
  818.  
  819. Formatted output
  820. ================
  821.  
  822.    Formatted output can be made with `format':
  823.  
  824.      format(FORMAT-STRING, ...)
  825.  
  826. which works much like the C function `printf'.  The first argument is a
  827. format string, which can contain `%' specifications, and the expansion
  828. of `format' is the formatted string.
  829.  
  830.    Its use is best described by a few examples:
  831.  
  832.      define(`foo', `The brown fox jumped over the lazy dog')
  833.      =>
  834.      format(`The string "%s" is %d characters long', foo, len(foo))
  835.      =>The string "The brown fox jumped over the lazy dog" is 38 characters long
  836.  
  837.    Using the `forloop' macro defined in *Note Loops::, this example
  838. shows how `format' can be used to produce tabular output.
  839.  
  840.      forloop(`i', 1, 10, `format(`%6d squared is %10d
  841.      ', i, eval(i**2))')
  842.      =>     1 squared is        1
  843.      =>     2 squared is        4
  844.      =>     3 squared is        9
  845.      =>     4 squared is       16
  846.      =>     5 squared is       25
  847.      =>     6 squared is       36
  848.      =>     7 squared is       49
  849.      =>     8 squared is       64
  850.      =>     9 squared is       81
  851.      =>    10 squared is      100
  852.  
  853.    The builtin `format' is modeled after the ANSI C `printf' function,
  854. and supports the normal `%' specifiers: `c', `s', `d', `o', `x', `X',
  855. `u', `e', `E' and `f'; it supports field widths and precisions, and the
  856. modifiers `+', `-', ` ', `0', `#', `h' and `l'.  For more details on
  857. the functioning of `printf', see the C Library Manual.
  858.  
  859. 
  860. File: m4.info,  Node: Arithmetic,  Next: UNIX commands,  Prev: Text handling,  Up: Top
  861.  
  862. Macros for doing arithmetic
  863. ***************************
  864.  
  865.    Integer arithmetic is included in `m4', with a C-like syntax.  As
  866. convenient shorthands, there are builtins for simple increment and
  867. decrement operations.
  868.  
  869. * Menu:
  870.  
  871. * Incr::                        Decrement and increment operators
  872. * Eval::                        Evaluating integer expressions
  873.  
  874. 
  875. File: m4.info,  Node: Incr,  Next: Eval,  Prev: Arithmetic,  Up: Arithmetic
  876.  
  877. Decrement and increment operators
  878. =================================
  879.  
  880.    Increment and decrement of integers are supported using the builtins
  881. `incr' and `decr':
  882.  
  883.      incr(NUMBER)
  884.      decr(NUMBER)
  885.  
  886. which expand to the numerical value of NUMBER, incremented, or
  887. decremented, respectively, by one.
  888.  
  889.      incr(4)
  890.      =>5
  891.      decr(7)
  892.      =>6
  893.  
  894.    The builtin macros `incr' and `decr' are recognized only when given
  895. arguments.
  896.  
  897. 
  898. File: m4.info,  Node: Eval,  Prev: Incr,  Up: Arithmetic
  899.  
  900. Evaluating integer expressions
  901. ==============================
  902.  
  903.    Integer expressions are evaluated with `eval':
  904.  
  905.      eval(EXPRESSION, opt RADIX, opt WIDTH)
  906.  
  907. which expands to the value of EXPRESSION.
  908.  
  909.    Expressions can contain the following operators, listed in order of
  910. decreasing precedence.
  911.  
  912. `-'
  913.      Unary minus
  914.  
  915. `**'
  916.      Exponentiation
  917.  
  918. `*  /  %'
  919.      Multiplication, division and modulo
  920.  
  921. `+  -'
  922.      Addition and subtraction
  923.  
  924. `<<  >>'
  925.      Shift left or right
  926.  
  927. `==  !=  >  >=  <  <='
  928.      Relational operators
  929.  
  930. `!'
  931.      Logical negation
  932.  
  933. `~'
  934.      Bitwise negation
  935.  
  936. `&'
  937.      Bitwise and
  938.  
  939. `^'
  940.      Bitwise exclusive-or
  941.  
  942. `|'
  943.      Bitwise or
  944.  
  945. `&&'
  946.      Logical and
  947.  
  948. `||'
  949.      Logical or
  950.  
  951.    All operators, except exponentiation, are left associative.
  952.  
  953.    Note that many `m4' implementations use `^' as an alternate operator
  954. for the exponentiation, while many others use `^' for the bitwise
  955. exclusive-or.  GNU `m4' changed its behavior: it used to exponentiate
  956. for `^', it now computes the bitwise exclusive-or.
  957.  
  958.    Numbers without special prefix are given decimal.  A simple `0'
  959. prefix introduces an octal number.  `0x' introduces an hexadecimal
  960. number.  `0b' introduces a binary number.  `0r' introduces a number
  961. expressed in any radix between 1 and 36: the prefix should be
  962. immediately followed by the decimal expression of the radix, a colon,
  963. then the digits making the number.  For any radix, the digits are `0',
  964. `1', `2', ....  Beyond `9', the digits are `a', `b' ... up to `z'.
  965. Lower and upper case letters can be used interchangeably in numbers
  966. prefixes and as number digits.
  967.  
  968.    Parentheses may be used to group subexpressions whenever needed.
  969. For the relational operators, a true relation returns `1', and a false
  970. relation return `0'.
  971.  
  972.    Here are a few examples of use of `eval'.
  973.  
  974.      eval(-3 * 5)
  975.      =>-15
  976.      eval(index(`Hello world', `llo') >= 0)
  977.      =>1
  978.      define(`square', `eval(($1)**2)')
  979.      =>
  980.      square(9)
  981.      =>81
  982.      square(square(5)+1)
  983.      =>676
  984.      define(`foo', `666')
  985.      =>
  986.      eval(`foo'/6)
  987.      error-->51.eval:14: m4: Bad expression in eval: foo/6
  988.      =>
  989.      eval(foo/6)
  990.      =>111
  991.  
  992.    As the second to last example shows, `eval' does not handle macro
  993. names, even if they expand to a valid expression (or part of a valid
  994. expression).  Therefore all macros must be expanded before they are
  995. passed to `eval'.
  996.  
  997.    If RADIX is specified, it specifies the radix to be used in the
  998. expansion.  The default radix is 10.  The result of `eval' is always
  999. taken to be signed.  The WIDTH argument specifies a minimum output
  1000. width.  The result is zero-padded to extend the expansion to the
  1001. requested width.
  1002.  
  1003.      eval(666, 10)
  1004.      =>666
  1005.      eval(666, 11)
  1006.      =>556
  1007.      eval(666, 6)
  1008.      =>3030
  1009.      eval(666, 6, 10)
  1010.      =>0000003030
  1011.      eval(-666, 6, 10)
  1012.      =>-000003030
  1013.  
  1014.    Take note that RADIX cannot be larger than 36.
  1015.  
  1016.    The builtin macro `eval' is recognized only when given arguments.
  1017.  
  1018. 
  1019. File: m4.info,  Node: UNIX commands,  Next: Miscellaneous,  Prev: Arithmetic,  Up: Top
  1020.  
  1021. Running UNIX commands
  1022. *********************
  1023.  
  1024.    There are a few builtin macros in `m4' that allow you to run UNIX
  1025. commands from within `m4'.
  1026.  
  1027. * Menu:
  1028.  
  1029. * Syscmd::                      Executing simple commands
  1030. * Esyscmd::                     Reading the output of commands
  1031. * Sysval::                      Exit codes
  1032. * Maketemp::                    Making names for temporary files
  1033.  
  1034. 
  1035. File: m4.info,  Node: Syscmd,  Next: Esyscmd,  Prev: UNIX commands,  Up: UNIX commands
  1036.  
  1037. Executing simple commands
  1038. =========================
  1039.  
  1040.    Any shell command can be executed, using `syscmd':
  1041.  
  1042.      syscmd(SHELL-COMMAND)
  1043.  
  1044. which executes SHELL-COMMAND as a shell command.
  1045.  
  1046.    The expansion of `syscmd' is void, *not* the output from
  1047. SHELL-COMMAND!  Output or error messages from SHELL-COMMAND are not
  1048. read by `m4'.  *Note Esyscmd:: if you need to process the command
  1049. output.
  1050.  
  1051.    Prior to executing the command, `m4' flushes its output buffers.
  1052. The default standard input, output and error of SHELL-COMMAND are the
  1053. same as those of `m4'.
  1054.  
  1055.    The builtin macro `syscmd' is recognized only when given arguments.
  1056.  
  1057. 
  1058. File: m4.info,  Node: Esyscmd,  Next: Sysval,  Prev: Syscmd,  Up: UNIX commands
  1059.  
  1060. Reading the output of commands
  1061. ==============================
  1062.  
  1063.    If you want `m4' to read the output of a UNIX command, use `esyscmd':
  1064.  
  1065.      esyscmd(SHELL-COMMAND)
  1066.  
  1067. which expands to the standard output of the shell command SHELL-COMMAND.
  1068.  
  1069.    Prior to executing the command, `m4' flushes its output buffers.
  1070. The default standard input and error output of SHELL-COMMAND are the
  1071. same as those of `m4'.  The error output of SHELL-COMMAND is not a part
  1072. of the expansion: it will appear along with the error output of `m4'.
  1073.  
  1074.    Assume you are positioned into the `checks' directory of GNU `m4'
  1075. distribution, then:
  1076.  
  1077.      define(`vice', `esyscmd(grep Vice ../COPYING)')
  1078.      =>
  1079.      vice
  1080.      =>  Ty Coon, President of Vice
  1081.      =>
  1082.  
  1083.    Note how the expansion of `esyscmd' has a trailing newline.
  1084.  
  1085.    The builtin macro `esyscmd' is recognized only when given arguments.
  1086.  
  1087. 
  1088. File: m4.info,  Node: Sysval,  Next: Maketemp,  Prev: Esyscmd,  Up: UNIX commands
  1089.  
  1090. Exit codes
  1091. ==========
  1092.  
  1093.    To see whether a shell command succeeded, use `sysval':
  1094.  
  1095.      sysval
  1096.  
  1097. which expands to the exit status of the last shell command run with
  1098. `syscmd' or `esyscmd'.
  1099.  
  1100.      syscmd(`false')
  1101.      =>
  1102.      ifelse(sysval, 0, zero, non-zero)
  1103.      =>non-zero
  1104.      syscmd(`true')
  1105.      =>
  1106.      sysval
  1107.      =>0
  1108.  
  1109. 
  1110. File: m4.info,  Node: Maketemp,  Prev: Sysval,  Up: UNIX commands
  1111.  
  1112. Making names for temporary files
  1113. ================================
  1114.  
  1115.    Commands specified to `syscmd' or `esyscmd' might need a temporary
  1116. file, for output or for some other purpose.  There is a builtin macro,
  1117. `maketemp', for making temporary file names:
  1118.  
  1119.      maketemp(TEMPLATE)
  1120.  
  1121. which expands to a name of a non-existent file, made from the string
  1122. TEMPLATE, which should end with the string `XXXXXX'.  The six `X''s are
  1123. then replaced, usually with something that includes the process id of
  1124. the `m4' process, in order to make the filename unique.
  1125.  
  1126.      maketemp(`/tmp/fooXXXXXX')
  1127.      =>/tmp/fooa07346
  1128.      maketemp(`/tmp/fooXXXXXX')
  1129.      =>/tmp/fooa07346
  1130.  
  1131.    As seen in the example, several calls of `maketemp' might expand to
  1132. the same string, since the selection criteria is whether the file exists
  1133. or not.  If a file has not been created before the next call, the two
  1134. macro calls might expand to the same name.
  1135.  
  1136.    The builtin macro `maketemp' is recognized only when given arguments.
  1137.  
  1138. 
  1139. File: m4.info,  Node: Miscellaneous,  Next: Frozen files,  Prev: UNIX commands,  Up: Top
  1140.  
  1141. Miscellaneous builtin macros
  1142. ****************************
  1143.  
  1144.    This chapter describes various builtins, that do not really belong in
  1145. any of the previous chapters.
  1146.  
  1147. * Menu:
  1148.  
  1149. * Errprint::                    Printing error messages
  1150. * M4exit::                      Exiting from m4
  1151.  
  1152. 
  1153. File: m4.info,  Node: Errprint,  Next: M4exit,  Prev: Miscellaneous,  Up: Miscellaneous
  1154.  
  1155. Printing error messages
  1156. =======================
  1157.  
  1158.    You can print error messages using `errprint':
  1159.  
  1160.      errprint(MESSAGE, ...)
  1161.  
  1162. which simply prints MESSAGE and the rest of the arguments on the
  1163. standard error output.
  1164.  
  1165.    The expansion of `errprint' is void.
  1166.  
  1167.      errprint(`Illegal arguments to forloop
  1168.      ')
  1169.      error-->Illegal arguments to forloop
  1170.      =>
  1171.  
  1172.    A trailing newline is *not* printed automatically, so it must be
  1173. supplied as part of the argument, as in the example.  (BSD flavored
  1174. `m4''s do append a trailing newline on each `errprint' call).
  1175.  
  1176.    To make it possible to specify the location of the error, two
  1177. utility builtins exist:
  1178.  
  1179.      __file__
  1180.      __line__
  1181.  
  1182. which expands to the quoted name of the current input file, and the
  1183. current input line number in that file.
  1184.  
  1185.      errprint(`m4:'__file__:__line__: `Input error
  1186.      ')
  1187.      error-->m4:56.errprint:2: Input error
  1188.      =>
  1189.  
  1190. 
  1191. File: m4.info,  Node: M4exit,  Prev: Errprint,  Up: Miscellaneous
  1192.  
  1193. Exiting from `m4'
  1194. =================
  1195.  
  1196.    If you need to exit from `m4' before the entire input has been read,
  1197. you can use `m4exit':
  1198.  
  1199.      m4exit(opt CODE)
  1200.  
  1201. which causes `m4' to exit, with exit code CODE.  If CODE is left out,
  1202. the exit code is zero.
  1203.  
  1204.      define(`fatal_error', `errprint(`m4: '__file__: __line__`: fatal error: $*
  1205.      ')m4exit(1)')
  1206.      =>
  1207.      fatal_error(`This is a BAD one, buster')
  1208.      error-->m4: 57.m4exit: 5: fatal error: This is a BAD one, buster
  1209.  
  1210.    After this macro call, `m4' will exit with exit code 1.  This macro
  1211. is only intended for error exits, since the normal exit procedures are
  1212. not followed, e.g., diverted text is not undiverted, and saved text
  1213. (*note M4wrap::.) is not reread.
  1214.  
  1215. 
  1216. File: m4.info,  Node: Frozen files,  Next: Compatibility,  Prev: Miscellaneous,  Up: Top
  1217.  
  1218. Fast loading of frozen states
  1219. *****************************
  1220.  
  1221.    Some bigger `m4' applications may be built over a common base
  1222. containing hundreds of definitions and other costly initializations.
  1223. Usually, the common base is kept in one or more declarative files,
  1224. which files are listed on each `m4' invocation prior to the user's
  1225. input file, or else, `include''d from this input file.
  1226.  
  1227.    Reading the common base of a big application, over and over again,
  1228. may be time consuming.  GNU `m4' offers some machinery to speed up the
  1229. start of an application using lengthy common bases.  Presume the user
  1230. repeatedly uses:
  1231.  
  1232.      m4 base.m4 input.m4
  1233.  
  1234. with a varying contents of `input.m4', but a rather fixed contents for
  1235. `base.m4'.  Then, the user might rather execute:
  1236.  
  1237.      m4 -F base.m4f base.m4
  1238.  
  1239. once, and further execute, as often as needed:
  1240.  
  1241.      m4 -R base.m4f input.m4
  1242.  
  1243. with the varying input.  The first call, containing the `-F' option,
  1244. only reads and executes file `base.m4', so defining various application
  1245. macros and computing other initializations.  Only once the input file
  1246. `base.m4' has been completely processed, GNU `m4' produces on
  1247. `base.m4f' a "frozen" file, that is, a file which contains a kind of
  1248. snapshot of the `m4' internal state.
  1249.  
  1250.    Later calls, containing the `-R' option, are able to reload the
  1251. internal state of `m4''s memory, from `base.m4f', *prior* to reading
  1252. any other input files.  By this mean, instead of starting with a virgin
  1253. copy of `m4', input will be read after having effectively recovered the
  1254. effect of a prior run.  In our example, the effect is the same as if
  1255. file `base.m4' has been read anew.  However, this effect is achieved a
  1256. lot faster.
  1257.  
  1258.    Only one frozen file may be created or read in any one `m4'
  1259. invocation.  It is not possible to recover two frozen files at once.
  1260. However, frozen files may be updated incrementally, through using `-R'
  1261. and `-F' options simultaneously.  For example, if some care is taken,
  1262. the command:
  1263.  
  1264.      m4 file1.m4 file2.m4 file3.m4 file4.m4
  1265.  
  1266. could be broken down in the following sequence, accumulating the same
  1267. output:
  1268.  
  1269.      m4 -F file1.m4f file1.m4
  1270.      m4 -R file1.m4f -F file2.m4f file2.m4
  1271.      m4 -R file2.m4f -F file3.m4f file3.m4
  1272.      m4 -R file3.m4f file4.m4
  1273.  
  1274.    Some care is necessary because not every effort has been made for
  1275. this to work in all cases.  In particular, the trace attribute of
  1276. macros is not handled, nor the current setting of `changeword'.  Also,
  1277. interactions for some options of `m4' being used in one call and not
  1278. for the next, have not been fully analyzed yet.  On the other end, you
  1279. may be confident that stacks of `pushdef''ed definitions are handled
  1280. correctly, so are `undefine''d or renamed builtins, changed strings for
  1281. quotes or comments.
  1282.  
  1283.    When an `m4' run is to be frozen, the automatic undiversion which
  1284. takes place at end of execution is inhibited.  Instead, all positively
  1285. numbered diversions are saved into the frozen file.  The active
  1286. diversion number is also transmitted.
  1287.  
  1288.    A frozen file to be reloaded need not reside in the current
  1289. directory.  It is looked up the same way as an `include' file (*note
  1290. Search Path::.).
  1291.  
  1292.    Frozen files are sharable across architectures.  It is safe to write
  1293. a frozen file one one machine and read it on another, given that the
  1294. second machine uses the same, or a newer version of GNU `m4'.  These
  1295. are simple (editable) text files, made up of directives, each starting
  1296. with a capital letter and ending with a newline (NL).  Wherever a
  1297. directive is expected, the character `#' introduces a comment line,
  1298. empty lines are also ignored.  In the following descriptions, LENGTHs
  1299. always refer to corresponding STRINGs.  Numbers are always expressed in
  1300. decimal.  The directives are:
  1301.  
  1302. `V NUMBER NL'
  1303.      Confirms the format of the file.  NUMBER should be 1.
  1304.  
  1305. `C LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  1306.      Uses STRING1 and STRING2 as the beginning comment and end comment
  1307.      strings.
  1308.  
  1309. `Q LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  1310.      Uses STRING1 and STRING2 as the beginning quote and end quote
  1311.      strings.
  1312.  
  1313. `F LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  1314.      Defines, through `pushdef', a definition for STRING1 expanding to
  1315.      the function whose builtin name is STRING2.
  1316.  
  1317. `T LENGTH1 , LENGTH2 NL STRING1 STRING2 NL'
  1318.      Defines, though `pushdef', a definition for STRING1 expanding to
  1319.      the text given by STRING2.
  1320.  
  1321. `D NUMBER, LENGTH NL STRING NL'
  1322.      Selects diversion NUMBER, making it current, then copy STRING in
  1323.      the current diversion.  NUMBER may be a negative number for a
  1324.      non-existing diversion.  To merely specify an active selection,
  1325.      use this command with an empty STRING.  With 0 as the diversion
  1326.      NUMBER, STRING will be issued on standard output at reload time,
  1327.      however this may not be produced from within `m4'.
  1328.  
  1329. 
  1330. File: m4.info,  Node: Compatibility,  Next: Concept index,  Prev: Frozen files,  Up: Top
  1331.  
  1332. Compatibility with other versions of `m4'
  1333. *****************************************
  1334.  
  1335.    This chapter describes the differences between this implementation of
  1336. `m4', and the implementation found under UNIX, notably System V,
  1337. Release 3.
  1338.  
  1339.    There are also differences in BSD flavors of `m4'.  No attempt is
  1340. made to summarize these here.
  1341.  
  1342. * Menu:
  1343.  
  1344. * Extensions::                  Extensions in GNU m4
  1345. * Incompatibilities::           Facilities in System V m4 not in GNU m4
  1346. * Other Incompat::              Other incompatibilities
  1347.  
  1348. 
  1349. File: m4.info,  Node: Extensions,  Next: Incompatibilities,  Prev: Compatibility,  Up: Compatibility
  1350.  
  1351. Extensions in GNU `m4'
  1352. ======================
  1353.  
  1354.    This version of `m4' contains a few facilities, that do not exist in
  1355. System V `m4'.  These extra facilities are all suppressed by using the
  1356. `-G' command line option, unless overridden by other command line
  1357. options.
  1358.  
  1359.    * In the `$'N notation for macro arguments, N can contain several
  1360.      digits, while the System V `m4' only accepts one digit.  This
  1361.      allows macros in GNU `m4' to take any number of arguments, and not
  1362.      only nine (*note Arguments::.).
  1363.  
  1364.    * Files included with `include' and `sinclude' are sought in a user
  1365.      specified search path, if they are not found in the working
  1366.      directory.  The search path is specified by the `-I' option and the
  1367.      `M4PATH' environment variable (*note Search Path::.).
  1368.  
  1369.    * Arguments to `undivert' can be non-numeric, in which case the named
  1370.      file will be included uninterpreted in the output (*note
  1371.      Undivert::.).
  1372.  
  1373.    * Formatted output is supported through the `format' builtin, which
  1374.      is modeled after the C library function `printf' (*note Format::.).
  1375.  
  1376.    * Searches and text substitution through regular expressions are
  1377.      supported by the `regexp' (*note Regexp::.) and `patsubst' (*note
  1378.      Patsubst::.) builtins.
  1379.  
  1380.    * The output of shell commands can be read into `m4' with `esyscmd'
  1381.      (*note Esyscmd::.).
  1382.  
  1383.    * There is indirect access to any builtin macro with `builtin'
  1384.      (*note Builtin::.).
  1385.  
  1386.    * Macros can be called indirectly through `indir' (*note Indir::.).
  1387.  
  1388.    * The name of the current input file and the current input line
  1389.      number are accessible through the builtins `__file__' and
  1390.      `__line__' (*note Errprint::.).
  1391.  
  1392.    * The format of the output from `dumpdef' and macro tracing can be
  1393.      controlled with `debugmode' (*note Debug Levels::.).
  1394.  
  1395.    * The destination of trace and debug output can be controlled with
  1396.      `debugfile' (*note Debug Output::.).
  1397.  
  1398.    In addition to the above extensions, GNU `m4' implements the
  1399. following command line options: `-F', `-G', `-I', `-L', `-R', `-V',
  1400. `-W', `-d', `-l', `-o' and `-t'.  *Note Invoking m4::, for a
  1401. description of these options.
  1402.  
  1403.    Also, the debugging and tracing facilities in GNU `m4' are much more
  1404. extensive than in most other versions of `m4'.
  1405.  
  1406. 
  1407. File: m4.info,  Node: Incompatibilities,  Next: Other Incompat,  Prev: Extensions,  Up: Compatibility
  1408.  
  1409. Facilities in System V `m4' not in GNU `m4'
  1410. ===========================================
  1411.  
  1412.    The version of `m4' from System V contains a few facilities that
  1413. have not been implemented in GNU `m4' yet.
  1414.  
  1415.    * System V `m4' supports multiple arguments to `defn'.  This is not
  1416.      implemented in GNU `m4'.  Its usefulness is unclear to me.
  1417.  
  1418. 
  1419. File: m4.info,  Node: Other Incompat,  Prev: Incompatibilities,  Up: Compatibility
  1420.  
  1421. Other incompatibilities
  1422. =======================
  1423.  
  1424.    There are a few other incompatibilities between this implementation
  1425. of `m4', and the System V version.
  1426.  
  1427.    * GNU `m4' implements sync lines differently from System V `m4',
  1428.      when text is being diverted.  GNU `m4' outputs the sync lines when
  1429.      the text is being diverted, and System V `m4' when the diverted
  1430.      text is being brought back.
  1431.  
  1432.      The problem is which lines and filenames should be attached to
  1433.      text that is being, or has been, diverted.  System V `m4' regards
  1434.      all the diverted text as being generated by the source line
  1435.      containing the `undivert' call, whereas GNU `m4' regards the
  1436.      diverted text as being generated at the time it is diverted.
  1437.  
  1438.      I expect the sync line option to be used mostly when using `m4' as
  1439.      a front end to a compiler.  If a diverted line causes a compiler
  1440.      error, the error messages should most probably refer to the place
  1441.      where the diversion were made, and not where it was inserted again.
  1442.  
  1443.    * GNU `m4' makes no attempt at prohiting autoreferential definitions
  1444.      like:
  1445.  
  1446.           define(`x', `x')
  1447.           define(`x', `x ')
  1448.  
  1449.      There is nothing inherently wrong with defining `x' to return `x'.
  1450.      The wrong thing is to expand `x' unquoted.  In `m4', one might
  1451.      use macros to hold strings, as we do for variables in other
  1452.      programming languages, further checking them with:
  1453.  
  1454.           ifelse(defn(`HOLDER'), `VALUE', ...)
  1455.  
  1456.      In cases like this one, an interdiction for a macro to hold its own
  1457.      name would be a useless limitation.  Of course, this leave more
  1458.      rope for the GNU `m4' user to hang himself!  Rescanning hangs may
  1459.      be avoided through careful programming, a little like for endless
  1460.      loops in traditional programming languages.
  1461.  
  1462.    * GNU `m4' without `-G' option will define the macro `__gnu__' to
  1463.      expand to the empty string.
  1464.  
  1465.      On UNIX systems, GNU `m4' without the `-G' option will define the
  1466.      macro `__unix__', otherwise the macro `unix'.  Both will expand to
  1467.      the empty string.
  1468.  
  1469.