1 | m4_dnl
|
---|
2 | m4_dnl Copyright (C) 2000 Stephen Cleary
|
---|
3 | m4_dnl
|
---|
4 | m4_dnl This file can be redistributed and/or modified under the terms found
|
---|
5 | m4_dnl in "copyright.html"
|
---|
6 | m4_dnl This software and its documentation is provided "as is" without express or
|
---|
7 | m4_dnl implied warranty, and with no claim as to its suitability for any purpose.
|
---|
8 | m4_dnl
|
---|
9 | m4_dnl See http://www.boost.org for updates, documentation, and revision history.
|
---|
10 | m4_dnl
|
---|
11 | m4_dnl
|
---|
12 | m4_dnl
|
---|
13 | m4_dnl BOOST_M4_FOR: repeat a given text for a range of values
|
---|
14 | m4_dnl $1 - variable to hold the current value.
|
---|
15 | m4_dnl $2 - the starting value.
|
---|
16 | m4_dnl $3 - the ending value (text is _not_ repeated for this value).
|
---|
17 | m4_dnl $4 - the text to repeat.
|
---|
18 | m4_dnl $5 - the delimeter text (optional).
|
---|
19 | m4_dnl
|
---|
20 | m4_dnl If the starting value is < ending value:
|
---|
21 | m4_dnl Will repeat $4, binding $1 to the values in the range [$2, $3).
|
---|
22 | m4_dnl Else (that is, starting value >= ending value):
|
---|
23 | m4_dnl Will do nothing
|
---|
24 | m4_dnl Repeats $5 in-between each occurrence of $4
|
---|
25 | m4_dnl
|
---|
26 | m4_dnl Logic:
|
---|
27 | m4_dnl Set $1 to $2 and call BOOST_M4_FOR_LIST_HELPER:
|
---|
28 | m4_dnl If $1 >= $3, do nothing
|
---|
29 | m4_dnl Else
|
---|
30 | m4_dnl output $4,
|
---|
31 | m4_dnl set $1 to itself incremented,
|
---|
32 | m4_dnl If $1 != $3, output $5,
|
---|
33 | m4_dnl and use recursion
|
---|
34 | m4_dnl
|
---|
35 | m4_define(`BOOST_M4_FOR',
|
---|
36 | `m4_ifelse(m4_eval($# < 4 || $# > 5), 1,
|
---|
37 | `m4_errprint(m4___file__:m4___line__: `Boost m4 script: BOOST_M4_FOR: Wrong number of arguments ($#)')',
|
---|
38 | `m4_pushdef(`$1', `$2')BOOST_M4_FOR_HELPER($@)m4_popdef(`$1')')')m4_dnl
|
---|
39 | m4_define(`BOOST_M4_FOR_HELPER',
|
---|
40 | `m4_ifelse(m4_eval($1 >= $3), 1, ,
|
---|
41 | `$4`'m4_define(`$1', m4_incr($1))m4_ifelse(m4_eval($1 != $3), 1, `$5')`'BOOST_M4_FOR_HELPER($@)')')m4_dnl
|
---|
42 | m4_dnl
|
---|
43 | m4_dnl Testing/Examples:
|
---|
44 | m4_dnl
|
---|
45 | m4_dnl The following line will output:
|
---|
46 | m4_dnl "repeat.m4:42: Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (3)"
|
---|
47 | m4_dnl BOOST_M4_FOR(i, 1, 3)
|
---|
48 | m4_dnl
|
---|
49 | m4_dnl The following line will output:
|
---|
50 | m4_dnl "repeat.m4:46: Boost m4 script: BOOST_M4_FOR: Wrong number of arguments (6)"
|
---|
51 | m4_dnl BOOST_M4_FOR(i, 1, 3, i, ` ', 13)
|
---|
52 | m4_dnl
|
---|
53 | m4_dnl The following line will output (nothing):
|
---|
54 | m4_dnl ""
|
---|
55 | m4_dnl BOOST_M4_FOR(i, 7, 0, i )
|
---|
56 | m4_dnl
|
---|
57 | m4_dnl The following line will output (nothing):
|
---|
58 | m4_dnl ""
|
---|
59 | m4_dnl BOOST_M4_FOR(i, 0, 0, i )
|
---|
60 | m4_dnl
|
---|
61 | m4_dnl The following line will output:
|
---|
62 | m4_dnl "0 1 2 3 4 5 6 "
|
---|
63 | m4_dnl BOOST_M4_FOR(i, 0, 7, i )
|
---|
64 | m4_dnl
|
---|
65 | m4_dnl The following line will output:
|
---|
66 | m4_dnl "-13 -12 -11 "
|
---|
67 | m4_dnl BOOST_M4_FOR(i, -13, -10, i )
|
---|
68 | m4_dnl
|
---|
69 | m4_dnl The following two lines will output:
|
---|
70 | m4_dnl "(0, 0) (0, 1) (0, 2) (0, 3) "
|
---|
71 | m4_dnl "(1, 0) (1, 1) (1, 2) (1, 3) "
|
---|
72 | m4_dnl "(2, 0) (2, 1) (2, 2) (2, 3) "
|
---|
73 | m4_dnl "(3, 0) (3, 1) (3, 2) (3, 3) "
|
---|
74 | m4_dnl "(4, 0) (4, 1) (4, 2) (4, 3) "
|
---|
75 | m4_dnl "(5, 0) (5, 1) (5, 2) (5, 3) "
|
---|
76 | m4_dnl "(6, 0) (6, 1) (6, 2) (6, 3) "
|
---|
77 | m4_dnl "(7, 0) (7, 1) (7, 2) (7, 3) "
|
---|
78 | m4_dnl ""
|
---|
79 | m4_dnl BOOST_M4_FOR(i, 0, 8, BOOST_M4_FOR(j, 0, 4, (i, j) )
|
---|
80 | m4_dnl )
|
---|
81 | m4_dnl
|
---|
82 | m4_dnl The following line will output (nothing):
|
---|
83 | m4_dnl ""
|
---|
84 | m4_dnl BOOST_M4_FOR(i, 7, 0, i, |)
|
---|
85 | m4_dnl
|
---|
86 | m4_dnl The following line will output (nothing):
|
---|
87 | m4_dnl ""
|
---|
88 | m4_dnl BOOST_M4_FOR(i, 0, 0, i, |)
|
---|
89 | m4_dnl
|
---|
90 | m4_dnl The following line will output:
|
---|
91 | m4_dnl "0|1|2|3|4|5|6"
|
---|
92 | m4_dnl BOOST_M4_FOR(i, 0, 7, i, |)
|
---|
93 | m4_dnl
|
---|
94 | m4_dnl The following line will output:
|
---|
95 | m4_dnl "-13, -12, -11"
|
---|
96 | m4_dnl BOOST_M4_FOR(i, -13, -10, i, `, ')
|
---|
97 | m4_dnl
|
---|
98 | m4_dnl The following two lines will output:
|
---|
99 | m4_dnl "[(0, 0), (0, 1), (0, 2), (0, 3)],"
|
---|
100 | m4_dnl "[(1, 0), (1, 1), (1, 2), (1, 3)],"
|
---|
101 | m4_dnl "[(2, 0), (2, 1), (2, 2), (2, 3)],"
|
---|
102 | m4_dnl "[(3, 0), (3, 1), (3, 2), (3, 3)],"
|
---|
103 | m4_dnl "[(4, 0), (4, 1), (4, 2), (4, 3)],"
|
---|
104 | m4_dnl "[(5, 0), (5, 1), (5, 2), (5, 3)],"
|
---|
105 | m4_dnl "[(6, 0), (6, 1), (6, 2), (6, 3)],"
|
---|
106 | m4_dnl "[(7, 0), (7, 1), (7, 2), (7, 3)]"
|
---|
107 | m4_dnl BOOST_M4_FOR(i, 0, 8, `[BOOST_M4_FOR(j, 0, 4, (i, j), `, ')]', `,
|
---|
108 | m4_dnl ')
|
---|
109 | m4_dnl |
---|