1 /*
2  *
3  *  C++ Portable Types Library (PTypes)
4  *  Version 2.1.1  Released 27-Jun-2007
5  *
6  *  Copyright (C) 2001-2007 Hovik Melikyan
7  *
8  *  http://www.melikyan.com/ptypes/
9  *
10  */
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 
16 #include "pport.h"
17 
18 #if defined(WIN32) && !defined(NO_CRIT_MSGBOX)
19 #  include <windows.h>
20 #  define CRIT_MSGBOX
21 #endif
22 
23 
24 PTYPES_BEGIN
25 
26 
defhandler(int code,const char * msg)27 static void ptdecl defhandler(int code, const char* msg)
28 {
29 #ifdef CRIT_MSGBOX
30     char buf[2048];
31     _snprintf(buf, sizeof(buf) - 1, "Fatal [%05x]: %s", code, msg);
32     MessageBox(0, buf, "Internal error", MB_OK | MB_ICONSTOP);
33 #else
34     fprintf(stderr, "\nInternal [%04x]: %s\n", code, msg);
35 #endif
36 }
37 
38 static _pcrithandler crith = defhandler;
39 
40 
getcrithandler()41 _pcrithandler ptdecl getcrithandler()
42 {
43     return crith;
44 }
45 
46 
setcrithandler(_pcrithandler newh)47 _pcrithandler ptdecl setcrithandler(_pcrithandler newh)
48 {
49     _pcrithandler ret = crith;
50     crith = newh;
51     return ret;
52 }
53 
54 
fatal(int code,const char * msg)55 void ptdecl fatal(int code, const char* msg)
56 {
57     if (crith != nil)
58         (*crith)(code, msg);
59     exit(code);
60 }
61 
62 
63 PTYPES_END
64