autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

m4_default_quoted


From: Eric Blake
Subject: m4_default_quoted
Date: Mon, 06 Oct 2008 21:04:25 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In reviewing the shell function series, I'm convinced that
m4_default_quoted will be useful.  For instance, the proposal:

>  [m4_provide_if([$1], [],
> -            [m4_divert_text([M4SH-INIT], [m4_default([$2], [$1])])])])
> +            [m4_divert_text(m4_default([$3], [M4SH-INIT]),
> +                            [m4_default([$2], [$1])])])])

the first m4_default is not robust if M4SH or INIT is defined as a macro,
but is easily corrected by using m4_default_quoted.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjq0bkACgkQ84KuGfSFAYD1sQCgnu5cjOQZ67F8U3Zoz7kvJTop
ia4AoLzoIUOMaiWpTaQaeI3FbGTTeWip
=3olu
-----END PGP SIGNATURE-----
>From b30850a851f566f71f4a23c68a403326e1ca867b Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 23 Sep 2008 06:57:15 -0600
Subject: [PATCH] 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.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |    6 ++++++
 NEWS                   |    3 +++
 doc/autoconf.texi      |   23 ++++++++++++++++++++---
 lib/m4sugar/m4sugar.m4 |   33 +++++++++++++++++++++++++--------
 4 files changed, 54 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0cadf4a..f7833fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-10-06  Eric Blake  <address@hidden>
 
+       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 c34bedb..0156127 100644
--- 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
+
 
 * Major changes in Autoconf 2.63 (2008-09-09) [stable]
   Released by Eric Blake, based on git versions 2.62.*.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 939eaea..f258666 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10720,10 +10720,27 @@ Conditional constructs
 @end defmac
 
 @defmac m4_default (@var{expr-1}, @var{expr-2})
address@hidden m4_default_quoted (@var{expr-1}, @var{expr-2})
 @msindex{default}
-If @var{expr-1} is not empty, use it.  Otherwise, expand to
address@hidden  Useful for providing a fixed default if the expression
-that results in @var{expr-1} would otherwise be empty.
address@hidden
+If @var{expr-1} is not empty, use it.  Otherwise, select @var{expr-2}.
address@hidden 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.
+
address@hidden
+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])
address@hidden
+demo1([], [active])
address@hidden
+demo2([active], [default])
address@hidden
+demo2([], [active])
address@hidden
address@hidden example
 @end defmac
 
 @defmac m4_ifndef (@var{macro}, @var{if-not-defined}, @ovar{if-defined})
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 3607e45..04a41e3 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -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
-- 
1.6.0.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]