NBash
1divert(-1)
2
3m4 has multiple output queues that can be manipulated with the
4`divert' macro. Valid queues range from 0 to 10, inclusive, with
5the default queue being 0. As an extension, GNU m4 supports more
6diversions, limited only by integer type size.
7
8Calling the `divert' macro with an invalid queue causes text to be
9discarded until another call. Note that even while output is being
10discarded, quotes around `divert' and other macros are needed to
11prevent expansion.
12
13# Macros aren't expanded within comments, meaning that keywords such
14# as divert and other built-ins may be used without consequence.
15
16# HTML utility macro:
17
18define(`H2_COUNT', 0)
19
20# The H2_COUNT macro is redefined every time the H2 macro is used:
21
22define(`H2',
23`define(`H2_COUNT', incr(H2_COUNT))<h2>H2_COUNT. $1</h2>')
24
25divert(1)dnl
26dnl
27dnl The dnl macro causes m4 to discard the rest of the line, thus
28dnl preventing unwanted blank lines from appearing in the output.
29dnl
30H2(First Section)
31H2(Second Section)
32H2(Conclusion)
33dnl
34divert(0)dnl
35dnl
36<HTML>
37undivert(1)dnl One of the queues is being pushed to output.
38</HTML>