autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] Support a stack of LINENO values for AS_MESSAGE.


From: Paolo Bonzini
Subject: [PATCH] Support a stack of LINENO values for AS_MESSAGE.
Date: Tue, 14 Oct 2008 08:13:30 +0200

Ok, so here is what I concocted to get correct line numbers in shell
functions.  The idea is that the line number of the outermost invocation
wins.

In C-like syntax, that would be just

  if (++depth == 1)
    as_lineno=<SOMETHING>
  ...
  if (--depth == 0)
    unset as_lineno

but we have to find a portable way to do ++ and --.  The solution is
to use, as a unary counter, a variable X whose contents are "X=X=X="
(with a number of occurrences equal to the counter vaue).  Then,
"eval $X" is enough to subtract one, and X=X=$X adds one.  This is
nicely packaged in a couple of m4sh macros (tested, but not yet
documented), so that clients do not need to know about $as_lineno.

Ok?

Paolo

2008-10-14  Paolo Bonzini  <address@hidden>

        * lib/m4sugar/m4sh.m4 (_AS_ECHO_LOG): If defined, use $as_lineno as
        the line number emitted to the log file.
        (AS_LINENO_PUSH, AS_LINENO_POP): New.
        * tests/m4sh.at (LINENO Stack): New test.
---
 lib/m4sugar/m4sh.m4 |   20 +++++++++++++++++++-
 tests/m4sh.at       |   28 ++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 9c09dc0..9c1af0f 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -655,7 +655,7 @@ m4_define([_AS_ECHO],
 # Log the string to AS_MESSAGE_LOG_FD.
 m4_define([_AS_ECHO_LOG],
 [AS_REQUIRE([_AS_LINENO_PREPARE])dnl
-_AS_ECHO([$as_me:$LINENO: $1], [AS_MESSAGE_LOG_FD])])
+_AS_ECHO([$as_me:${as_lineno-$LINENO}: $1], [AS_MESSAGE_LOG_FD])])
 
 
 # _AS_ECHO_N_PREPARE
@@ -714,6 +714,24 @@ m4_define([AS_ERROR],
 
 
 
+# AS_LINENO_PUSH([LINENO])
+# ------------------------
+# If this is the outermost call to AS_LINENO_PUSH, make sure that
+# AS_MESSAGE will print LINENO as the line number.
+m4_defun([AS_LINENO_PUSH], 
+[dnl No, I am not going to comment on how this works.  The fun is yours.
+as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack])
+
+
+# AS_LINENO_POP([LINENO])
+# ------------------------
+# If this is call balances the outermost call to AS_LINENO_PUSH,
+# AS_MESSAGE will restart printing $LINENO as the line number.
+m4_defun([AS_LINENO_POP],
+[eval $as_lineno_stack; test "x$as_lineno_stack" = x && AS_UNSET([as_lineno])])
+
+
+
 ## -------------------------------------- ##
 ## 4. Portable versions of common tools.  ##
 ## -------------------------------------- ##
diff --git a/tests/m4sh.at b/tests/m4sh.at
index e7ea7aa..14207c8 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -96,6 +96,34 @@ AT_CLEANUP
 
 
 
+## ---------------------- ##
+## LINENO stack support.  ##
+## ---------------------- ##
+
+AT_SETUP([LINENO stack])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+
+AS_LINENO_PUSH([9999])
+test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
+AS_LINENO_PUSH([8888])
+test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
+AS_LINENO_POP
+test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
+AS_LINENO_POP
+test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
+
+AS_EXIT([0])
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP
+
+
 ## ------------ ##
 ## AS_DIRNAME.  ##
 ## ------------ ##
-- 
1.5.5





reply via email to

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