[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nested [] with whitespace in misc description leads to _m4_text_wrap
From: |
Eric Blake |
Subject: |
Re: nested [] with whitespace in misc description leads to _m4_text_wrap_word errors |
Date: |
Wed, 28 Oct 2009 14:47:12 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Eric Blake <ebb9 <at> byu.net> writes:
> > $ cat configure.ac
> > AC_INIT
> > AC_ARG_VAR(VAR, [[cow moo] desc])
> > AC_OUTPUT
> >
> > $ autoconf
> > configure:1210: error: possibly undefined macro: _m4_text_wrap_word
>
> Thanks for the report. The regression came at commit b07a2b3d, when I
> swapped to a more efficient whitespace mapping operator, and nothing in
> the testsuite exercises it (yet). I'm still playing with it, but I'm
> hoping that I can do a cleanup pass that recognizes any whitespace inside
> extra [ ] during _m4_split, and skip replacing just those instances.
I ended up taking a different approach. Too many things use _m4_split to
change its behavior, but since m4_text_wrap is already dealing with text, it
turned out to be pretty simple to supply the quadrigraphs that the user should
have used in the first place. However, note that whitespace inside embedded
quotes is still normalized; m4_text_wrap([[a b]]) gives [a b], not [a b], and
even I don't have enough m4 magic to work around that.
Hmm, while writing this, I noticed a potential optimization - there is no need
for m4_escape to waste time on four separate m4_bpatsubst if string didn't have
any problematic bytes in the first place. I'll whip out a followup patch
shortly.
From: Eric Blake <address@hidden>
Date: Wed, 28 Oct 2009 08:17:27 -0600
Subject: [PATCH] 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@&address@hidden): Test it.
* NEWS: Document this.
* doc/autoconf.texi (Text processing Macros) <m4_escape>:
Likewise.
Reported by Mike Frysinger.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 11 +++++++++++
NEWS | 8 ++++++++
doc/autoconf.texi | 7 +++++++
lib/m4sugar/m4sugar.m4 | 17 ++++++++++++++++-
tests/m4sugar.at | 15 ++++++++++++---
5 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b660bcc..0bdb5be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-10-28 Eric Blake <address@hidden>
+
+ 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@&address@hidden): Test it.
+ * NEWS: Document this.
+ * doc/autoconf.texi (Text processing Macros) <m4_escape>:
+ Likewise.
+ Reported by Mike Frysinger.
+
2009-09-16 Eric Blake <address@hidden>
Optimize AC_REPLACE_FUNCS.
diff --git a/NEWS b/NEWS
index 666cd4f..4fca50c 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 a713a06..6049b59 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -12298,6 +12298,13 @@ Text processing Macros
@end example
@end defmac
address@hidden m4_escape (@var{string})
address@hidden
+Convert all instances of @samp{[}, @samp{]}, @samp{#}, and @samp{$}
+within @var{string} into their respective quadrigraphs. The result is
+still a quoted string.
address@hidden 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 2e53ea3..6fddff4 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 d37681b..aa30291 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -1127,6 +1127,7 @@ AT_CLEANUP
## -------------- ##
AT_SETUP([m4@&address@hidden)
+AT_KEYWORDS([m4@&address@hidden)
# 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@&address@hidden)
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|@address@hidden:@@:>@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
--
1.6.4.2