[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
m4_chomp [was: Use newer m4_map_args_{w,sep}]
From: |
Eric Blake |
Subject: |
m4_chomp [was: Use newer m4_map_args_{w,sep}] |
Date: |
Thu, 13 Nov 2008 21:58:24 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Eric Blake <ebb9 <at> byu.net> writes:
> The idea is using m4_regexp to grab the index of the last newline with no
> subsequent text (if there is one), using m4_translit to work around
> difficulties in matching literal newline in regexp. Using a newline after
> $1 guarantees a match, so I can avoid the m4 1.4.9 bug without using
> _m4_index.
I'm probably going to commit this series soon; it provides m4_chomp and a first
use case for it (you can now declare an autotest title with underquoted #).
Eric Blake (3):
Remove _m4_index.
Add m4_chomp, m4_esyscmd_s.
Support underquoted # in some m4_expand clients.
>From 9891f56748c200d321fdf334c0fef649c98b6920 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 12 Nov 2008 21:10:35 -0700
Subject: [PATCH] Remove _m4_index.
* lib/m4sugar/m4sugar.m4 (_m4_index): Delete; it is more efficient
to make callers guarantee a match.
(m4_init): Adjust caller.
* lib/autoconf/status.m4 (_AC_CONFIG_COMPUTE_DEST): Likewise.
* lib/autoconf/general.m4 (_AC_DEFINE_Q): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 7 +++++++
lib/autoconf/general.m4 | 5 +++--
lib/autoconf/status.m4 | 5 +++--
lib/m4sugar/m4sugar.m4 | 20 +-------------------
4 files changed, 14 insertions(+), 23 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 31dd4f2..17a7d0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2008-11-13 Eric Blake <address@hidden>
+ Remove _m4_index.
+ * lib/m4sugar/m4sugar.m4 (_m4_index): Delete; it is more efficient
+ to make callers guarantee a match.
+ (m4_init): Adjust caller.
+ * lib/autoconf/status.m4 (_AC_CONFIG_COMPUTE_DEST): Likewise.
+ * lib/autoconf/general.m4 (_AC_DEFINE_Q): Likewise.
+
Optimize single-argument loop.
* lib/autoconf/functions.m4 (AC_CHECK_FUNCS): Avoid forks when
loop only has one argument.
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 4afa794..aa5e611 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2078,9 +2078,10 @@ m4_define([AC_DEFINE_UNQUOTED], [_AC_DEFINE_Q([], $@)])
# is defined with over-quotation, so that we can avoid m4_defn; this
# is only safe because the name should not contain $.
#
-# Use _m4_index to avoid a bug in m4_format in older m4.
+# Guarantee a match in m4_index, so as to avoid a bug with precision
+# -1 in m4_format in older m4.
m4_define([_AC_DEFINE_Q],
-[m4_pushdef([AC_name], m4_format([[[%.*s]]], _m4_index([$2], [(]), [$2]))]dnl
+[m4_pushdef([AC_name], m4_format([[[%.*s]]], m4_index([$2(], [(]), [$2]))]dnl
[AC_DEFINE_TRACE(AC_name)]dnl
[m4_cond([m4_index([$3], [
])], [-1], [],
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index c134bb7..aabd28b 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -247,9 +247,10 @@ m4_define([_AC_CONFIG_FOOS],
# _AC_CONFIG_COMPUTE_DEST(STRING)
# -------------------------------
# Compute the DEST from STRING by stripping any : and following
-# characters. Use _m4_index to avoid a bug in m4_format in older m4.
+# characters. Guarantee a match in m4_index, so as to avoid a bug
+# with precision -1 in m4_format in older m4.
m4_define([_AC_CONFIG_COMPUTE_DEST],
-[m4_format([[%.*s]], _m4_index([$1], [:]), [$1])])
+[m4_format([[%.*s]], m4_index([$1:], [:]), [$1])])
# _AC_CONFIG_REGISTER(MODE, TAG, [COMMANDS])
# ------------------------------------------
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 8884714..7671f0f 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -625,22 +625,6 @@ m4_define([m4_dumpdefs],
[m4_map_args([$0], $@)])])
-# _m4_index(HAYSTACK, NEEDLE)
-# ---------------------------
-# Like the original, except return -2 instead of -1 if NEEDLE is not
-# present in HAYSTACK. That way, it can be used to work around a bug
-# in m4 1.4.9 and earlier where m4_format did not accept a precision
-# of -1; this macro can be safely used in the idiom:
-# m4_format([[%.*s]], _m4_index([$1],[$2]), [$1])
-# to grab the prefix of $1 up to but excluding $2, if it was present,
-# otherwise the entire $1.
-m4_define([_m4_index],
-[$0_(m4_index($@))])
-
-m4_define([_m4_index_],
-[m4_if([$1], [-1], [-2], [$1])])
-
-
# m4_popdef(NAME)
# ---------------
# Like the original, except guarantee a warning when using something which is
@@ -2991,8 +2975,7 @@ m4_pattern_forbid([^dnl$])
# If __m4_version__ is defined, we assume that we are being run by M4
# 1.6 or newer, and thus that $@ recursion is linear and debugmode(d)
-# is available for faster checks of dereferencing undefined macros,
-# and we don't need to worry about _m4_format bugs with _m4_index.
+# is available for faster checks of dereferencing undefined macros.
# But if it is missing, we assume we are being run by M4 1.4.x, that
# $@ recursion is quadratic, and that we need foreach-based
# replacement macros. Use the raw builtin to avoid tripping up
@@ -3001,7 +2984,6 @@ m4_pattern_forbid([^dnl$])
m4_ifdef([__m4_version__],
[m4_debugmode([+d])
m4_define([m4_defn], _m4_defn([_m4_defn]))
-m4_define([_m4_index], _m4_defn([m4_index]))
m4_define([m4_popdef], _m4_defn([_m4_popdef]))
m4_define([m4_undefine], _m4_defn([_m4_undefine]))],
[m4_builtin([include], [m4sugar/foreach.m4])])
--
1.6.0.2
>From 0fc12997a0970e28343840305b476fd879914986 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 12 Nov 2008 21:45:42 -0700
Subject: [PATCH] Add m4_chomp, m4_esyscmd_s.
* lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp): New macros.
* doc/autoconf.texi (Redefined M4 Macros) <m4_esyscmd_s>: Document
them.
(Text processing Macros) <m4_chomp>: Likewise.
* NEWS: Likewise.
* tests/m4sugar.at (m4@&address@hidden): New test.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++++
NEWS | 4 ++--
doc/autoconf.texi | 15 +++++++++++++++
lib/m4sugar/m4sugar.m4 | 25 +++++++++++++++++++++++++
tests/m4sugar.at | 24 ++++++++++++++++++++++++
5 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 17a7d0c..9b5c1de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2008-11-13 Eric Blake <address@hidden>
+ Add m4_chomp, m4_esyscmd_s.
+ * lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp): New macros.
+ * doc/autoconf.texi (Redefined M4 Macros) <m4_esyscmd_s>: Document
+ them.
+ (Text processing Macros) <m4_chomp>: Likewise.
+ * NEWS: Likewise.
+ * tests/m4sugar.at (m4@&address@hidden): New test.
+
Remove _m4_index.
* lib/m4sugar/m4sugar.m4 (_m4_index): Delete; it is more efficient
to make callers guarantee a match.
diff --git a/NEWS b/NEWS
index f5f3d6e..ef18fe1 100644
--- a/NEWS
+++ b/NEWS
@@ -23,8 +23,8 @@ GNU Autoconf NEWS - User visible changes.
`autoreconf -I dir' option.
** The following documented m4sugar macros are new:
- m4_curry m4_default_quoted m4_map_args m4_map_args_pair
- m4_set_map
+ m4_chomp m4_curry m4_default_quoted m4_esyscmd_s m4_map_args
+ m4_map_args_pair m4_set_map
** The following m4sugar macros are documented now:
m4_copy m4_dumpdefs m4_rename
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 07db254..85f90b3 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10440,6 +10440,14 @@ Redefined M4 Macros
silently does nothing if @var{name} is undefined.
@end defmac
address@hidden m4_esyscmd_s (@var{command})
address@hidden
+Like @code{m4_esyscmd}, this macro expands to the result of running
address@hidden in a shell. The difference is that any trailing newlines
+are removed, so that the output behaves more like shell command
+substitution.
address@hidden defmac
+
@defmac m4_exit (@var{exit-status})
@msindex{exit}
This macro corresponds to @code{m4exit}.
@@ -11392,6 +11400,13 @@ Text processing Macros
@end example
@end defmac
address@hidden m4_chomp (@var{string})
address@hidden
+Remove all trailing newlines from @var{string}. The result is still a
+quoted string. Unlike @code{m4_flatten}, embedded newlines are left
+intact, and backslash does not influence the result.
address@hidden defmac
+
@defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
@var{suffix-1}, @ovar{suffix-2}, @dots{})
@msindex{combine}
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 7671f0f..69294d1 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -624,6 +624,13 @@ m4_define([m4_dumpdefs],
[$#], [1], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])],
[m4_map_args([$0], $@)])])
+# m4_esyscmd_s(COMMAND)
+# ---------------------
+# Like m4_esyscmd, except strip any trailing newlines, thus behaving
+# more like shell command substitution.
+m4_define([m4_esyscmd_s],
+[m4_chomp(m4_esyscmd([$1]))])
+
# m4_popdef(NAME)
# ---------------
@@ -822,6 +829,8 @@ m4_define([m4_echo], address@hidden)
# with balanced quotes (use quadrigraphs to get around this). The input
# is not likely to have unbalanced -=<{(/)}>=- quotes, and it is possible
# to have unbalanced (), provided it was specified with proper [] quotes.
+# Likewise, ARG must either avoid unquoted comments, or must be sure
+# to include the trailing newline to end the comment.
#
# Exploit that extra () will group unquoted commas and the following
# whitespace, then convert () to []. m4_bpatsubst can't handle newlines
@@ -2089,6 +2098,22 @@ m4_define([_m4_split],
-=<{(]$3[)}>=-)]m4_changequote([, ])])
+# m4_chomp(STRING)
+# ----------------
+# Return STRING quoted, but with any trailing newlines removed.
+# Unlike m4_flatten, this does not touch embedded newlines, and does
+# not look at backslash.
+#
+# m4_bregexp tends to be line-oriented, so matching newlines directly
+# is difficult; hence we use m4_translit to give a nicer pattern to
+# match. Guarantee a match, so as to avoid a bug with precision -1 in
+# m4_format in older m4. Inline m4_defn and 255 spaces for speed.
+m4_define([m4_chomp],
+[m4_format([[%.*s]], m4_bregexp(m4_translit([$1], [
+]]m4_dquote(_m4_defn([m4_cr_all]))[, [/]]m4_format([%255s], [])[),
+ [/*$]), [$1])])
+
+
# m4_flatten(STRING)
# ------------------
# If STRING contains end of lines, replace them with spaces. If there
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 5a90493..c4e3f7e 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -871,6 +871,30 @@ $1$#$@
AT_CLEANUP
+## -------------- ##
+## m4_esyscmd_s. ##
+## -------------- ##
+
+AT_SETUP([m4@&address@hidden)
+AT_KEYWORDS([m4@&address@hidden)
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([hi], [hello])dnl
+m4_define([world], [WORLD])dnl
+m4_chomp([abc])
+m4_esyscmd_s([echo hi world])
+m4_esyscmd_s([echo '[goodbye,
+cruel world
+
+]'])
+]], [[abc
+hello WORLD
+goodbye,
+cruel world
+]])
+
+AT_CLEANUP
+
## ---------- ##
## M4 Loops. ##
## ---------- ##
--
1.6.0.2
>From ecb705fe15360245777af4d79171274b7a8d6d53 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 13 Nov 2008 14:46:22 -0700
Subject: [PATCH] Support underquoted # in some m4_expand clients.
* lib/autotest/general.m4 (AT_SETUP): Protect against comments.
* tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Test this.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 4 ++++
lib/autotest/general.m4 | 3 ++-
tests/autotest.at | 5 +++--
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b5c1de..d6c2337 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2008-11-13 Eric Blake <address@hidden>
+ Support underquoted # in some m4_expand clients.
+ * lib/autotest/general.m4 (AT_SETUP): Protect against comments.
+ * tests/autotest.at (AT_CHECK_AT_TITLE_CHAR): Test this.
+
Add m4_chomp, m4_esyscmd_s.
* lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp): New macros.
* doc/autoconf.texi (Redefined M4 Macros) <m4_esyscmd_s>: Document
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index e497c02..d92ee24 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -1597,7 +1597,8 @@ m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
m4_define([AT_capture_files], [])
m4_define([AT_line], AT_LINE)
m4_define([AT_xfail], [at_xfail=no])
-m4_define([AT_description], m4_expand([$1]))
+m4_define([AT_description], m4_chomp(m4_expand([$1
+])))
m4_define([AT_ordinal], m4_incr(AT_ordinal))
m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
m4_divert_push([TEST_GROUPS])dnl
diff --git a/tests/autotest.at b/tests/autotest.at
index d674c81..0279b91 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -464,8 +464,9 @@ 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([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], [(@{:@)@:address@hidden, [(())])
--
1.6.0.2
- Re: Use newer m4_map_args_{w,sep}, (continued)
- Re: Use newer m4_map_args_{w,sep}, Eric Blake, 2008/11/11
- Re: Use newer m4_map_args_{w,sep}, Paolo Bonzini, 2008/11/11
- Re: Use newer m4_map_args_{w,sep}, Eric Blake, 2008/11/11
- Re: Use newer m4_map_args_{w,sep}, Eric Blake, 2008/11/11
- Re: Use newer m4_map_args_{w,sep}, Ralf Wildenhues, 2008/11/12
- Re: Use newer m4_map_args_{w,sep}, Paolo Bonzini, 2008/11/12
- Re: Use newer m4_map_args_{w,sep}, Eric Blake, 2008/11/12
- Re: Use newer m4_map_args_{w,sep}, Paolo Bonzini, 2008/11/12
- Re: Use newer m4_map_args_{w,sep}, Ben Pfaff, 2008/11/13
- Re: Use newer m4_map_args_{w,sep}, Paolo Bonzini, 2008/11/13
- m4_chomp [was: Use newer m4_map_args_{w,sep}],
Eric Blake <=
- Re: m4_chomp [was: Use newer m4_map_args_{w,sep}], Paolo Bonzini, 2008/11/14
- Re: m4_chomp [was: Use newer m4_map_args_{w,sep}], Eric Blake, 2008/11/14
- Re: m4_chomp [was: Use newer m4_map_args_{w,sep}], Paolo Bonzini, 2008/11/14
- Re: m4_chomp [was: Use newer m4_map_args_{w,sep}], Eric Blake, 2008/11/14
- Re: m4_chomp, Eric Blake, 2008/11/14
- fewer forks in AC_DEFINE [was: Use newer m4_map_args_{w,sep}], Eric Blake, 2008/11/19
- Re: fewer forks in AC_DEFINE [was: Use newer m4_map_args_{w,sep}], Ralf Wildenhues, 2008/11/20
- Re: fewer forks in AC_DEFINE [was: Use newer m4_map_args_{w,sep}], Eric Blake, 2008/11/20
- Re: fewer forks in AC_DEFINE, Ralf Wildenhues, 2008/11/20
- Re: fewer forks in AC_DEFINE, Eric Blake, 2008/11/20