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.

154 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1988-1999 Microsoft Corporation
  3. Module Name:
  4. cdebug.c
  5. Abstract:
  6. Internal debugging support
  7. --*/
  8. #include "cmd.h"
  9. #if CMD_DEBUG_ENABLE
  10. /*** MSDOS Ver 4.0 Command Interpreter Part 20 of 22 CDEBUG.C
  11. *
  12. * This file contains all of the C routines in Command's debugging
  13. * package.
  14. *
  15. * The printing of debugging messages can be sectionally enabled at
  16. * runtime through the first 2 arguments passed to this program. The
  17. * first one controls the groups to enable and the second one controls
  18. * the level of detail in the groups to enable. (Numbers are in hex.)
  19. *
  20. * Group Level Meaning
  21. * ===========================================================
  22. * 0001 Main Command Loop Code (Main & Dispatch)
  23. * 0001 Main function
  24. * 0002 Dispatch function
  25. * 0002 Command Initialization
  26. * 0001 Argument checking
  27. * 0002 Environment initialization
  28. * 0004 Rest of initialization
  29. * 0004 Parser
  30. * 0001 Parsing
  31. * 0002 Lexing
  32. * 0004 Input routine
  33. * 0008 Dump parse tree to stdin
  34. * 0010 Byte input routine
  35. * 0008 Operators
  36. * 0001 Pipe level
  37. * 0002 Detach level
  38. * 0004 Other operators level
  39. * 0010 Path Commands
  40. * 0001 Mkdir level
  41. * 0002 Chdir level
  42. * 0004 Rmdir level
  43. * 0020 File Commands
  44. * 0001 Copy level
  45. * 0002 Delete level
  46. * 0004 Rename level
  47. * 0040 Informational Commands
  48. * 0001 Directory level
  49. * 0002 Type level
  50. * 0004 Version level
  51. * 0008 Volume level
  52. * 0016 Priv level
  53. * 0032 Console Level
  54. * 0064 Dislplay Level
  55. * 0080 Environment Commands
  56. * 0001 Path level
  57. * 0002 Prompt level
  58. * 0004 Set level
  59. * 0008 Other envirnment functions
  60. * 0010 Environment scanning for external commands
  61. * 0100 Batch Processor
  62. * 0001 Batch processor
  63. * 0002 FOR processor
  64. * 0004 IF processor
  65. * 0008 Other batch commands
  66. * 0200 External Command Execution
  67. * 0001 External commands level
  68. * 0400 Other Commands
  69. * 0001 Break command
  70. * 0002 Cls command
  71. * 0004 Ctty command
  72. * 0008 Exit command
  73. * 0010 Verify command
  74. * 0800 Signal Handler
  75. * 0001 Main Signal handler level
  76. * 0002 Init Signal handler level
  77. * 1000 Memory Manager
  78. * 0001 Memory allocators
  79. * 0002 List managers
  80. * 0004 Segment manipulators
  81. * 2000 Common command tools
  82. * 1000 ScanFSpec level
  83. * 2000 SetFSSetAndSaveDir() level
  84. * 4000 TokStr() level
  85. * 8000 FullPath level
  86. * 4000 Clock manipulators
  87. * 0001 Date command level
  88. * 0002 Time command level
  89. *
  90. *
  91. * None of the debugging code is included in the program if the
  92. * value DBG is defined.
  93. *
  94. *
  95. * Eric K. Evans, Microsoft
  96. */
  97. /*** Modification History
  98. *
  99. */
  100. extern unsigned DebGroup ;
  101. extern unsigned DebLevel ;
  102. /*** Deb - conditionally print debugging messages
  103. *
  104. * Deb(MsgGroup, MsgLevel, msg, arg0, arg1, arg2, arg3, arg4)
  105. *
  106. * Args:
  107. * MsgGroup - The group of the message that wants to be printed.
  108. * MsgLevel - The level of the message that wants to be printed.
  109. * msg - A printf style message string.
  110. * arg0-4 - The other args to be printed.
  111. *
  112. */
  113. void
  114. Deb(ULONG MsgGroup, ULONG MsgLevel, CHAR *msg, ...)
  115. {
  116. CHAR Buffer[ 512 ];
  117. va_list args;
  118. CHAR *pch = Buffer;
  119. int cb;
  120. va_start( args, msg );
  121. cb = _vsnprintf( Buffer, 512, msg, args );
  122. va_end( args );
  123. if (cb > 512)
  124. fprintf(stderr, "Debug output buffer length exceeded - crash imminent\n");
  125. Buffer[511] = '\0'; // null-terminate the buffer in case the _vsnprintf filled the buffer
  126. while (*pch) {
  127. if (*pch == '\n' || *pch == '\r')
  128. *pch = '#';
  129. pch++;
  130. }
  131. if ((MsgGroup & DebGroup) && (MsgLevel & DebLevel)) {
  132. OutputDebugStringA(Buffer);
  133. OutputDebugStringA("\n");
  134. }
  135. }
  136. #endif // DBG