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.

213 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. str.cpp
  5. Abstract:
  6. Author:
  7. Vlad Sadovsky (vlads) 26-Jan-1997
  8. Revision History:
  9. 26-Jan-1997 VladS created
  10. --*/
  11. #include "cplusinc.h"
  12. #include "sticomm.h"
  13. extern "C" {
  14. static CHAR szFmt0[] = "File %.40s, Line %u";
  15. static CHAR szFmt1[] = "%.60s: File %.40s, Line %u";
  16. static CHAR szMBCaption[] = "ASSERTION FAILED";
  17. static TCHAR szFAE[] = TEXT("ASSERTION FAILURE IN APP");
  18. BOOL fDoMessageBox = FALSE;
  19. VOID UIAssertHelper(
  20. const CHAR* pszFileName,
  21. UINT nLine )
  22. {
  23. CHAR szBuff[sizeof(szFmt0)+60+40];
  24. wsprintfA(szBuff, szFmt0, pszFileName, nLine);
  25. MessageBoxA(NULL, szBuff, szMBCaption,
  26. (MB_TASKMODAL | MB_ICONSTOP | MB_OK) );
  27. FatalAppExit(0, szFAE);
  28. }
  29. VOID UIAssertSzHelper(
  30. const TCHAR* pszMessage,
  31. const CHAR* pszFileName,
  32. UINT nLine )
  33. {
  34. CHAR szBuff[sizeof(szFmt1)+60+40];
  35. wsprintfA(szBuff, szFmt1, pszMessage, pszFileName, nLine);
  36. MessageBoxA(NULL, szBuff, szMBCaption,
  37. (MB_TASKMODAL | MB_ICONSTOP | MB_OK) );
  38. FatalAppExit(0, szFAE);
  39. }
  40. VOID AssertHelper(
  41. const CHAR* pszFileName,
  42. UINT nLine )
  43. {
  44. //DPRINTF(DM_ASSERT,szFmt0, pszFileName, nLine);
  45. Break();
  46. }
  47. VOID AssertSzHelper(
  48. const TCHAR* pszMessage,
  49. const CHAR* pszFileName,
  50. UINT nLine )
  51. {
  52. //DPRINTF(DM_ASSERT,szFmt1, pszMessage, pszFileName, nLine);
  53. Break();
  54. }
  55. //========== Debug output routines =========================================
  56. UINT uiStiDebugMask = 0xffff;
  57. UINT WINAPI StiSetDebugMask(UINT mask)
  58. {
  59. #ifdef DEBUG
  60. UINT uiOld = uiStiDebugMask;
  61. uiStiDebugMask = mask;
  62. return uiOld;
  63. #else
  64. return 0;
  65. #endif
  66. }
  67. UINT WINAPI StiGetDebugMask()
  68. {
  69. #ifdef DEBUG
  70. return uiStiDebugMask;
  71. #else
  72. return 0;
  73. #endif
  74. }
  75. #ifndef WINCAPI
  76. #define WINCAPI __cdecl
  77. #endif
  78. #ifdef DEBUG
  79. /* debug message output log file */
  80. UINT g_uSpewLine = 0;
  81. PCTSTR g_pcszSpewFile = NULL;
  82. TCHAR s_cszLogFile[MAX_PATH] = {'\0'};
  83. TCHAR s_cszDebugName[MAX_PATH] = {'\0'};
  84. UINT WINAPI StiSetDebugParameters(PTSTR pszName,PTSTR pszLogFile)
  85. {
  86. lstrcpy(s_cszLogFile,pszLogFile);
  87. lstrcpy(s_cszDebugName,pszName);
  88. return 0;
  89. }
  90. BOOL LogOutputDebugString(PCTSTR pcsz)
  91. {
  92. BOOL bResult = FALSE;
  93. UINT ucb;
  94. TCHAR 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) && *s_cszLogFile) {
  99. HANDLE hfLog;
  100. lstrcat(rgchLogFile, TEXT("\\"));
  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. TCHAR *achDebugDisplayPrefix[] = {TEXT("t "),TEXT("w "),TEXT("e "),TEXT("a "),TEXT("t "),TEXT("t "),TEXT("t "),TEXT("t "),TEXT("t "),TEXT("t "),TEXT("t ")};
  121. void WINCAPI StiDebugMsg(UINT mask, LPCTSTR pszMsg, ...)
  122. {
  123. TCHAR ach[1024];
  124. UINT uiDisplayMask = mask & 0xff;
  125. va_list list;
  126. va_start (list, pszMsg);
  127. // Determine prefix
  128. *ach = TEXT('\0');
  129. if (uiStiDebugMask & DM_PREFIX) {
  130. // Add trace type
  131. ::lstrcat(ach,achDebugDisplayPrefix[uiDisplayMask]);
  132. // Add component name
  133. ::lstrcat(ach,s_cszDebugName);
  134. // Add thread ID
  135. TCHAR szThreadId[16];
  136. ::wsprintf(szThreadId,TEXT("[%#lx] "),::GetCurrentThreadId());
  137. ::lstrcat(ach,szThreadId);
  138. }
  139. ::wvsprintf(ach+::lstrlen(ach), pszMsg, list);
  140. va_end(list);
  141. ::lstrcat(ach,TEXT("\r\n"));
  142. if (uiStiDebugMask & DM_LOG_FILE) {
  143. LogOutputDebugString(ach);
  144. }
  145. // Check if we need to display this trace
  146. if (uiStiDebugMask & uiDisplayMask) {
  147. OutputDebugString(ach);
  148. }
  149. }
  150. #endif
  151. } /* extern "C" */