* 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>
+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.
** 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.
@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
[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).
# 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]))]],
## -------------- ##
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
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)
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 */
Super long
documentation.
-First, second , third, [,quoted]
+First, second , third, [,quoted space]
$@ Some $1 $2 $3
$* $4 embedded