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.

229 lines
3.3 KiB

  1. #ifndef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #endif
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include "Log.h"
  7. extern BOOL g_fVerbose;
  8. extern FILE *g_fpLog;
  9. /*++
  10. LogString2FP:
  11. Arguments:
  12. fp supplies the stream
  13. szMsg supplies the content to be logged
  14. Return Value:
  15. None.
  16. Author:
  17. Eric Perlin (ericperl) 07/26/2000
  18. --*/
  19. void LogString2FP(
  20. IN FILE *fp,
  21. IN LPCWSTR szMsg
  22. )
  23. {
  24. #if defined(_UNICODE) || defined(UNICODE)
  25. fwprintf(fp, L"%s", szMsg);
  26. #else
  27. fwprintf(fp, L"%S", szMsg); // Conversion required
  28. #endif
  29. }
  30. /*++
  31. LogString:
  32. Arguments:
  33. szMsg supplies the content to be logged
  34. Return Value:
  35. None.
  36. Author:
  37. Eric Perlin (ericperl) 07/26/2000
  38. --*/
  39. void LogString(
  40. IN PLOGCONTEXT pLogCtx,
  41. IN LPCWSTR szMsg
  42. )
  43. {
  44. #if defined(_UNICODE) || defined(UNICODE)
  45. pLogCtx->szLogCrt += swprintf(pLogCtx->szLogCrt, L"%s", szMsg);
  46. #else
  47. pLogCtx->szLogCrt += sprintf(pLogCtx->szLogCrt, "%S", szMsg);
  48. #endif
  49. }
  50. /*++
  51. LogThisOnly:
  52. Implements logging according to the following matrix:
  53. Console Output:
  54. | Verbose | Not |
  55. -----------------------------
  56. Not Exp.| cerr | cerr |
  57. -----------------------------
  58. Expected| cout | / |
  59. -----------------------------
  60. If a log was specified, everything is logged.
  61. Arguments:
  62. szMsg supplies the content to be logged
  63. fExpected indicates the expected status
  64. Return Value:
  65. None.
  66. Author:
  67. Eric Perlin (ericperl) 05/31/2000
  68. --*/
  69. void LogThisOnly(
  70. IN LPCWSTR szMsg,
  71. IN BOOL fExpected
  72. )
  73. {
  74. LogLock();
  75. if (!fExpected)
  76. {
  77. LogString2FP(stderr, szMsg);
  78. }
  79. else if (g_fVerbose)
  80. {
  81. LogString2FP(stdout, szMsg);
  82. }
  83. if (NULL != g_fpLog)
  84. {
  85. LogString2FP(g_fpLog, szMsg);
  86. }
  87. LogUnlock();
  88. }
  89. /*++
  90. LogString:
  91. Arguments:
  92. szHeader supplies a header
  93. szMsg supplies the content to be logged
  94. Return Value:
  95. None.
  96. Author:
  97. Eric Perlin (ericperl) 07/26/2000
  98. --*/
  99. void LogString(
  100. IN PLOGCONTEXT pLogCtx,
  101. IN LPCWSTR szHeader,
  102. IN LPCWSTR szS
  103. )
  104. {
  105. if (szHeader)
  106. {
  107. LogString(pLogCtx, szHeader);
  108. }
  109. if (NULL == szS)
  110. {
  111. LogString(pLogCtx, L"<null>");
  112. }
  113. else if (0 == wcslen(szS))
  114. {
  115. LogString(pLogCtx, L"<empty>");
  116. }
  117. else
  118. {
  119. LogString(pLogCtx, szS);
  120. }
  121. if (szHeader)
  122. {
  123. LogString(pLogCtx, L"\n");
  124. }
  125. }
  126. /*++
  127. LogMultiString:
  128. Arguments:
  129. szMS supplies the multi-string to be logged
  130. szHeader supplies a header
  131. Return Value:
  132. None.
  133. Author:
  134. Eric Perlin (ericperl) 07/26/2000
  135. --*/
  136. void LogMultiString(
  137. IN PLOGCONTEXT pLogCtx,
  138. IN LPCWSTR szMS,
  139. IN LPCWSTR szHeader
  140. )
  141. {
  142. if (szHeader)
  143. {
  144. LogString(pLogCtx, szHeader, L" ");
  145. }
  146. if (NULL == szMS)
  147. {
  148. LogString(pLogCtx, L" <null>");
  149. if (szHeader)
  150. {
  151. LogString(pLogCtx, L"\n");
  152. }
  153. }
  154. else if ( (TCHAR)'\0' == *szMS )
  155. {
  156. LogString(pLogCtx, L" <empty>");
  157. if (szHeader)
  158. {
  159. LogString(pLogCtx, L"\n");
  160. }
  161. }
  162. else
  163. {
  164. LPCWSTR sz = szMS;
  165. while ( (WCHAR)'\0' != *sz )
  166. {
  167. // Display the value.
  168. LogString(pLogCtx, L" ", sz);
  169. // Advance to the next value.
  170. sz = sz + wcslen(sz) + 1;
  171. }
  172. }
  173. }