home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / m4-1.4-bin.lha / info / m4.info-1 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  51KB  |  1,061 lines

  1. This is Info file m4.info, produced by Makeinfo-1.63 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: Top,  Next: Preliminaries,  Prev: (dir),  Up: (dir)
  21. GNU `m4'
  22. ********
  23.    GNU `m4' is an implementation of the traditional UNIX macro
  24. processor.  It is mostly SVR4 compatible, although it has some
  25. extensions (for example, handling more than 9 positional parameters to
  26. macros).  `m4' also has builtin functions for including files, running
  27. shell commands, doing arithmetic, etc.  Autoconf needs GNU `m4' for
  28. generating `configure' scripts, but not for running them.
  29.    GNU `m4' was originally written by Ren'e Seindal, with subsequent
  30. changes by Franc,ois Pinard and other volunteers on the Internet.  All
  31. names and email addresses can be found in the file `THANKS' from the
  32. GNU `m4' distribution.
  33.    This is release 1.4.  It is now to be considered stable, future
  34. releases are only meant to fix bugs, increase speed, or improve
  35. documentation.  However...
  36.    An experimental feature, which would improve `m4' usefulness, allows
  37. for changing the syntax for what is a "word" in `m4'.  You should use:
  38.      ./configure --enable-changeword
  39. if you want this feature compiled in.  The current implementation slows
  40. down `m4' considerably and is hardly acceptable.  So, it might go away,
  41. do not count on it yet.
  42. * Menu:
  43. * Preliminaries::               Introduction and preliminaries
  44. * Syntax::                      Lexical and syntactic conventions
  45. * Macros::                      How to invoke macros
  46. * Definitions::                 How to define new macros
  47. * Conditionals::                Conditionals and loops
  48. * Debugging::                   How to debug macros and input
  49. * Input Control::               Input control
  50. * File Inclusion::              File inclusion
  51. * Diversions::                  Diverting and undiverting output
  52. * Text handling::               Macros for text handling
  53. * Arithmetic::                  Macros for doing arithmetic
  54. * UNIX commands::               Macros for running UNIX commands
  55. * Miscellaneous::               Miscellaneous builtin macros
  56. * Frozen files::                Fast loading of frozen states
  57. * Compatibility::               Compatibility with other versions of m4
  58. * Concept index::               Index for many concepts
  59. * Macro index::                 Index for all m4 macros
  60.  -- The Detailed Node Listing --
  61. Introduction and preliminaries
  62. * Intro::                       Introduction to `m4'
  63. * History::                     Historical references
  64. * Invoking m4::                 Invoking `m4'
  65. * Bugs::                        Problems and bugs
  66. * Manual::                      Using this manual
  67. Lexical and syntactic conventions
  68. * Names::                       Macro names
  69. * Quoted strings::              Quoting input to m4
  70. * Other tokens::                Other kinds of input tokens
  71. * Comments::                    Comments in m4 input
  72. How to invoke macros
  73. * Invocation::                  Macro invocation
  74. * Inhibiting Invocation::       Preventing macro invocation
  75. * Macro Arguments::             Macro arguments
  76. * Quoting Arguments::           On Quoting Arguments to macros
  77. * Macro expansion::             Expanding macros
  78. How to define new macros
  79. * Define::                      Defining a new macro
  80. * Arguments::                   Arguments to macros
  81. * Pseudo Arguments::            Pseudo arguments to macros
  82. * Undefine::                    Deleting a macro
  83. * Defn::                        Renaming macros
  84. * Pushdef::                     Temporarily redefining macros
  85. * Indir::                       Indirect call of macros
  86. * Builtin::                     Indirect call of builtins
  87. Conditionals, loops and recursion
  88. * Ifdef::                       Testing if a macro is defined
  89. * Ifelse::                      If-else construct, or multibranch
  90. * Loops::                       Loops and recursion in m4
  91. How to debug macros and input
  92. * Dumpdef::                     Displaying macro definitions
  93. * Trace::                       Tracing macro calls
  94. * Debug Levels::                Controlling debugging output
  95. * Debug Output::                Saving debugging output
  96. Input control
  97. * Dnl::                         Deleting whitespace in input
  98. * Changequote::                 Changing the quote characters
  99. * Changecom::                   Changing the comment delimiters
  100. * Changeword::                  Changing the lexical structure of words
  101. * M4wrap::                      Saving input until end of input
  102. File inclusion
  103. * Include::                     Including named files
  104. * Search Path::                 Searching for include files
  105. Diverting and undiverting output
  106. * Divert::                      Diverting output
  107. * Undivert::                    Undiverting output
  108. * Divnum::                      Diversion numbers
  109. * Cleardiv::                    Discarding diverted text
  110. Macros for text handling
  111. * Len::                         Calculating length of strings
  112. * Index::                       Searching for substrings
  113. * Regexp::                      Searching for regular expressions
  114. * Substr::                      Extracting substrings
  115. * Translit::                    Translating characters
  116. * Patsubst::                    Substituting text by regular expression
  117. * Format::                      Formatting strings (printf-like)
  118. Macros for doing arithmetic
  119. * Incr::                        Decrement and increment operators
  120. * Eval::                        Evaluating integer expressions
  121. Running UNIX commands
  122. * Syscmd::                      Executing simple commands
  123. * Esyscmd::                     Reading the output of commands
  124. * Sysval::                      Exit codes
  125. * Maketemp::                    Making names for temporary files
  126. Miscellaneous builtin macros
  127. * Errprint::                    Printing error messages
  128. * M4exit::                      Exiting from m4
  129. Compatibility with other versions of `m4'
  130. * Extensions::                  Extensions in GNU m4
  131. * Incompatibilities::           Facilities in System V m4 not in GNU m4
  132. * Other Incompat::              Other incompatibilities
  133. File: m4.info,  Node: Preliminaries,  Next: Syntax,  Prev: Top,  Up: Top
  134. Introduction and preliminaries
  135. ******************************
  136.    This first chapter explains what is GNU `m4', where `m4' comes from,
  137. how to read and use this documentation, how to call the `m4' program
  138. and how to report bugs about it.  It concludes by giving tips for
  139. reading the remainder of the manual.
  140.    The following chapters then detail all the features of the `m4'
  141. language.
  142. * Menu:
  143. * Intro::                       Introduction to `m4'
  144. * History::                     Historical references
  145. * Invoking m4::                 Invoking `m4'
  146. * Bugs::                        Problems and bugs
  147. * Manual::                      Using this manual
  148. File: m4.info,  Node: Intro,  Next: History,  Prev: Preliminaries,  Up: Preliminaries
  149. Introduction to `m4'
  150. ====================
  151.    `m4' is a macro processor, in the sense that it copies its input to
  152. the output, expanding macros as it goes.  Macros are either builtin or
  153. user-defined, and can take any number of arguments.  Besides just doing
  154. macro expansion, `m4' has builtin functions for including named files,
  155. running UNIX commands, doing integer arithmetic, manipulating text in
  156. various ways, recursion, etc...  `m4' can be used either as a front-end
  157. to a compiler, or as a macro processor in its own right.
  158.    The `m4' macro processor is widely available on all UNIXes.
  159. Usually, only a small percentage of users are aware of its existence.
  160. However, those who do often become commited users.  The growing
  161. popularity of GNU Autoconf, which prerequires GNU `m4' for *generating*
  162. the `configure' scripts, is an incentive for many to install it, while
  163. these people will not themselves program in `m4'.  GNU `m4' is mostly
  164. compatible with the System V, Release 3 version, except for some minor
  165. differences.  *Note Compatibility:: for more details.
  166.    Some people found `m4' to be fairly addictive.  They first use `m4'
  167. for simple problems, then take bigger and bigger challenges, learning
  168. how to write complex `m4' sets of macros along the way.  Once really
  169. addicted, users pursue writing of sophisticated `m4' applications even
  170. to solve simple problems, devoting more time debugging their `m4'
  171. scripts than doing real work.  Beware that `m4' may be dangerous for
  172. the health of compulsive programmers.
  173. File: m4.info,  Node: History,  Next: Invoking m4,  Prev: Intro,  Up: Preliminaries
  174. Historical references
  175. =====================
  176.    The historical notes included here are fairly incomplete, and not
  177. authoritative at all.  Please knowledgeable users help us to more
  178. properly write this section.
  179.    `GPM' has been an important ancestor of `m4'.  See C. Stratchey: "A
  180. General Purpose Macro generator", Computer Journal 8,3 (1965), pp. 225
  181. ff.  `GPM' is also succintly described into David Gries classic
  182. "Compiler Construction for Digital Computers".
  183.    While `GPM' was *pure*, `m4' was meant to deal more with the true
  184. intricacies of real life: macros could be recognized with being
  185. pre-announced, skipping whitespace or end-of-lines was made easier,
  186. more constructs were builtin instead of derived, etc.
  187.    Originally, `m4' was the engine for Rational FORTRAN preprocessor,
  188. that is, the `ratfor' equivalent of `cpp'.
  189. File: m4.info,  Node: Invoking m4,  Next: Bugs,  Prev: History,  Up: Preliminaries
  190. Invoking `m4'
  191. =============
  192.    The format of the `m4' command is:
  193.      `m4' [OPTION...] [MACRO-DEFINITIONS...] [INPUT-FILE...]
  194.    All options begin with `-', or if long option names are used, with a
  195. `--'.  A long option name need not be written completely, and
  196. unambigous prefix is sufficient.  `m4' understands the following
  197. options:
  198. `--version'
  199.      Print the version number of the program on standard output, then
  200.      immediately exit `m4' without reading any INPUT-FILES.
  201. `--help'
  202.      Print an help summary on standard output, then immediately exit
  203.      `m4' without reading any INPUT-FILES.
  204. `--traditional'
  205.      Suppress all the extensions made in this implementation, compared
  206.      to the System V version.  *Note Compatibility::, for a list of
  207.      these.
  208. `--fatal-warnings'
  209.      Stop execution and exit `m4' once the first warning has been
  210.      issued, considering all of them to be fatal.
  211. `-dFLAGS'
  212. `--debug=FLAGS'
  213.      Set the debug-level according to the flags FLAGS.  The debug-level
  214.      controls the format and amount of information presented by the
  215.      debugging functions.  *Note Debug Levels:: for more details on the
  216.      format and meaning of FLAGS.
  217. `-lNUM'
  218. `--arglength=NUM'
  219.      Restrict the size of the output generated by macro tracing.  *Note
  220.      Debug Levels:: for more details.
  221. `-oFILE'
  222. `--error-output=FILE'
  223.      Redirect debug and trace output to the named file.  Error messages
  224.      are still printed on the standard error output.  *Note Debug
  225.      Output:: for more details.
  226. `-IDIR'
  227. `--include=DIR'
  228.      Make `m4' search DIR for included files that are not found in the
  229.      current working directory.  *Note Search Path:: for more details.
  230. `--interactive'
  231.      Makes this invocation of `m4' interactive.  This means that all
  232.      output will be unbuffered, and interrupts will be ignored.
  233. `--synclines'
  234.      Generate synchronisation lines, for use by the C preprocessor or
  235.      other similar tools.  This is useful, for example, when `m4' is
  236.      used as a front end to a compiler.  Source file name and line
  237.      number information is conveyed by directives of the form `#line
  238.      LINENUM "FILENAME"', which are inserted as needed into the middle
  239.      of the input.  Such directives mean that the following line
  240.      originated or was expanded from the contents of input file
  241.      FILENAME at line LINENUM.  The `"FILENAME"' part is often omitted
  242.      when the file name did not change from the previous directive.
  243.      Synchronisation directives are always given on complete lines per
  244.      themselves.  When a synchronisation discrepancy occurs in the
  245.      middle of an output line, the associated synchronisation directive
  246.      is delayed until the beginning of the next generated line.
  247. `--prefix-builtins'
  248.      Internally modify *all* builtin macro names so they all start with
  249.      the prefix `m4_'.  For example, using this option, one should write
  250.      `m4_define' instead of `define', and `m4___file__' instead of
  251.      `__file__'.
  252. `-WREGEXP'
  253. `--word-regexp=REGEXP'
  254.      Use an alternative syntax for macro names.  This experimental
  255.      option might not be present on all GNU `m4' implementations.
  256.      (*note Changeword::.).
  257. `-HN'
  258. `--hashsize=N'
  259.      Make the internal hash table for symbol lookup be N entries big.
  260.      The number should be prime.  The default is 509 entries.  It
  261.      should not be necessary to increase this value, unless you define
  262.      an excessive number of macros.
  263. `-LN'
  264. `--nesting-limit=N'
  265.      Artificially limit the nesting of macro calls to N levels,
  266.      stopping program execution if this limit is ever exceeded.  When
  267.      not specified, nesting is limited to 250 levels.
  268.      The precise effect of this option might be more correctly
  269.      associated with textual nesting than dynamic recursion.  It has
  270.      been useful when some complex `m4' input was generated by
  271.      mechanical means.  Most users would never need this option.  If
  272.      shown to be obtrusive, this option (which is still experimental)
  273.      might well disappear.
  274.      This option does *not* have the ability to break endless
  275.      rescanning loops, while these do not necessarily consume much
  276.      memory or stack space.  Through clever usage of rescanning loops,
  277.      one can request complex, time-consuming computations to `m4' with
  278.      useful results.  Putting limitations in this area would break `m4'
  279.      power.  There are many pathological cases: `define(`a', `a')a' is
  280.      only the simplest example (but *note Compatibility::.).  Expecting
  281.      GNU `m4' to detect these would be a little like expecting a
  282.      compiler system to detect and diagnose endless loops: it is a
  283.      quite *hard* problem in general, if not undecidable!
  284. `--quiet'
  285. `--silent'
  286.      Suppress warnings about missing or superflous arguments in macro
  287.      calls.
  288.      These options are present for compatibility with System V `m4', but
  289.      do nothing in this implementation.
  290. `-NN'
  291. `--diversions=N'
  292.      These options are present only for compatibility with previous
  293.      versions of GNU `m4', and were controlling the number of possible
  294.      diversions which could be used at the same time.  They do nothing,
  295.      because there is no fixed limit anymore.
  296.    Macro definitions and deletions can be made on the command line, by
  297. using the `-D' and `-U' options.  They have the following format:
  298. `-DNAME'
  299. `-DNAME=VALUE'
  300. `--define=NAME'
  301. `--define=NAME=VALUE'
  302.      This enters NAME into the symbol table, before any input files are
  303.      read.  If `=VALUE' is missing, the value is taken to be the empty
  304.      string.  The VALUE can be any string, and the macro can be defined
  305.      to take arguments, just as if it was defined from within the input.
  306. `-UNAME'
  307. `--undefine=NAME'
  308.      This deletes any predefined meaning NAME might have.  Obviously,
  309.      only predefined macros can be deleted in this way.
  310. `-tNAME'
  311. `--trace=NAME'
  312.      This enters NAME into the symbol table, as undefined but traced.
  313.      The macro will consequently be traced from the point it is defined.
  314. `-FFILE'
  315. `--freeze-state FILE'
  316.      Once execution is finished, write out the frozen state on the
  317.      specified FILE (*note Frozen files::.).
  318. `-RFILE'
  319. `--reload-state FILE'
  320.      Before execution starts, recover the internal state from the
  321.      specified frozen FILE (*note Frozen files::.).
  322.    The remaining arguments on the command line are taken to be input
  323. file names.  If no names are present, the standard input is read.  A
  324. file name of `-' is taken to mean the standard input.
  325.    The input files are read in the sequence given.  The standard input
  326. can only be read once, so the filename `-' should only appear once on
  327. the command line.
  328. File: m4.info,  Node: Bugs,  Next: Manual,  Prev: Invoking m4,  Up: Preliminaries
  329. Problems and bugs
  330. =================
  331.    If you have problems with GNU `m4' or think you've found a bug,
  332. please report it.  Before reporting a bug, make sure you've actually
  333. found a real bug.  Carefully reread the documentation and see if it
  334. really says you can do what you're trying to do.  If it's not clear
  335. whether you should be able to do something or not, report that too; it's
  336. a bug in the documentation!
  337.    Before reporting a bug or trying to fix it yourself, try to isolate
  338. it to the smallest possible input file that reproduces the problem.
  339. Then send us the input file and the exact results `m4' gave you.  Also
  340. say what you expected to occur; this will help us decide whether the
  341. problem was really in the documentation.
  342.    Once you've got a precise problem, send e-mail to (Internet)
  343. `bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  344. `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  345. number of `m4' you are using.  You can get this information with the
  346. command `m4 --version'.
  347.    Non-bug suggestions are always welcome as well.  If you have
  348. questions about things that are unclear in the documentation or are
  349. just obscure features, please report them too.
  350. File: m4.info,  Node: Manual,  Prev: Bugs,  Up: Preliminaries
  351. Using this manual
  352. =================
  353.    This manual contains a number of examples of `m4' input and output,
  354. and a simple notation is used to distinguish input, output and error
  355. messages from `m4'.  Examples are set out from the normal text, and
  356. shown in a fixed width font, like this
  357.      This is an example of an example!
  358.    To distinguish input from output, all output from `m4' is prefixed
  359. by the string `=>', and all error messages by the string `error-->'.
  360.      Example of input line
  361.      =>Output line from m4
  362.      error-->and an error message
  363.    As each of the predefined macros in `m4' is described, a prototype
  364. call of the macro will be shown, giving descriptive names to the
  365. arguments, e.g.,
  366.      regexp(STRING, REGEXP, opt REPLACEMENT)
  367.    All macro arguments in `m4' are strings, but some are given special
  368. interpretation, e.g., as numbers, filenames, regular expressions, etc.
  369.    The `opt' before the third argument shows that this argument is
  370. optional--if it is left out, it is taken to be the empty string.  An
  371. ellipsis (`...') last in the argument list indicates that any number of
  372. arguments may follow.
  373.    This document consistently writes and uses "builtin", without an
  374. hyphen, as if it were an English word.  This is how the `builtin'
  375. primitive is spelled within `m4'.
  376. File: m4.info,  Node: Syntax,  Next: Macros,  Prev: Preliminaries,  Up: Top
  377. Lexical and syntactic conventions
  378. *********************************
  379.    As `m4' reads its input, it separates it into "tokens".  A token is
  380. either a name, a quoted string, or any single character, that is not a
  381. part of either a name or a string.  Input to `m4' can also contain
  382. comments.
  383. * Menu:
  384. * Names::                       Macro names
  385. * Quoted strings::              Quoting input to m4
  386. * Other tokens::                Other kinds of input tokens
  387. * Comments::                    Comments in m4 input
  388. File: m4.info,  Node: Names,  Next: Quoted strings,  Prev: Syntax,  Up: Syntax
  389. Names
  390. =====
  391.    A name is any sequence of letters, digits, and the character `_'
  392. (underscore), where the first character is not a digit.  If a name has
  393. a macro definition, it will be subject to macro expansion (*note
  394. Macros::.).
  395.    Examples of legal names are: `foo', `_tmp', and `name01'.
  396. File: m4.info,  Node: Quoted strings,  Next: Other tokens,  Prev: Names,  Up: Syntax
  397. Quoted strings
  398. ==============
  399.    A quoted string is a sequence of characters surrounded by the quotes
  400. ``' and `'', where the number of start and end quotes within the string
  401. balances.  The value of a string token is the text, with one level of
  402. quotes stripped off.  Thus
  403.      `'
  404.    is the empty string, and
  405.      ``quoted''
  406.    is the string
  407.      `quoted'
  408.    The quote characters can be changed at any time, using the builtin
  409. macro `changequote'.  *Note Changequote:: for more information.
  410. File: m4.info,  Node: Other tokens,  Next: Comments,  Prev: Quoted strings,  Up: Syntax
  411. Other tokens
  412. ============
  413.    Any character, that is neither a part of a name, nor of a quoted
  414. string, is a token by itself.
  415. File: m4.info,  Node: Comments,  Prev: Other tokens,  Up: Syntax
  416. Comments
  417. ========
  418.    Comments in `m4' are normally delimited by the characters `#' and
  419. newline.  All characters between the comment delimiters are ignored,
  420. but the entire comment (including the delimiters) is passed through to
  421. the output--comments are *not* discarded by `m4'.
  422.    Comments cannot be nested, so the first newline after a `#' ends the
  423. comment.  The commenting effect of the begin comment character can be
  424. inhibited by quoting it.
  425.    The comment delimiters can be changed to any string at any time,
  426. using the builtin macro `changecom'.  *Note Changecom:: for more
  427. information.
  428. File: m4.info,  Node: Macros,  Next: Definitions,  Prev: Syntax,  Up: Top
  429. How to invoke macros
  430. ********************
  431.    This chapter covers macro invocation, macro arguments and how macro
  432. expansion is treated.
  433. * Menu:
  434. * Invocation::                  Macro invocation
  435. * Inhibiting Invocation::       Preventing macro invocation
  436. * Macro Arguments::             Macro arguments
  437. * Quoting Arguments::           On Quoting Arguments to macros
  438. * Macro expansion::             Expanding macros
  439. File: m4.info,  Node: Invocation,  Next: Inhibiting Invocation,  Prev: Macros,  Up: Macros
  440. Macro invocation
  441. ================
  442.    Macro invocations has one of the forms
  443.      name
  444. which is a macro invocation without any arguments, or
  445.      name(arg1, arg2, ..., argN)
  446. which is a macro invocation with N arguments.  Macros can have any
  447. number of arguments.  All arguments are strings, but different macros
  448. might interpret the arguments in different ways.
  449.    The opening parenthesis *must* follow the NAME directly, with no
  450. spaces in between.  If it does not, the macro is called with no
  451. arguments at all.
  452.    For a macro call to have no arguments, the parentheses *must* be
  453. left out.  The macro call
  454.      name()
  455. is a macro call with one argument, which is the empty string, not a call
  456. with no arguments.
  457. File: m4.info,  Node: Inhibiting Invocation,  Next: Macro Arguments,  Prev: Invocation,  Up: Macros
  458. Preventing macro invocation
  459. ===========================
  460.    An innovation of the `m4' language, compared to some of its
  461. predecessors (like Stratchey's `GPM', for example), is the ability to
  462. recognize macro calls without resorting to any special, prefixed
  463. invocation character.  While generally useful, this feature might
  464. sometimes be the source of spurious, unwanted macro calls.  So, GNU
  465. `m4' offers several mechanisms or techniques for inhibiting the
  466. recognition of names as macro calls.
  467.    First of all, many builtin macros cannot meaningfully be called
  468. without arguments.  For any of these macros, whenever an opening
  469. parenthesis does not immediately follow their name, the builtin macro
  470. call is not triggered.  This solves the most usual cases, like for
  471. `include' or `eval'.  Later in this document, the sentence "This macro
  472. is recognized only when given arguments" refers to this specific
  473. provision.
  474.    There is also a command call option (`--prefix-builtins', or `-P')
  475. which requires all builtin macro names to be prefixed by `m4_' for them
  476. to be recognized.  The option has no effect whatsoever on user defined
  477. macros.  For example, with this option, one has to write `m4_dnl' and
  478. even `m4_m4exit'.
  479.    If your version of GNU `m4' has the `changeword' feature compiled
  480. in, there it offers far more flexibility in specifying the syntax of
  481. macro names, both builtin or user-defined.  *Note Changeword:: for more
  482. information on this experimental feature.
  483.    Of course, the simplest way to prevent a name to be interpreted as a
  484. call to an existing macro is to quote it.  The remainder of this
  485. section studies a little more deeply how quoting affects macro
  486. invocation, and how quoting can be used to inhibit macro invocation.
  487.    Even if quoting is usually done over the whole macro name, it can
  488. also be done over only a few characters of this name.  It is also
  489. possible to quote the empty string, but this works only *inside* the
  490. name.  For example:
  491.      `divert'
  492.      `d'ivert
  493.      di`ver't
  494.      div`'ert
  495. all yield the string `divert'.  While in both:
  496.      `'divert
  497.      divert`'
  498. the `divert' builtin macro will be called.
  499.    The output of macro evaluations is always rescanned.  The following
  500. example would yield the string `de', exactly as if `m4' has been given
  501. `substr(abcde, 3, 2)' as input:
  502.      define(`x', `substr(ab')
  503.      define(`y', `cde, 3, 2)')
  504.      x`'y
  505.    Unquoted strings on either side of a quoted string are subject to
  506. being recognized as macro names.  In the following example, quoting the
  507. empty string allows for the `dnl' macro to be recognized as such:
  508.      define(`macro', `di$1')
  509.      macro(v)`'dnl
  510. Without the quotes, this would rather yield the string `divdnl'
  511. followed by an end of line.
  512.    Quoting may prevent recognizing as a macro name the concatenation of
  513. a macro expansion with the surrounding characters.  In this example:
  514.      define(`macro', `di$1')
  515.      macro(v)`ert'
  516. the input will produce the string `divert'.  If the quote was removed,
  517. the `divert' builtin would be called instead.
  518. File: m4.info,  Node: Macro Arguments,  Next: Quoting Arguments,  Prev: Inhibiting Invocation,  Up: Macros
  519. Macro arguments
  520. ===============
  521.    When a name is seen, and it has a macro definition, it will be
  522. expanded as a macro.
  523.    If the name is followed by an opening parenthesis, the arguments
  524. will be collected before the macro is called.  If too few arguments are
  525. supplied, the missing arguments are taken to be the empty string.  If
  526. there are too many arguments, the excess arguments are ignored.
  527.    Normally `m4' will issue warnings if a builtin macro is called with
  528. an inappropriate number of arguments, but it can be suppressed with the
  529. `-Q' command line option.  For user defined macros, there is no check
  530. of the number of arguments given.
  531.    Macros are expanded normally during argument collection, and whatever
  532. commas, quotes and parentheses that might show up in the resulting
  533. expanded text will serve to define the arguments as well.  Thus, if FOO
  534. expands to `, b, c', the macro call
  535.      bar(a foo, d)
  536.    is a macro call with four arguments, which are `a ', `b', `c' and
  537. `d'.  To understand why the first argument contains whitespace,
  538. remember that leading unquoted whitespace is never part of an argument,
  539. but trailing whitespace always is.
  540. File: m4.info,  Node: Quoting Arguments,  Next: Macro expansion,  Prev: Macro Arguments,  Up: Macros
  541. Quoting macro arguments
  542. =======================
  543.    Each argument has leading unquoted whitespace removed.  Within each
  544. argument, all unquoted parentheses must match.  For example, if FOO is
  545. a macro,
  546.      foo(() (`(') `(')
  547.    is a macro call, with one argument, whose value is `() (() ('.
  548.    It is common practice to quote all arguments to macros, unless you
  549. are sure you want the arguments expanded.  Thus, in the above example
  550. with the parentheses, the `right' way to do it is like this:
  551.      foo(`() (() (')
  552.    It is, however, in certain cases necessary to leave out quotes for
  553. some arguments, and there is nothing wrong in doing it.  It just makes
  554. life a bit harder, if you are not careful.
  555. File: m4.info,  Node: Macro expansion,  Prev: Quoting Arguments,  Up: Macros
  556. Macro expansion
  557. ===============
  558.    When the arguments, if any, to a macro call have been collected, the
  559. macro is expanded, and the expansion text is pushed back onto the input
  560. (unquoted), and reread.  The expansion text from one macro call might
  561. therefore result in more macros being called, if the calls are included,
  562. completely or partially, in the first macro calls' expansion.
  563.    Taking a very simple example, if FOO expands to `bar', and BAR
  564. expands to `Hello world', the input
  565.      foo
  566. will expand first to `bar', and when this is reread and expanded, into
  567. `Hello world'.
  568. File: m4.info,  Node: Definitions,  Next: Conditionals,  Prev: Macros,  Up: Top
  569. How to define new macros
  570. ************************
  571.    Macros can be defined, redefined and deleted in several different
  572. ways.  Also, it is possible to redefine a macro, without losing a
  573. previous value, which can be brought back at a later time.
  574. * Menu:
  575. * Define::                      Defining a new macro
  576. * Arguments::                   Arguments to macros
  577. * Pseudo Arguments::            Pseudo arguments to macros
  578. * Undefine::                    Deleting a macro
  579. * Defn::                        Renaming macros
  580. * Pushdef::                     Temporarily redefining macros
  581. * Indir::                       Indirect call of macros
  582. * Builtin::                     Indirect call of builtins
  583. File: m4.info,  Node: Define,  Next: Arguments,  Prev: Definitions,  Up: Definitions
  584. Defining a macro
  585. ================
  586.    The normal way to define or redefine macros is to use the builtin
  587. `define':
  588.      define(NAME [, EXPANSION])
  589. which defines NAME to expand to EXPANSION.  If EXPANSION is not given,
  590. it is taken to be empty.
  591.    The expansion of `define' is void.
  592.    The following example defines the macro FOO to expand to the text
  593. `Hello World.'.
  594.      define(`foo', `Hello world.')
  595.      =>
  596.      foo
  597.      =>Hello world.
  598.    The empty line in the output is there because the newline is not a
  599. part of the macro definition, and it is consequently copied to the
  600. output.  This can be avoided by use of the macro `dnl'.  *Note Dnl::,
  601. for details.
  602.    The macro `define' is recognized only with parameters.
  603. File: m4.info,  Node: Arguments,  Next: Pseudo Arguments,  Prev: Define,  Up: Definitions
  604. Arguments to macros
  605. ===================
  606.    Macros can have arguments.  The Nth argument is denoted by `$n' in
  607. the expansion text, and is replaced by the Nth actual argument, when
  608. the macro is expanded.  Here is a example of a macro with two
  609. arguments.  It simply exchanges the order of the two arguments.
  610.      define(`exch', `$2, $1')
  611.      =>
  612.      exch(arg1, arg2)
  613.      =>arg2, arg1
  614.    This can be used, for example, if you like the arguments to `define'
  615. to be reversed.
  616.      define(`exch', `$2, $1')
  617.      =>
  618.      define(exch(``expansion text'', ``macro''))
  619.      =>
  620.      macro
  621.      =>expansion text
  622.    *Note Quoting Arguments::, for an explanation of the double quotes.
  623.    GNU `m4' allows the number following the `$' to consist of one or
  624. more digits, allowing macros to have any number of arguments.  This is
  625. not so in UNIX implementations of `m4', which only recognize one digit.
  626.    As a special case, the zero'th argument, `$0', is always the name of
  627. the macro being expanded.
  628.      define(`test', ``Macro name: $0'')
  629.      =>
  630.      test
  631.      =>Macro name: test
  632.    If you want quoted text to appear as part of the expansion text,
  633. remember that quotes can be nested in quoted strings.  Thus, in
  634.      define(`foo', `This is macro `foo'.')
  635.      =>
  636.      foo
  637.      =>This is macro foo.
  638. The `foo' in the expansion text is *not* expanded, since it is a quoted
  639. string, and not a name.
  640. File: m4.info,  Node: Pseudo Arguments,  Next: Undefine,  Prev: Arguments,  Up: Definitions
  641. Special arguments to macros
  642. ===========================
  643.    There is a special notation for the number of actual arguments
  644. supplied, and for all the actual arguments.
  645.    The number of actual arguments in a macro call is denoted by `$#' in
  646. the expansion text.  Thus, a macro to display the number of arguments
  647. given can be
  648.      define(`nargs', `$#')
  649.      =>
  650.      nargs
  651.      =>0
  652.      nargs()
  653.      =>1
  654.      nargs(arg1, arg2, arg3)
  655.      =>3
  656.    The notation `$*' can be used in the expansion text to denote all
  657. the actual arguments, unquoted, with commas in between.  For example
  658.      define(`echo', `$*')
  659.      =>
  660.      echo(arg1,    arg2, arg3 , arg4)
  661.      =>arg1,arg2,arg3 ,arg4
  662.    Often each argument should be quoted, and the notation `$@' handles
  663. that.  It is just like `$*', except that it quotes each argument.  A
  664. simple example of that is:
  665.      define(`echo', `$@')
  666.      =>
  667.      echo(arg1,    arg2, arg3 , arg4)
  668.      =>arg1,arg2,arg3 ,arg4
  669.    Where did the quotes go?  Of course, they were eaten, when the
  670. expanded text were reread by `m4'.  To show the difference, try
  671.      define(`echo1', `$*')
  672.      =>
  673.      define(`echo2', `$@')
  674.      =>
  675.      define(`foo', `This is macro `foo'.')
  676.      =>
  677.      echo1(foo)
  678.      =>This is macro This is macro foo..
  679.      echo2(foo)
  680.      =>This is macro foo.
  681. *Note Trace::, if you do not understand this.
  682.    A `$' sign in the expansion text, that is not followed by anything
  683. `m4' understands, is simply copied to the macro expansion, as any other
  684. text is.
  685.      define(`foo', `$$$ hello $$$')
  686.      =>
  687.      foo
  688.      =>$$$ hello $$$
  689.    If you want a macro to expand to something like `$12', put a pair of
  690. quotes after the `$'.  This will prevent `m4' from interpreting the `$'
  691. sign as a reference to an argument.
  692. File: m4.info,  Node: Undefine,  Next: Defn,  Prev: Pseudo Arguments,  Up: Definitions
  693. Deleting a macro
  694. ================
  695.    A macro definition can be removed with `undefine':
  696.      undefine(NAME)
  697. which removes the macro NAME.  The macro name must necessarily be
  698. quoted, since it will be expanded otherwise.
  699.    The expansion of `undefine' is void.
  700.      foo
  701.      =>foo
  702.      define(`foo', `expansion text')
  703.      =>
  704.      foo
  705.      =>expansion text
  706.      undefine(`foo')
  707.      =>
  708.      foo
  709.      =>foo
  710.    It is not an error for NAME to have no macro definition.  In that
  711. case, `undefine' does nothing.
  712.    The macro `undefine' is recognized only with parameters.
  713. File: m4.info,  Node: Defn,  Next: Pushdef,  Prev: Undefine,  Up: Definitions
  714. Renaming macros
  715. ===============
  716.    It is possible to rename an already defined macro.  To do this, you
  717. need the builtin `defn':
  718.      defn(NAME)
  719. which expands to the *quoted definition* of NAME.  If the argument is
  720. not a defined macro, the expansion is void.
  721.    If NAME is a user-defined macro, the quoted definition is simply the
  722. quoted expansion text.  If, instead, NAME is a builtin, the expansion
  723. is a special token, which points to the builtin's internal definition.
  724. This token is only meaningful as the second argument to `define' (and
  725. `pushdef'), and is ignored in any other context.
  726.    Its normal use is best understood through an example, which shows
  727. how to rename `undefine' to `zap':
  728.      define(`zap', defn(`undefine'))
  729.      =>
  730.      zap(`undefine')
  731.      =>
  732.      undefine(`zap')
  733.      =>undefine(zap)
  734.    In this way, `defn' can be used to copy macro definitions, and also
  735. definitions of builtin macros.  Even if the original macro is removed,
  736. the other name can still be used to access the definition.
  737.    The macro `defn' is recognized only with parameters.
  738. File: m4.info,  Node: Pushdef,  Next: Indir,  Prev: Defn,  Up: Definitions
  739. Temporarily redefining macros
  740. =============================
  741.    It is possible to redefine a macro temporarily, reverting to the
  742. previous definition at a later time.  This is done with the builtins
  743. `pushdef' and `popdef':
  744.      pushdef(NAME [, EXPANSION])
  745.      popdef(NAME)
  746. which are quite analogous to `define' and `undefine'.
  747.    These macros work in a stack-like fashion.  A macro is temporarily
  748. redefined with `pushdef', which replaces an existing definition of
  749. NAME, while saving the previous definition, before the new one is
  750. installed.  If there is no previous definition, `pushdef' behaves
  751. exactly like `define'.
  752.    If a macro has several definitions (of which only one is accessible),
  753. the topmost definition can be removed with `popdef'.  If there is no
  754. previous definition, `popdef' behaves like `undefine'.
  755.      define(`foo', `Expansion one.')
  756.      =>
  757.      foo
  758.      =>Expansion one.
  759.      pushdef(`foo', `Expansion two.')
  760.      =>
  761.      foo
  762.      =>Expansion two.
  763.      popdef(`foo')
  764.      =>
  765.      foo
  766.      =>Expansion one.
  767.      popdef(`foo')
  768.      =>
  769.      foo
  770.      =>foo
  771.    If a macro with several definitions is redefined with `define', the
  772. topmost definition is *replaced* with the new definition.  If it is
  773. removed with `undefine', *all* the definitions are removed, and not
  774. only the topmost one.
  775.      define(`foo', `Expansion one.')
  776.      =>
  777.      foo
  778.      =>Expansion one.
  779.      pushdef(`foo', `Expansion two.')
  780.      =>
  781.      foo
  782.      =>Expansion two.
  783.      define(`foo', `Second expansion two.')
  784.      =>
  785.      foo
  786.      =>Second expansion two.
  787.      undefine(`foo')
  788.      =>
  789.      foo
  790.      =>foo
  791.    It is possible to temporarily redefine a builtin with `pushdef' and
  792. `defn'.
  793.    The macros `pushdef' and `popdef' are recognized only with
  794. parameters.
  795. File: m4.info,  Node: Indir,  Next: Builtin,  Prev: Pushdef,  Up: Definitions
  796. Indirect call of macros
  797. =======================
  798.    Any macro can be called indirectly with `indir':
  799.      indir(NAME, ...)
  800. which results in a call to the macro NAME, which is passed the rest of
  801. the arguments.  This can be used to call macros with "illegal" names
  802. (`define' allows such names to be defined):
  803.      define(`$$internal$macro', `Internal macro (name `$0')')
  804.      =>
  805.      $$internal$macro
  806.      =>$$internal$macro
  807.      indir(`$$internal$macro')
  808.      =>Internal macro (name $$internal$macro)
  809.    The point is, here, that larger macro packages can have private
  810. macros defined, that will not be called by accident.  They can *only* be
  811. called through the builtin `indir'.
  812. File: m4.info,  Node: Builtin,  Prev: Indir,  Up: Definitions
  813. Indirect call of builtins
  814. =========================
  815.    Builtin macros can be called indirectly with `builtin':
  816.      builtin(NAME, ...)
  817. which results in a call to the builtin NAME, which is passed the rest
  818. of the arguments.  This can be used, if NAME has been given another
  819. definition that has covered the original.
  820.    The macro `builtin' is recognized only with parameters.
  821. File: m4.info,  Node: Conditionals,  Next: Debugging,  Prev: Definitions,  Up: Top
  822. Conditionals, loops and recursion
  823. *********************************
  824.    Macros, expanding to plain text, perhaps with arguments, are not
  825. quite enough.  We would like to have macros expand to different things,
  826. based on decisions taken at run-time.  E.g., we need some kind of
  827. conditionals.  Also, we would like to have some kind of loop construct,
  828. so we could do something a number of times, or while some condition is
  829. true.
  830. * Menu:
  831. * Ifdef::                       Testing if a macro is defined
  832. * Ifelse::                      If-else construct, or multibranch
  833. * Loops::                       Loops and recursion in m4
  834. File: m4.info,  Node: Ifdef,  Next: Ifelse,  Prev: Conditionals,  Up: Conditionals
  835. Testing macro definitions
  836. =========================
  837.    There are two different builtin conditionals in `m4'.  The first is
  838. `ifdef':
  839.      ifdef(NAME, STRING-1, opt STRING-2)
  840. which makes it possible to test whether a macro is defined or not.  If
  841. NAME is defined as a macro, `ifdef' expands to STRING-1, otherwise to
  842. STRING-2.  If STRING-2 is omitted, it is taken to be the empty string
  843. (according to the normal rules).
  844.      ifdef(`foo', ``foo' is defined', ``foo' is not defined')
  845.      =>foo is not defined
  846.      define(`foo', `')
  847.      =>
  848.      ifdef(`foo', ``foo' is defined', ``foo' is not defined')
  849.      =>foo is defined
  850.    The macro `ifdef' is recognized only with parameters.
  851. File: m4.info,  Node: Ifelse,  Next: Loops,  Prev: Ifdef,  Up: Conditionals
  852. Comparing strings
  853. =================
  854.    The other conditional, `ifelse', is much more powerful.  It can be
  855. used as a way to introduce a long comment, as an if-else construct, or
  856. as a multibranch, depending on the number of arguments supplied:
  857.      ifelse(COMMENT)
  858.      ifelse(STRING-1, STRING-2, EQUAL, opt NOT-EQUAL)
  859.      ifelse(STRING-1, STRING-2, EQUAL, ...)
  860. Used with only one argument, the `ifelse' simply discards it and
  861. produces no output.  This is a common `m4' idiom for introducing a
  862. block comment, as an alternative to repeatedly using `dnl'.  This
  863. special usage is recognized by GNU `m4', so that in this case, the
  864. warning about missing arguments is never triggered.
  865.    If called with three or four arguments, `ifelse' expands into EQUAL,
  866. if STRING-1 and STRING-2 are equal (character for character), otherwise
  867. it expands to NOT-EQUAL.
  868.      ifelse(foo, bar, `true')
  869.      =>
  870.      ifelse(foo, foo, `true')
  871.      =>true
  872.      ifelse(foo, bar, `true', `false')
  873.      =>false
  874.      ifelse(foo, foo, `true', `false')
  875.      =>true
  876.    However, `ifelse' can take more than four arguments.  If given more
  877. than four arguments, `ifelse' works like a `case' or `switch' statement
  878. in traditional programming languages.  If STRING-1 and STRING-2 are
  879. equal, `ifelse' expands into EQUAL, otherwise the procedure is repeated
  880. with the first three arguments discarded.  This calls for an example:
  881.      ifelse(foo, bar, `third', gnu, gnats, `sixth', `seventh')
  882.      =>seventh
  883.    Naturally, the normal case will be slightly more advanced than these
  884. examples.  A common use of `ifelse' is in macros implementing loops of
  885. various kinds.
  886.    The macro `ifelse' is recognized only with parameters.
  887. File: m4.info,  Node: Loops,  Prev: Ifelse,  Up: Conditionals
  888. Loops and recursion
  889. ===================
  890.    There is no direct support for loops in `m4', but macros can be
  891. recursive.  There is no limit on the number of recursion levels, other
  892. than those enforced by your hardware and operating system.
  893.    Loops can be programmed using recursion and the conditionals
  894. described previously.
  895.    There is a builtin macro, `shift', which can, among other things, be
  896. used for iterating through the actual arguments to a macro:
  897.      shift(...)
  898. It takes any number of arguments, and expands to all but the first
  899. argument, separated by commas, with each argument quoted.
  900.      shift(bar)
  901.      =>
  902.      shift(foo, bar, baz)
  903.      =>bar,baz
  904.    An example of the use of `shift' is this macro, which reverses the
  905. order of its arguments:
  906.      define(`reverse', `ifelse($#, 0, , $#, 1, ``$1'',
  907.                    `reverse(shift($@)), `$1'')')
  908.      =>
  909.      reverse
  910.      =>
  911.      reverse(foo)
  912.      =>foo
  913.      reverse(foo, bar, gnats, and gnus)
  914.      =>and gnus, gnats, bar, foo
  915.    While not a very interesting macro, it does show how simple loops
  916. can be made with `shift', `ifelse' and recursion.
  917.    Here is an example of a loop macro that implements a simple forloop.
  918. It can, for example, be used for simple counting:
  919.      forloop(`i', 1, 8, `i ')
  920.      =>1 2 3 4 5 6 7 8
  921.    The arguments are a name for the iteration variable, the starting
  922. value, the final value, and the text to be expanded for each iteration.
  923. With this macro, the macro `i' is defined only within the loop.  After
  924. the loop, it retains whatever value it might have had before.
  925.    For-loops can be nested, like
  926.      forloop(`i', 1, 4, `forloop(`j', 1, 8, `(i, j) ')
  927.      ')
  928.      =>(1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8)
  929.      =>(2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8)
  930.      =>(3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8)
  931.      =>(4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (4, 7) (4, 8)
  932.      =>
  933.    The implementation of the `forloop' macro is fairly straightforward.
  934. The `forloop' macro itself is simply a wrapper, which saves the
  935. previous definition of the first argument, calls the internal macro
  936. `_forloop', and re-establishes the saved definition of the first
  937. argument.
  938.    The macro `_forloop' expands the fourth argument once, and tests to
  939. see if it is finished.  If it has not finished, it increments the
  940. iteration variable (using the predefined macro `incr', *note Incr::.),
  941. and recurses.
  942.    Here is the actual implementation of `forloop':
  943.      define(`forloop',
  944.             `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
  945.      define(`_forloop',
  946.             `$4`'ifelse($1, `$3', ,
  947.                 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
  948.    Notice the careful use of quotes.  Only three macro arguments are
  949. unquoted, each for its own reason.  Try to find out *why* these three
  950. arguments are left unquoted, and see what happens if they are quoted.
  951.    Now, even though these two macros are useful, they are still not
  952. robust enough for general use. They lack even basic error handling of
  953. cases like start value less than final value, and the first argument
  954. not being a name.  Correcting these errors are left as an exercise to
  955. the reader.
  956. File: m4.info,  Node: Debugging,  Next: Input Control,  Prev: Conditionals,  Up: Top
  957. How to debug macros and input
  958. *****************************
  959.    When writing macros for `m4', most of the time they woould not work
  960. as intended (as is the case with most programming languages).  There is
  961. a little support for macro debugging in `m4'.
  962. * Menu:
  963. * Dumpdef::                     Displaying macro definitions
  964. * Trace::                       Tracing macro calls
  965. * Debug Levels::                Controlling debugging output
  966. * Debug Output::                Saving debugging output
  967. File: m4.info,  Node: Dumpdef,  Next: Trace,  Prev: Debugging,  Up: Debugging
  968. Displaying macro definitions
  969. ============================
  970.    If you want to see what a name expands into, you can use the builtin
  971. `dumpdef':
  972.      dumpdef(...)
  973. which accepts any number of arguments.  If called without any arguments,
  974. it displays the definitions of all known names, otherwise it displays
  975. the definitions of the names given.  The output is printed directly on
  976. the standard error output.
  977.    The expansion of `dumpdef' is void.
  978.      define(`foo', `Hello world.')
  979.      =>
  980.      dumpdef(`foo')
  981.      error-->foo:    `Hello world.'
  982.      =>
  983.      dumpdef(`define')
  984.      error-->define:    <define>
  985.      =>
  986.    The last example shows how builtin macros definitions are displayed.
  987.    *Note Debug Levels:: for information on controlling the details of
  988. the display.
  989. File: m4.info,  Node: Trace,  Next: Debug Levels,  Prev: Dumpdef,  Up: Debugging
  990. Tracing macro calls
  991. ===================
  992.    It is possible to trace macro calls and expansions through the
  993. builtins `traceon' and `traceoff':
  994.      traceon(...)
  995.      traceoff(...)
  996. When called without any arguments, `traceon' and `traceoff' will turn
  997. tracing on and off, respectively,  for all defined macros.  When called
  998. with arguments, only the named macros are affected.
  999.    The expansion of `traceon' and `traceoff' is void.
  1000.    Whenever a traced macro is called and the arguments have been
  1001. collected, the call is displayed.  If the expansion of the macro call
  1002. is not void, the expansion can be displayed after the call.  The output
  1003. is printed directly on the standard error output.
  1004.      define(`foo', `Hello World.')
  1005.      =>
  1006.      define(`echo', `$@')
  1007.      =>
  1008.      traceon(`foo', `echo')
  1009.      =>
  1010.      foo
  1011.      error-->m4trace: -1- foo -> `Hello World.'
  1012.      =>Hello World.
  1013.      echo(gnus, and gnats)
  1014.      error-->m4trace: -1- echo(`gnus', `and gnats') -> ``gnus',`and gnats''
  1015.      =>gnus,and gnats
  1016.    The number between dashes is the depth of the expansion.  It is one
  1017. most of the time, signifying an expansion at the outermost level, but it
  1018. increases when macro arguments contain unquoted macro calls.
  1019.    *Note Debug Levels:: for information on controlling the details of
  1020. the display.
  1021. File: m4.info,  Node: Debug Levels,  Next: Debug Output,  Prev: Trace,  Up: Debugging
  1022. Controlling debugging output
  1023. ============================
  1024.    The `-d' option to `m4' controls the amount of details presented,
  1025. when using the macros described in the preceding sections.
  1026.    The FLAGS following the option can be one or more of the following:
  1027.      Trace all macro calls made in this invocation of `m4'.
  1028.      Show the actual arguments in each macro call.  This applies to all
  1029.      macro calls if the `t' flag is used, otherwise only the macros
  1030.      covered by calls of `traceon'.
  1031.      Show the expansion of each macro call, if it is not void.  This
  1032.      applies to all macro calls if the `t' flag is used, otherwise only
  1033.      the macros covered by calls of `traceon'.
  1034.      Quote actual arguments and macro expansions in the display with the
  1035.      current quotes.
  1036.      Show several trace lines for each macro call.  A line is shown
  1037.      when the macro is seen, but before the arguments are collected; a
  1038.      second line when the arguments have been collected and a third
  1039.      line after the call has completed.
  1040.      Add a unique `macro call id' to each line of the trace output.
  1041.      This is useful in connection with the `c' flag above.
  1042.      Show the name of the current input file in each trace output line.
  1043.      Show the the current input line number in each trace output line.
  1044.      Print a message when a named file is found through the path search
  1045.      mecanism (*note Search Path::.), giving the actual filename used.
  1046.      Print a message each time the current input file is changed,
  1047.      giving file name and input line number.
  1048.      A shorthand for all of the above flags.
  1049.    If no flags are specified with the `-d' option, the default is
  1050. `aeq'. The examples in the previous two sections assumed the default
  1051. flags.
  1052.    There is a builtin macro `debugmode', which allows on-the-fly
  1053. control of the debugging output format:
  1054.      debugmode(opt FLAGS)
  1055. The argument FLAGS should be a subset of the letters listed above.  As
  1056. special cases, if the argument starts with a `+', the flags are added
  1057. to the current debug flags, and if it starts with a `-', they are
  1058. removed.  If no argument is present, the debugging flags are set to
  1059. zero (as if no `-d' was given), and with an empty argument the flags
  1060. are reset to the default.
  1061.