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.

152 lines
3.3 KiB

  1. /*** debug.c - Debug functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Copyright (c) 1996,1997 Microsoft Corporation
  6. * Author: Michael Tsang (MikeTs)
  7. * Created 09/07/96
  8. *
  9. * MODIFICATION HISTORY
  10. */
  11. #include "pch.h"
  12. #include <stdarg.h> //for va_*
  13. #ifdef TRACING
  14. #define TRACEFILE_NAME "tracelog.txt"
  15. FILE *gpfileTrace = NULL;
  16. PSZ gpszTraceFile = NULL;
  17. int giTraceLevel = 0;
  18. int giIndent = 0;
  19. /***LP OpenTrace - Initialize tracing
  20. *
  21. * This function opens the device that the trace output will go to.
  22. * It will first try the caller's filename, or else the default filenmae.
  23. *
  24. * ENTRY
  25. * pszTraceOut -> output device name
  26. *
  27. * EXIT
  28. * None
  29. */
  30. VOID LOCAL OpenTrace(char *pszTraceOut)
  31. {
  32. if ((gpfileTrace == NULL) && (giTraceLevel > 0))
  33. {
  34. if ((pszTraceOut == NULL) ||
  35. ((gpfileTrace = fopen(pszTraceOut, "w")) == NULL))
  36. {
  37. gpfileTrace = fopen(TRACEFILE_NAME, "w");
  38. }
  39. }
  40. } //OpenTrace
  41. /***LP CloseTrace - Finish tracing
  42. *
  43. * This function close the device that the trace output will go to.
  44. *
  45. * ENTRY
  46. * None
  47. *
  48. * EXIT
  49. * None
  50. */
  51. VOID LOCAL CloseTrace(VOID)
  52. {
  53. if (gpfileTrace != NULL)
  54. {
  55. fclose(gpfileTrace);
  56. gpfileTrace = NULL;
  57. }
  58. giTraceLevel = 0;
  59. } //CloseTrace
  60. /***LP EnterProc - Entering a procedure
  61. *
  62. * ENTRY
  63. * n - trace level of this procedure
  64. * pszFormat -> format string
  65. * ... - variable arguments according to format string
  66. *
  67. * EXIT
  68. * None
  69. */
  70. VOID CDECL EnterProc(int n, char *pszFormat, ...)
  71. {
  72. int i;
  73. va_list marker;
  74. if (n <= giTraceLevel)
  75. {
  76. if (gpfileTrace != NULL)
  77. {
  78. fprintf(gpfileTrace, "%s:", MODNAME);
  79. for (i = 0; i < giIndent; ++i)
  80. fprintf(gpfileTrace, "| ");
  81. va_start(marker, pszFormat);
  82. vfprintf(gpfileTrace, pszFormat, marker);
  83. fflush(gpfileTrace);
  84. va_end(marker);
  85. }
  86. ++giIndent;
  87. }
  88. } //EnterProc
  89. /***LP ExitProc - Exiting a procedure
  90. *
  91. * ENTRY
  92. * n - trace level of this procedure
  93. * pszFormat -> format string
  94. * ... - variable arguments according to format string
  95. *
  96. * EXIT
  97. * None
  98. */
  99. VOID CDECL ExitProc(int n, char *pszFormat, ...)
  100. {
  101. int i;
  102. va_list marker;
  103. if (n <= giTraceLevel)
  104. {
  105. --giIndent;
  106. if (gpfileTrace != NULL)
  107. {
  108. fprintf(gpfileTrace, "%s:", MODNAME);
  109. for (i = 0; i < giIndent; ++i)
  110. fprintf(gpfileTrace, "| ");
  111. va_start(marker, pszFormat);
  112. vfprintf(gpfileTrace, pszFormat, marker);
  113. fflush(gpfileTrace);
  114. va_end(marker);
  115. }
  116. }
  117. } //ExitProc
  118. #endif //ifdef TRACING
  119. /***LP ErrPrintf - Print to stderr
  120. *
  121. * ENTRY
  122. * pszFormat -> format string
  123. * ... - variable arguments according to format string
  124. *
  125. * EXIT
  126. * None
  127. */
  128. VOID CDECL ErrPrintf(char *pszFormat, ...)
  129. {
  130. va_list marker;
  131. va_start(marker, pszFormat);
  132. vfprintf(stdout, pszFormat, marker);
  133. va_end(marker);
  134. } //ErrPrintf