1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: syserror.cpp,v 1.11 2000/12/29 20:11:42 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 ******************************************************************************/
31 * sys_error System error handler
34 * sys_error (severity, msg, args . . .)
35 * int severity Severity of error
36 * char *msg Error message
37 * args Argument list, direct transfer to printf stack
38 * Can take 24 byte transfer
41 static int s_reportErrorLevel = ERR_WARNING; // Set error reporting level
43 bool g_bRunningWXWindows = false;
45 void sys_error (int severity, const char *msg, ...)
51 std::string strOutput;
52 sys_verror (strOutput, severity, msg, arg);
54 // if (g_bRunningWXWindows)
\r
55 // theApp->getLog() << strOutput.c_str();
\r
57 std::cout << strOutput;
\r
62 static int s_nErrorCount = 0;
63 const static int MAX_ERROR_COUNT = 20;
66 void sys_verror (std::string& strOutput, int severity, const char *msg, va_list arg)
68 if (severity < s_reportErrorLevel)
69 return; // ignore error if less than reporting level
71 std::ostringstream os;
\r
74 if (severity != ERR_FATAL) {
75 if (s_nErrorCount > MAX_ERROR_COUNT)
77 else if (s_nErrorCount == MAX_ERROR_COUNT) {
78 os << "*****************************************************************\n";
79 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";
81 os << "*** No further errors will be reported ***\n";
82 os << "*****************************************************************\n";
\r
90 os << "FATAL ERROR: ";
93 os << "SEVERE ERROR: ";
96 os << "WARNING ERROR: ";
102 os << "Illegal error severity #" << severity << ": ";
108 vsnprintf (errStr, sizeof(errStr), msg, arg);
110 vsprintf (errStr, msg, arg);
\r
112 strncpy (errStr, sizeof(errStr), "Error message not available on this platform.");
115 os << errStr << "\n";
116 strOutput = os.str();
\r
118 if (severity == ERR_FATAL)
119 throw std::runtime_error (errStr);
121 #if INTERACTIVE_ERROR_DISPLAY
122 std::cout << "A - Abort C - Continue W - Turn off warnings? ";
126 int c = cio_kb_waitc("AaBbCcWw", TRUE); /* get code from keyboard */
129 fputc (NEWLINE, stderr);
137 sys_error_level (ERR_SEVERE); /* report severe & fatal errors */
146 * sys_error_level Set error reporting level
149 * sys_error_level (severity)
150 * int severity Report all error as serious as severity and beyond
153 * Causes the system to ignore all error below the level of severity
154 * For example, if severity == ERR_SEVERE, then report severe & fatal
155 * error and ignore warnings
159 sys_error_level (int severity)
161 if (severity == ERR_FATAL ||
162 severity == ERR_SEVERE ||
163 severity == ERR_WARNING ||
\r
164 severity == ERR_TRACE)
165 s_reportErrorLevel = severity;
167 s_reportErrorLevel = ERR_WARNING;