Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.6 KiB

  1. /* common.h
  2. *
  3. * Common functions useful for Windows programs.
  4. *
  5. * InitializeDebugOutput(szAppName):
  6. *
  7. * Read debug level for this application (named <szAppName>) from
  8. * win.ini's [debug] section, which should look like this:
  9. *
  10. * [debug]
  11. * location=aux ; use OutputDebugString() to output
  12. * foobar=2 ; this app has debug level 2
  13. * blorg=0 ; this app has debug output disabled
  14. *
  15. * If you want debug output to go to a file instead of to the AUX
  16. * device (or the debugger), use "location=>filename". To append to
  17. * the file instead of rewriting the file, use "location=>>filename".
  18. *
  19. * If DEBUG is not #define'd, then the call to InitializeDebugOutput()
  20. * generates no code,
  21. *
  22. * TerminateDebugOutput():
  23. *
  24. * End debug output for this application. If DEBUG is not #define'd,
  25. * then the call to InitializeDebugOutput() generates no code.
  26. *
  27. * DPF((szFormat, args...))
  28. *
  29. * If debugging output for this applicaton is enabled (see
  30. * InitializeDebugOutput()), print debug output specified by format
  31. * string <szFormat>, which may contain wsprintf()-style formatting
  32. * codes corresponding to arguments <args>. Example:
  33. *
  34. * DPF(("in WriteFile(): szFile='%s', dwFlags=0x%08lx\n",
  35. * (LSPTR) szFile, dwFlags));
  36. *
  37. * DPF2((szFormat, args...))
  38. * DPF3((szFormat, args...))
  39. * DPF4((szFormat, args...))
  40. *
  41. * Like DPF, but only output the debug string if the debug level for
  42. * this application is at least 2, 3, or 4, respectively.
  43. *
  44. * Assert(fExpr)
  45. *
  46. * If DEBUG is #define'd, then generate an "assertion failed" message box
  47. * allowing the user to abort the program, enter the debugger (the "Retry"
  48. * button), or ignore the error. If DEBUG is not #define'd then Assert()
  49. * generates no code.
  50. *
  51. * AssertEval(fExpr)
  52. *
  53. * Like Assert(), but evaluate and return <fExpr>, even if DEBUG
  54. * is not #define'd. (Use if you want the BOOL expression to be
  55. * evaluated even in a retail build.)
  56. */
  57. #ifdef DEBUG
  58. /* Assert() macros */
  59. #undef Assert
  60. #undef AssertSz
  61. #undef AssertEval
  62. #define AssertSz(x,sz) ((x) ? (void)0 : (void)_Assert(sz, __FILE__, __LINE__))
  63. #define Assert(expr) AssertSz(expr, #expr)
  64. #define AssertEval(expr) Assert(expr)
  65. /* debug printf macros */
  66. #define DPF( _x_ ) if (giDebugLevel >= 1) _DebugPrintf _x_
  67. #define DPF0( _x_ ) _DebugPrintf _x_
  68. #define DPF1( _x_ ) if (giDebugLevel >= 1) _DebugPrintf _x_
  69. #define DPF2( _x_ ) if (giDebugLevel >= 2) _DebugPrintf _x_
  70. #define DPF3( _x_ ) if (giDebugLevel >= 3) _DebugPrintf _x_
  71. #define DPF4( _x_ ) if (giDebugLevel >= 4) _DebugPrintf _x_
  72. #define DOUT( _x_ ) if (giDebugLevel >= 1) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  73. #define DOUT0( _x_ ) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  74. #define DOUT1( _x_ ) if (giDebugLevel >= 1) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  75. #define DOUT2( _x_ ) if (giDebugLevel >= 2) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  76. #define DOUT3( _x_ ) if (giDebugLevel >= 3) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  77. #define DOUT4( _x_ ) if (giDebugLevel >= 4) {static char _based(_segname("_CODE")) smag[] = _x_; _DebugPrintf(smag); }
  78. /* prototypes */
  79. void FAR PASCAL InitializeDebugOutput(LPSTR szAppName);
  80. void FAR PASCAL TerminateDebugOutput(void);
  81. void FAR PASCAL _Assert(char *szExp, char *szFile, int iLine);
  82. void FAR CDECL _DebugPrintf(LPSTR szFormat, ...);
  83. extern int giDebugLevel; // current debug level
  84. #else
  85. /* Assert() macros */
  86. #define AssertSz(expr,x) ((void)0)
  87. #define Assert(expr) ((void)0)
  88. #define AssertEval(expr) (expr)
  89. /* debug printf macros */
  90. #define DPF( x )
  91. #define DPF0( x )
  92. #define DPF1( x )
  93. #define DPF2( x )
  94. #define DPF3( x )
  95. #define DPF4( x )
  96. #define DOUT( x )
  97. #define DOUT0( x )
  98. #define DOUT1( x )
  99. #define DOUT2( x )
  100. #define DOUT3( x )
  101. #define DOUT4( x )
  102. /* stubs for debugging function prototypes */
  103. #define InitializeDebugOutput(szAppName) 0
  104. #define TerminateDebugOutput() 0
  105. #endif
  106. /* flags for _llseek() */
  107. #ifndef SEEK_SET
  108. #define SEEK_SET 0 // seek relative to start of file
  109. #define SEEK_CUR 1 // seek relative to current position
  110. #define SEEK_END 2 // seek relative to end of file
  111. #endif
  112.