[RSHELL]
[reactos.git] / base / shell / rshell / wraplog.cpp
1 #include "precomp.h"
2 #include "wraplog.h"
3 #include <stdio.h>
4
5 static INT openCount = 0;
6 static INT callLevel;
7 static FILE*log;
8
9 static INT nTemps;
10 static CHAR strTemp[10][256];
11
12 void WrapLogOpen()
13 {
14 if (openCount == 0)
15 {
16 log = fopen("G:\\RShellWrap.log", "w");
17 nTemps = 0;
18 callLevel = 0;
19 }
20 openCount++;
21 }
22
23 void WrapLogClose()
24 {
25 openCount--;
26 if (openCount == 0)
27 {
28 fclose(log);
29 log = NULL;
30 }
31 }
32
33 void __cdecl WrapLogMsg(_Printf_format_string_ const char* msg, ...)
34 {
35 va_list args;
36 for (int i = 0; i < callLevel; i++)
37 fputs(" ", log);
38 fputs("-- ", log);
39 va_start(args, msg);
40 vfprintf(log, msg, args);
41 va_end(args);
42 fflush(log);
43 nTemps = 0;
44 }
45
46 void __cdecl WrapLogEnter(_Printf_format_string_ const char* msg, ...)
47 {
48 va_list args;
49 for (int i = 0; i < callLevel; i++)
50 fputs(" ", log);
51 fputs("ENTER >> ", log);
52 va_start(args, msg);
53 vfprintf(log, msg, args);
54 va_end(args);
55 fflush(log);
56 callLevel++;
57 nTemps = 0;
58 }
59
60 void __cdecl WrapLogExit(_Printf_format_string_ const char* msg, ...)
61 {
62 va_list args;
63 callLevel--;
64 for (int i = 0; i < callLevel; i++)
65 fputs(" ", log);
66 fputs("EXIT <<< ", log);
67 va_start(args, msg);
68 vfprintf(log, msg, args);
69 va_end(args);
70 fflush(log);
71 nTemps = 0;
72 }
73
74 template <class T>
75 LPSTR Wrap(const T& value);
76
77 template <>
78 LPSTR Wrap<GUID>(REFGUID guid)
79 {
80 LPSTR cStr = strTemp[nTemps++];
81 StringCchPrintfA(cStr, _countof(strTemp[0]),
82 "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
83 guid.Data1, guid.Data2, guid.Data3,
84 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
85 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
86 return cStr;
87 }
88
89 template <>
90 LPSTR Wrap<RECT>(const RECT& rect)
91 {
92 LPSTR cStr = strTemp[nTemps++];
93 StringCchPrintfA(cStr, _countof(strTemp[0]),
94 "{L: %d, T: %d, R: %d, B: %d}",
95 rect.left, rect.top, rect.right, rect.bottom);
96 return cStr;
97 }
98
99 template <>
100 LPSTR Wrap<OLECMD>(const OLECMD& cmd)
101 {
102 LPSTR cStr = strTemp[nTemps++];
103 StringCchPrintfA(cStr, _countof(strTemp[0]),
104 "{ID: %d, F: %d}",
105 cmd.cmdID, cmd.cmdf);
106 return cStr;
107 }
108
109 template <>
110 LPSTR Wrap<MSG>(const MSG& msg)
111 {
112 LPSTR cStr = strTemp[nTemps++];
113 StringCchPrintfA(cStr, _countof(strTemp[0]),
114 "{HWND: %d, Code: %d, W: %p, L: %p, T: %d, P.X: %d, P.Y: %d}",
115 msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.time, msg.pt.x, msg.pt.y);
116 return cStr;
117 }
118
119 template <>
120 LPSTR Wrap<BANDSITEINFO>(const BANDSITEINFO& bsi)
121 {
122 LPSTR cStr = strTemp[nTemps++];
123 StringCchPrintfA(cStr, _countof(strTemp[0]),
124 "{dwMask: %08x, dwState: %08x, dwStyle: %08x}",
125 bsi.dwMask, bsi.dwState, bsi.dwStyle);
126 return cStr;
127 }