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.

253 lines
7.1 KiB

  1. /*****************************************************************************
  2. * *
  3. * BUGOUT.C *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1991 - 1994. *
  6. * All Rights reserved. *
  7. * *
  8. ******************************************************************************
  9. * *
  10. * Module Description: DEBUGGING OUPUT ROUTINES FOR ORKIN DEBUGGING LIBRARY *
  11. * *
  12. ******************************************************************************
  13. * *
  14. * Previous Owner: DavidJes *
  15. * Current Owner: RHobbs *
  16. * *
  17. *****************************************************************************/
  18. static char * s_aszModule = __FILE__; /* For error report */
  19. #include <mvopsys.h>
  20. #include <orkin.h>
  21. #include <stdarg.h>
  22. //
  23. // the following was ripped off from the \\looney\brothers skelapp2 project:
  24. //
  25. #define SEEK_SET 0 // seek relative to start of file
  26. #define SEEK_CUR 1 // seek relative to current position
  27. #define SEEK_END 2 // seek relative to end of file
  28. /* globals */
  29. int giDebugLevel = 0; // current debug level (0 = disabled)
  30. int gfhDebugFile = -1; // file handle for debug output (or -1)
  31. #ifdef _DEBUG
  32. /* InitializeDebugOutput(szAppName)
  33. *
  34. * Read the current debug level of this application (named <szAppName>)
  35. * from the [debug] section of win.ini, as well as the current location
  36. * for debug output.
  37. */
  38. void FAR PASCAL EXPORT_API InitializeDebugOutput(LPSTR szAppName)
  39. {
  40. #ifndef _MAC
  41. char achLocation[300]; // debug output location
  42. /* debugging is disabled by default (and if an error occurs below) */
  43. giDebugLevel = 0;
  44. gfhDebugFile = -1;
  45. /* get the debug output location */
  46. if ( (GetProfileString("debug", szAppName, "", achLocation,
  47. sizeof(achLocation)) == sizeof(achLocation)) ||
  48. (achLocation[0] == 0) )
  49. return;
  50. if (achLocation[0] == '>')
  51. {
  52. /* <achLocation> is the name of a file to overwrite (if
  53. * a single '>' is given) or append to (if '>>' is given)
  54. */
  55. if (achLocation[1] == '>')
  56. gfhDebugFile = _lopen(achLocation + 2, OF_WRITE);
  57. else
  58. gfhDebugFile = _lcreat(achLocation + 1, 0);
  59. if (gfhDebugFile < 0)
  60. return;
  61. if (achLocation[1] == '>')
  62. _llseek(gfhDebugFile, 0, SEEK_END);
  63. }
  64. else
  65. if (lstrcmpi(achLocation, "aux") != 0)
  66. {
  67. /* use OutputDebugString() for debug output */
  68. }
  69. else
  70. {
  71. /* invalid "location=" -- keep debugging disabled */
  72. return;
  73. }
  74. /* get the debug level */
  75. giDebugLevel = GetProfileInt("debug", szAppName, 0);
  76. #endif
  77. }
  78. /* TerminateDebugOutput()
  79. *
  80. * Terminate debug output for this application.
  81. */
  82. void FAR PASCAL EXPORT_API TerminateDebugOutput(void)
  83. {
  84. if (gfhDebugFile >= 0)
  85. _lclose(gfhDebugFile);
  86. gfhDebugFile = -1;
  87. giDebugLevel = 0;
  88. }
  89. /* _DebugPrintf(iDebugLevel, szFormat, szArg1)
  90. *
  91. * If the application's debug level is at or above <iDebugLevel>,
  92. * then output debug string <szFormat> with formatting codes
  93. * replaced with arguments in the argument list pointed to by <szArg1>.
  94. */
  95. void FAR PASCAL EXPORT_API _DebugPrintf(int iDebugLevel, LPSTR szFormat, LPSTR szArg1)
  96. {
  97. static char ach[300]; // debug output (avoid stack overflow)
  98. int cch; // length of debug output string
  99. NPSTR pchSrc, pchDst;
  100. char *achT = ach;
  101. if (giDebugLevel != 0 && giDebugLevel < iDebugLevel)
  102. return;
  103. achT += wsprintf(achT, "%ld:", GetTickCount());
  104. wvsprintf(achT, szFormat, *((va_list *)szArg1));
  105. /* expand the newlines into carrige-return-line-feed pairs;
  106. * first, figure out how long the new (expanded) string will be
  107. */
  108. for (pchSrc = pchDst = ach; *pchSrc != 0; pchSrc++, pchDst++)
  109. if (*pchSrc == '\n')
  110. pchDst++;
  111. /* is <ach> large enough? */
  112. cch = (int)((INT_PTR)pchDst - (INT_PTR)ach); /*** MATTSMI 2/7/92 - cast so that large model version works ***/
  113. assert(cch < sizeof(ach));
  114. *pchDst-- = 0;
  115. /* working backwards, expand \n's to \r\n's */
  116. while (pchSrc-- > ach)
  117. if ((*pchDst-- = *pchSrc) == '\n')
  118. *pchDst-- = '\r';
  119. /* output the debug string */
  120. if (gfhDebugFile > 0)
  121. _lwrite(gfhDebugFile, ach, cch);
  122. #ifndef CHICAGO // Debug messages mess-up the com ports under chicago!
  123. else
  124. OutputDebugString(ach);
  125. #endif
  126. }
  127. /* _DPF1()
  128. *
  129. * Helper function called by DPF() macro.
  130. */
  131. void FAR EXPORT_API _cdecl _DPF1(LPSTR szFormat, // debug output format string
  132. ...) // placeholder for first argument
  133. {
  134. va_list valist;
  135. va_start( valist, szFormat );
  136. _DebugPrintf(1, szFormat, (LPSTR) &valist);
  137. va_end( valist );
  138. }
  139. /* _DPF2()
  140. *
  141. * Helper function called by DPF2() macro.
  142. */
  143. void FAR EXPORT_API _cdecl _DPF2(LPSTR szFormat, // debug output format string
  144. ...) // placeholder for first argument
  145. {
  146. va_list valist;
  147. va_start( valist, szFormat );
  148. _DebugPrintf(2, szFormat, (LPSTR) &valist);
  149. va_end( valist );
  150. }
  151. /* _DPF3()
  152. *
  153. * Helper function called by DPF3() macro.
  154. */
  155. void FAR EXPORT_API _cdecl _DPF3(szFormat, ...)
  156. LPSTR szFormat; // debug output format string
  157. {
  158. va_list valist;
  159. va_start( valist, szFormat );
  160. _DebugPrintf(3, szFormat, (LPSTR) &valist);
  161. va_end( valist );
  162. }
  163. /* _DPF4()
  164. *
  165. * Helper function called by DPF4() macro.
  166. */
  167. void FAR EXPORT_API _cdecl _DPF4(szFormat, ...)
  168. LPSTR szFormat; // debug output format string
  169. {
  170. va_list valist;
  171. va_start( valist, szFormat );
  172. _DebugPrintf(4, szFormat, (LPSTR) &valist);
  173. va_end( valist );
  174. }
  175. #else // DEBUG
  176. // stubs for non-debug
  177. void FAR PASCAL EXPORT_API _InitializeDebugOutput(LPSTR szAppName)
  178. {
  179. }
  180. void FAR PASCAL EXPORT_API _TerminateDebugOutput(void)
  181. {
  182. }
  183. void FAR EXPORT_API _cdecl _DPF1(LPSTR szFormat, // debug output format string
  184. int iArg1, ...) // placeholder for first argument
  185. {
  186. }
  187. void FAR EXPORT_API _cdecl _DPF2(LPSTR szFormat, // debug output format string
  188. int iArg1, ...) // placeholder for first argument
  189. {
  190. }
  191. void FAR EXPORT_API _cdecl _DPF3(szFormat, iArg1, ...)
  192. LPSTR szFormat; // debug output format string
  193. int iArg1; // placeholder for first argument
  194. {
  195. }
  196. void FAR EXPORT_API _cdecl _DPF4(szFormat, iArg1, ...)
  197. LPSTR szFormat; // debug output format string
  198. int iArg1; // placeholder for first argument
  199. {
  200. }
  201. #endif // DEBUG