CVSROOT: /sources/m4
Module name: m4
Branch: branch-1_4
Changes by: Eric Blake <ericb> 06/07/03 13:16:19
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.29
retrieving revision 1.1.1.1.2.30
diff -u -b -r1.1.1.1.2.29 -r1.1.1.1.2.30
--- doc/m4.texinfo 30 Jun 2006 18:58:11 -0000 1.1.1.1.2.29
+++ doc/m4.texinfo 3 Jul 2006 13:16:18 -0000 1.1.1.1.2.30
@@ -1629,10 +1629,11 @@
Here is an example of a loop macro that implements a simple for loop. It
can, for example, be used for simple counting:
[EMAIL PROTECTED] ignore
@example
+include(`forloop.m4')
[EMAIL PROTECTED]
forloop(`i', `1', `8', `i ')
[EMAIL PROTECTED] 2 3 4 5 6 7 8
[EMAIL PROTECTED] 2 3 4 5 6 7 8 @comment
@end example
The arguments are a name for the iteration variable, the starting value,
@@ -1642,14 +1643,15 @@
For-loops can be nested, like
[EMAIL PROTECTED] ignore
@example
+include(`forloop.m4')
[EMAIL PROTECTED]
forloop(`i', `1', `4', `forloop(`j', `1', `8', `(i, j) ')
')
[EMAIL PROTECTED](1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8)
[EMAIL PROTECTED](2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8)
[EMAIL PROTECTED](3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8)
[EMAIL PROTECTED](4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (4, 7) (4, 8)
[EMAIL PROTECTED](1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8)
@comment
[EMAIL PROTECTED](2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8)
@comment
[EMAIL PROTECTED](3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8)
@comment
[EMAIL PROTECTED](4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (4, 7) (4, 8)
@comment
@result{}
@end example
@@ -1664,16 +1666,19 @@
the iteration variable (using the predefined macro @code{incr},
@pxref{Incr}), and recurses.
-Here is the actual implementation of @code{forloop}:
+Here is the actual implementation of @code{forloop}, distributed as
[EMAIL PROTECTED]/forloop.m4} in this package:
[EMAIL PROTECTED] ignore
@example
-define(`forloop',
- `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
[EMAIL PROTECTED]
-define(`_forloop',
- `$4`'ifelse($1, `$3', ,
- `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
+undivert(`forloop.m4')
[EMAIL PROTECTED](`-1')
[EMAIL PROTECTED] forloop(var, from, to, stmt)
[EMAIL PROTECTED](`forloop',
[EMAIL PROTECTED] `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3',
`$4')popdef(`$1')')
[EMAIL PROTECTED](`_forloop',
[EMAIL PROTECTED] `$4`'ifelse($1, `$3', ,
[EMAIL PROTECTED] `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
[EMAIL PROTECTED]'dnl
@result{}
@end example
@@ -2365,7 +2370,10 @@
@result{}
@end example
-Assume in the following that the file @file{incl.m4} contains the lines:
+The rest of this section assumes that @code{m4} is invoked with the
[EMAIL PROTECTED] option pointing to the @file{examples} directory shipped as
+part of the GNU @code{m4} package. The file @file{examples/incl.m4} in
+the distribution contains the lines:
@comment ignore
@example
Include file start
@@ -2602,8 +2610,8 @@
GNU @code{m4} allows named files to be undiverted. Given a non-numeric
argument, the contents of the file named will be copied, uninterpreted, to
the current output. This complements the builtin @code{include}
-(@pxref{Include}). To illustrate the difference, assume the file
[EMAIL PROTECTED] contains the word @samp{bar}:
+(@pxref{Include}). To illustrate the difference, the file
[EMAIL PROTECTED]/foo} contains the word @samp{bar}:
@example
define(`bar', `BAR')
@@ -2978,8 +2986,9 @@
Using the @code{forloop} macro defined in @xref{Loops}, this
example shows how @code{format} can be used to produce tabular output.
[EMAIL PROTECTED] ignore
@example
+include(`forloop.m4')
[EMAIL PROTECTED]
forloop(`i', `1', `10', `format(`%6d squared is %10d
', i, eval(i**2))')
@result{} 1 squared is 1
@@ -2992,6 +3001,7 @@
@result{} 8 squared is 64
@result{} 9 squared is 81
@result{} 10 squared is 100
[EMAIL PROTECTED]
@end example
The builtin @code{format} is modeled after the ANSI C @samp{printf}
@@ -3867,10 +3877,11 @@
processes all arguments, with output separated by spaces.
However, it is possible to emulate @acronym{POSIX} behavior by
-including the sample file @file{wrapfifo.m4}:
+including the file @file{examples/wrapfifo.m4} from the distribution:
@example
undivert(`wrapfifo.m4')dnl
[EMAIL PROTECTED] Redefine m4wrap to have FIFO semantics.
@result{}define(`_m4wrap_level', `0')dnl
@result{}define(`m4wrap',
@result{}`ifdef(`m4wrap'_m4wrap_level,