Add a function glp_have_error() to check whether we are currently handling an error message. diff -ru glpk-4.55/doc/glpk06.tex glpk-4.55-patched//doc/glpk06.tex --- glpk-4.55/doc/glpk06.tex 2014-08-22 08:00:00.000000000 +0200 +++ glpk-4.55-patched//doc/glpk06.tex 2015-11-05 10:01:32.244898918 +0100 @@ -303,6 +303,23 @@ a global jump using the standard function \verb|longjmp|, in which case the application program {\it must} call the routine \verb|glp_free_env|. +\subsection{glp\_have\_error --- are we currently handling an error?} + +\synopsis + +\begin{verbatim} + int glp_have_error(void); +\end{verbatim} + +\description + +The routine \verb|glp_have_error| returns 0 in normal operation and 1 +if GLPK is currently handling an error. + +This can be used by a custom output handler (installed with +\verb|glp_term_hook|) to determine whether or not the message to be +displayed is an error message. + \subsection{glp\_alloc --- allocate memory block} \synopsis diff -ru glpk-4.55/src/env/env.h glpk-4.55-patched//src/env/env.h --- glpk-4.55/src/env/env.h 2014-08-22 08:00:00.000000000 +0200 +++ glpk-4.55-patched//src/env/env.h 2015-11-05 09:57:19.049622663 +0100 @@ -161,6 +161,9 @@ void glp_error_hook(void (*func)(void *info), void *info); /* install hook to intercept abnormal termination */ +int glp_have_error(void); +/* are we currently handling an error? */ + #define put_err_msg _glp_put_err_msg void put_err_msg(const char *msg); /* provide error message string */ diff -ru glpk-4.55/src/env/error.c glpk-4.55-patched//src/env/error.c --- glpk-4.55/src/env/error.c 2014-08-22 08:00:00.000000000 +0200 +++ glpk-4.55-patched//src/env/error.c 2015-11-05 09:59:57.588718768 +0100 @@ -47,6 +47,7 @@ va_end(arg); xprintf("Error detected in file %s at line %d\n", env->err_file, env->err_line); + env->err_file = NULL; if (env->err_hook != NULL) env->err_hook(env->err_info); abort(); @@ -120,6 +121,28 @@ } /*********************************************************************** +* NAME +* +* glp_have_error - are we currently handling an error? +* +* SYNOPSIS +* +* int glp_have_error(void); +* +* DESCRIPTION +* +* The routine glp_have_error returns 0 in normal operation and 1 if +* GLPK is currently handling an error. +* +* This can be used by a term hook to determine whether or not the +* message to be displayed is an error message. */ + +int glp_have_error(void) +{ ENV *env = get_env_ptr(); + return env->err_file != NULL; +} + +/*********************************************************************** * NAME * * put_err_msg - provide error message string diff -ru glpk-4.55/src/glpk.h glpk-4.55-patched//src/glpk.h --- glpk-4.55/src/glpk.h 2014-08-22 08:00:00.000000000 +0200 +++ glpk-4.55-patched//src/glpk.h 2015-11-05 09:57:11.291421102 +0100 @@ -839,6 +839,9 @@ void glp_error_hook(void (*func)(void *info), void *info); /* install hook to intercept abnormal termination */ +int glp_have_error(void); +/* are we currently handling an error? */ + #define glp_malloc(size) glp_alloc(1, size) /* allocate memory block (obsolete) */