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