]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Add m4_default_quoted.
authorEric Blake <ebb9@byu.net>
Tue, 23 Sep 2008 12:57:15 +0000 (06:57 -0600)
committerEric Blake <ebb9@byu.net>
Tue, 7 Oct 2008 02:19:32 +0000 (20:19 -0600)
* lib/m4sugar/m4sugar.m4 (m4_default_quoted): New macro.
(m4_for, m4_expand_once, m4_text_wrap, m4_text_box): Use it.
* doc/autoconf.texi (Conditional constructs): Document it.
* NEWS: Likewise.

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

index 0cadf4a70a226751f7dc48c46588c7f54df4ebe2..f7833faee74b40e37743f54d6b8735447d9ab237 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-10-06  Eric Blake  <ebb9@byu.net>
 
+       Add m4_default_quoted.
+       * lib/m4sugar/m4sugar.m4 (m4_default_quoted): New macro.
+       (m4_for, m4_expand_once, m4_text_wrap, m4_text_box): Use it.
+       * doc/autoconf.texi (Conditional constructs): Document it.
+       * NEWS: Likewise.
+
        Fix build with case-insensitive make, again.
        * Makefile.am (pkgdata_DATA): Protect by MAKE_CASE_SENSITIVE.
        Reported via Keith Marshall, originally by newthinker in
diff --git a/NEWS b/NEWS
index c34bedb4dcd1abf4f207765b47d9f2ba505f2c72..01561274df9097fe3e98fb418a03fa2b1af5b21f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ GNU Autoconf NEWS - User visible changes.
 
 ** Autotest testsuites accept an option --jobs[=N] for parallel testing.
 
+** The following m4sugar macros are new:
+   m4_default_quoted
+
 \f
 * Major changes in Autoconf 2.63 (2008-09-09) [stable]
   Released by Eric Blake, based on git versions 2.62.*.
index 939eaea7f7c5720863ca4a36b6498b339d6a9dcf..f258666f7393da49165d769934c88d8e913cb968 100644 (file)
@@ -10720,10 +10720,27 @@ m4_cond([m4_index([$1], [\])], [-1], [$2],
 @end defmac
 
 @defmac m4_default (@var{expr-1}, @var{expr-2})
+@defmacx m4_default_quoted (@var{expr-1}, @var{expr-2})
 @msindex{default}
-If @var{expr-1} is not empty, use it.  Otherwise, expand to
-@var{expr-2}.  Useful for providing a fixed default if the expression
-that results in @var{expr-1} would otherwise be empty.
+@msindex{default_quoted}
+If @var{expr-1} is not empty, use it.  Otherwise, select @var{expr-2}.
+@code{m4_default} expands the result, while @code{m4_default_quoted}
+does not.  Useful for providing a fixed default if the expression that
+results in @var{expr-1} would otherwise be empty.
+
+@example
+m4_define([active], [ACTIVE])dnl
+m4_define([demo1], [m4_default([$1], [$2])])dnl
+m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
+demo1([active], [default])
+@result{}ACTIVE
+demo1([], [active])
+@result{}ACTIVE
+demo2([active], [default])
+@result{}active
+demo2([], [active])
+@result{}active
+@end example
 @end defmac
 
 @defmac m4_ifndef (@var{macro}, @var{if-not-defined}, @ovar{if-defined})
index 3607e4555b419ff1872518e7c8dbc2655bb065ae..04a41e382437bbb030abb1cea17fe64b92a373b3 100644 (file)
@@ -510,7 +510,7 @@ m4_define([m4_define_default],
 
 # m4_default(EXP1, EXP2)
 # ----------------------
-# Returns EXP1 if non empty, otherwise EXP2.
+# Returns EXP1 if non empty, otherwise EXP2.  Expand the result.
 #
 # This macro is called on hot paths, so inline the contents of m4_ifval,
 # for one less round of expansion.
@@ -518,6 +518,23 @@ m4_define([m4_default],
 [m4_if([$1], [], [$2], [$1])])
 
 
+# m4_default_quoted(EXP1, EXP2)
+# -----------------------------
+# Returns EXP1 if non empty, otherwise EXP2.  Leave the result quoted.
+#
+# For comparison:
+#   m4_define([active], [ACTIVE])
+#   m4_default([active], [default]) => ACTIVE
+#   m4_default([], [active]) => ACTIVE
+#   m4_default_quoted([active], [default]) => active
+#   m4_default_quoted([], [active]) => active
+#
+# This macro is called on hot paths, so inline the contents of m4_ifval,
+# for one less round of expansion.
+m4_define([m4_default_quoted],
+[m4_if([$1], [], [[$2]], [[$1]])])
+
+
 # m4_defn(NAME)
 # -------------
 # Like the original, except guarantee a warning when using something which is
@@ -866,12 +883,12 @@ m4_define([m4_unquote], [$*])
 m4_define([m4_for],
 [m4_pushdef([$1], m4_eval([$2]))]dnl
 [m4_cond([m4_eval(([$3]) > ([$2]))], 1,
-          [m4_pushdef([_m4_step], m4_eval(m4_default([$4],
+          [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
              1)))m4_assert(_m4_step > 0)_$0([$1], _m4_defn([$1]),
   m4_eval((([$3]) - ([$2])) / _m4_step * _m4_step + ([$2])),
   _m4_step, [$5])],
         [m4_eval(([$3]) < ([$2]))], 1,
-          [m4_pushdef([_m4_step], m4_eval(m4_default([$4],
+          [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
              -1)))m4_assert(_m4_step < 0)_$0([$1], _m4_defn([$1]),
   m4_eval((([$2]) - ([$3])) / -(_m4_step) * _m4_step + ([$2])),
   _m4_step, [$5])],
@@ -1698,9 +1715,9 @@ m4_define([_m4_divert_grow], _m4_divert([GROW]))
 # If TEXT has never been expanded, expand it *here*.  Use WITNESS as
 # as a memory that TEXT has already been expanded.
 m4_define([m4_expand_once],
-[m4_provide_if(m4_ifval([$2], [[$2]], [[$1]]),
+[m4_provide_if(m4_default_quoted([$2], [$1]),
               [],
-              [m4_provide(m4_ifval([$2], [[$2]], [[$1]]))[]$1])])
+              [m4_provide(m4_default_quoted([$2], [$1]))[]$1])])
 
 
 # m4_provide(MACRO-NAME)
@@ -2160,8 +2177,8 @@ 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_if([$3], [], [[$2]], [[$3]]),
-     m4_if([$4], [], [79], [[$4]]))])
+[_$0([$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]))]],
@@ -2203,7 +2220,7 @@ dnl finally, clean up the local variabls
 m4_define([m4_text_box],
 [m4_pushdef([m4_Border],
            m4_translit(m4_format([%*s], m4_qlen(m4_expand([$1])), []),
-                       [ ], m4_if([$2], [], [[-]], [[$2]])))dnl
+                       [ ], m4_default_quoted([$2], [-])))dnl
 @%:@@%:@ m4_Border @%:@@%:@
 @%:@@%:@ $1 @%:@@%:@
 @%:@@%:@ m4_Border @%:@@%:@_m4_popdef([m4_Border])dnl