From 882a1fbf72219c9aa1a2731e79290733adb35fe6 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 16 Jul 2008 12:47:48 -0600 Subject: [PATCH] Partial m4sugar merge from autoconf: m4_wrap vs. m4 1.6. * data/m4sugar/m4sugar.m4 (m4_unquote, m4_wrap_lifo): New macros. (m4_wrap): Guarantee FIFO order, in spite of m4 1.6. (m4_init): Consolidate wrapped text into single m4_wrap. * data/bison.m4 (b4_check_user_names_wrap): Stick with LIFO order in wrapped text. Signed-off-by: Eric Blake --- ChangeLog | 9 ++++++++ data/bison.m4 | 2 +- data/m4sugar/m4sugar.m4 | 46 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f17e07fc..114f5e2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-08-06 Eric Blake + + Partial m4sugar merge from autoconf: m4_wrap vs. m4 1.6. + * data/m4sugar/m4sugar.m4 (m4_unquote, m4_wrap_lifo): New macros. + (m4_wrap): Guarantee FIFO order, in spite of m4 1.6. + (m4_init): Consolidate wrapped text into single m4_wrap. + * data/bison.m4 (b4_check_user_names_wrap): Stick with LIFO order + in wrapped text. + 2008-08-05 Eric Blake Partial m4sugar merge from autoconf: builtins, version.m4. diff --git a/data/bison.m4 b/data/bison.m4 index 8c210e8d..bad62963 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -550,7 +550,7 @@ m4_define([b4_check_user_names_wrap], [b4_percent_]$1[_user_]$2[s], [[b4_percent_]$1[_bison_]$2[s]])])]) -m4_wrap([ +m4_wrap_lifo([ b4_check_user_names_wrap([[define]], [[variable]]) b4_check_user_names_wrap([[code]], [[qualifier]]) ]) diff --git a/data/m4sugar/m4sugar.m4 b/data/m4sugar/m4sugar.m4 index 3ac4e00d..4fa54b39 100644 --- a/data/m4sugar/m4sugar.m4 +++ b/data/m4sugar/m4sugar.m4 @@ -141,7 +141,7 @@ m4_rename_m4([index]) m4_rename_m4([indir]) m4_rename_m4([len]) m4_rename([m4exit], [m4_exit]) -m4_rename([m4wrap], [m4_wrap]) +m4_undefine([m4wrap]) m4_ifdef([mkstemp],dnl added in M4 1.4.8 [m4_rename_m4([mkstemp]) m4_copy([m4_mkstemp], [m4_maketemp]) @@ -575,6 +575,41 @@ m4_define([m4_undefine], m4_builtin([undefine], $@)]) +# m4_unquote(ARGS) +# ---------------- +# Remove one layer of quotes from each ARG, performing one level of +# expansion. For one argument, m4_unquote([arg]) is more efficient than +# m4_do([arg]), but for multiple arguments, the difference is that +# m4_unquote separates arguments with commas while m4_do concatenates. +m4_define([m4_unquote], [$*]) + +# _m4_wrap(PRE, POST) +# ------------------- +# Helper macro for m4_wrap and m4_wrap_lifo. Allows nested calls to +# m4_wrap within wrapped text. +# Skip m4_defn and m4_popdef for speed. +m4_define([_m4_wrap], +[m4_ifdef([$0_text], + [m4_define([$0_text], [$1]m4_builtin([defn], [$0_text])[$2])], + [m4_builtin([m4wrap], [m4_unquote(m4_builtin([defn], + [$0_text])m4_builtin([popdef], [$0_text]))])m4_define([$0_text], [$1$2])])]) + +# m4_wrap(TEXT) +# ------------- +# Append TEXT to the list of hooks to be executed at the end of input. +# Whereas the order of the original may be LIFO in the underlying m4, +# this version is always FIFO. +m4_define([m4_wrap], +[_m4_wrap([], [$1[]])]) + +# m4_wrap_lifo(TEXT) +# ------------------ +# Prepend TEXT to the list of hooks to be executed at the end of input. +# Whereas the order of m4_wrap may be FIFO in the underlying m4, this +# version is always LIFO. +m4_define([m4_wrap_lifo], +[_m4_wrap([$1[]])]) + ## -------------------------- ## ## 8. Implementing m4 loops. ## ## -------------------------- ## @@ -1783,10 +1818,11 @@ m4_define([m4_init], m4_pattern_forbid([^_?m4_]) m4_pattern_forbid([^dnl$]) +# _m4_divert_diversion should be defined: +m4_divert_push([KILL]) + # Check the divert push/pop perfect balance. -m4_wrap([m4_ifdef([_m4_divert_diversion], +m4_wrap([m4_divert_pop([]) + m4_ifdef([_m4_divert_diversion], [m4_fatal([$0: unbalanced m4_divert_push:]_m4_divert_n_stack)])[]]) - -m4_divert_push([KILL]) -m4_wrap([m4_divert_pop([KILL])[]]) ]) -- 2.45.2