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.

239 lines
6.2 KiB

  1. //+---------------------------------------------------------------------------
  2. // Copyright (C) 1991, Microsoft Corporation.
  3. //
  4. // File: assert.cxx
  5. //
  6. // Contents: Debugging output routines for idsmgr.dll
  7. //
  8. // Functions: _Assert
  9. // _PopUpError
  10. //
  11. // History: 23-Jul-91 KyleP Created.
  12. // 09-Oct-91 KevinRo Major changes and comments added
  13. // 18-Oct-91 vich moved debug print routines out
  14. // 10-Jun-92 BryanT Switched to w4crt.h instead of wchar.h
  15. //
  16. //----------------------------------------------------------------------------
  17. //
  18. // This one file **always** uses debugging options
  19. //
  20. #if DBG == 1
  21. #include <stdarg.h>
  22. # include <debnot.h>
  23. # include <dprintf.h> // w4printf, w4dprintf prototypes
  24. extern "C"
  25. {
  26. #include <windows.h>
  27. #ifndef WIN32
  28. #define MessageBoxA MessageBox
  29. #define wsprintfA wsprintf
  30. #endif
  31. }
  32. int APINOT _PopUpError(char const *szMsg,int iLine, char const *szFile);
  33. unsigned long Win4InfoLevel = DEF_INFOLEVEL;
  34. unsigned long Win4InfoMask = 0xffffffff;
  35. unsigned long Win4AssertLevel = ASSRT_MESSAGE | ASSRT_BREAK | ASSRT_POPUP;
  36. //+---------------------------------------------------------------------------
  37. //
  38. // Function: _asdprintf
  39. //
  40. // Synopsis: Calls vdprintf to output a formatted message.
  41. //
  42. // History: 18-Oct-91 vich Created
  43. //
  44. //----------------------------------------------------------------------------
  45. inline void _asdprintf(char const *pszfmt, ...)
  46. {
  47. va_list va;
  48. va_start(va, pszfmt);
  49. vdprintf(DEB_FORCE, "Assert", pszfmt, va);
  50. va_end(va);
  51. }
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Function: _Win4Assert, private
  55. //
  56. // Synopsis: Display assertion information
  57. //
  58. // Effects: Called when an assertion is hit.
  59. //
  60. // History: 12-Jul-91 AlexT Created.
  61. // 05-Sep-91 AlexT Catch Throws and Catches
  62. // 19-Oct-92 HoiV Added events for TOM
  63. //
  64. //----------------------------------------------------------------------------
  65. void APINOT _Win4Assert(char const * szFile, int iLine, char const * szMessage)
  66. {
  67. if (Win4AssertLevel & ASSRT_MESSAGE)
  68. {
  69. _asdprintf("%s File: %s Line: %u\n", szMessage, szFile, iLine);
  70. }
  71. if (Win4AssertLevel & ASSRT_POPUP)
  72. {
  73. int id = _PopUpError(szMessage,iLine,szFile);
  74. if (id == IDCANCEL)
  75. {
  76. #ifndef FLAT
  77. _asm int 3;
  78. #else
  79. DebugBreak();
  80. #endif
  81. }
  82. }
  83. else if (Win4AssertLevel & ASSRT_BREAK)
  84. {
  85. #ifndef FLAT
  86. _asm int 3;
  87. #else
  88. DebugBreak();
  89. #endif
  90. }
  91. }
  92. //+------------------------------------------------------------
  93. // Function: _SetWin4InfoLevel(unsigned long ulNewLevel)
  94. //
  95. // Synopsis: Sets the global info level for debugging output
  96. // Returns: Old info level
  97. //
  98. //-------------------------------------------------------------
  99. unsigned long APINOT _SetWin4InfoLevel(unsigned long ulNewLevel)
  100. {
  101. unsigned long ul;
  102. ul = Win4InfoLevel;
  103. Win4InfoLevel = ulNewLevel;
  104. return(ul);
  105. }
  106. //+------------------------------------------------------------
  107. // Function: _SetWin4InfoMask(unsigned long ulNewMask)
  108. //
  109. // Synopsis: Sets the global info mask for debugging output
  110. // Returns: Old info mask
  111. //
  112. //-------------------------------------------------------------
  113. unsigned long APINOT _SetWin4InfoMask(unsigned long ulNewMask)
  114. {
  115. unsigned long ul;
  116. ul = Win4InfoMask;
  117. Win4InfoMask = ulNewMask;
  118. return(ul);
  119. }
  120. //+------------------------------------------------------------
  121. // Function: _SetWin4AssertLevel(unsigned long ulNewLevel)
  122. //
  123. // Synopsis: Sets the global assert level for debugging output
  124. // Returns: Old assert level
  125. //
  126. //-------------------------------------------------------------
  127. unsigned long APINOT _SetWin4AssertLevel(unsigned long ulNewLevel)
  128. {
  129. unsigned long ul;
  130. ul = Win4AssertLevel;
  131. Win4AssertLevel = ulNewLevel;
  132. return(ul);
  133. }
  134. //+------------------------------------------------------------
  135. // Function: _PopUpError
  136. //
  137. // Synopsis: Displays a dialog box using provided text,
  138. // and presents the user with the option to
  139. // continue or cancel.
  140. //
  141. // Arguments:
  142. // szMsg -- The string to display in main body of dialog
  143. // iLine -- Line number of file in error
  144. // szFile -- Filename of file in error
  145. //
  146. // Returns:
  147. // IDCANCEL -- User selected the CANCEL button
  148. // IDOK -- User selected the OK button
  149. //-------------------------------------------------------------
  150. int APINOT _PopUpError(char const *szMsg,int iLine, char const *szFile)
  151. {
  152. int id;
  153. static char szAssertCaption[100];
  154. #ifdef WIN32
  155. #undef wsprintfA
  156. #undef MessageBoxA
  157. #endif
  158. wsprintfA(szAssertCaption, "File: %s line %u", szFile,iLine);
  159. id = MessageBoxA(NULL,
  160. (char *) szMsg,
  161. (LPSTR) szAssertCaption,
  162. MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OKCANCEL);
  163. return id;
  164. }
  165. //+------------------------------------------------------------
  166. // Function: vdprintf
  167. //
  168. // Synopsis: Prints debug output using a pointer to the
  169. // variable information. Used primarily by the
  170. // xxDebugOut macros
  171. //
  172. // Arguements:
  173. // ulCompMask -- Component level mask used to determine
  174. // output ability
  175. // pszComp -- String const of component prefix.
  176. // ppszfmt -- Pointer to output format and data
  177. //
  178. //-------------------------------------------------------------
  179. void APINOT vdprintf(unsigned long ulCompMask,
  180. char const *pszComp,
  181. char const *ppszfmt,
  182. va_list pargs)
  183. {
  184. if ((ulCompMask & DEB_FORCE) == DEB_FORCE ||
  185. ((ulCompMask | Win4InfoLevel) & Win4InfoMask))
  186. {
  187. {
  188. if (! (ulCompMask & DEB_NOCOMPNAME))
  189. {
  190. w4dprintf("%s: ", pszComp);
  191. }
  192. w4vdprintf(ppszfmt, pargs);
  193. // Chicago and Win32s debugging is usually through wdeb386
  194. // which needs carriage returns
  195. #if WIN32 == 50 || WIN32 == 200
  196. w4dprintf("\r");
  197. #endif
  198. }
  199. }
  200. }
  201. #endif // DBG == 1