]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Fix m4_text_wrap handling of quoted whitespace.
authorEric Blake <ebb9@byu.net>
Wed, 28 Oct 2009 14:17:27 +0000 (08:17 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 29 Oct 2009 01:53:58 +0000 (19:53 -0600)
* lib/m4sugar/m4sugar.m4 (m4_escape): New macro.
(m4_text_wrap): Use it to avoid issues with embedded [ and ].
* tests/m4sugar.at (m4@&t@_text_wrap): Test it.
* NEWS: Document this.
* doc/autoconf.texi (Text processing Macros) <m4_escape>:
Likewise.
Reported by Mike Frysinger.

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

index f96f511643172c5d90b0c6828c04fe6991a02c6c..41dfb1e973f08b64c130217f1f2477517054e164 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-10-28  Eric Blake  <ebb9@byu.net>
+
+       Fix m4_text_wrap handling of quoted whitespace.
+       * lib/m4sugar/m4sugar.m4 (m4_escape): New macro.
+       (m4_text_wrap): Use it to avoid issues with embedded [ and ].
+       * tests/m4sugar.at (m4@&t@_text_wrap): Test it.
+       * NEWS: Document this.
+       * doc/autoconf.texi (Text processing Macros) <m4_escape>:
+       Likewise.
+       Reported by Mike Frysinger.
+
 2009-10-27  Eric Blake  <ebb9@byu.net>
 
        Mention another feature of AC_RUN_IFELSE.
diff --git a/NEWS b/NEWS
index 666cd4fbf7e05bd86d6239afc13e35a229a33275..4fca50c3bd0c24b3169aa0909b342e304417bc97 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,14 @@ GNU Autoconf NEWS - User visible changes.
 ** The following m4sugar macros now quote their expansion:
    m4_toupper  m4_tolower
 
+** The following m4sugar macros are new:
+   m4_escape
+
+** The m4sugar macro m4_text_wrap now copes with embedded quoting without
+   requiring quadrigraphs.  For uses like AC_ARG_VAR([a], [[b c]]),
+   this gives the intuitive behavior of "[b c]" in the output (2.63
+   gave the output of "[b], [c]", and 2.64 encountered a failure).
+
 ** The `$tmp' temporary directory used in config.status is documented for
    public use now.
 
index a713a069d20850cf7a252cf05be0686428fddf8f..6049b591dfe379b6d03698b6ec8488350b967025 100644 (file)
@@ -12298,6 +12298,13 @@ m4_combine([, ], [[]], [-], [1], [2])
 @end example
 @end defmac
 
+@defmac m4_escape (@var{string})
+@msindex{escape}
+Convert all instances of @samp{[}, @samp{]}, @samp{#}, and @samp{$}
+within @var{string} into their respective quadrigraphs.  The result is
+still a quoted string.
+@end defmac
+
 @defmac m4_flatten (@var{string})
 @msindex{flatten}
 Flatten @var{string} into a single line.  Delete all backslash-newline
index 2e53ea3729622169b47c0356ccf54932d373e378..6fddff440491f1cb0bd5f6e33573e35814d6c405 100644 (file)
@@ -2542,6 +2542,20 @@ m4_define([m4_append_uniq_w],
 [m4_map_args_w([$2], [_m4_append_uniq([$1],], [, [ ])])])
 
 
+# m4_escape(STRING)
+# -----------------
+# Output quoted STRING, but with embedded #, $, [ and ] turned into
+# quadrigraphs.
+m4_define([m4_escape],
+[m4_changequote([-=<{(],[)}>=-])]dnl
+[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(
+         -=<{(-=<{(-=<{(-=<{(-=<{($1)}>=-)}>=-)}>=-)}>=-)}>=-,
+       -=<{(#)}>=-, -=<{(@%:@)}>=-),
+      -=<{(\[)}>=-, -=<{(@<:@)}>=-),
+    -=<{(\])}>=-, -=<{(@:>@)}>=-),
+  -=<{(\$)}>=-, -=<{(@S|@)}>=-)m4_changequote([,])])
+
+
 # m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
 # -------------------------------------------------------
 # Expands into STRING wrapped to hold in WIDTH columns (default = 79).
@@ -2592,8 +2606,9 @@ m4_define([m4_append_uniq_w],
 # with m4_do, to avoid time wasted on dnl during expansion (since this is
 # already a time-consuming macro).
 m4_define([m4_text_wrap],
-[_$0([$1], [$2], m4_default_quoted([$3], [$2]),
+[_$0(m4_escape([$1]), [$2], m4_default_quoted([$3], [$2]),
      m4_default_quoted([$4], [79]))])
+
 m4_define([_m4_text_wrap],
 m4_do(dnl set up local variables, to avoid repeated calculations
 [[m4_pushdef([m4_Indent], m4_qlen([$2]))]],
index d37681b234d1e175c87262caa9ea336c68ce5729..aa30291812738231521e1804d6907470bb68d8b0 100644 (file)
@@ -1127,6 +1127,7 @@ AT_CLEANUP
 ## -------------- ##
 
 AT_SETUP([m4@&t@_text_wrap])
+AT_KEYWORDS([m4@&t@_escape])
 
 # m4_text_wrap is used to display the help strings.  Also, check that
 # commas and $ are not swallowed.  This can easily happen because of
@@ -1134,6 +1135,11 @@ AT_SETUP([m4@&t@_text_wrap])
 
 AT_DATA_M4SUGAR([script.4s],
 [[m4_init[]m4_divert([0])dnl
+m4_define([a], [OOPS])dnl
+m4_escape([a[b $c#]d])
+m4_if(m4_escape([a[b $c#]d]), [a[b $c#]d], [oops],
+      m4_escape([a[b $c#]d]), [a@<:@b @S|@c@%:@@:>@d], [pass], [oops])
+
 m4_text_wrap([Short string */], [   ], [/* ], 20)
 
 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
@@ -1144,13 +1150,16 @@ m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
 
 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
 
-m4_text_wrap([First, second  , third, [,quoted]])
+m4_text_wrap([First, second  , third, [,quoted  space]])
 m4_define([xfff], [oops])
 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
 ]])
 
 AT_DATA([expout],
-[[/* Short string */
+[[a[b $c#]d
+pass
+
+/* Short string */
 
 /* Much longer
    string */
@@ -1164,7 +1173,7 @@ AT_DATA([expout],
           Super long
           documentation.
 
-First, second , third, [,quoted]
+First, second , third, [,quoted space]
 
  $@ Some $1 $2 $3
  $* $4 embedded