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