]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/m4sugar/m4sugar.m4 (m4_case, m4_bmatch, m4_normalize)
authorAkim Demaille <akim@epita.fr>
Mon, 8 Oct 2001 08:22:49 +0000 (08:22 +0000)
committerAkim Demaille <akim@epita.fr>
Mon, 8 Oct 2001 08:22:49 +0000 (08:22 +0000)
(m4_list_cmp): Use $0 to reinvoke yourself.
(m4_patsubsts): New.
(m4_strip, m4_version_unletter): Use it.
* tests/atspecific.m4 (AT_DATA_M4SUGAR, AT_DATA_M4SH): Likewise.

ChangeLog
lib/m4sugar/m4sugar.m4
tests/atspecific.m4
tests/tools.at

index aaa7680dd34cf6cafb645485e070736beec684b4..b03dd7338675b7cc029a3acf1f508f7cce27ee86 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2001-10-08  Akim Demaille  <akim@epita.fr>
+
+       * lib/m4sugar/m4sugar.m4 (m4_case, m4_bmatch, m4_normalize)
+       (m4_list_cmp): Use $0 to reinvoke yourself.
+       (m4_patsubsts): New.
+       (m4_strip, m4_version_unletter): Use it.
+       * tests/atspecific.m4 (AT_DATA_M4SUGAR, AT_DATA_M4SH): Likewise.
+
+       
 2001-10-08  Akim Demaille  <akim@epita.fr>
 
        * lib/autoconf/autoconf.m4, lib/autoconf/general.m4,
index 8e459d4ca7a0351fc4989c31cc97aa23a33fb37f..6733134d4d2bab11eea9632764655b4bcfce430d 100644 (file)
@@ -400,7 +400,7 @@ m4_define([m4_case],
        [$#], 1, [],
        [$#], 2, [$2],
        [$1], [$2], [$3],
-       [m4_case([$1], m4_shiftn(3, $@))])])
+       [$0([$1], m4_shiftn(3, $@))])])
 
 
 # m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
@@ -422,7 +422,7 @@ m4_define([m4_bmatch],
 [m4_if([$#], 0, [],
        [$#], 1, [],
        [$#], 2, [$2],
-       m4_bregexp([$1], [$2]), -1, [m4_bmatch([$1], m4_shiftn(3, $@))],
+       m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
        [$3])])
 
 
@@ -431,6 +431,30 @@ m4_define([m4_bmatch],
 ## 6. Enhanced version of some primitives.  ##
 ## ---------------------------------------- ##
 
+# m4_patsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ---------------------------------------------------
+# m4 equivalent of
+#
+#   $_ = STRING;
+#   s/RE1/SUBST1/g;
+#   s/RE2/SUBST2/g;
+#   ...
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# I would have liked to name this macro `m4_patsubst', unfortunately,
+# due to quotation problems, I need to double quote $1 below, therefore
+# the anchors are broken :(  I can't let users be trapped by that.
+m4_define([m4_bpatsubsts],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+       [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+       [$#], 2, [m4_builtin([patsubst], $@)],
+       [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
+           m4_shiftn(3, $@))])])
+
+
+
 # m4_do(STRING, ...)
 # ------------------
 # This macro invokes all its arguments (in sequence, of course).  It is
@@ -1442,17 +1466,16 @@ m4_define([m4_flatten],
 # of brackets around $1 (don't forget that the result must be quoted
 # too, hence one more quoting than applications).
 #
-# Then notice the patsubst of the middle: it is in charge of removing
-# the leading space.  Why not just `patsubst(..., [^ ])'?  Because this
-# macro will receive the output of the preceding patsubst, i.e. more or
-# less [[STRING]].  So if there is a leading space in STRING, then it is
-# the *third* character, since there are two leading `['; Equally for
-# the outer patsubst.
+# Then notice the 2 last pattens: they are in charge of removing the
+# leading/trailing spaces.  Why not just `[^ ]'?  Because they are
+# applied to doubly quoted strings, i.e. more or less [[STRING]].  So
+# if there is a leading space in STRING, then it is the *third*
+# character, since there are two leading `['; equally for the last pattern.
 m4_define([m4_strip],
-[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]],
-                                        [[     ]+], [ ]),
-                           [^\(..\) ], [\1]),
-              [ \(.\)$], [\1])])
+[m4_bpatsubsts([[$1]],
+               [[      ]+], [ ],
+               [^\(..\) ],    [\1],
+               [ \(..\)$],    [\1])])
 
 
 # m4_normalize(STRING)
@@ -1479,7 +1502,7 @@ m4_defun([m4_join],
 [m4_case([$#],
          [1], [],
          [2], [[$2]],
-         [[$2][$1]m4_join([$1], m4_shift(m4_shift($@)))])])
+         [[$2][$1]$0([$1], m4_shiftn(2, $@))])])
 
 
 
@@ -1660,12 +1683,12 @@ m4_define([m4_cmp],
 #   m4_list_cmp((1),        (1, 2)) -> -1
 m4_define([m4_list_cmp],
 [m4_if([$1$2], [()()], 0,
-       [$1], [()], [m4_list_cmp((0), [$2])],
-       [$2], [()], [m4_list_cmp([$1], (0))],
+       [$1], [()], [$0((0), [$2])],
+       [$2], [()], [$0([$1], (0))],
        [m4_case(m4_cmp(m4_car$1, m4_car$2),
                 -1, -1,
                  1, 1,
-                 0, [m4_list_cmp((m4_shift$1), (m4_shift$2))])])])
+                 0, [$0((m4_shift$1), (m4_shift$2))])])])
 
 
 
@@ -1684,13 +1707,13 @@ m4_define([m4_list_cmp],
 # This macro is absolutely not robust to active macro, it expects
 # reasonable version numbers and is valid up to `z', no double letters.
 m4_define([m4_version_unletter],
-[m4_translit(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([$1],
-                                                   [\([0-9]+\)\([abcdefghi]\)],
-                                                    [m4_eval(\1 + 1).-1.\2]),
-                                       [\([0-9]+\)\([jklmnopqrs]\)],
-                                       [m4_eval(\1 + 1).-1.1\2]),
+[m4_translit(m4_bpatsubsts([$1],
+                           [\([0-9]+\)\([abcdefghi]\)],
+                             [m4_eval(\1 + 1).-1.\2],
+                           [\([0-9]+\)\([jklmnopqrs]\)],
+                             [m4_eval(\1 + 1).-1.1\2],
                            [\([0-9]+\)\([tuvwxyz]\)],
-                           [m4_eval(\1 + 1).-1.2\2]),
+                             [m4_eval(\1 + 1).-1.2\2]),
              [abcdefghijklmnopqrstuvwxyz],
              [12345678901234567890123456])])
 
index 1ae9a3fb06dc19820d3a22d059c0a1417beb16c4..13cab5e11da2e2b75650c93b1c9bf23de8066cab 100644 (file)
 
 
 # AT_DATA_M4SUGAR(FILENAME, CONTENTS)
-# --------------------------------
+# -----------------------------------
 # Escape the invalid tokens with @&t@.
 m4_define([AT_DATA_M4SUGAR],
 [AT_DATA([$1],
-[m4_bpatsubst(m4_bpatsubst([[$2]], [\(m4\)_], [\1@&t@_]),
-                           [dnl], [d@&t@nl])])])
+[m4_bpatsubsts([$2],
+               [\(m4\)_], [\1@&t@_],
+               [dnl],     [d@&t@nl])])])
 
 
 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
@@ -51,8 +52,9 @@ AT_CHECK([autom4te --language=m4sugar script.4s -o script $1],
 # Escape the invalid tokens with @&t@.
 m4_define([AT_DATA_M4SH],
 [AT_DATA([$1],
-[m4_bpatsubst(m4_bpatsubst([[$2]], [\(m4\|AS\)_], [\1@&t@_]),
-                           [dnl], [d@&t@nl])])])
+[m4_bpatsubsts([$2],
+               [\(m4\|AS\)_], [\1@&t@_],
+               [dnl],         [d@&t@nl])])])
 
 
 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
index ab1eb5246839bab536053d0d7c82c6f96c00d40d..c7b5c432e9503c8248d614c5ef529b18470a8338 100644 (file)
@@ -247,7 +247,7 @@ m4_foo
 _m4_bar
 AS_FOO
 _AS_BAR
-[d@&t@nl]
+[dnl]
 ]])
 
 AT_DATA_M4SH([experr],