--- src/tools.c.orig	Sat Mar 14 18:37:45 2009
+++ src/tools.c	Sat Mar 14 18:37:57 2009
@@ -5,6 +5,8 @@
 
 #include <NTL/new.h>
 
+#include <cstdio>
+
 NTL_START_IMPL
 
 
@@ -8,8 +8,35 @@
 NTL_START_IMPL


+/*
+   The following code differs from vanilla NTL 5.4.2.
+
+   We add a SetErrorCallbackFunction(). This sets a global callback function _function_,
+   which gets called with parameter _context_ and an error message string whenever Error()
+   gets called.
+
+   Note that if the custom error handler *returns*, then NTL will dump the error message
+   back to stderr and abort() as it habitually does.
+
+   -- David Harvey (2008-04-12)
+*/
+
+void (*ErrorCallbackFunction)(const char*, void*) = NULL;
+void *ErrorCallbackContext = NULL;
+
+
+void SetErrorCallbackFunction(void (*function)(const char*, void*), void *context)
+{
+   ErrorCallbackFunction = function;
+   ErrorCallbackContext = context;
+}
+
+
 void Error(const char *s)
 {
+   if (ErrorCallbackFunction != NULL)
+      ErrorCallbackFunction(s, ErrorCallbackContext);
+
    cerr << s << "\n";
    abort();
 }
