--- src/error.c.orig 2018-11-01 16:56:12.000000000 -0600
+++ src/error.c 2019-02-07 13:12:12.925660213 -0700
@@ -33,6 +33,8 @@
static Obj ErrorInner;
+static Obj ERROR_OUTPUT = NULL;
+static Obj IsOutputStream;
/****************************************************************************
@@ -40,6 +42,44 @@ static Obj ErrorInner;
*F * * * * * * * * * * * * * * error functions * * * * * * * * * * * * * * *
*/
+/****************************************************************************
+**
+*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
+** ERROR_OUTPUT global variable defined in
+** error.g, or "*errout*" otherwise
+*/
+UInt OpenErrorOutput( void )
+{
+ /* Try to print the output to stream. Use *errout* as a fallback. */
+ UInt ret = 0;
+
+ if (ERROR_OUTPUT != NULL) {
+ if (IsStringConv(ERROR_OUTPUT)) {
+ ret = OpenOutput(CSTR_STRING(ERROR_OUTPUT));
+ }
+ else {
+ if (CALL_1ARGS(IsOutputStream, ERROR_OUTPUT) == True) {
+ ret = OpenOutputStream(ERROR_OUTPUT);
+ }
+ }
+ }
+
+ if (!ret) {
+ /* It may be we already tried and failed to open *errout* above but
+ * but this is an extreme case so it can't hurt to try again
+ * anyways */
+ ret = OpenOutput("*errout*");
+ if (ret) {
+ Pr("failed to open error stream\n", 0, 0);
+ }
+ else {
+ Panic("failed to open *errout*");
+ }
+ }
+
+ return ret;
+}
+
/****************************************************************************
**
@@ -615,6 +655,8 @@ static Int InitKernel(StructInitInfo * m
InitHdlrFuncsFromTable(GVarFuncs);
ImportFuncFromLibrary("ErrorInner", &ErrorInner);
+ ImportFuncFromLibrary("IsOutputStream", &IsOutputStream);
+ ImportGVarFromLibrary("ERROR_OUTPUT", &ERROR_OUTPUT);
// return success
return 0;
--- src/error.h.orig 2018-11-01 16:56:12.000000000 -0600
+++ src/error.h 2019-02-07 13:12:12.926660201 -0700
@@ -32,6 +32,14 @@ Int RegisterBreakloopObserver(intfunc fu
/****************************************************************************
**
+*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
+** ERROR_OUTPUT global variable defined in
+** error.g, or "*errout*" otherwise
+*/
+extern UInt OpenErrorOutput();
+
+/****************************************************************************
+**
*F ErrorQuit( <msg>, <arg1>, <arg2> ) . . . . . . . . . . . print and quit
*/
extern void ErrorQuit(const Char * msg, Int arg1, Int arg2) NORETURN;
--- src/scanner.c.orig 2018-11-01 16:56:12.000000000 -0600
+++ src/scanner.c 2019-02-07 13:12:12.929660164 -0700
@@ -16,6 +16,7 @@
#include "scanner.h"
+#include "error.h"
#include "gapstate.h"
#include "gaputils.h"
#include "io.h"
@@ -42,7 +43,7 @@ static void SyntaxErrorOrWarning(const C
if (STATE(NrErrLine) == 0) {
// open error output
- OpenOutput("*errout*");
+ OpenErrorOutput();
// print the message ...
if (error)