home *** CD-ROM | disk | FTP | other *** search
- /*
- Company: Sensaura
- Copyright: (C) 1998
-
- File Name: Debug.c
- File Description: Source file for debug support functions
- Author: Adam Philp
- Version: DEV1.00
- Last Update: 10-JUL-98
-
- Target Compiler: Microsoft Visual C++ Version 5.0
- */
-
-
- #ifdef _DEBUG // File only compiles to code if this is a debug build
-
- /*
- Included files
- */
-
- #include <windows.h>
-
- #include <stdarg.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "debug.h"
-
- /*
- Local definitions
- */
-
- #define DEBUG_BUFFER_SIZE 256
-
- #define DEBUG_OK 0
- #define DEBUG_ERR_MODULE -1
- #define DEBUG_ERR_LEVEL -2
- #define DEBUG_ERR_FILE -3
- #define DEBUG_ERR_WRITE -4
- #define DEBUG_ERR_INIT -5
-
- /*
- Local functions
- */
-
- int DebugInit(void);
- int DebugOutput(const char* lpcszString);
- int DebugPrintf(const char* lpcszFormat, ...);
-
- /*
- Local variables
- */
-
- int DebugThreshold = 10;
- int DebugOldThreshold = 10;
- const char* lpcszTraceFileName = NULL;
- int NumTraceLine = 0;
- char achDebugString[DEBUG_BUFFER_SIZE];
-
-
- /*
- Module code
- */
-
- extern void DebugTraceDisable()
- {
- DebugThreshold = -1;
- }
-
- extern void DebugTraceEnable()
- {
- DebugThreshold = DebugOldThreshold;
- }
-
- void DebugTracePrepare(const char* lpcszFileName, int NumLine)
- {
- lpcszTraceFileName = strrchr(lpcszFileName, '\\');
-
- if(lpcszTraceFileName == NULL)
- lpcszTraceFileName = lpcszFileName;
- else
- ++lpcszTraceFileName;
-
- NumTraceLine = NumLine;
- }
-
- void DebugTrace(int DebugLevel, const char* lpcszFormat, ...)
- {
- int Length;
- va_list argPtr;
- char achTraceMessage[DEBUG_BUFFER_SIZE];
-
- if(DebugLevel > DebugThreshold)
- return;
-
- va_start(argPtr, lpcszFormat);
-
- Length = vsprintf( achTraceMessage, lpcszFormat, argPtr );
-
- while (achTraceMessage[ --Length ] == '\n') // Remove trailing carriage returns
- achTraceMessage[Length] = '\0';
-
- DebugPrintf("%-12s #%d:\t%s\n", lpcszTraceFileName, NumTraceLine, achTraceMessage);
- }
-
- int DebugPrintf(const char* lpcszFormat, ...)
- {
- int RetVal;
- va_list argPtr;
-
- va_start(argPtr, lpcszFormat);
- RetVal = vsprintf(achDebugString, lpcszFormat, argPtr);
- if(RetVal == EOF)
- return DEBUG_ERR_WRITE;
-
- OutputDebugString(achDebugString);
- return RetVal;
- }
-
- #endif // _DEBUG
-
-