home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Extras / Sensaura / SDK1.0 / data1.cab / Example_Files / DS3DDemo / Source / Debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-13  |  2.3 KB  |  122 lines

  1. /*
  2.     Company:            Sensaura
  3.     Copyright:          (C) 1998
  4.  
  5.     File Name:            Debug.c
  6.     File Description:    Source file for debug support functions
  7.     Author:                Adam Philp
  8.     Version:            DEV1.00
  9.     Last Update:        10-JUL-98
  10.  
  11.     Target Compiler:    Microsoft Visual C++ Version 5.0
  12. */
  13.  
  14.  
  15. #ifdef _DEBUG            // File only compiles to code if this is a debug build
  16.  
  17. /*
  18.     Included files
  19. */
  20.  
  21. #include <windows.h>
  22.  
  23. #include <stdarg.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. #include "debug.h"
  28.  
  29. /*
  30.     Local definitions
  31. */
  32.  
  33. #define DEBUG_BUFFER_SIZE    256
  34.  
  35. #define DEBUG_OK               0
  36. #define DEBUG_ERR_MODULE       -1
  37. #define DEBUG_ERR_LEVEL        -2
  38. #define DEBUG_ERR_FILE         -3
  39. #define DEBUG_ERR_WRITE        -4
  40. #define DEBUG_ERR_INIT        -5
  41.  
  42. /*
  43.     Local functions
  44. */
  45.  
  46. int DebugInit(void);
  47. int DebugOutput(const char* lpcszString);
  48. int    DebugPrintf(const char* lpcszFormat, ...);
  49.  
  50. /*
  51.     Local variables
  52. */
  53.  
  54. int            DebugThreshold = 10;
  55. int            DebugOldThreshold = 10;
  56. const char*    lpcszTraceFileName = NULL;
  57. int            NumTraceLine = 0;
  58. char        achDebugString[DEBUG_BUFFER_SIZE];
  59.  
  60.  
  61. /*
  62.     Module code
  63. */
  64.  
  65. extern void DebugTraceDisable()
  66. {
  67.     DebugThreshold = -1;
  68. }
  69.  
  70. extern void DebugTraceEnable()
  71. {
  72.     DebugThreshold = DebugOldThreshold;
  73. }
  74.  
  75. void DebugTracePrepare(const char* lpcszFileName, int NumLine)
  76. {
  77.     lpcszTraceFileName = strrchr(lpcszFileName, '\\');
  78.  
  79.     if(lpcszTraceFileName == NULL)
  80.         lpcszTraceFileName = lpcszFileName;
  81.     else
  82.         ++lpcszTraceFileName;
  83.  
  84.     NumTraceLine = NumLine;
  85. }
  86.  
  87. void DebugTrace(int DebugLevel, const char* lpcszFormat, ...)
  88. {
  89.     int        Length;
  90.     va_list argPtr;
  91.     char    achTraceMessage[DEBUG_BUFFER_SIZE];
  92.  
  93.     if(DebugLevel > DebugThreshold)
  94.         return;
  95.  
  96.        va_start(argPtr, lpcszFormat);
  97.  
  98.     Length = vsprintf( achTraceMessage, lpcszFormat, argPtr );
  99.  
  100.       while (achTraceMessage[ --Length ] == '\n')    // Remove trailing carriage returns
  101.         achTraceMessage[Length] = '\0';
  102.  
  103.     DebugPrintf("%-12s #%d:\t%s\n", lpcszTraceFileName, NumTraceLine, achTraceMessage);
  104. }
  105.  
  106. int DebugPrintf(const char* lpcszFormat, ...)
  107. {
  108.     int        RetVal;
  109.     va_list argPtr;
  110.  
  111.     va_start(argPtr, lpcszFormat);
  112.     RetVal = vsprintf(achDebugString, lpcszFormat, argPtr);
  113.     if(RetVal == EOF)
  114.         return DEBUG_ERR_WRITE;
  115.  
  116.     OutputDebugString(achDebugString);
  117.     return RetVal;
  118. }
  119.  
  120. #endif             // _DEBUG
  121.  
  122.