1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2001 Kevin Rosenberg
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"
35 * sys_error System error handler
38 * sys_error (severity, msg, args . . .)
39 * int severity Severity of error
40 * char *msg Error message
41 * args Argument list, direct transfer to printf stack
44 static int s_reportErrorLevel = ERR_TRACE; // 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) {
59 wxCommandEvent eventLog (wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT );
60 wxString msg (wxConvCurrent->cMB2WX(strOutput.c_str()));
61 if (msg.length() > 0) {
63 eventLog.SetString( msg );
64 wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event, thread safe
68 wxLog::OnLog (wxLOG_Message, wxConvCurrent->cMB2WX(strOutput.c_str()), time(NULL));
73 std::cout << strOutput << "\n";
75 std::cout << strOutput << "\n";
81 static unsigned long s_nErrorCount = 0;
82 unsigned long int g_lSysErrorMaxCount = 2000;
85 void sys_verror (std::string& strOutput, int severity, const char *msg, va_list arg)
87 if (severity < s_reportErrorLevel)
88 return; // ignore error if less than reporting level
90 std::ostringstream os;
92 if (severity > ERR_TRACE)
95 if (severity != ERR_FATAL) {
96 if (s_nErrorCount > g_lSysErrorMaxCount)
98 else if (s_nErrorCount == g_lSysErrorMaxCount) {
99 os << "*****************************************************************\n";
100 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";
102 os << "*** No further errors will be reported ***\n";
103 os << "*****************************************************************\n";
104 strOutput = os.str();
111 os << "FATAL ERROR: ";
114 os << "SEVERE ERROR: ";
117 os << "WARNING ERROR: ";
123 os << "Illegal error severity #" << severity << ": ";
129 vsnprintf (errStr, sizeof(errStr), msg, arg);
131 vsprintf (errStr, msg, arg);
133 strncpy (errStr, sizeof(errStr), "Error message not available on this platform.");
137 strOutput = os.str();
139 if (severity == ERR_FATAL) {
140 std::cerr << strOutput << "\n";
141 throw std::runtime_error (strOutput);
144 #if INTERACTIVE_ERROR_DISPLAY
145 std::cout << "A - Abort C - Continue W - Turn off warnings? ";
149 int c = cio_kb_waitc("AaBbCcWw", TRUE); /* get code from keyboard */
152 fputc (NEWLINE, stderr);
160 sys_error_level (ERR_SEVERE); /* report severe & fatal errors */
169 * sys_error_level Set error reporting level
172 * sys_error_level (severity)
173 * int severity Report all error as serious as severity and beyond
176 * Causes the system to ignore all error below the level of severity
177 * For example, if severity == ERR_SEVERE, then report severe & fatal
178 * error and ignore warnings
182 sys_error_level (int severity)
184 if (severity == ERR_FATAL ||
185 severity == ERR_SEVERE ||
186 severity == ERR_WARNING ||
187 severity == ERR_TRACE)
188 s_reportErrorLevel = severity;
190 s_reportErrorLevel = ERR_WARNING;