-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathi_system.cpp
127 lines (113 loc) · 3.48 KB
/
i_system.cpp
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
125
126
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// Copyright(C) 2013 James Haley
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// System functions
//
//-----------------------------------------------------------------------------
#include "z_zone.h"
#include "i_system.h"
static int error_exitcode;
static bool has_exited;
enum
{
I_ERRORLEVEL_NONE, // no error
I_ERRORLEVEL_MESSAGE, // not really an error, just an exit message
I_ERRORLEVEL_NORMAL, // a "normal" error (such as a missing patch)
I_ERRORLEVEL_FATAL // kill with a vengeance
};
//
// I_FatalError
//
// haleyjd 05/21/10: Call this for super-evil errors such as heap corruption,
// system-related problems, etc.
//
void I_FatalError(int code, const char *error, ...)
{
// Flag a fatal error, so that some shutdown code will not be executed;
// chiefly, saving the configuration files, which can malfunction in
// unpredictable ways when heap corruption is present. We do this even
// if an error has already occurred, since, for example, if a Z_ChangeTag
// error happens during M_SaveDefaults, we do not want to subsequently
// run M_SaveSysConfig etc. in I_Quit.
error_exitcode = I_ERRORLEVEL_FATAL;
if(code == I_ERR_ABORT)
{
// kill with utmost contempt
abort();
}
else
{
va_list argptr;
va_start(argptr, error);
vprintf(error, argptr);
va_end(argptr);
if(!has_exited) // If it hasn't exited yet, exit now -- killough
{
has_exited = 1; // Prevent infinitely recursive exits -- killough
exit(-1);
}
else
abort(); // double fault, must abort
}
}
//
// I_Error
//
// Normal error reporting / exit routine.
//
void I_Error(const char *error, ...) // killough 3/20/98: add const
{
// do not demote error level
if(error_exitcode < I_ERRORLEVEL_NORMAL)
error_exitcode = I_ERRORLEVEL_NORMAL; // a normal error
va_list argptr;
va_start(argptr,error);
vprintf(error, argptr);
va_end(argptr);
if(!has_exited) // If it hasn't exited yet, exit now -- killough
{
has_exited = 1; // Prevent infinitely recursive exits -- killough
exit(-1);
}
else
I_FatalError(I_ERR_ABORT, "I_Error: double faulted\n");
}
//
// I_ErrorVA
//
// haleyjd: varargs version of I_Error used chiefly by libConfuse.
//
void I_ErrorVA(const char *error, va_list args)
{
// do not demote error level
if(error_exitcode < I_ERRORLEVEL_NORMAL)
error_exitcode = I_ERRORLEVEL_NORMAL;
vprintf(error, args);
if(!has_exited)
{
has_exited = 1;
exit(-1);
}
else
I_FatalError(I_ERR_ABORT, "I_ErrorVA: double faulted\n");
}
// EOF