]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Improve corner case of m4_expand.
authorEric Blake <ebb9@byu.net>
Wed, 24 Oct 2007 02:47:08 +0000 (20:47 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 24 Oct 2007 03:04:12 +0000 (21:04 -0600)
* lib/m4sugar/m4sugar.m4 (m4_expand, _m4_expand): Rewrite more
efficiently.
* tests/m4sh.at (AS@&t@_HELP_STRING): Test overquoted comma.
* doc/autoconf.texi (Evaluation Macros) <m4_expand>: Update
documentation.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
doc/autoconf.texi
lib/m4sugar/m4sugar.m4
tests/m4sh.at

index 3c4b592d11e94123f8f6c0d8c784f7442a112983..b0411e17f9bfab9d737b7c6607ea24bebdf8ee59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-10-23  Eric Blake  <ebb9@byu.net>
+
+       Improve corner case of m4_expand.
+       * lib/m4sugar/m4sugar.m4 (m4_expand, _m4_expand): Rewrite more
+       efficiently.
+       * tests/m4sh.at (AS@&t@_HELP_STRING): Test overquoted comma.
+       * doc/autoconf.texi (Evaluation Macros) <m4_expand>: Update
+       documentation.
+
 2007-10-23  Paul Eggert  <eggert@cs.ucla.edu>
 
        * doc/make-stds.texi: Update from gnulib.
index e23f709fa0d15e3934c4648457676b73273ee77f..f05b2ec485e70eaf3da898c7ba04efd9b115b363 100644 (file)
@@ -10771,8 +10771,8 @@ on quoted text.  The distinction is in the treatment of whitespace
 following a comma in the original @var{arg}.  Any time multiple
 arguments are collected into one with @code{m4_quote}, the M4 argument
 collection rules discard the whitespace.  However, with @code{m4_expand},
-whitespace is discarded only if it results from unquoted commas in the
-expansion of macros contained in @var{arg}.
+whitespace is preserved, even after the expansion of macros contained in
+@var{arg}.
 
 Note that @code{m4_expand} cannot parse everything.  The expansion of
 @var{arg} must not contain unbalanced quotes (although quadrigraphs can
@@ -10786,7 +10786,7 @@ m4_define([active2], [[ACT, IVE]])dnl
 m4_quote(active, active)
 @result{}ACT,IVE,ACT,IVE
 m4_expand([active, active])
-@result{}ACT,IVE, ACT,IVE
+@result{}ACT, IVE, ACT, IVE
 m4_quote(active2, active2)
 @result{}ACT, IVE,ACT, IVE
 m4_expand([active2, active2])
index 7ac53d54d445b398da5efde1d6debae7c6c40aea..e4bf9b291cf9055290697daf37376dc2fefd53a6 100644 (file)
@@ -665,34 +665,25 @@ m4_define([m4_echo], [$@])
 # --------------
 # Return the expansion of ARG as a single string.  Unlike m4_quote($1), this
 # correctly preserves whitespace following single-quoted commas that appeared
-# within ARG (however, it does not preserve whitespace after any unquoted
-# commas encountered in the expansion).
+# within ARG.
 #
 #   m4_define([active], [ACT, IVE])
 #   m4_define([active2], [[ACT, IVE]])
 #   m4_quote(active, active2)
 #   => ACT,IVE,ACT, IVE
 #   m4_expand([active, active2])
-#   => ACT,IVE, ACT, IVE
+#   => ACT, IVE, ACT, IVE
 #
 # Unfortunately, due to limitations in m4, ARG must contain balanced quotes
 # (use quadrigraphs) and balanced parentheses (use creative shell comments
 # when writing shell case statements).
 #
-# Splitting a quoted ARG on `,' preserves space, but produces a quoted list.
-# Unquote the list, then expand each argument while preserving the leading
-# spaces; finally, collect each argument back into the final string.
-m4_define([m4_expand],
-[m4_quote(_$0(m4_unquote(m4_split([$1], [,]))))])
-
-# _m4_expand(ARGS)
-# ----------------
-# Return the expansion of each ARG, separated by `,'.  Less efficient than
-# m4_unquote, but preserves quoted leading space in each ARG.
+# Exploit that extra () will group unquoted commas and the following
+# whitespace, then convert () to [].  m4_bpatsubst can't handle newlines
+# inside $1, and m4_substr strips quoting.  So we (ab)use m4_changequote.
+m4_define([m4_expand], [_$0(($1))])
 m4_define([_m4_expand],
-[m4_if([$#], [0], [],
-       [$#], [1], [$1],
-       [$1,$0(m4_shift($@))])])
+[m4_changequote([(], [)])$1m4_changequote`'m4_changequote(`[', `]')])
 
 
 # m4_ignore(ARGS)
@@ -1904,8 +1895,8 @@ m4_define([m4_append],
 # as the algorithm no longer guarantees uniqueness.
 m4_define([m4_append_uniq],
 [m4_ifval([$3], [m4_if(m4_index([$2], [$3]), [-1], [],
-                       [m4_warn([syntax],
-                               [$0: `$2' contains `$3'])])])_$0($@)])
+                      [m4_warn([syntax],
+                               [$0: `$2' contains `$3'])])])_$0($@)])
 m4_define([_m4_append_uniq],
 [m4_ifdef([$1],
          [m4_if(m4_index([$3]m4_builtin([defn], [$1])[$3], [$3$2$3]), [-1],
@@ -1920,7 +1911,7 @@ m4_define([_m4_append_uniq],
 # Avoid overhead of m4_defn by using m4_builtin.
 m4_define([m4_append_uniq_w],
 [m4_foreach_w([m4_Word], [$2],
-              [_m4_append_uniq([$1], m4_builtin([defn], [m4_Word]), [ ])])])
+             [_m4_append_uniq([$1], m4_builtin([defn], [m4_Word]), [ ])])])
 
 
 # m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
index 9c6624cd02fd8ede7fa83f0b4ea3eee8dbfbbdb1..966ca9a7ac7cc08be33d664ccac1590e5aae2032 100644 (file)
@@ -491,7 +491,7 @@ AT_CLEANUP
 ## -------------- ##
 
 AT_SETUP([AS@&t@_HELP_STRING])
-AT_KEYWORDS([m4@&t@_text_wrap])
+AT_KEYWORDS([m4@&t@_text_wrap m4@&t@_expand])
 
 AT_DATA_M4SH([script.as],
 [[AS_INIT
@@ -547,6 +547,7 @@ m4_define([mac], [MACRO])dnl
 echo "AS_HELP_STRING([--mac], [mac])"
 echo "AS_HELP_STRING([--o1, --o2], [two
 options,       one  description])"
+echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
 [            ])"
 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
@@ -612,6 +613,7 @@ AT_CHECK([./script], [0],
                           80 characters.
   --MACRO                 mac
   --o1, --o2              two options, one description
+  [--o3, --o4]            comma inside literal quoting
   --tune1   check out the tuned formatting
   --tune2   check out the tuned formatting
   --tune3                 check out the