1 /*------------------------------------------------------------------------------
2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3 *
4 * Distributable under the terms of either the Apache License (Version 2.0) or
5 * the GNU Lesser General Public License, as specified in the COPYING file.
6 ------------------------------------------------------------------------------*/
7 #define _CL__CND_DEBUG
8 #include "CLucene/_SharedHeader.h"
9 #include "_condition.h"
10 #include "CLucene/util/Misc.h"
11
12 #define __CND_STR_PRECONDITION "PRECONDITION"
13 #define __CND_STR_CONDITION "CONDITION"
14 #define __CND_STR_WARNING "WARNING"
15 #define __CND_STR_MESSAGE "MESSAGE"
16 #define __CND_STR_DEBUGMESSAGE "DEBUG MESSAGE"
17 #define __CND_STR_EXIT "EXIT"
18
19 #ifndef _CND_DEBUG_DONTIMPLEMENT_OUTDEBUG
_Cnd_OutDebug(const char * FormattedMsg,const char * StrTitle,const char * File,int32_t Line,int32_t Title,const char * Mes2,int32_t fatal)20 void _Cnd_OutDebug( const char* FormattedMsg, const char* StrTitle, const char* File, int32_t Line, int32_t Title, const char* Mes2, int32_t fatal ){
21 #ifdef __WINDOWS_H
22 /*Display a standard messagebox*/
23 MessageBox(NULL, FormattedMsg, StrTitle, (fatal==1 ? MB_ICONSTOP:MB_ICONEXCLAMATION) | MB_OK | MB_TASKMODAL);
24 #else
25 printf("%s\n",FormattedMsg);
26 #endif
27
28 #if defined(_CND_DEBUG_WARN_DEBUGGER) /*attempt to signal windows debugger*/
29 OutputDebugString(FormattedMsg);
30 DebugBreak(); /*Position debugger just before exit program*/
31 #endif
32
33 if ( fatal )
34 debugFatalExit(1);
35 }
36 #endif
37
__cnd_FormatDebug(const char * File,int32_t Line,int32_t Title,const char * Mes2,int32_t fatal)38 void __cnd_FormatDebug( const char* File, int32_t Line, int32_t Title, const char* Mes2, int32_t fatal ) {
39 char M[512];
40 const char* StrTitle = NULL;
41
42 if( Mes2 )
43 _snprintf(M,512,"file:%s line:%d\n%s",File,Line,Mes2);
44 else
45 _snprintf(M,512,"file:%s line:%d",File,Line);
46
47 /*Determine which title to use*/
48 switch( Title ) {
49 case CND_STR_PRECONDITION: {
50 StrTitle = __CND_STR_PRECONDITION;
51 break;
52 }
53 case CND_STR_CONDITION: {
54 StrTitle = __CND_STR_CONDITION;
55 break;
56 }
57 case CND_STR_WARNING: {
58 StrTitle = __CND_STR_WARNING;
59 break;
60 }
61 case CND_STR_MESSAGE: {
62 StrTitle = __CND_STR_MESSAGE;
63 break;
64 }
65 case CND_STR_DEBUGMESSAGE: {
66 StrTitle = __CND_STR_DEBUGMESSAGE;
67 break;
68 }
69 case CND_STR_EXIT: {
70 StrTitle = __CND_STR_EXIT;
71 break;
72 }
73 default:
74 break;
75 }/*switch*/
76
77 _Cnd_OutDebug(M, StrTitle, File, Line, Title, Mes2, fatal);
78 }
79