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.

198 lines
4.7 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. uiassert.c
  7. Environment specific stuff for the UIASSERT & REQUIRE macro
  8. This file contains the environment specific (windows vs. OS/2/DOS)
  9. features of the assert macro, specifically, the output method
  10. (everything is hidden by the standard C-Runtime).
  11. FILE HISTORY:
  12. johnl 10/17/90 Created
  13. johnl 10/18/90 Added OutputDebugString
  14. beng 04/30/91 Made a 'C' file
  15. beng 08/05/91 Withdrew expressions; reprototyped
  16. all functions
  17. beng 09/17/91 Withdrew additional consistency checks
  18. beng 09/26/91 Withdrew nprintf calls
  19. gregj 03/23/93 Ported to Chicago environment
  20. */
  21. #include "npcommon.h"
  22. #include "npassert.h"
  23. extern "C" {
  24. const CHAR szShouldBeAnsi[] = "String should be ANSI but isn't";
  25. const CHAR szShouldBeOEM[] = "String should be OEM but isn't";
  26. static CHAR szFmt0[] = "File %.40s, Line %u";
  27. static CHAR szFmt1[] = "%.60s: File %.40s, Line %u";
  28. static CHAR szMBCaption[] = "ASSERTION FAILED";
  29. static CHAR szFAE[] = "ASSERTION FAILURE IN APP";
  30. VOID UIAssertHelper(
  31. const CHAR* pszFileName,
  32. UINT nLine )
  33. {
  34. CHAR szBuff[sizeof(szFmt0)+60+40];
  35. wsprintf(szBuff, szFmt0, pszFileName, nLine);
  36. MessageBox(NULL, szBuff, szMBCaption,
  37. (MB_TASKMODAL | MB_ICONSTOP | MB_OK) );
  38. FatalAppExit(0, szFAE);
  39. }
  40. VOID UIAssertSzHelper(
  41. const CHAR* pszMessage,
  42. const CHAR* pszFileName,
  43. UINT nLine )
  44. {
  45. CHAR szBuff[sizeof(szFmt1)+60+40];
  46. wsprintf(szBuff, szFmt1, pszMessage, pszFileName, nLine);
  47. MessageBox(NULL, szBuff, szMBCaption,
  48. (MB_TASKMODAL | MB_ICONSTOP | MB_OK) );
  49. FatalAppExit(0, szFAE);
  50. }
  51. //========== Debug output routines =========================================
  52. UINT uiNetDebugMask = 0xffff;
  53. UINT WINAPI NetSetDebugMask(UINT mask)
  54. {
  55. #ifdef DEBUG
  56. UINT uiOld = uiNetDebugMask;
  57. uiNetDebugMask = mask;
  58. return uiOld;
  59. #else
  60. return 0;
  61. #endif
  62. }
  63. UINT WINAPI NetGetDebugMask()
  64. {
  65. #ifdef DEBUG
  66. return uiNetDebugMask;
  67. #else
  68. return 0;
  69. #endif
  70. }
  71. #ifndef WINCAPI
  72. #ifdef WIN32
  73. #define WINCAPI __cdecl
  74. #else
  75. #define WINCAPI __far __cdecl
  76. #endif
  77. #endif
  78. #ifdef DEBUG
  79. /* debug message output log file */
  80. UINT g_uSpewLine = 0;
  81. PCSTR g_pcszSpewFile = NULL;
  82. CHAR s_cszLogFile[MAX_PATH] = {'\0'};
  83. CHAR s_cszDebugName[MAX_PATH] = {'\0'};
  84. UINT WINAPI NetSetDebugParameters(PSTR pszName,PSTR pszLogFile)
  85. {
  86. lstrcpy(s_cszLogFile,pszLogFile);
  87. lstrcpy(s_cszDebugName,pszName);
  88. return 0;
  89. }
  90. BOOL LogOutputDebugString(PCSTR pcsz)
  91. {
  92. BOOL bResult = FALSE;
  93. UINT ucb;
  94. char rgchLogFile[MAX_PATH];
  95. if (IS_EMPTY_STRING(s_cszLogFile) )
  96. return FALSE;
  97. ucb = GetWindowsDirectory(rgchLogFile, sizeof(rgchLogFile));
  98. if (ucb > 0 && ucb < sizeof(rgchLogFile)) {
  99. HANDLE hfLog;
  100. lstrcat(rgchLogFile, "\\");
  101. lstrcat(rgchLogFile, s_cszLogFile);
  102. hfLog = ::CreateFile(rgchLogFile,
  103. GENERIC_WRITE,
  104. 0,
  105. NULL,
  106. OPEN_ALWAYS,
  107. 0,
  108. NULL);
  109. if (hfLog != INVALID_HANDLE_VALUE) {
  110. if (SetFilePointer(hfLog, 0, NULL, FILE_END) != INVALID_FILE_SIZE) {
  111. DWORD dwcbWritten;
  112. bResult = WriteFile(hfLog, pcsz, lstrlen(pcsz), &dwcbWritten, NULL);
  113. if (! CloseHandle(hfLog) && bResult)
  114. bResult = FALSE;
  115. }
  116. }
  117. }
  118. return(bResult);
  119. }
  120. CHAR *achDebugDisplayPrefix[] = {"t ","w ","e ","a ","t ","t ","t ","t ","t ","t ","t "};
  121. void WINCAPI NetDebugMsg(UINT mask, LPCSTR pszMsg, ...)
  122. {
  123. char ach[1024];
  124. UINT uiDisplayMask = mask & 0xff;
  125. // Determine prefix
  126. *ach = '\0';
  127. if (uiNetDebugMask & DM_PREFIX) {
  128. // Add trace type
  129. ::lstrcat(ach,achDebugDisplayPrefix[uiDisplayMask]);
  130. // Add component name
  131. ::lstrcat(ach,s_cszDebugName);
  132. // Add thread ID
  133. CHAR szThreadId[16];
  134. ::wsprintf(szThreadId,"[%#lx] ",::GetCurrentThreadId());
  135. ::lstrcat(ach,szThreadId);
  136. }
  137. ::wvsprintf(ach+::lstrlen(ach), pszMsg, (va_list)((&pszMsg) + 1));
  138. ::lstrcat(ach,"\r\n");
  139. if (uiNetDebugMask & DM_LOG_FILE) {
  140. LogOutputDebugString(ach);
  141. }
  142. // Check if we need to display this trace
  143. if (uiNetDebugMask & uiDisplayMask) {
  144. OutputDebugString(ach);
  145. }
  146. }
  147. #endif
  148. } /* extern "C" */