1 /*****************************************************************************/
2 /* */
3 /* CHECK.CC */
4 /* */
5 /* (C) 1993-96 Ullrich von Bassewitz */
6 /* Wacholderweg 14 */
7 /* D-70597 Stuttgart */
8 /* EMail: uz@ibb.schwaben.com */
9 /* */
10 /*****************************************************************************/
11
12
13
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25
26
27 /*****************************************************************************/
28 /* Data */
29 /*****************************************************************************/
30
31
32
33 const char* _MsgInternalError = "Internal error: ";
34 const char* _MsgAbstractCall = "Call to abstract method";
35 const char* _MsgPrecondition = "Precondition violated: ";
36 const char* _MsgCheckFailed = "Check failed: ";
37
38
39
40 /*****************************************************************************/
41 /* Code */
42 /*****************************************************************************/
43
44
45
46 static void _CheckFailed (const char* Msg, const char* Cond,
47 int Code, const char* File, int Line);
48
49
50
51
52 // The fail vector
53 void (*CheckFailed) (const char*, const char* Cond,
54 int Code, const char* File, int Line) = _CheckFailed;
55
56
57
58
_CheckFailed(const char * Msg,const char * Cond,int Code,const char * File,int Line)59 static void _CheckFailed (const char* Msg, const char* Cond,
60 int Code, const char* File, int Line)
61 {
62 fprintf (stderr, "%s%s", Msg, Cond);
63 if (Code) {
64 fprintf (stderr, " (= %d), file ", Code);
65 } else {
66 fprintf (stderr, ", file ");
67 }
68 fprintf (stderr, "%s, line %d\n", File, Line);
69 exit (3);
70 }
71
72
73
Check(const char * Msg,const char * Cond,int Code,const char * File,int Line)74 void Check (const char* Msg, const char* Cond,
75 int Code, const char* File, int Line)
76 {
77 if (Code != 0) {
78 CheckFailed (Msg, Cond, Code, File, Line);
79 }
80 }
81
82
83
84
85