From fd2a7534f1b979660985e51142d1d2cef5330b98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 13 Mar 1997 17:54:10 -0800
Subject: [PATCH] better error messages

Rev: bin/hilfe:1.8
---
 bin/hilfe | 58 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/bin/hilfe b/bin/hilfe
index 65c20f3f29..2b4e2213e7 100755
--- a/bin/hilfe
+++ b/bin/hilfe
@@ -69,6 +69,30 @@ object eval(string f)
   return o;
 }
 
+mixed do_evaluate(string a, int show_result)
+{
+  mixed foo, c;
+  if(foo=eval(a))
+  {
+    if(c=catch(a=sprintf("%O",foo->___Foo4711())))
+    {
+      if(arrayp(c) && sizeof(c)==2 && arrayp(c[1]))
+      {
+	c[1]=c[1][sizeof(backtrace())..];
+	write(describe_backtrace(c));
+      }else{
+	write(sprintf("Error in evalutation: %O\n",c));
+      }
+    }else{
+      if(show_result)
+	write("Result: "+a+"\n");
+      else
+	write("Ok.\n");
+      variables=foo->query_variables();
+    }
+  }
+}
+
 string input="";
 
 string skipwhite(string f)
@@ -354,16 +378,7 @@ mixed parse_function(string fun)
   case "while":
   case "foreach":
     /* parse loop */
-    if(foo=eval("mixed ___Foo4711() { "+fun+" ; }\n"))
-    {
-      if(c=catch(foo->___Foo4711()))
-      {
-	write("error during evaluation: "+c);
-      }else{
-	write("Ok.\n");
-	variables=foo->query_variables();
-      }
-    }
+    do_evaluate("mixed ___Foo4711() { "+fun+" ; }\n",0);
     return 1;
 
   case "int":
@@ -420,16 +435,7 @@ mixed parse_statement(string ex)
   case "while":
   case "foreach":
     /* parse loop */
-    if(foo=eval("mixed ___Foo4711() { "+ex+" ; }\n"))
-    {
-      if(c=catch(foo->___Foo4711()))
-      {
-	write("error during evaluation: "+c);
-      }else{
-	write("Ok.\n");
-	variables=foo->query_variables();
-      }
-    }
+    do_evaluate("mixed ___Foo4711() { "+ex+" ; }\n",0);
     return 1;
 
   case "int":
@@ -487,17 +493,7 @@ mixed parse_statement(string ex)
   default:
     if(ex==";") return 1;
     /* parse expressions */
-    a="mixed ___Foo4711() { return (mixed)("+ex[0..strlen(ex)-2]+"); }\n";
-    if(foo=eval(a))
-    {
-      if(c=catch(a=sprintf("%O",foo->___Foo4711())))
-      {
-	write(sprintf("error during evaluation: %O",c));
-      }else{
-	write("Result: "+a+"\n");
-	variables=foo->query_variables();
-      }
-    }
+    do_evaluate("mixed ___Foo4711() { return (mixed)("+ex[0..strlen(ex)-2]+"); }\n",1);
     return 1;
   }
 }
-- 
GitLab