1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2001 Kevin Rosenberg
5 ** $Id: syserror.cpp,v 1.19 2001/01/28 19:10:18 kevin Exp $
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
30 #include "../src/ctsim.h"
34 * sys_error System error handler
37 * sys_error (severity, msg, args . . .)
38 * int severity Severity of error
39 * char *msg Error message
40 * args Argument list, direct transfer to printf stack
41 * Can take 24 byte transfer
44 static int s_reportErrorLevel = ERR_WARNING; // Set error reporting level
47 void sys_error (int severity, const char *msg, ...)
53 std::string strOutput;
54 sys_verror (strOutput, severity, msg, arg);
57 if (g_bRunningWXWindows)
58 wxLog::OnLog (wxLOG_Message, strOutput.c_str(), time(NULL));
61 std::cout << strOutput;
66 static int s_nErrorCount = 0;
67 const static int MAX_ERROR_COUNT = 20;
70 void sys_verror (std::string& strOutput, int severity, const char *msg, va_list arg)
72 if (severity < s_reportErrorLevel)
73 return; // ignore error if less than reporting level
75 std::ostringstream os;
78 if (severity != ERR_FATAL) {
79 if (s_nErrorCount > MAX_ERROR_COUNT)
81 else if (s_nErrorCount == MAX_ERROR_COUNT) {
82 os << "*****************************************************************\n";
83 os << "*** M A X I M U M E R R O R C O U N T R E A C H E D ***\n";
85 os << "*** No further errors will be reported ***\n";
86 os << "*****************************************************************\n";
94 os << "FATAL ERROR: ";
97 os << "SEVERE ERROR: ";
100 os << "WARNING ERROR: ";
106 os << "Illegal error severity #" << severity << ": ";
112 vsnprintf (errStr, sizeof(errStr), msg, arg);
114 vsprintf (errStr, msg, arg);
116 strncpy (errStr, sizeof(errStr), "Error message not available on this platform.");
119 os << errStr << "\n";
120 strOutput = os.str();
122 if (severity == ERR_FATAL) {
123 std::cerr << strOutput;
124 throw std::runtime_error (strOutput);
127 #if INTERACTIVE_ERROR_DISPLAY
128 std::cout << "A - Abort C - Continue W - Turn off warnings? ";
132 int c = cio_kb_waitc("AaBbCcWw", TRUE); /* get code from keyboard */
135 fputc (NEWLINE, stderr);
143 sys_error_level (ERR_SEVERE); /* report severe & fatal errors */
152 * sys_error_level Set error reporting level
155 * sys_error_level (severity)
156 * int severity Report all error as serious as severity and beyond
159 * Causes the system to ignore all error below the level of severity
160 * For example, if severity == ERR_SEVERE, then report severe & fatal
161 * error and ignore warnings
165 sys_error_level (int severity)
167 if (severity == ERR_FATAL ||
168 severity == ERR_SEVERE ||
169 severity == ERR_WARNING ||
170 severity == ERR_TRACE)
171 s_reportErrorLevel = severity;
173 s_reportErrorLevel = ERR_WARNING;