From b30850a851f566f71f4a23c68a403326e1ca867b Mon Sep 17 00:00:00 2001 From: Eric Blake 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 --- 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 0cadf4a7..f7833fae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-10-06 Eric Blake + 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 c34bedb4..01561274 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 939eaea7..f258666f 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -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}) diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 3607e455..04a41e38 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 -- 2.47.2