422 |
[m4_if([$#], 0, [], |
[m4_if([$#], 0, [], |
423 |
[$#], 1, [], |
[$#], 1, [], |
424 |
[$#], 2, [$2], |
[$#], 2, [$2], |
425 |
m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))], |
[m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))], |
426 |
[$3])]) |
[$3])])]) |
427 |
|
|
428 |
|
|
429 |
# m4_map(MACRO, LIST) |
# m4_map(MACRO, LIST) |
437 |
m4_map([$1], m4_cdr($2))])]) |
m4_map([$1], m4_cdr($2))])]) |
438 |
|
|
439 |
|
|
440 |
|
# m4_map_sep(MACRO, SEPARATOR, LIST) |
441 |
|
# ---------------------------------- |
442 |
|
# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N |
443 |
|
# are the elements of LIST (which can be lists themselves, for multiple |
444 |
|
# arguments MACROs). |
445 |
|
m4_define([m4_map_sep], |
446 |
|
[m4_if([$3], [[]], [], |
447 |
|
[$1(m4_fst($3))[]dnl |
448 |
|
m4_if(m4_cdr($3), |
449 |
|
[[]], [], |
450 |
|
[$2])[]dnl |
451 |
|
m4_map_sep([$1], [$2], m4_cdr($3))])]) |
452 |
|
|
453 |
|
|
454 |
## ---------------------------------------- ## |
## ---------------------------------------- ## |
455 |
## 6. Enhanced version of some primitives. ## |
## 6. Enhanced version of some primitives. ## |
456 |
## ---------------------------------------- ## |
## ---------------------------------------- ## |
483 |
# ------------------ |
# ------------------ |
484 |
# This macro invokes all its arguments (in sequence, of course). It is |
# This macro invokes all its arguments (in sequence, of course). It is |
485 |
# useful for making your macros more structured and readable by dropping |
# useful for making your macros more structured and readable by dropping |
486 |
# unecessary dnl's and have the macros indented properly. |
# unnecessary dnl's and have the macros indented properly. |
487 |
m4_define([m4_do], |
m4_define([m4_do], |
488 |
[m4_if($#, 0, [], |
[m4_if($#, 0, [], |
489 |
$#, 1, [$1], |
$#, 1, [$1], |
629 |
# Implementing `foreach' loops in m4 is much more tricky than it may |
# Implementing `foreach' loops in m4 is much more tricky than it may |
630 |
# seem. Actually, the example of a `foreach' loop in the m4 |
# seem. Actually, the example of a `foreach' loop in the m4 |
631 |
# documentation is wrong: it does not quote the arguments properly, |
# documentation is wrong: it does not quote the arguments properly, |
632 |
# which leads to undesired expansions. |
# which leads to undesirable expansions. |
633 |
# |
# |
634 |
# The example in the documentation is: |
# The example in the documentation is: |
635 |
# |
# |
1498 |
# of brackets around $1 (don't forget that the result must be quoted |
# of brackets around $1 (don't forget that the result must be quoted |
1499 |
# too, hence one more quoting than applications). |
# too, hence one more quoting than applications). |
1500 |
# |
# |
1501 |
# Then notice the 2 last pattens: they are in charge of removing the |
# Then notice the 2 last patterns: they are in charge of removing the |
1502 |
# leading/trailing spaces. Why not just `[^ ]'? Because they are |
# leading/trailing spaces. Why not just `[^ ]'? Because they are |
1503 |
# applied to doubly quoted strings, i.e. more or less [[STRING]]. So |
# applied to doubly quoted strings, i.e. more or less [[STRING]]. So |
1504 |
# if there is a leading space in STRING, then it is the *third* |
# if there is a leading space in STRING, then it is the *third* |