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.
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}.
@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}
[$#], [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)
# ---------------
# 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
-=<{(]$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