c1e870539cb835406b79d6ee8e4d7b154df19cda
[reactos.git] / lib / winedbgc / trace.c
1 /////////////////////////////////////////////////////////////////////////////
2 // Diagnostic Trace
3 //
4 #include <stdio.h> 
5 #include <stdarg.h>
6 #include <tchar.h>
7 #define WIN32_LEAN_AND_MEAN
8 #include "windows.h"
9 #include "trace.h"
10
11
12 #ifdef _DEBUG
13
14 #ifdef WIN32
15 //#define WIN32_LEAN_AND_MEAN           // Exclude rarely-used stuff from Windows headers
16 //#include <windows.h>
17 //#include <assert.h>
18 //WINBASEAPI VOID WINAPI DebugBreak(VOID);
19 //WINBASEAPI VOID WINAPI OutputDebugStringA(LPCSTR lpOutputString);
20 //WINBASEAPI VOID WINAPI OutputDebugStringW(LPCWSTR lpOutputString);
21 //void __stdcall DebugBreak(void);
22 //void __stdcall OutputDebugStringA(char* lpOutputString);
23 //void __stdcall OutputDebugStringW(wchar_t* lpOutputString);
24 #ifdef UNICODE
25 #define OutputDebugString  OutputDebugStringW
26 #else
27 #define OutputDebugString  OutputDebugStringA
28 #endif // !UNICODE
29
30 #else
31 #include "hardware.h"
32 #endif // WIN32
33
34
35 #undef THIS_FILE
36 static char THIS_FILE[] = __FILE__;
37
38 void _DebugBreak(void)
39 {
40     DebugBreak();
41 }
42
43 void Trace(TCHAR* lpszFormat, ...)
44 {
45     va_list args;
46     int nBuf;
47     TCHAR szBuffer[512];
48
49     va_start(args, lpszFormat);
50 //  nBuf = vsprintf(szBuffer, lpszFormat, args);
51 //  nBuf = _vsntprintf(szBuffer, _countof(szBuffer), lpszFormat, args);
52 #ifdef _UNICODE
53     nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
54 #else
55     nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
56 #endif
57     OutputDebugString(szBuffer);
58     // was there an error? was the expanded string too long?
59 //    ASSERT(nBuf >= 0);
60     va_end(args);
61 }
62
63 void Assert(void* assert, TCHAR* file, int line, void* msg)
64 {
65     if (msg == NULL) {
66         printf("ASSERT -- %s occured on line %u of file %s.\n",
67                assert, line, file);
68     } else {
69         printf("ASSERT -- %s occured on line %u of file %s: Message = %s.\n",
70                assert, line, file, msg);
71     }
72 }
73
74
75 #else
76
77 //inline void Trace(TCHAR* lpszFormat, ...) { };
78 //inline void Assert(void* assert, TCHAR* file, int line, void* msg) { };
79 void Trace(TCHAR* lpszFormat, ...) { };
80 void Assert(void* assert, TCHAR* file, int line, void* msg) { };
81
82 #endif //_DEBUG
83 /////////////////////////////////////////////////////////////////////////////