1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: syserror.cpp,v 1.8 2000/12/17 23:30:48 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 ******************************************************************************/
26 #include "ctsupport.h"
30 * sys_error System error handler
33 * sys_error (severity, msg, args . . .)
34 * int severity Severity of error
35 * char *msg Error message
36 * args Argument list, direct transfer to printf stack
37 * Can take 24 byte transfer
40 static int errorlevel = ERR_WARNING; /* Set error reporting level */
43 void sys_error (int severity, const char *msg, ...)
49 sys_verror (severity, msg, arg);
54 static int nErrorCount = 0;
55 const static int MAX_ERROR_COUNT = 20;
58 void sys_verror (int severity, const char *msg, va_list arg)
60 if (severity < errorlevel)
61 return; // ignore error if less than max level
64 if (severity != ERR_FATAL) {
65 if (nErrorCount > MAX_ERROR_COUNT)
67 else if (nErrorCount == MAX_ERROR_COUNT) {
68 std::cout << "*****************************************************************\n";
69 std::cout << "*** 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";
70 std::cout << "*** ***\n";
71 std::cout << "*** No further errors will be reported ***\n";
72 std::cout << "*****************************************************************\n";
79 std::cout << "FATAL ERROR: ";
82 std::cout << "SEVERE ERROR: ";
85 std::cout << "WARNING ERROR: ";
88 std::cout << "Illegal error code #" << severity << ": ";
94 vsnprintf (errStr, sizeof(errStr), msg, arg);
96 vsprintf (errStr, msg, arg);
\r
98 strncpy (errStr, sizeof(errStr), "Error message not available on this platform.");
101 std::cout << errStr << std::endl;
103 if (severity == ERR_FATAL)
104 throw std::runtime_error (errStr);
106 #if INTERACTIVE_ERROR_DISPLAY
107 std::cout << "A - Abort C - Continue W - Turn off warnings? ";
111 int c = cio_kb_waitc("AaBbCcWw", TRUE); /* get code from keyboard */
114 fputc (NEWLINE, stderr);
122 sys_error_level (ERR_SEVERE); /* report severe & fatal errors */
131 * sys_error_level Set error reporting level
134 * sys_error_level (severity)
135 * int severity Report all error as serious as severity and beyond
138 * Causes the system to ignore all error below the level of severity
139 * For example, if severity == ERR_SEVERE, then report severe & fatal
140 * error and ignore warnings
144 sys_error_level (int severity)
146 if (severity == ERR_FATAL ||
147 severity == ERR_SEVERE ||
148 severity == ERR_WARNING)
149 errorlevel = severity;
151 errorlevel = ERR_WARNING;