]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Add m4_chomp, m4_esyscmd_s.
authorEric Blake <ebb9@byu.net>
Thu, 13 Nov 2008 04:45:42 +0000 (21:45 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 20 Nov 2008 22:42:39 +0000 (15:42 -0700)
* lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp, m4_chomp_all):
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@&t@_esyscmd_s): New test.

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

index 08bb49022f48908571ea89157dc340fd383fd0cb..d2d2f7bccf0bb211fb21d60704eede6d7cf531ac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2008-11-20  Eric Blake  <ebb9@byu.net>
 
+       Add m4_chomp, m4_esyscmd_s.
+       * lib/m4sugar/m4sugar.m4 (m4_esyscmd_e, m4_chomp, m4_chomp_all):
+       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@&t@_esyscmd_s): 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 6ef072591c1ca5518144a4b809495d2cba5e87c2..297b3ea5b6cac9d3339d721a62b9915b765d0d57 100644 (file)
--- 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
index db3f7cc434fb13b908f906190fe5f3fbeb352e12..9e59d27aa44efc11d2fe7c33776d7672466b90fb 100644 (file)
@@ -10440,6 +10440,14 @@ calls @code{m4_dumpdef} for all of the
 silently does nothing if @var{name} is undefined.
 @end defmac
 
+@defmac m4_esyscmd_s (@var{command})
+@msindex{esyscmd_s}
+Like @code{m4_esyscmd}, this macro expands to the result of running
+@var{command} in a shell.  The difference is that any trailing newlines
+are removed, so that the output behaves more like shell command
+substitution.
+@end defmac
+
 @defmac m4_exit (@var{exit-status})
 @msindex{exit}
 This macro corresponds to @code{m4exit}.
@@ -11392,6 +11400,17 @@ numbers
 @end example
 @end defmac
 
+@defmac m4_chomp (@var{string})
+@defmacx m4_chomp_all (@var{string})
+@msindex{chomp}
+@msindex{chomp_all}
+Output @var{string} in quotes, but without a trailing newline.  The
+macro @code{m4_chomp} is slightly faster, and removes at most one
+newline; the macro @code{m4_chomp_all} removes all consecutive trailing
+newlines.  Unlike @code{m4_flatten}, embedded newlines are left intact,
+and backslash does not influence the result.
+@end defmac
+
 @defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
   @var{suffix-1}, @ovar{suffix-2}, @dots{})
 @msindex{combine}
index 7671f0f5d77a23ce036ec72cbcc6ce8e69728db5..c9a7f9893e2e7c77735375218cabd508cab4c51a 100644 (file)
@@ -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_all(m4_esyscmd([$1]))])
+
 
 # m4_popdef(NAME)
 # ---------------
@@ -822,6 +829,8 @@ m4_define([m4_echo], [$@])
 # 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,28 @@ m4_define([_m4_split],
               -=<{(]$3[)}>=-)]m4_changequote([, ])])
 
 
+# m4_chomp(STRING)
+# m4_chomp_all(STRING)
+# --------------------
+# Return STRING quoted, but without a trailing newline.  m4_chomp
+# removes at most one newline, while m4_chomp_all removes all
+# consecutive trailing newlines.  Embedded newlines are not touched,
+# and a trailing backslash-newline leaves just a trailing backslash.
+#
+# m4_bregexp is slower than m4_index, and we don't always want to
+# remove all newlines; hence the two variants.  We massage characters
+# to give a nicer pattern to match, particularly since m4_bregexp is
+# line-oriented.  Both versions must guarantee a match, to avoid bugs
+# with precision -1 in m4_format in older m4.
+m4_define([m4_chomp],
+[m4_format([[%.*s]], m4_index(m4_translit([[$1]], [
+/.], [/  ])[./.], [/.]), [$1])])
+
+m4_define([m4_chomp_all],
+[m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [
+/], [/ ]), [/*$]), [$1])])
+
+
 # m4_flatten(STRING)
 # ------------------
 # If STRING contains end of lines, replace them with spaces.  If there
index 5a90493ae311b19a95f2804b985d73244bc98390..d1ee1fe6affe9aa058b06f3bdb6f9ccb35a9327f 100644 (file)
@@ -871,6 +871,34 @@ $1$#$@
 
 AT_CLEANUP
 
+## -------------- ##
+## m4_esyscmd_s.  ##
+## -------------- ##
+
+AT_SETUP([m4@&t@_esyscmd_s])
+AT_KEYWORDS([m4@&t@_chomp m4@&t@_chomp_all])
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([world], [WORLD])dnl
+m4_chomp([abc])
+m4_chomp([world
+
+])
+m4_esyscmd_s([echo hello world])
+m4_esyscmd_s([echo '[goodbye,
+cruel world
+
+]'])
+]], [[abc
+world
+
+hello WORLD
+goodbye,
+cruel world
+]])
+
+AT_CLEANUP
+
 ## ---------- ##
 ## M4 Loops.  ##
 ## ---------- ##