-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglpenv04.c
124 lines (114 loc) · 3.83 KB
/
glpenv04.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* glpenv04.c (error handling) */
/***********************************************************************
* This code is part of GLPK (GNU Linear Programming Kit).
*
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
* 2009, 2010, 2011, 2013 Andrew Makhorin, Department for Applied
* Informatics, Moscow Aviation Institute, Moscow, Russia. All rights
* reserved. E-mail: <[email protected]>.
*
* GLPK is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GLPK is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
#include "glpapi.h"
/***********************************************************************
* NAME
*
* glp_error - display error message and terminate execution
*
* SYNOPSIS
*
* void glp_error(const char *fmt, ...);
*
* DESCRIPTION
*
* The routine glp_error (implemented as a macro) formats its
* parameters using the format control string fmt, writes the formatted
* message to the terminal, and abnormally terminates the program. */
static void error(const char *fmt, ...)
{ ENV *env = get_env_ptr();
va_list arg;
env->term_out = GLP_ON;
va_start(arg, fmt);
xvprintf(fmt, arg);
va_end(arg);
xprintf("Error detected in file %s at line %d\n", env->err_file,
env->err_line);
if (env->err_hook != NULL)
env->err_hook(env->err_info);
abort();
exit(EXIT_FAILURE);
/* no return */
}
_glp_error glp_error_(const char *file, int line)
{ ENV *env = get_env_ptr();
env->err_file = file;
env->err_line = line;
return error;
}
/***********************************************************************
* NAME
*
* glp_assert - check for logical condition
*
* SYNOPSIS
*
* #include "glplib.h"
* void glp_assert(int expr);
*
* DESCRIPTION
*
* The routine glp_assert (implemented as a macro) checks for a logical
* condition specified by the parameter expr. If the condition is false
* (i.e. the value of expr is zero), the routine writes a message to
* the terminal and abnormally terminates the program. */
void glp_assert_(const char *expr, const char *file, int line)
{ glp_error_(file, line)("Assertion failed: %s\n", expr);
/* no return */
}
/***********************************************************************
* NAME
*
* glp_error_hook - install hook to intercept abnormal termination
*
* SYNOPSIS
*
* void glp_error_hook(void (*func)(void *info), void *info);
*
* DESCRIPTION
*
* The routine glp_error_hook installs a user-defined hook routine to
* intercept abnormal termination.
*
* The parameter func specifies the user-defined hook routine. It is
* called from the routine glp_error before the latter calls the abort
* function to abnormally terminate the application program because of
* fatal error. The parameter info is a transit pointer, specified in
* the corresponding call to the routine glp_error_hook; it may be used
* to pass some information to the hook routine.
*
* To uninstall the hook routine the parameters func and info should be
* specified as NULL. */
void glp_error_hook(void (*func)(void *info), void *info)
{ ENV *env = get_env_ptr();
if (func == NULL)
{ env->err_hook = NULL;
env->err_info = NULL;
}
else
{ env->err_hook = func;
env->err_info = info;
}
return;
}
/* eof */