]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Require a perfect divert push/pop balance.
authorAkim Demaille <akim@epita.fr>
Thu, 18 Jan 2001 09:16:08 +0000 (09:16 +0000)
committerAkim Demaille <akim@epita.fr>
Thu, 18 Jan 2001 09:16:08 +0000 (09:16 +0000)
* m4sugar.m4 (m4_divert, m4_divert_push, m4_divert_pop): Keep
track of them in m4_divert_stack.
(m4_divert_pop): Accept the expected current diversion as
argument and m4_fatal if incorrect, or if there is nothing to pop.
(globally): Specify the known m4_divert_pop.
Preserve symbolic values when possible.
* acgeneral.m4: No longer push the first diversion.
Specify the known m4_divert_pop.
(AC_PLAIN_SCRIPT): When m4_divert_push a diversion, m4_wrap its
pop.
(AC_INIT): Run AC_PLAIN_SCRIPT first, not last.
* tests/m4sh.at (AS_DIRNAME & AS_DIRNAME_SED): Can't use m4_defun
without m4_init.
* m4sugar.m4: Likewise.

ChangeLog
acgeneral.m4
lib/autoconf/general.m4
lib/m4sugar/m4sugar.m4
m4sugar.m4
tests/m4sh.at
tests/m4sugar.at
tests/tools.at

index 6e583d7da483b6cd46626cb7e8b553a3f0c7bcf6..7bc65b8797d5c130eb72937a4b86d96ec8cf75e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2001-01-18  Akim Demaille  <akim@epita.fr>
+
+       Require a perfect divert push/pop balance.
+
+       * m4sugar.m4 (m4_divert, m4_divert_push, m4_divert_pop): Keep
+       track of them in m4_divert_stack.
+       (m4_divert_pop): Accept the expected current diversion as
+       argument and m4_fatal if incorrect, or if there is nothing to pop.
+       (globally): Specify the known m4_divert_pop.
+       Preserve symbolic values when possible.
+       * acgeneral.m4: No longer push the first diversion.
+       Specify the known m4_divert_pop.
+       (AC_PLAIN_SCRIPT): When m4_divert_push a diversion, m4_wrap its
+       pop.
+       (AC_INIT): Run AC_PLAIN_SCRIPT first, not last.
+       * tests/m4sh.at (AS_DIRNAME & AS_DIRNAME_SED): Can't use m4_defun
+       without m4_init.
+       * m4sugar.m4: Likewise.
+
 2001-01-18  Akim Demaille  <akim@epita.fr>
 
        * m4sugar.m4 (m4_defn, m4_undefine, m4_popdef): Unlike the
index 3f8e143124f35297f4609d5c8b3288dfc4765f4a..35348ba9e1b3ed8447f8a2efbad66a9e86071f00 100644 (file)
@@ -149,12 +149,6 @@ m4_copy([m4_divert_push],[AC_DIVERT_PUSH])
 m4_copy([m4_divert_pop], [AC_DIVERT_POP])
 
 
-# Throw away output until AC_INIT is called.
-# FIXME: Should not be here.
-m4_pushdef([_m4_divert_diversion], _m4_divert([KILL]))
-
-
-
 ## ------------------------------- ##
 ## Defining macros in autoconf::.  ##
 ## ------------------------------- ##
@@ -782,7 +776,7 @@ cat >>config.log <<EOF
 ## ------------ ##
 
 EOF
-m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])])dnl
+m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])[]])dnl
 
 _AC_INIT_DEFAULTS_FDS
 #
@@ -816,7 +810,7 @@ ac_exeext=
 # change it if the script calls AC_OBJEXT.
 ac_objext=o
 
-m4_divert_pop()dnl
+m4_divert_pop([DEFAULTS])dnl
 ])# _AC_INIT_DEFAULTS
 
 
@@ -865,7 +859,7 @@ fi
 dnl Double slashes in pathnames in object file debugging info
 dnl mess up M-x gdb in Emacs.
 srcdir=`echo "$srcdir" | sed 's%\([[^/]]\)/*$%\1%'`
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
 ])# _AC_INIT_SRCDIR
 
 
@@ -1255,7 +1249,7 @@ fi
 ac_tool_prefix=
 test -n "$host_alias" && ac_tool_prefix=$host_alias-
 
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
 ])# _AC_INIT_PARSE_ARGS
 
 
@@ -1326,7 +1320,7 @@ Fine tuning of the installation directories:
 EOF
 
   cat <<\EOF]
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
 dnl The order of the diversions here is
 dnl - HELP_BEGIN
 dnl   which may be prolongated by extra generic options such as with X or
@@ -1359,7 +1353,7 @@ m4_ifset([AC_PACKAGE_STRING],
      short | recursive ) echo "Configuration of AC_PACKAGE_STRING:";;
    esac])
   cat <<\EOF
-m4_divert_pop()dnl
+m4_divert_pop([HELP_ENABLE])dnl
 m4_divert_push([HELP_END])dnl
 m4_ifset([AC_PACKAGE_BUGREPORT], [
 Report bugs to <AC_PACKAGE_BUGREPORT>.])
@@ -1403,7 +1397,7 @@ if test "$ac_init_help" = "recursive"; then
 fi
 
 test -n "$ac_init_help" && exit 0
-m4_divert_pop()dnl
+m4_divert_pop([HELP_END])dnl
 ])# _AC_INIT_HELP
 
 
@@ -1496,7 +1490,7 @@ AC_SUBST(FFLAGS)dnl
 AC_SUBST(DEFS)dnl
 AC_SUBST(LDFLAGS)dnl
 AC_SUBST(LIBS)dnl
-m4_divert_pop()dnl
+m4_divert_pop([INIT_PREPARE])dnl
 ])# _AC_INIT_PREPARE
 
 
@@ -1520,7 +1514,9 @@ m4_define([AC_PLAIN_SCRIPT],
 [m4_init
 m4_pattern_forbid([^A]m4_dquote(m4_defn([m4_cr_LETTERS]))[_])
 m4_pattern_forbid([_AC_])
-m4_divert_push([BODY])])
+m4_divert_push([BODY])dnl
+m4_wrap([m4_divert_pop([BODY])[]])dnl
+])
 
 
 
@@ -1531,7 +1527,8 @@ m4_divert_push([BODY])])
 # Note that the order is important: first initialize, then set the
 # AC_CONFIG_SRCDIR.
 m4_define([AC_INIT],
-[m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
+[AC_PLAIN_SCRIPT
+m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
 m4_divert_text([BINSH], [@%:@! /bin/sh])
 _AC_INIT_DEFAULTS
 _AC_INIT_PARSE_ARGS
@@ -1544,8 +1541,6 @@ dnl it dumps into a diversion prepared by _AC_INIT_VERSION.
 _AC_INIT_NOTICE
 _AC_INIT_COPYRIGHT
 m4_ifval([$2], , [m4_ifval([$1], [AC_CONFIG_SRCDIR([$1])])])dnl
-# Initialize the diversion setup.
-AC_PLAIN_SCRIPT
 ])
 
 
@@ -1705,7 +1700,7 @@ Program names:
   --program-prefix=PREFIX            prepend PREFIX to installed program names
   --program-suffix=SUFFIX            append SUFFIX to installed program names
   --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
 if test "$program_transform_name" = s,x,x,; then
   program_transform_name=
 else
@@ -3432,7 +3427,7 @@ m4_define([_AC_CONFIG_DEPENDENCIES],
 [m4_divert_push([KILL])
 AC_FOREACH([AC_File], [$1],
   [_AC_CONFIG_DEPENDENCY(m4_patsubst(AC_File, [:], [,]))])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ])
 
 
@@ -3460,7 +3455,7 @@ AC_CONFIG_IF_MEMBER(AC_Dest, [AC_LIST_HEADERS],
   AC_CONFIG_IF_MEMBER(AC_Dest, [AC_LIST_FILES],
      [AC_FATAL(`AC_Dest' [is already registered with AC_CONFIG_FILES or AC_OUTPUT.])])
 m4_popdef([AC_Dest])])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ])
 
 
@@ -3497,7 +3492,7 @@ m4_if([$2],,, [AC_FOREACH([AC_Name], [$1],
 [    ]m4_patsubst(AC_Name, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_commands="$ac_config_commands $1"
 ])dnl
 
@@ -3575,7 +3570,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_headers="$ac_config_headers m4_normalize([$1])"
 ])dnl
 
@@ -3612,7 +3607,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_links="$ac_config_links m4_normalize([$1])"
 ])dnl
 
@@ -3683,7 +3678,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_files="$ac_config_files m4_normalize([$1])"
 ])dnl
 
index 3f8e143124f35297f4609d5c8b3288dfc4765f4a..35348ba9e1b3ed8447f8a2efbad66a9e86071f00 100644 (file)
@@ -149,12 +149,6 @@ m4_copy([m4_divert_push],[AC_DIVERT_PUSH])
 m4_copy([m4_divert_pop], [AC_DIVERT_POP])
 
 
-# Throw away output until AC_INIT is called.
-# FIXME: Should not be here.
-m4_pushdef([_m4_divert_diversion], _m4_divert([KILL]))
-
-
-
 ## ------------------------------- ##
 ## Defining macros in autoconf::.  ##
 ## ------------------------------- ##
@@ -782,7 +776,7 @@ cat >>config.log <<EOF
 ## ------------ ##
 
 EOF
-m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])])dnl
+m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])[]])dnl
 
 _AC_INIT_DEFAULTS_FDS
 #
@@ -816,7 +810,7 @@ ac_exeext=
 # change it if the script calls AC_OBJEXT.
 ac_objext=o
 
-m4_divert_pop()dnl
+m4_divert_pop([DEFAULTS])dnl
 ])# _AC_INIT_DEFAULTS
 
 
@@ -865,7 +859,7 @@ fi
 dnl Double slashes in pathnames in object file debugging info
 dnl mess up M-x gdb in Emacs.
 srcdir=`echo "$srcdir" | sed 's%\([[^/]]\)/*$%\1%'`
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
 ])# _AC_INIT_SRCDIR
 
 
@@ -1255,7 +1249,7 @@ fi
 ac_tool_prefix=
 test -n "$host_alias" && ac_tool_prefix=$host_alias-
 
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
 ])# _AC_INIT_PARSE_ARGS
 
 
@@ -1326,7 +1320,7 @@ Fine tuning of the installation directories:
 EOF
 
   cat <<\EOF]
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
 dnl The order of the diversions here is
 dnl - HELP_BEGIN
 dnl   which may be prolongated by extra generic options such as with X or
@@ -1359,7 +1353,7 @@ m4_ifset([AC_PACKAGE_STRING],
      short | recursive ) echo "Configuration of AC_PACKAGE_STRING:";;
    esac])
   cat <<\EOF
-m4_divert_pop()dnl
+m4_divert_pop([HELP_ENABLE])dnl
 m4_divert_push([HELP_END])dnl
 m4_ifset([AC_PACKAGE_BUGREPORT], [
 Report bugs to <AC_PACKAGE_BUGREPORT>.])
@@ -1403,7 +1397,7 @@ if test "$ac_init_help" = "recursive"; then
 fi
 
 test -n "$ac_init_help" && exit 0
-m4_divert_pop()dnl
+m4_divert_pop([HELP_END])dnl
 ])# _AC_INIT_HELP
 
 
@@ -1496,7 +1490,7 @@ AC_SUBST(FFLAGS)dnl
 AC_SUBST(DEFS)dnl
 AC_SUBST(LDFLAGS)dnl
 AC_SUBST(LIBS)dnl
-m4_divert_pop()dnl
+m4_divert_pop([INIT_PREPARE])dnl
 ])# _AC_INIT_PREPARE
 
 
@@ -1520,7 +1514,9 @@ m4_define([AC_PLAIN_SCRIPT],
 [m4_init
 m4_pattern_forbid([^A]m4_dquote(m4_defn([m4_cr_LETTERS]))[_])
 m4_pattern_forbid([_AC_])
-m4_divert_push([BODY])])
+m4_divert_push([BODY])dnl
+m4_wrap([m4_divert_pop([BODY])[]])dnl
+])
 
 
 
@@ -1531,7 +1527,8 @@ m4_divert_push([BODY])])
 # Note that the order is important: first initialize, then set the
 # AC_CONFIG_SRCDIR.
 m4_define([AC_INIT],
-[m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
+[AC_PLAIN_SCRIPT
+m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
 m4_divert_text([BINSH], [@%:@! /bin/sh])
 _AC_INIT_DEFAULTS
 _AC_INIT_PARSE_ARGS
@@ -1544,8 +1541,6 @@ dnl it dumps into a diversion prepared by _AC_INIT_VERSION.
 _AC_INIT_NOTICE
 _AC_INIT_COPYRIGHT
 m4_ifval([$2], , [m4_ifval([$1], [AC_CONFIG_SRCDIR([$1])])])dnl
-# Initialize the diversion setup.
-AC_PLAIN_SCRIPT
 ])
 
 
@@ -1705,7 +1700,7 @@ Program names:
   --program-prefix=PREFIX            prepend PREFIX to installed program names
   --program-suffix=SUFFIX            append SUFFIX to installed program names
   --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
 if test "$program_transform_name" = s,x,x,; then
   program_transform_name=
 else
@@ -3432,7 +3427,7 @@ m4_define([_AC_CONFIG_DEPENDENCIES],
 [m4_divert_push([KILL])
 AC_FOREACH([AC_File], [$1],
   [_AC_CONFIG_DEPENDENCY(m4_patsubst(AC_File, [:], [,]))])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ])
 
 
@@ -3460,7 +3455,7 @@ AC_CONFIG_IF_MEMBER(AC_Dest, [AC_LIST_HEADERS],
   AC_CONFIG_IF_MEMBER(AC_Dest, [AC_LIST_FILES],
      [AC_FATAL(`AC_Dest' [is already registered with AC_CONFIG_FILES or AC_OUTPUT.])])
 m4_popdef([AC_Dest])])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ])
 
 
@@ -3497,7 +3492,7 @@ m4_if([$2],,, [AC_FOREACH([AC_Name], [$1],
 [    ]m4_patsubst(AC_Name, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_commands="$ac_config_commands $1"
 ])dnl
 
@@ -3575,7 +3570,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_headers="$ac_config_headers m4_normalize([$1])"
 ])dnl
 
@@ -3612,7 +3607,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_links="$ac_config_links m4_normalize([$1])"
 ])dnl
 
@@ -3683,7 +3678,7 @@ m4_ifval([$2], [AC_FOREACH([AC_File], [$1],
 [    ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
 ])])])
 _AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
 ac_config_files="$ac_config_files m4_normalize([$1])"
 ])dnl
 
index 37f8c404fe5d14e35f99623f9d27ed30e7633f9b..0bfcce400d864c04a17858d461bdaee428d8b8f6 100644 (file)
@@ -702,15 +702,10 @@ m4_define([_m4_divert(KILL)],           -1)
 # -------------------------
 # Change the diversion stream to DIVERSION-NAME.
 m4_define([m4_divert],
-[m4_builtin([divert], _m4_divert([$1]))dnl
-])
-
-
-# m4_undivert(DIVERSION-NAME)
-# ---------------------------
-# Undivert DIVERSION-NAME.
-m4_define([m4_undivert],
-[m4_builtin([undivert], _m4_divert([$1]))dnl
+[m4_define([m4_divert_stack],
+           m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_builtin([divert], _m4_divert([$1]))dnl
 ])
 
 
@@ -718,19 +713,29 @@ m4_define([m4_undivert],
 # ------------------------------
 # Change the diversion stream to DIVERSION-NAME, while stacking old values.
 m4_define([m4_divert_push],
-[m4_pushdef([_m4_divert_diversion], _m4_divert([$1]))dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_pushdef([m4_divert_stack],
+            m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_pushdef([_m4_divert_diversion], [$1])dnl
+m4_builtin([divert], _m4_divert(_m4_divert_diversion))dnl
 ])
 
 
-# m4_divert_pop
-# -------------
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
 # Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
 m4_define([m4_divert_pop],
-[m4_popdef([_m4_divert_diversion])dnl
-m4_ifndef([_m4_divert_diversion],
-          [m4_fatal([too many m4_divert_pop])])dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_ifval([$1],
+     [m4_if(_m4_divert([$1]), m4_divnum, [],
+            [m4_fatal([$0($1): unexpected current diversion: ]m4_divnum)])])dnl
+m4_popdef([_m4_divert_diversion])dnl
+dnl m4_ifndef([_m4_divert_diversion],
+dnl           [m4_fatal([too many m4_divert_pop])])dnl
+m4_builtin([divert],
+           m4_ifdef([_m4_divert_diversion],
+                    [_m4_divert(_m4_divert_diversion)], -1))dnl
+m4_popdef([m4_divert_stack])dnl
 ])
 
 
@@ -741,10 +746,18 @@ m4_divert(_m4_divert_diversion)dnl
 m4_define([m4_divert_text],
 [m4_divert_push([$1])dnl
 $2
-m4_divert_pop()dnl
+m4_divert_pop([$1])dnl
 ])
 
 
+# m4_undivert(DIVERSION-NAME)
+# ---------------------------
+# Undivert DIVERSION-NAME.
+m4_define([m4_undivert],
+[m4_builtin([undivert], _m4_divert([$1]))])
+
+
+
 
 ## -------------------------------------------- ##
 ## 8. Defining macros with bells and whistles.  ##
@@ -1142,7 +1155,7 @@ m4_divert_push([GROW])])dnl
 m4_define([_m4_defun_epi],
 [m4_divert_pop()dnl
 m4_if(_m4_divert_dump, _m4_divert_diversion,
-      [m4_undivert(_m4_divert([GROW]))dnl
+      [m4_undivert([GROW])dnl
 m4_undefine([_m4_divert_dump])])dnl
 m4_expansion_stack_pop()dnl
 m4_popdef([_m4_expanding($1)])dnl
@@ -1245,10 +1258,11 @@ m4_ifndef([_m4_divert_dump],
           [m4_fatal([$0: cannot be used outside of an m4_defun'd macro])])dnl
 m4_provide_ifelse([$1],
                   [],
-                  [m4_divert_push(m4_eval(_m4_divert_diversion - 1))dnl
+                  [m4_divert_push(m4_eval(m4_divnum - 1))dnl
 m4_default([$2], [$1])
-m4_divert(_m4_divert_dump)m4_undivert(_m4_divert_diversion)dnl
-m4_divert_pop()])dnl
+m4_divert(m4_defn([_m4_divert_dump]))dnl
+m4_undivert(m4_defn([_m4_divert_diversion]))dnl
+m4_divert_pop(m4_defn([_m4_divert_dump]))])dnl
 m4_provide_ifelse([$1],
                   [],
                   [m4_warn([syntax],
@@ -1696,14 +1710,21 @@ m4_if(m4_sysval, [0], [],
 
 # m4_init
 # -------
-m4_defun([m4_init],
+m4_define([m4_init],
 [# We need a tmp directory.
 m4_ifndef([m4_tmpdir],
           [m4_define([m4_tmpdir], [/tmp])])
 
-
 # M4sugar reserves `m4_[A-Za-z0-9_]*'.  We'd need \b and +,
 # but they are not portable.
 m4_pattern_forbid([^m4_])
 m4_pattern_forbid([^dnl$])
+
+# Check the divert push/pop perfect balance.
+m4_wrap([m4_ifdef([_m4_divert_diversion],
+         [m4_fatal([$0: unbalanced m4_divert_push:]
+m4_defn([m4_divert_stack]))])[]])
+
+m4_divert_push([KILL])
+m4_wrap([m4_divert_pop([KILL])[]])
 ])
index 37f8c404fe5d14e35f99623f9d27ed30e7633f9b..0bfcce400d864c04a17858d461bdaee428d8b8f6 100644 (file)
@@ -702,15 +702,10 @@ m4_define([_m4_divert(KILL)],           -1)
 # -------------------------
 # Change the diversion stream to DIVERSION-NAME.
 m4_define([m4_divert],
-[m4_builtin([divert], _m4_divert([$1]))dnl
-])
-
-
-# m4_undivert(DIVERSION-NAME)
-# ---------------------------
-# Undivert DIVERSION-NAME.
-m4_define([m4_undivert],
-[m4_builtin([undivert], _m4_divert([$1]))dnl
+[m4_define([m4_divert_stack],
+           m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_builtin([divert], _m4_divert([$1]))dnl
 ])
 
 
@@ -718,19 +713,29 @@ m4_define([m4_undivert],
 # ------------------------------
 # Change the diversion stream to DIVERSION-NAME, while stacking old values.
 m4_define([m4_divert_push],
-[m4_pushdef([_m4_divert_diversion], _m4_divert([$1]))dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_pushdef([m4_divert_stack],
+            m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_pushdef([_m4_divert_diversion], [$1])dnl
+m4_builtin([divert], _m4_divert(_m4_divert_diversion))dnl
 ])
 
 
-# m4_divert_pop
-# -------------
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
 # Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
 m4_define([m4_divert_pop],
-[m4_popdef([_m4_divert_diversion])dnl
-m4_ifndef([_m4_divert_diversion],
-          [m4_fatal([too many m4_divert_pop])])dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_ifval([$1],
+     [m4_if(_m4_divert([$1]), m4_divnum, [],
+            [m4_fatal([$0($1): unexpected current diversion: ]m4_divnum)])])dnl
+m4_popdef([_m4_divert_diversion])dnl
+dnl m4_ifndef([_m4_divert_diversion],
+dnl           [m4_fatal([too many m4_divert_pop])])dnl
+m4_builtin([divert],
+           m4_ifdef([_m4_divert_diversion],
+                    [_m4_divert(_m4_divert_diversion)], -1))dnl
+m4_popdef([m4_divert_stack])dnl
 ])
 
 
@@ -741,10 +746,18 @@ m4_divert(_m4_divert_diversion)dnl
 m4_define([m4_divert_text],
 [m4_divert_push([$1])dnl
 $2
-m4_divert_pop()dnl
+m4_divert_pop([$1])dnl
 ])
 
 
+# m4_undivert(DIVERSION-NAME)
+# ---------------------------
+# Undivert DIVERSION-NAME.
+m4_define([m4_undivert],
+[m4_builtin([undivert], _m4_divert([$1]))])
+
+
+
 
 ## -------------------------------------------- ##
 ## 8. Defining macros with bells and whistles.  ##
@@ -1142,7 +1155,7 @@ m4_divert_push([GROW])])dnl
 m4_define([_m4_defun_epi],
 [m4_divert_pop()dnl
 m4_if(_m4_divert_dump, _m4_divert_diversion,
-      [m4_undivert(_m4_divert([GROW]))dnl
+      [m4_undivert([GROW])dnl
 m4_undefine([_m4_divert_dump])])dnl
 m4_expansion_stack_pop()dnl
 m4_popdef([_m4_expanding($1)])dnl
@@ -1245,10 +1258,11 @@ m4_ifndef([_m4_divert_dump],
           [m4_fatal([$0: cannot be used outside of an m4_defun'd macro])])dnl
 m4_provide_ifelse([$1],
                   [],
-                  [m4_divert_push(m4_eval(_m4_divert_diversion - 1))dnl
+                  [m4_divert_push(m4_eval(m4_divnum - 1))dnl
 m4_default([$2], [$1])
-m4_divert(_m4_divert_dump)m4_undivert(_m4_divert_diversion)dnl
-m4_divert_pop()])dnl
+m4_divert(m4_defn([_m4_divert_dump]))dnl
+m4_undivert(m4_defn([_m4_divert_diversion]))dnl
+m4_divert_pop(m4_defn([_m4_divert_dump]))])dnl
 m4_provide_ifelse([$1],
                   [],
                   [m4_warn([syntax],
@@ -1696,14 +1710,21 @@ m4_if(m4_sysval, [0], [],
 
 # m4_init
 # -------
-m4_defun([m4_init],
+m4_define([m4_init],
 [# We need a tmp directory.
 m4_ifndef([m4_tmpdir],
           [m4_define([m4_tmpdir], [/tmp])])
 
-
 # M4sugar reserves `m4_[A-Za-z0-9_]*'.  We'd need \b and +,
 # but they are not portable.
 m4_pattern_forbid([^m4_])
 m4_pattern_forbid([^dnl$])
+
+# Check the divert push/pop perfect balance.
+m4_wrap([m4_ifdef([_m4_divert_diversion],
+         [m4_fatal([$0: unbalanced m4_divert_push:]
+m4_defn([m4_divert_stack]))])[]])
+
+m4_divert_push([KILL])
+m4_wrap([m4_divert_pop([KILL])[]])
 ])
index 640dba1aa5e1ddc58fd94c3b8b4b6885e7ec0b84..9a947228279e6b714293583f591468e9987baab5 100644 (file)
@@ -12,7 +12,8 @@ AT_BANNER([M4sh.])
 AT_SETUP([[AS_DIRNAME & AS_DIRNAME_SED]])
 
 AT_DATA(configure.ac,
-[[_AS_EXPR_PREPARE
+[[AC_PLAIN_SCRIPT
+_AS_EXPR_PREPARE
 
 define([AS_DIRNAME_TEST],
 [dir=`AS_DIRNAME([$1])`
@@ -23,7 +24,6 @@ dir=`AS_DIRNAME_SED([$1])`
 test "$dir" = "$2" ||
   echo "dirname_sed($1) = $dir instead of $2" >&2])
 
-AC_PLAIN_SCRIPT
 AS_DIRNAME_TEST([//1],         [//])
 AS_DIRNAME_TEST([/1],          [/])
 AS_DIRNAME_TEST([./1],         [.])
index 2e1267bdabcf14c78fd096b2dc4d7d35fc92c5bb..bf09ffabf072e5a94f84e00948a57d2df5938b92 100644 (file)
@@ -73,18 +73,19 @@ m4_defun([bar],
 m4_defun([baz],
 [m4_require([foo])])
 
+m4_init
 baz
 ]])
 
 AT_CHECK_AUTOCONF([], 1, [],
-[[configure.ac:10: error: m4_require: circular dependency of foo
-configure.ac:10: foo is required by...
+[[configure.ac:11: error: m4_require: circular dependency of foo
+configure.ac:11: foo is required by...
 configure.ac:5: bar is expanded from...
-configure.ac:10: bar is required by...
+configure.ac:11: bar is required by...
 configure.ac:2: foo is expanded from...
-configure.ac:10: foo is required by...
+configure.ac:11: foo is required by...
 configure.ac:8: baz is expanded from...
-configure.ac:10: the top level
+configure.ac:11: the top level
 ]])
 
 AT_CLEANUP
index c1fcac53cce0b0c06b85877f0a7397e2d12bbecf..fcfb1b37d02749e1263b3be143be9fc6ed74eac1 100644 (file)
@@ -106,9 +106,9 @@ AT_CLEANUP(configure)
 AT_SETUP([autoconf --trace: user macros])
 
 AT_DATA(configure.ac,
-[[define([active], [ACTIVE])
-AC_DEFUN([TRACE1], [TRACE2(m4_shift($@))])
-AC_DEFUN([TRACE2], [[$2], $1])
+[[m4_define([active], [ACTIVE])
+m4_define([TRACE1], [TRACE2(m4_shift($@))])
+m4_define([TRACE2], [[$2], $1])
 TRACE1(foo, bar, baz)
 TRACE1(foo, TRACE1(bar, baz))
 TRACE1(foo, active, baz)