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.

176 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This file implements the debug code for the
  7. fax project. All components that require
  8. debug prints, asserts, etc.
  9. Author:
  10. Wesley Witt (wesw) 22-Dec-1995
  11. Environment:
  12. User Mode
  13. --*/
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <tchar.h>
  18. #include "faxreg.h"
  19. #include "faxutil.h"
  20. BOOL ConsoleDebugOutput = FALSE;
  21. INT FaxDebugLevel = -1;
  22. #if 0
  23. VOID
  24. ConsoleDebugPrint(
  25. LPCTSTR buf
  26. )
  27. {
  28. }
  29. #endif
  30. DWORD
  31. GetDebugLevel(
  32. VOID
  33. )
  34. {
  35. DWORD rc;
  36. DWORD err;
  37. DWORD size;
  38. DWORD type;
  39. HKEY hkey;
  40. err = RegOpenKey(HKEY_LOCAL_MACHINE,
  41. REGKEY_FAXSERVER,
  42. &hkey);
  43. if (err != ERROR_SUCCESS)
  44. return 0;
  45. size = sizeof(DWORD);
  46. err = RegQueryValueEx(hkey,
  47. REGVAL_DBGLEVEL,
  48. 0,
  49. &type,
  50. (LPBYTE)&rc,
  51. &size);
  52. if (err != ERROR_SUCCESS || type != REG_DWORD)
  53. rc = 0;
  54. RegCloseKey(hkey);
  55. return rc;
  56. }
  57. void
  58. dprintf(
  59. LPCTSTR Format,
  60. ...
  61. )
  62. /*++
  63. Routine Description:
  64. Prints a debug string
  65. Arguments:
  66. format - printf() format string
  67. ... - Variable data
  68. Return Value:
  69. None.
  70. --*/
  71. {
  72. TCHAR buf[1024];
  73. DWORD len;
  74. va_list arg_ptr;
  75. static BOOL bChecked = FALSE;
  76. if (!bChecked) {
  77. FaxDebugLevel = (INT) GetDebugLevel();
  78. bChecked = TRUE;
  79. }
  80. if (FaxDebugLevel <= 0) {
  81. return;
  82. }
  83. va_start(arg_ptr, Format);
  84. _vsntprintf(buf, sizeof(buf), Format, arg_ptr);
  85. ConsoleDebugPrint( buf );
  86. len = _tcslen( buf );
  87. if (buf[len-1] != TEXT('\n')) {
  88. buf[len] = TEXT('\r');
  89. buf[len+1] = TEXT('\n');
  90. buf[len+2] = 0;
  91. }
  92. OutputDebugString( buf );
  93. }
  94. VOID
  95. AssertError(
  96. LPCTSTR Expression,
  97. LPCTSTR File,
  98. ULONG LineNumber
  99. )
  100. /*++
  101. Routine Description:
  102. Thie function is use together with the Assert MACRO.
  103. It checks to see if an expression is FALSE. if the
  104. expression is FALSE, then you end up here.
  105. Arguments:
  106. Expression - The text of the 'C' expression
  107. File - The file that caused the assertion
  108. LineNumber - The line number in the file.
  109. Return Value:
  110. None.
  111. --*/
  112. {
  113. dprintf(
  114. TEXT("Assertion error: [%s] %s @ %d\n"),
  115. Expression,
  116. File,
  117. LineNumber
  118. );
  119. __try {
  120. DebugBreak();
  121. } __except (UnhandledExceptionFilter(GetExceptionInformation())) {
  122. // Nothing to do in here.
  123. }
  124. }