summaryrefslogtreecommitdiff
path: root/protocols/YAMN/debug.cpp
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2012-06-06 08:58:27 +0000
committerKirill Volinsky <mataes2007@gmail.com>2012-06-06 08:58:27 +0000
commitb61ba851da0157ace3bdfc1ebbf87156b0b76413 (patch)
treed6c567db57af1eb09c254a8bee13c305282334f8 /protocols/YAMN/debug.cpp
parenta4c70f6bedb25e5cffb08dfc5cbc2597d1642d6b (diff)
protocols plugins moved to protocols
git-svn-id: http://svn.miranda-ng.org/main/trunk@327 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/YAMN/debug.cpp')
-rw-r--r--protocols/YAMN/debug.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/protocols/YAMN/debug.cpp b/protocols/YAMN/debug.cpp
new file mode 100644
index 0000000000..9b9793a965
--- /dev/null
+++ b/protocols/YAMN/debug.cpp
@@ -0,0 +1,139 @@
+/*
+ * YAMN plugin main file
+ * Miranda homepage: http://miranda-icq.sourceforge.net/
+ *
+ * Debug functions used in DEBUG release (you need to global #define DEBUG to get debug version)
+ *
+ * (c) majvan 2002-2004
+ */
+
+#include "yamn.h"
+#include "debug.h"
+#ifdef YAMN_DEBUG
+#include "version.h"
+
+#if defined (WIN9X)
+ #define YAMN_VER "YAMN " YAMN_VERSION_C " (Win9x)"
+#elif defined(WIN2IN1)
+ #define YAMN_VER "YAMN " YAMN_VERSION_C " (2in1)"
+#else
+ #define YAMN_VER "YAMN " YAMN_VERSION_C " (WinNT)"
+#endif
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+TCHAR DebugUserDirectory[MAX_PATH] = _T(".");
+LPCRITICAL_SECTION FileAccessCS;
+
+#ifdef DEBUG_SYNCHRO
+TCHAR DebugSynchroFileName2[]=_T("%s\\yamn-debug.synchro.log");
+HANDLE SynchroFile;
+#endif
+
+#ifdef DEBUG_COMM
+TCHAR DebugCommFileName2[]=_T("%s\\yamn-debug.comm.log");
+HANDLE CommFile;
+#endif
+
+#ifdef DEBUG_DECODE
+TCHAR DebugDecodeFileName2[]=_T("%s\\yamn-debug.decode.log");
+HANDLE DecodeFile;
+#endif
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+void InitDebug()
+{
+#if defined (DEBUG_SYNCHRO) || defined (DEBUG_COMM) || defined (DEBUG_DECODE)
+ TCHAR DebugFileName[MAX_PATH];
+#endif
+ if (FileAccessCS==NULL)
+ {
+ FileAccessCS=new CRITICAL_SECTION;
+ InitializeCriticalSection(FileAccessCS);
+ }
+
+#ifdef DEBUG_SYNCHRO
+ _stprintf(DebugFileName,DebugSynchroFileName2,DebugUserDirectory);
+
+ SynchroFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
+ DebugLog(SynchroFile,"Synchro debug file created by %s\n",YAMN_VER);
+#endif
+
+#ifdef DEBUG_COMM
+ _stprintf(DebugFileName,DebugCommFileName2,DebugUserDirectory);
+
+ CommFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
+ DebugLog(CommFile,"Communication debug file created by %s\n",YAMN_VER);
+#endif
+
+#ifdef DEBUG_DECODE
+ _stprintf(DebugFileName,DebugDecodeFileName2,DebugUserDirectory);
+
+ DecodeFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
+ DebugLog(DecodeFile,"Decoding kernel debug file created by %s\n",YAMN_VER);
+#endif
+}
+
+void UnInitDebug()
+{
+#ifdef DEBUG_SYNCHRO
+ DebugLog(SynchroFile,"File is being closed normally.");
+ CloseHandle(SynchroFile);
+#endif
+#ifdef DEBUG_COMM
+ DebugLog(CommFile,"File is being closed normally.");
+ CloseHandle(CommFile);
+#endif
+#ifdef DEBUG_DECODE
+ DebugLog(DecodeFile,"File is being closed normally.");
+ CloseHandle(DecodeFile);
+#endif
+}
+
+
+void DebugLog(HANDLE File,const char *fmt,...)
+{
+ char *str;
+ char tids[32];
+ va_list vararg;
+ int strsize;
+ DWORD Written;
+
+ va_start(vararg,fmt);
+ str=(char *)malloc(strsize=65536);
+ mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId());
+ while(_vsnprintf(str,strsize,fmt,vararg)==-1)
+ str=(char *)realloc(str,strsize+=65536);
+ va_end(vararg);
+ EnterCriticalSection(FileAccessCS);
+ WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL);
+ WriteFile(File,str,(DWORD)strlen(str),&Written,NULL);
+ LeaveCriticalSection(FileAccessCS);
+ free(str);
+}
+
+void DebugLogW(HANDLE File,const WCHAR *fmt,...)
+{
+ WCHAR *str;
+ char tids[32];
+ va_list vararg;
+ int strsize;
+ DWORD Written;
+
+ va_start(vararg,fmt);
+ str=(WCHAR *)malloc((strsize=65536)*sizeof(WCHAR));
+ mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId());
+ while(_vsnwprintf(str,strsize,fmt,vararg)==-1)
+ str=(WCHAR *)realloc(str,(strsize+=65536)*sizeof(WCHAR));
+ va_end(vararg);
+ EnterCriticalSection(FileAccessCS);
+ WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL);
+ WriteFile(File,str,(DWORD)wcslen(str)*sizeof(WCHAR),&Written,NULL);
+ LeaveCriticalSection(FileAccessCS);
+ free(str);
+}
+
+#endif //ifdef DEBUG \ No newline at end of file