]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Improve m4_expand robustness, part 2.
authorEric Blake <ebb9@byu.net>
Wed, 19 Nov 2008 18:38:18 +0000 (11:38 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 20 Nov 2008 23:05:04 +0000 (16:05 -0700)
* lib/m4sugar/m4sugar.m4 (m4_expand): Support unterminated
comments, by wrapping old implementation...
(_m4_expand): ...as this, and renaming old core...
(_m4_expand_): ...to this.
(m4_text_box): Use lighter-weight _m4_expand.
* lib/m4sugar/m4sh.m4 (_AS_DETECT_EXPAND)
(_AS_DETECT_BETTER_SHELL, AS_FUNCTION_DESCRIBE): Likewise.
* lib/autotest/general.m4 (AT_KEYWORDS): Likewise.
* tests/m4sugar.at (m4@&t@_expand): Enhance test.
* tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Likewise.
* doc/autoconf.texi (Evaluation Macros) <m4_expand>: Mention new
functionality.

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

index 380f7c78c1f2320f4e3d0896c333e0139ff28ac7..d44cdd0355ad553bfeaf5b4e92a8400d786334a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2008-11-20  Eric Blake  <ebb9@byu.net>
 
+       Improve m4_expand robustness, part 2.
+       * lib/m4sugar/m4sugar.m4 (m4_expand): Support unterminated
+       comments, by wrapping old implementation...
+       (_m4_expand): ...as this, and renaming old core...
+       (_m4_expand_): ...to this.
+       (m4_text_box): Use lighter-weight _m4_expand.
+       * lib/m4sugar/m4sh.m4 (_AS_DETECT_EXPAND)
+       (_AS_DETECT_BETTER_SHELL, AS_FUNCTION_DESCRIBE): Likewise.
+       * lib/autotest/general.m4 (AT_KEYWORDS): Likewise.
+       * tests/m4sugar.at (m4@&t@_expand): Enhance test.
+       * tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Likewise.
+       * doc/autoconf.texi (Evaluation Macros) <m4_expand>: Mention new
+       functionality.
+
        Improve m4_expand robustness, part 1.
        * lib/m4sugar/m4sugar.m4 (_m4_expand): Tolerate unquoted
        unbalanced `)'.
index 9e59d27aa44efc11d2fe7c33776d7672466b90fb..7a154b796db147e2dbe08e38800c85d018cf6b3f 100644 (file)
@@ -11163,12 +11163,15 @@ discarding whitespace after unquoted commas, this macro is a no-op.
 Return the expansion of @var{arg} as a quoted string.  Whereas
 @code{m4_quote} is designed to collect expanded text into a single
 argument, @code{m4_expand} is designed to perform one level of expansion
-on quoted text.  The distinction is in the treatment of whitespace
+on quoted text.  One 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 preserved, even after the expansion of macros contained in
-@var{arg}.
+@var{arg}.  Additionally, @code{m4_expand} is able to expand text that
+would involve an unterminated comment, whereas expanding that same text
+as the argument to @code{m4_quote} runs into difficulty in finding the
+end of the argument.
 
 @example
 m4_define([active], [ACT, IVE])dnl
@@ -11181,11 +11184,17 @@ m4_quote(active2, active2)
 @result{}ACT, IVE,ACT, IVE
 m4_expand([active2, active2])
 @result{}ACT, IVE, ACT, IVE
+m4_expand([# m4_echo])
+@result{}# m4_echo
+m4_quote(# m4_echo)
+)
+@result{}# m4_echo)
+@result{}
 @end example
 
 Note that @code{m4_expand} cannot handle an @var{arg} that expands to
 literal unbalanced quotes, but that quadrigraphs can be used when
-unbalanced output is necessary.  Likewise, unbalanced parentheses must
+unbalanced output is necessary.  Likewise, unbalanced parentheses should
 be supplied with double quoting or a quadrigraph.
 
 @example
index 704dbbf946369c9306041291d481397c14d929e9..ebde0b30ddf87f4bee7491d2753e7e6946793c30 100644 (file)
@@ -1636,7 +1636,8 @@ m4_case([$1],
 # Since the -k option is case-insensitive, the list is stored in lower case
 # to avoid duplicates that differ only by case.
 _AT_DEFINE_SETUP([AT_KEYWORDS],
-[m4_append_uniq_w([AT_keywords], m4_tolower(m4_dquote(m4_expand([$1]))))])
+[m4_append_uniq_w([AT_keywords], m4_tolower(m4_dquote(_m4_expand([$1
+]))))])
 
 
 # AT_CAPTURE_FILE(FILE)
index 0b32440563744f8e09841df252687eace615f118..43643873e6c70c4a7642f58dc9d69241739416fd 100644 (file)
@@ -165,7 +165,7 @@ $1], [^], [@%:@ ])])])
 # we must piece-meal the assignment of VAR such that $LINENO expansion
 # occurs in a single line.
 m4_define([_AS_DETECT_EXPAND],
-[$1="m4_bpatsubst(m4_dquote(AS_ESCAPE(m4_expand(m4_set_contents([$2], [
+[$1="m4_bpatsubst(m4_dquote(AS_ESCAPE(_m4_expand(m4_set_contents([$2], [
 ])))), [\\\$LINENO\(.*\)$], [";$1=$$1$LINENO;$1=$$1"\1])"])
 
 
@@ -219,7 +219,7 @@ dnl Remove any tests from suggested that are also required
 [m4_set_map([_AS_DETECT_SUGGESTED_BODY], [_AS_DETECT_SUGGESTED_PRUNE])]dnl
 [m4_pushdef([AS_EXIT], [exit m4_default([$1], 1)])]dnl
 [if test "x$CONFIG_SHELL" = x; then
-  as_bourne_compatible="AS_ESCAPE(m4_expand([_AS_BOURNE_COMPATIBLE]))"
+  as_bourne_compatible="AS_ESCAPE(_m4_expand([_AS_BOURNE_COMPATIBLE]))"
   _AS_DETECT_EXPAND([as_required], [_AS_DETECT_REQUIRED_BODY])
   _AS_DETECT_EXPAND([as_suggested], [_AS_DETECT_SUGGESTED_BODY])
   AS_IF([_AS_RUN(["$as_required"])],
@@ -1341,8 +1341,8 @@ _ASBOX])
 m4_define([AS_FUNCTION_DESCRIBE],
 [@%:@ $1[]m4_ifval([$2], [ $2])
 @%:@ m4_translit(m4_format([%*s],
-                  m4_qlen(m4_expand([$1[]m4_ifval([$2], [ $2])])), []),
-                [ ], [-])
+          m4_decr(m4_qlen(_m4_expand([$1[]m4_ifval([$2], [ $2])
+]))), []), [ ], [-])
 m4_text_wrap([$3], [@%:@ ], [], [$4])])
 
 
index 7074d90c8991072df219667d111ea535e489eebf..46579953ee378c4bbb0a381d3c20eb65bac0f302 100644 (file)
@@ -813,7 +813,8 @@ m4_define([m4_echo], [$@])
 
 
 # m4_expand(ARG)
-# --------------
+# _m4_expand(ARG)
+# ---------------
 # Return the expansion of ARG as a single string.  Unlike
 # m4_quote($1), this preserves whitespace following single-quoted
 # commas that appear within ARG.  It also deals with shell case
@@ -830,7 +831,9 @@ m4_define([m4_echo], [$@])
 # something with balanced quotes (use quadrigraphs to get around
 # this), and should not contain the unlikely delimiters -=<{( or
 # )}>=-.  It is possible to have unbalanced quoted `(' or `)', as well
-# as unbalanced unquoted `)'.
+# as unbalanced unquoted `)'.  m4_expand can handle unterminated
+# comments or dnl on the final line, at the expense of speed, while
+# _m4_expand is faster but must be given a terminated expansion.
 #
 # Exploit that extra unquoted () will group unquoted commas and the
 # following whitespace.  m4_bpatsubst can't handle newlines inside $1,
@@ -845,9 +848,12 @@ m4_define([m4_echo], [$@])
 # this time with one more `(' in the second argument and in the
 # open-quote delimiter.  We must also ignore the slop from the
 # previous try.  The final macro is thus half line-noise, half art.
-m4_define([m4_expand], [_$0([$1], [(], -=<{($1)}>=-, [}>=-])])
+m4_define([m4_expand], [m4_chomp(_$0([$1
+]))])
+
+m4_define([_m4_expand], [$0_([$1], [(], -=<{($1)}>=-, [}>=-])])
 
-m4_define([_m4_expand],
+m4_define([_m4_expand_],
 [m4_if([$4], [}>=-],
        [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])],
        [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])])
@@ -2434,9 +2440,9 @@ m4_define([_m4_text_wrap_word],
 # will post-process.
 m4_define([m4_text_box],
 [m4_pushdef([m4_Border],
-           m4_translit(m4_format([%*s], m4_qlen(m4_expand([$1])), []),
-                       [ ], m4_default_quoted([$2], [-])))dnl
-[##] m4_Border [##]
+           m4_translit(m4_format([%*s], m4_decr(m4_qlen(_m4_expand([$1
+]))), []), [ ], m4_default_quoted([$2], [-])))]dnl
+[[##] m4_Border [##]
 [##] $1 [##]
 [##] m4_Border [##]_m4_popdef([m4_Border])])
 
index d674c81a22e0f277071a7f5e7d500eef66479e98..631c0c8052725877d7bc4c2ffe78f7b5dc1af5b5 100644 (file)
@@ -464,9 +464,10 @@ AT_CHECK_AT_TITLE_CHAR([Backslash],     [\])
 AT_CHECK_AT_TITLE_CHAR([Brackets],   [[[]]], [[]])
 AT_CHECK_AT_TITLE_CHAR([Left bracket],  [@<@&t@:@], [@<:@])
 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:@&t@>@], [@:>@])
-AT_CHECK_AT_TITLE_CHAR([Pound],       [[#]], [#])
-AT_CHECK_AT_TITLE_CHAR([Quoted comma],[[,]], [,])
-AT_CHECK_AT_TITLE_CHAR([Comma],         [,], [,])
+AT_CHECK_AT_TITLE_CHAR([Quoted pound],  [[#]], [#])
+AT_CHECK_AT_TITLE_CHAR([Pound],         [#])
+AT_CHECK_AT_TITLE_CHAR([Quoted comma],  [[,]], [,])
+AT_CHECK_AT_TITLE_CHAR([Comma],         [,])
 dnl this test also hits quadrigraphs for ()
 AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:}@], [(())])
 AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
index 89e0fde6c753ce68407a0d433c7b20343523a9aa..708067b81dc547ce01df254b291ec11f77d5d728 100644 (file)
@@ -701,6 +701,12 @@ esac
 case d in
   *) echo active, ;;
 esac])
+dnl unterminated comment/dnl
+m4_expand([active # active])
+m4_expand([a
+dnl])
+m4_expand([a
+-dnl])
 ]],
 [[#active
 ACTIVE
@@ -717,6 +723,10 @@ esac
 case d in
   *) echo ACTIVE, ;;
 esac
+ACTIVE # active
+a
+a
+-
 ]])
 
 AT_CLEANUP