autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

25-fyi-m4-patsubsts.patch


From: Akim Demaille
Subject: 25-fyi-m4-patsubsts.patch
Date: Mon, 08 Oct 2001 10:30:02 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * 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.
        
        
Index: lib/m4sugar/m4sugar.m4
--- lib/m4sugar/m4sugar.m4 Sun, 07 Oct 2001 19:02:31 +0200 akim
+++ lib/m4sugar/m4sugar.m4 Sun, 07 Oct 2001 23:16:04 +0200 akim
@@ -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_define([m4_normalize],
 [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: tests/atspecific.m4
--- tests/atspecific.m4 Sun, 07 Oct 2001 19:02:31 +0200 akim
+++ tests/atspecific.m4 Sun, 07 Oct 2001 19:46:11 +0200 akim
@@ -24,12 +24,13 @@
 
 
 # AT_DATA_M4SUGAR(FILENAME, CONTENTS)
-# --------------------------------
+# -----------------------------------
 # Escape the invalid tokens with @&address@hidden
 m4_define([AT_DATA_M4SUGAR],
 [AT_DATA([$1],
-[m4_bpatsubst(m4_bpatsubst([[$2]], [\(m4\)_], [\1@&address@hidden),
-                           [dnl], [d@&address@hidden)])])
+[m4_bpatsubsts([$2],
+               [\(m4\)_], [\1@&address@hidden,
+               [dnl],     [d@&address@hidden)])])
 
 
 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
@@ -51,8 +52,9 @@ m4_define([AT_CHECK_M4SUGAR],
 # Escape the invalid tokens with @&address@hidden
 m4_define([AT_DATA_M4SH],
 [AT_DATA([$1],
-[m4_bpatsubst(m4_bpatsubst([[$2]], [\(m4\|AS\)_], [\1@&address@hidden),
-                           [dnl], [d@&address@hidden)])])
+[m4_bpatsubsts([$2],
+               [\(m4\|AS\)_], [\1@&address@hidden,
+               [dnl],         [d@&address@hidden)])])
 
 
 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
Index: tests/tools.at
--- tests/tools.at Sun, 07 Oct 2001 17:44:39 +0200 akim
+++ tests/tools.at Sun, 07 Oct 2001 19:42:59 +0200 akim
@@ -247,7 +247,7 @@ configure.ac:19:TRACE2:bar foo
 _m4_bar
 AS_FOO
 _AS_BAR
-[d@&address@hidden
+[dnl]
 ]])
 
 AT_DATA_M4SH([experr],



reply via email to

[Prev in Thread] Current Thread [Next in Thread]