1 /****************************************************************************
3 * Copyright 2008 Jose Fonseca
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ****************************************************************************/
29 static HANDLE g_hFile = INVALID_HANDLE_VALUE;
30 static TCHAR g_szFileName[MAX_PATH];
32 static void _Close(void) {
33 if(g_hFile != INVALID_HANDLE_VALUE) {
35 g_hFile = INVALID_HANDLE_VALUE;
39 static void _Open(const TCHAR *szName, const TCHAR *szExtension) {
45 _sntprintf(g_szFileName, MAX_PATH, TEXT("%s.%u.%s"), szName, dwCounter, szExtension);
47 _sntprintf(g_szFileName, MAX_PATH, TEXT("%s.%s"), szName, szExtension);
49 g_hFile = CreateFile(g_szFileName,
54 FILE_ATTRIBUTE_NORMAL,
57 } while(g_hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS);
60 static void _ReOpen(void) {
63 g_hFile = CreateFile(g_szFileName,
68 FILE_ATTRIBUTE_NORMAL,
72 static void Write(const char *szText) {
73 if(g_hFile == INVALID_HANDLE_VALUE)
76 DWORD dwBytesToWrite = (DWORD)strlen(szText);
77 DWORD dwBytesWritten = 0;
79 while (dwBytesWritten < dwBytesToWrite) {
80 OVERLAPPED overlapped;
81 memset(&overlapped, 0, sizeof(OVERLAPPED));
83 /* Write to end of file */
84 overlapped.Offset = 0xffffffff;
85 overlapped.OffsetHigh = 0xffffffff;
88 szText + dwBytesWritten,
89 dwBytesToWrite - dwBytesWritten,
91 &overlapped) == FALSE) {
93 _Open(TEXT("extra"), TEXT("xml"));
100 void Open(const TCHAR *szName) {
101 _Open(szName, TEXT("xml"));
102 Write("<?xml version='1.0' encoding='UTF-8'?>");
104 Write("<?xml-stylesheet type='text/xsl' href='d3dtrace.xsl'?>");
120 static void Escape(const char *s) {
129 void Tag(const char *name) {
135 void BeginTag(const char *name) {
141 void BeginTag(const char *name,
142 const char *attr1, const char *value1) {
152 void BeginTag(const char *name,
153 const char *attr1, const char *value1,
154 const char *attr2, const char *value2) {
168 void EndTag(const char *name) {
174 void Text(const char *text) {
178 void TextF(const char *format, ...) {
181 va_start(ap, format);
182 vsnprintf(szBuffer, sizeof(szBuffer), format, ap);
187 void BeginCall(const char *function) {
189 BeginTag("call", "name", function);
199 void BeginParam(const char *name, const char *type) {
201 BeginTag("param", "name", name, "type", type);
204 void EndParam(void) {
209 void BeginReturn(const char *type) {
211 BeginTag("return", "type", type);
214 void EndReturn(void) {
220 } /* namespace Log */