Source code of Windows XP (NT5)
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.

212 lines
6.6 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. npassert.h
  7. NP environment independent assertion/logging routines
  8. Usage:
  9. ASSERT(exp) Evaluates its argument. If "exp" evals to
  10. FALSE, then the app will terminate, naming
  11. the file name and line number of the assertion
  12. in the source.
  13. UIASSERT(exp) Synonym for ASSERT.
  14. ASSERTSZ(exp,sz) As ASSERT, except will also print the message
  15. "sz" with the assertion message should it fail.
  16. REQUIRE(exp) As ASSERT, except that its expression is still
  17. evaluated in retail versions. (Other versions
  18. of ASSERT disappear completely in retail builds.)
  19. ANSI_ASSERTABLE(sz) Declares "sz" to be a string buffer which
  20. can be used with the ASSERT_ANSI and ASSERT_OEM
  21. macros (effectively declares a debug-only BOOL
  22. associated with the string).
  23. ASSERT_ANSI(sz) Asserts that sz is in the ANSI character set.
  24. ASSERT_OEM(sz) Asserts that sz is in the OEM character set.
  25. IS_ANSI(sz) Declares that sz is in the ANSI character set
  26. (e.g., if it's just come back from a GetWindowText).
  27. IS_OEM(sz) Declares that sz is in the OEM character set.
  28. TO_ANSI(sz) Does OemToAnsi in place.
  29. TO_OEM(sz) Does AnsiToOem in place.
  30. COPY_TO_ANSI(src,dest) Does OemToAnsi, not in place.
  31. COPY_TO_OEM(src,dest) Does AnsiToOem, not in place.
  32. NOTE: the latter two, just like the APIs themselves, have the
  33. source first and destination second, opposite from strcpy().
  34. The ASSERT macros expect a symbol _FILENAME_DEFINED_ONCE, and will
  35. use the value of that symbol as the filename if found; otherwise,
  36. they will emit a new copy of the filename, using the ANSI C __FILE__
  37. macro. A client sourcefile may therefore define __FILENAME_DEFINED_ONCE
  38. in order to minimize the DGROUP footprint of a number of ASSERTs.
  39. FILE HISTORY:
  40. Johnl 11/15/90 Converted from CAssert to general purpose
  41. Johnl 12/06/90 Changed _FAR_ to _far in _assert prototype
  42. beng 04/30/91 Made C-includable
  43. beng 08/05/91 Made assertions occupy less dgroup; withdrew
  44. explicit heapchecking (which was crt
  45. dependent anyway)
  46. beng 09/17/91 Removed additional consistency checks;
  47. rewrote to minimize dgroup footprint,
  48. check expression in-line
  49. beng 09/19/91 Fixed my own over-cleverness
  50. beng 09/25/91 Fixed bug in retail REQUIRE
  51. gregj 03/23/93 Ported to Chicago environment
  52. gregj 05/11/93 Added ANSI/OEM asserting routines
  53. gregj 05/25/93 Added COPY_TO_ANSI and COPY_TO_OEM
  54. */
  55. #ifndef _NPASSERT_H_
  56. #define _NPASSERT_H_
  57. #if defined(__cplusplus)
  58. extern "C"
  59. {
  60. #else
  61. extern
  62. #endif
  63. VOID UIAssertHelper( const CHAR* pszFileName, UINT nLine );
  64. VOID UIAssertSzHelper( const CHAR* pszMessage, const CHAR* pszFileName, UINT nLine );
  65. extern const CHAR szShouldBeAnsi[];
  66. extern const CHAR szShouldBeOEM[];
  67. #if defined(__cplusplus)
  68. }
  69. #endif
  70. #if defined(DEBUG)
  71. # if defined(_FILENAME_DEFINED_ONCE)
  72. # define ASSERT(exp) \
  73. { if (!(exp)) UIAssertHelper(_FILENAME_DEFINED_ONCE, __LINE__); }
  74. # define ASSERTSZ(exp, sz) \
  75. { if (!(exp)) UIAssertSzHelper((sz), _FILENAME_DEFINED_ONCE, __LINE__); }
  76. # else
  77. # define ASSERT(exp) \
  78. { if (!(exp)) UIAssertHelper(__FILE__, __LINE__); }
  79. # define ASSERTSZ(exp, sz) \
  80. { if (!(exp)) UIAssertSzHelper((sz), __FILE__, __LINE__); }
  81. # endif
  82. # define UIASSERT(exp) ASSERT(exp)
  83. # define REQUIRE(exp) ASSERT(exp)
  84. #define EXTERN_ANSI_ASSERTABLE(sz) extern BOOL fAnsiIs##sz;
  85. #define ANSI_ASSERTABLE(sz) BOOL fAnsiIs##sz=FALSE;
  86. #define ASSERT_ANSI(sz) ASSERTSZ(fAnsiIs##sz,szShouldBeAnsi)
  87. #define ASSERT_OEM(sz) ASSERTSZ(!fAnsiIs##sz,szShouldBeOEM)
  88. #define IS_ANSI(sz) fAnsiIs##sz = TRUE;
  89. #define IS_OEM(sz) fAnsiIs##sz = FALSE;
  90. #define TO_ANSI(sz) { ASSERT_OEM(sz); ::OemToAnsi(sz,sz); IS_ANSI(sz); }
  91. #define TO_OEM(sz) { ASSERT_ANSI(sz); ::AnsiToOem(sz,sz); IS_OEM(sz); }
  92. #define COPY_TO_ANSI(s,d) { ASSERT_OEM(s); ::OemToAnsi(s,d); IS_ANSI(d); }
  93. #define COPY_TO_OEM(s,d) { ASSERT_ANSI(s); ::AnsiToOem(s,d); IS_OEM(d); }
  94. #else // !DEBUG
  95. # define ASSERT(exp) ;
  96. # define UIASSERT(exp) ;
  97. # define ASSERTSZ(exp, sz) ;
  98. # define REQUIRE(exp) { (exp); }
  99. #define EXTERN_ANSI_ASSERTABLE(sz) ;
  100. #define ANSI_ASSERTABLE(sz) ;
  101. #define ASSERT_ANSI(sz) ;
  102. #define ASSERT_OEM(sz) ;
  103. #define IS_ANSI(sz) ;
  104. #define IS_OEM(sz) ;
  105. #define TO_ANSI(sz) ::OemToAnsi(sz,sz)
  106. #define TO_OEM(sz) ::AnsiToOem(sz,sz)
  107. #define COPY_TO_ANSI(s,d) ::OemToAnsi(s,d)
  108. #define COPY_TO_OEM(s,d) ::AnsiToOem(s,d)
  109. #endif // DEBUG
  110. // Debug mask APIs
  111. // NOTE: You can #define your own DM_* values using bits in the HI BYTE
  112. #define DM_TRACE 0x0001 // Trace messages
  113. #define DM_WARNING 0x0002 // Warning
  114. #define DM_ERROR 0x0004 // Error
  115. #define DM_ASSERT 0x0008 // Assertions
  116. #define DM_LOG_FILE 0x0100
  117. #define DM_PREFIX 0x0200
  118. #if !defined(NetDebugMsg)
  119. //
  120. // DebugMsg(mask, msg, args...) - Generate wsprintf-formatted msg using
  121. // specified debug mask. System debug mask
  122. // governs whether message is output.
  123. //
  124. #if defined(__cplusplus)
  125. extern "C"
  126. {
  127. #else
  128. extern
  129. #endif
  130. #define REGVAL_STR_DEBUGMASK "DebugMask"
  131. void __cdecl NetDebugMsg(UINT mask, LPCSTR psz, ...);
  132. UINT WINAPI NetSetDebugParameters(PSTR pszName,PSTR pszLogFile);
  133. UINT WINAPI NetSetDebugMask(UINT mask);
  134. UINT WINAPI NetGetDebugMask(void);
  135. #if defined(__cplusplus)
  136. }
  137. #endif
  138. #endif
  139. #ifdef DEBUG
  140. #define Break() {_asm _emit 0xcc}
  141. //#define Trap() {_asm {_emit 0xcc}}
  142. //#define TrapC(c) {if(c) {Trap()}}
  143. #define DPRINTF NetDebugMsg
  144. #else
  145. #define Break()
  146. #define Trap()
  147. #define TrapC(c)
  148. // Nb: Following definition is needed to avoid compiler complaining
  149. // about empty function name in expression. In retail builds using this macro
  150. // will cause string parameters not appear in executable
  151. #define DPRINTF 1?(void)0 : (void)
  152. #endif
  153. #endif // _NPASSERT_H_