www.delorie.com/gnu/docs/m4/m4_46.html   search  
 
Buy GNU books!


GNU macro processor

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.1 Diverting output

Output is diverted using divert:

 
divert(opt number)

where number is the diversion to be used. If number is left out, it is assumed to be zero.

The expansion of divert is void.

When all the m4 input will have been processed, all existing diversions are automatically undiverted, in numerical order.

 
divert(1)
This text is diverted.
divert
=>
This text is not diverted.
=>This text is not diverted.
^D
=>
=>This text is diverted.

Several calls of divert with the same argument do not overwrite the previous diverted text, but append to it.

If output is diverted to a non-existent diversion, it is simply discarded. This can be used to suppress unwanted output. A common example of unwanted output is the trailing newlines after macro definitions. Here is how to avoid them.

 
divert(-1)
define(`foo', `Macro `foo'.')
define(`bar', `Macro `bar'.')
divert
=>

This is a common programming idiom in m4.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003