From: Eric Blake Date: Wed, 28 Oct 2009 14:17:27 +0000 (-0600) Subject: Fix m4_text_wrap handling of quoted whitespace. X-Git-Tag: v2.65~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2943c63f52dbed9926a4c87988a0b53c5939679e;p=thirdparty%2Fautoconf.git 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) : Likewise. Reported by Mike Frysinger. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index f96f5116..41dfb1e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-10-28 Eric Blake + + 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) : + Likewise. + Reported by Mike Frysinger. + 2009-10-27 Eric Blake Mention another feature of AC_RUN_IFELSE. diff --git a/NEWS b/NEWS index 666cd4fb..4fca50c3 100644 --- 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. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index a713a069..6049b591 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -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 diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 2e53ea37..6fddff44 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -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]))]], diff --git a/tests/m4sugar.at b/tests/m4sugar.at index d37681b2..aa302918 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -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