-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSERT.C
89 lines (75 loc) · 2.83 KB
/
ASSERT.C
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
/* ========================================================================
Copyright (c) 1990,1996 Synergistic Software
All Rights Reserved
========================================================================
Filename: ASSERT.C
Author: Greg Hightower
========================================================================
Contains the following general functions:
assert()
Contains the following internal functions:
======================================================================== */
/* ------------------------------------------------------------------------
Includes
------------------------------------------------------------------------ */
#include <stdarg.h>
#include "system.h"
#include "machine.h"
#include "machint.h"
/* ------------------------------------------------------------------------
Defines and Compile Flags
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Macros
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Prototypes
------------------------------------------------------------------------ */
void fatal_exit(const char *format, ...);
/* ------------------------------------------------------------------------
Global Variables
------------------------------------------------------------------------ */
#if !defined(_RELEASE)
/* ========================================================================
Function - _assert
Description - do bool expression check, fatal_err on FALSE value
SEE THE MACRO assert in SYSTEM.H
Returns - void
======================================================================== */
void _assert(BOOL fTest, char *FileName, SHORT LineNum)
{
if(!fTest)
{
fatal_exit("ASSERT FAILED! In %s on line %d\n",FileName,LineNum);
}
}
/* ========================================================================
Function - fatal_error
Description - aborts the game, displaying and writing to disk an error msg
Returns - void
======================================================================== */
void fatal_exit(const char *format, ...)
{
char texbuffer[200];
FILE *f;
va_list argp;
f=fopen("Fatal.err","wt");
va_start(argp, format);
vsprintf(texbuffer,format,argp);
close_graph();
remove_keyint();
printf("Fatal Error:%s\n",texbuffer);
fprintf(f,"Fatal Error:%s\n",texbuffer);
fclose(f);
printf("Exiting...\n");
#if defined(_DEBUG)
// if debuggable, crash into the debugger
{
volatile SHORT i = 0;
i /= 0;
}
#endif
// this exit is a catch all
exit(0);
}
#endif // !defined(_RELEASE)