1 /****************************************************************************
2 ** libebml : parse EBML files, see http://embl.sourceforge.net/
4 ** <file/class description>
6 ** Copyright (C) 2002-2004 Steve Lhomme. All rights reserved.
8 ** This file is part of libebml.
10 ** This library is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU Lesser General Public
12 ** License as published by the Free Software Foundation; either
13 ** version 2.1 of the License, or (at your option) any later version.
15 ** This library is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** Lesser General Public License for more details.
20 ** You should have received a copy of the GNU Lesser General Public
21 ** License along with this library; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
26 ** Contact license@matroska.org if any conditions of this licensing are
29 **********************************************************************/
33 \version \$Id: Debug.cpp 1268 2007-01-19 10:15:08Z robux4 $
34 \author Steve Lhomme <robux4 @ users.sf.net>
35 \author Moritz Bunkus <moritz @ bunkus.org>
40 #include <windows.h> // For OutputDebugString
46 #include "ebml/Debug.h"
48 START_LIBEBML_NAMESPACE
50 class ADbg globalDebug
;
54 //////////////////////////////////////////////////////////////////////
55 // Construction/Destruction
56 //////////////////////////////////////////////////////////////////////
60 ,my_time_included(false)
62 ,my_debug_output(true)
66 OutPut(-1,"ADbg Creation at debug level = %d (0x%08X)",my_level
,this);
72 OutPut(-1,"ADbg Deletion (0x%08X)",this);
75 inline int ADbg::_OutPut(const char * format
,va_list params
) const
83 if (my_time_included
) {
86 if (prefix
[0] == '\0')
87 wsprintfA(myformat
,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s\r\n",
97 wsprintfA(myformat
,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s - %s\r\n",
108 if (prefix
[0] == '\0')
109 wsprintfA( myformat
, "%s\r\n", format
);
111 wsprintfA( myformat
, "%s - %s\r\n", prefix
, format
);
113 result
= vsprintf(tst
,myformat
,params
);
116 OutputDebugStringA(tst
);
118 if (my_use_file
&& (hFile
!= NULL
)) {
119 SetFilePointer( hFile
, 0, 0, FILE_END
);
121 WriteFile( hFile
, tst
, lstrlenA(tst
), &written
, NULL
);
124 if (my_time_included
) {
129 nowSecs
= time(NULL
);
130 gettimeofday(&tv
, NULL
);
131 now
= gmtime(&nowSecs
);
132 if (prefix
[0] == '\0')
133 sprintf(myformat
,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s\r\n",
134 now
->tm_year
, now
->tm_mon
, now
->tm_mday
,
135 now
->tm_hour
, now
->tm_min
, tv
.tv_sec
,
136 (long)tv
.tv_usec
/ 1000, format
);
138 sprintf(myformat
,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s - %s\r\n",
139 now
->tm_year
, now
->tm_mon
, now
->tm_mday
,
140 now
->tm_hour
, now
->tm_min
, tv
.tv_sec
,
141 (long)tv
.tv_usec
/ 1000, prefix
, format
);
144 if (prefix
[0] == '\0')
145 sprintf( myformat
, "%s\r\n", format
);
147 sprintf( myformat
, "%s - %s\r\n", prefix
, format
);
150 result
= vsprintf(tst
,myformat
,params
);
155 if (my_use_file
&& (hFile
!= NULL
))
162 int ADbg::OutPut(int forLevel
, const char * format
,...) const
166 if (forLevel
>= my_level
) {
169 va_start(tstlist
, format
);
171 result
= _OutPut(format
,tstlist
);
178 int ADbg::OutPut(const char * format
,...) const
182 va_start(tstlist
, format
);
184 return _OutPut(format
,tstlist
);
187 bool ADbg::setDebugFile(const char * NewFilename
) {
189 result
= unsetDebugFile();
195 hFile
= CreateFileA(NewFilename
, GENERIC_WRITE
, FILE_SHARE_WRITE
|FILE_SHARE_READ
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
197 if (hFile
!= INVALID_HANDLE_VALUE
) {
198 SetFilePointer( hFile
, 0, 0, FILE_END
);
202 hFile
= fopen(NewFilename
, "w+");
204 fseek(hFile
, 0, SEEK_END
);
206 OutPut(-1,"Debug hFile Opening succeeded");
210 OutPut(-1,"Debug hFile %s Opening failed",NewFilename
);
216 bool ADbg::unsetDebugFile() {
217 bool result
= (hFile
== NULL
);
221 result
= (CloseHandle(hFile
) != 0);
224 result
= (fclose(hFile
) == 0);
228 OutPut(-1,"Debug hFile Closing succeeded");
235 #endif // !defined(NDEBUG)
237 END_LIBEBML_NAMESPACE