X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdebug.cpp;h=fb77b4277a07ddec150f50f2cd050a7e951c948d;hb=7169af5d07be6e496cef0ac88d0e13647041d198;hp=b165165e505f341d40be42a8289601cf4305758b;hpb=6d13a5166688e470590692eb91c3915ab332fe36;p=ttedit diff --git a/src/debug.cpp b/src/debug.cpp index b165165..fb77b42 100755 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1,206 +1,206 @@ -// -// DEBUG.CPP: Debugging support -// by James L. Hammons -// (C) 2002 Underground Software -// -// JLH = James Hammons -// -// Who When What -// --- ---------- ------------------------------------------------------------ -// JLH 07/31/2002 Created this file -// JLH 07/31/2002 Added debug log functions & system error logging functions -// JLH 08/16/2002 Added debug log function for SQL error reporting, made -// WriteLogMsg thread safe -// JLH 12/10/2002 Added code to have a background message window -// JLH 05/14/2004 Converted code to C++ (sans ODBC logging) -// JLH 05/15/2005 Converted code to generic C++ -// - -//#include -//#include -#include -#include -#include "debug.h" - -// EQUATES - -//#define USDB_WRITEMESSAGE WM_USER + 1 // Display a message on the debug window - -// Function prototypes - -//void CreateDebugWin(void); -//LRESULT CALLBACK DebugWinProc(HWND, UINT, WPARAM, LPARAM); - -// CONSTANTS - -const char logFilename[] = "debug.log"; - -// DATA - -FILE * logFile = NULL; - -// UNINITIALIZED DATA - -//CRITICAL_SECTION csLock; // Critical section lock - -// -// Open the debugging log file -// -void OpenDebugLog(void) -{ -// hLogFile = CreateFile(logFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, -// NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, NULL); -// InitializeCriticalSection(&csLock); - logFile = fopen(logFilename, "wb"); -#ifdef DEBUGWIN - CreateDebugWin(); -#endif -} - -// -// Close the debugging log file -// -void CloseDebugLog(void) -{ -// CloseHandle(hLogFile); - fclose(logFile); -// DeleteCriticalSection(&csLock); - -// if (hDebugWnd) -// DestroyWindow(hDebugWnd); -} - -// -// Write a message to the log file -// -/*void WriteLogMsg(char * msg) -{ - if (!msg) // Check for valid pointer - return; - - EnterCriticalSection(&csLock); - - if (hLogFile) - WriteFile(hLogFile, msg, lstrlen(msg), &wfBytesWritten, NULL); - - if (hDebugWnd) - SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)msg); - - LeaveCriticalSection(&csLock); -}//*/ - -// -// This logger is used mainly to ensure that text gets written to the log file -// even if the program crashes. The performance hit is acceptable in this case! -// -void WriteLogMsg(const char * msg, ...) -{ - if (!msg) // Check for valid pointer - return; - -// EnterCriticalSection(&csLock); - - va_list arg; - - va_start(arg, msg); -// wvsprintf(str, msg, arg); - if (logFile) - { - vfprintf(logFile, msg, arg); - fflush(logFile); - } - - va_end(arg); - -// if (hLogFile) -// WriteFile(hLogFile, str, lstrlen(msg), &wfBytesWritten, NULL); - -// if (hDebugWnd) -// SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)str); - -// LeaveCriticalSection(&csLock); -} - - -// -// Display a system error message on the screen -// -/*void DisplaySysError(HWND hWnd) -{ - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, - GetLastError(), 1024, pBuf, 0, NULL); - MessageBox(hWnd, pBuf, errTitle, MB_ICONERROR); - LocalFree(pBuf); -} - -// -// Create "live log" debug window -// -void CreateDebugWin(void) -{ - WNDCLASS wc; - - RtlZeroMemory(&wc, sizeof(wc)); - wc.lpfnWndProc = DebugWinProc; - wc.hInstance = GetModuleHandle(NULL); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); - wc.lpszClassName = CNDebug; - - if (!RegisterClass(&wc)) - return; - - hDebugWnd = CreateWindowEx(NULL, CNDebug, debugWin, - WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_SYSMENU, - 0, 0, 400, 400, NULL, NULL, NULL, NULL); -} - -// -// Debug "live log" window procedure -// -LRESULT CALLBACK DebugWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch (uMsg) - { - // ***************** - // *** WM_CREATE *** - // ***************** - - case WM_CREATE: - hEdit1 = CreateWindowEx(NULL, CNEdit, NULL, - WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL, - 0, 0, 1, 1, hWnd, NULL, NULL, NULL); - break; - - // ****************** - // *** WM_DESTROY *** - // ****************** - - case WM_DESTROY: - hDebugWnd = NULL; // Just in case user closes it himself... - break; - - // *************** - // *** WM_SIZE *** - // *************** - - case WM_SIZE: - SetWindowPos(hEdit1, NULL, 0, 0, lParam & 0xFFFF, lParam >> 16, SWP_NOMOVE | SWP_NOZORDER); - break; - - // ************************* - // *** USDB_WRITEMESSAGE *** - // ************************* - - case USDB_WRITEMESSAGE: - SendMessage(hEdit1, EM_SETSEL, -2, -2); - SendMessage(hEdit1, EM_REPLACESEL, wParam, lParam); - break; - - default: - return DefWindowProc(hWnd, uMsg, wParam, lParam); - } - - return 0; -} -//*/ +// +// DEBUG.CPP: Debugging support +// by James L. Hammons +// (C) 2002 Underground Software +// +// JLH = James Hammons +// +// Who When What +// --- ---------- ------------------------------------------------------------ +// JLH 07/31/2002 Created this file +// JLH 07/31/2002 Added debug log functions & system error logging functions +// JLH 08/16/2002 Added debug log function for SQL error reporting, made +// WriteLogMsg thread safe +// JLH 12/10/2002 Added code to have a background message window +// JLH 05/14/2004 Converted code to C++ (sans ODBC logging) +// JLH 05/15/2005 Converted code to generic C++ +// + +//#include +//#include +#include +#include +#include "debug.h" + +// EQUATES + +//#define USDB_WRITEMESSAGE WM_USER + 1 // Display a message on the debug window + +// Function prototypes + +//void CreateDebugWin(void); +//LRESULT CALLBACK DebugWinProc(HWND, UINT, WPARAM, LPARAM); + +// CONSTANTS + +const char logFilename[] = "debug.log"; + +// DATA + +FILE * logFile = NULL; + +// UNINITIALIZED DATA + +//CRITICAL_SECTION csLock; // Critical section lock + +// +// Open the debugging log file +// +void OpenDebugLog(void) +{ +// hLogFile = CreateFile(logFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, +// NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, NULL); +// InitializeCriticalSection(&csLock); + logFile = fopen(logFilename, "wb"); +#ifdef DEBUGWIN + CreateDebugWin(); +#endif +} + +// +// Close the debugging log file +// +void CloseDebugLog(void) +{ +// CloseHandle(hLogFile); + fclose(logFile); +// DeleteCriticalSection(&csLock); + +// if (hDebugWnd) +// DestroyWindow(hDebugWnd); +} + +// +// Write a message to the log file +// +/*void WriteLogMsg(char * msg) +{ + if (!msg) // Check for valid pointer + return; + + EnterCriticalSection(&csLock); + + if (hLogFile) + WriteFile(hLogFile, msg, lstrlen(msg), &wfBytesWritten, NULL); + + if (hDebugWnd) + SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)msg); + + LeaveCriticalSection(&csLock); +}//*/ + +// +// This logger is used mainly to ensure that text gets written to the log file +// even if the program crashes. The performance hit is acceptable in this case! +// +void WriteLogMsg(const char * msg, ...) +{ + if (!msg) // Check for valid pointer + return; + +// EnterCriticalSection(&csLock); + + va_list arg; + + va_start(arg, msg); +// wvsprintf(str, msg, arg); + if (logFile) + { + vfprintf(logFile, msg, arg); + fflush(logFile); + } + + va_end(arg); + +// if (hLogFile) +// WriteFile(hLogFile, str, lstrlen(msg), &wfBytesWritten, NULL); + +// if (hDebugWnd) +// SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)str); + +// LeaveCriticalSection(&csLock); +} + + +// +// Display a system error message on the screen +// +/*void DisplaySysError(HWND hWnd) +{ + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, + GetLastError(), 1024, pBuf, 0, NULL); + MessageBox(hWnd, pBuf, errTitle, MB_ICONERROR); + LocalFree(pBuf); +} + +// +// Create "live log" debug window +// +void CreateDebugWin(void) +{ + WNDCLASS wc; + + RtlZeroMemory(&wc, sizeof(wc)); + wc.lpfnWndProc = DebugWinProc; + wc.hInstance = GetModuleHandle(NULL); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); + wc.lpszClassName = CNDebug; + + if (!RegisterClass(&wc)) + return; + + hDebugWnd = CreateWindowEx(NULL, CNDebug, debugWin, + WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_SYSMENU, + 0, 0, 400, 400, NULL, NULL, NULL, NULL); +} + +// +// Debug "live log" window procedure +// +LRESULT CALLBACK DebugWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + // ***************** + // *** WM_CREATE *** + // ***************** + + case WM_CREATE: + hEdit1 = CreateWindowEx(NULL, CNEdit, NULL, + WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL, + 0, 0, 1, 1, hWnd, NULL, NULL, NULL); + break; + + // ****************** + // *** WM_DESTROY *** + // ****************** + + case WM_DESTROY: + hDebugWnd = NULL; // Just in case user closes it himself... + break; + + // *************** + // *** WM_SIZE *** + // *************** + + case WM_SIZE: + SetWindowPos(hEdit1, NULL, 0, 0, lParam & 0xFFFF, lParam >> 16, SWP_NOMOVE | SWP_NOZORDER); + break; + + // ************************* + // *** USDB_WRITEMESSAGE *** + // ************************* + + case USDB_WRITEMESSAGE: + SendMessage(hEdit1, EM_SETSEL, -2, -2); + SendMessage(hEdit1, EM_REPLACESEL, wParam, lParam); + break; + + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} +//*/