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.

619 lines
22 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. /*
  3. * johnkn's debug logging and assert macros
  4. *
  5. */
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif // __cplusplus
  9. #if !defined _INC_MMDEBUG_
  10. #define _INC_MMDEBUG_
  11. #if defined _DEBUG && !defined DEBUG
  12. #define DEBUG
  13. #endif
  14. //
  15. // prototypes for debug functions.
  16. //
  17. #define SQUAWKNUMZ(num) #num
  18. #define SQUAWKNUM(num) SQUAWKNUMZ(num)
  19. #define SQUAWK __FILE__ "(" SQUAWKNUM(__LINE__) ") ----"
  20. #define DEBUGLINE __FILE__ "(" SQUAWKNUM(__LINE__) ") "
  21. #if defined DEBUG || defined _DEBUG || defined DEBUG_RETAIL
  22. #define STATICFN
  23. int FAR _cdecl AuxDebugEx(int, LPTSTR, ...);
  24. void FAR _cdecl AuxRip(LPTSTR, ...);
  25. VOID WINAPI AuxDebugDump (int, LPVOID, int);
  26. LPCTSTR WINAPI AuxMMErrText(DWORD mmr);
  27. int WINAPI DebugSetOutputLevel (int,int);
  28. UINT WINAPI AuxFault (DWORD dwFaultMask);
  29. #if defined DEBUG_RETAIL && !defined DEBUG && !defined _DEBUG
  30. #define INLINE_BREAK
  31. #else
  32. #if !defined _WIN32 || defined _X86_
  33. #define INLINE_BREAK _asm {int 3}
  34. #else
  35. #define INLINE_BREAK DebugBreak()
  36. #endif
  37. #endif
  38. #define FAULT_HERE AuxFault
  39. #undef assert
  40. #define assert(exp) {\
  41. if (!(exp)) {\
  42. AuxDebugEx(-2, DEBUGLINE "assert failed: " #exp "\r\n"); \
  43. INLINE_BREAK;\
  44. }\
  45. }
  46. #undef assert2
  47. #define assert2(exp,sz) {\
  48. if (!(exp)) {\
  49. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n"); \
  50. INLINE_BREAK;\
  51. }\
  52. }
  53. #undef assert3
  54. #define assert3(exp,sz,arg) {\
  55. if (!(exp)) {\
  56. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (arg)); \
  57. INLINE_BREAK;\
  58. }\
  59. }
  60. #undef assert4
  61. #define assert4(exp,sz,arg1,arg2) {\
  62. if (!(exp)) {\
  63. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (arg1),(arg2)); \
  64. INLINE_BREAK;\
  65. }\
  66. }
  67. #undef assert5
  68. #define assert5(exp,sz,arg1,arg2,arg3) {\
  69. if (!(exp)) {\
  70. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (arg1),(arg2),(arg3)); \
  71. INLINE_BREAK;\
  72. }\
  73. }
  74. #else // defined(DEBUG) || defined(_DEBUG)
  75. #define AuxDebugEx 1 ? (void)0 :
  76. #define AuxDebugDump(a,b,c)
  77. #define AuxMMErrText(m) NULL
  78. #define AuxRip 1 ? (void)0 :
  79. #define assert(a) ((void)0)
  80. #define assert2(a,b) ((void)0)
  81. #define assert3(a,b,c) ((void)0)
  82. #define assert4(a,b,c,d) ((void)0)
  83. #define assert5(a,b,c,d,e) ((void)0)
  84. #define FAULT_HERE 1 ? (void)0 :
  85. #define INLINE_BREAK
  86. #define DebugSetOutputLevel(i,j)
  87. #define STATICFN static
  88. #endif // defined(DEBUG) || defined _DEBUG || defined DEBUG_RETAIL
  89. #ifndef DPF_CATEGORY
  90. #define DPF_CATEGORY 0x0100
  91. #endif
  92. // translate DPF's only in internal debug builds
  93. //
  94. #if defined DEBUG || defined _DEBUG
  95. #define DUMP(n,a,b) AuxDebugDump (DPF_CATEGORY | (n), a, b)
  96. #define RIP AuxDebugEx (0, DEBUGLINE), AuxRip
  97. #define AuxMMR(api,mmr) (mmr) ? AuxDebugEx(1, DEBUGLINE #api " error %d '%s'\r\n", mmr, AuxMMErrText(mmr)) : (int)0
  98. #define DPF(n,sz) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n")
  99. #define DPF1(n,sz,a) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a))
  100. #define DPF2(n,sz,a,b) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b))
  101. #define DPF3(n,sz,a,b,c) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b),(c))
  102. #define DPF4(n,sz,a,b,c,d) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b),(c),(d))
  103. #define DPF5(n,sz,a,b,c,d,e) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b),(c),(d),(e))
  104. #define DPF6(n,sz,a,b,c,d,e,f) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b),(c),(d),(d),(f))
  105. #define DPF7(n,sz,a,b,c,d,e,f,g) AuxDebugEx (DPF_CATEGORY | (n), DEBUGLINE sz "\r\n",(a),(b),(c),(d),(d),(f),(g))
  106. #else
  107. #define DUMP(n,a,b)
  108. #define RIP AuxRip
  109. #define AuxMMR(api,mmr)
  110. #define DPF(n,sz)
  111. #define DPF1(n,sz,a)
  112. #define DPF2(n,sz,a,b)
  113. #define DPF3(n,sz,a,b,c)
  114. #define DPF4(n,sz,a,b,c,d)
  115. #define DPF5(n,sz,a,b,c,d,e)
  116. #define DPF6(n,sz,a,b,c,d,e,f)
  117. #define DPF7(n,sz,a,b,c,d,e,f,g)
  118. #endif
  119. #endif //_INC_MMDEBUG_
  120. // =============================================================================
  121. //
  122. // include this in only one module in a DLL or APP
  123. //
  124. #if defined DEBUG || defined _DEBUG || defined DEBUG_RETAIL
  125. #if (defined _INC_MMDEBUG_CODE_) && (_INC_MMDEBUG_CODE_ != FALSE)
  126. #undef _INC_MMDEBUG_CODE_
  127. #define _INC_MMDEBUG_CODE_ FALSE
  128. #include <stdarg.h>
  129. #if !defined _WIN32 && !defined wvsprintfA
  130. #define wvsprintfA wvsprintf
  131. #endif
  132. static struct _mmerrors {
  133. DWORD mmr;
  134. LPCTSTR psz;
  135. } aMMErr[] = {
  136. MMSYSERR_NOERROR ,"Success",
  137. #ifdef DEBUG
  138. MMSYSERR_ERROR ,"unspecified error",
  139. MMSYSERR_BADDEVICEID ,"device ID out of range",
  140. MMSYSERR_NOTENABLED ,"driver failed enable",
  141. MMSYSERR_ALLOCATED ,"device already allocated",
  142. MMSYSERR_INVALHANDLE ,"device handle is invalid",
  143. MMSYSERR_NODRIVER ,"no device driver present",
  144. MMSYSERR_NOMEM ,"memory allocation error",
  145. MMSYSERR_NOTSUPPORTED ,"function isn't supported",
  146. MMSYSERR_BADERRNUM ,"error value out of range",
  147. MMSYSERR_INVALFLAG ,"invalid flag passed",
  148. MMSYSERR_INVALPARAM ,"invalid parameter passed",
  149. #if (WINVER >= 0x0400)
  150. MMSYSERR_HANDLEBUSY ,"handle in use by another thread",
  151. MMSYSERR_INVALIDALIAS ,"specified alias not found",
  152. MMSYSERR_BADDB ,"bad registry database",
  153. MMSYSERR_KEYNOTFOUND ,"registry key not found",
  154. MMSYSERR_READERROR ,"registry read error",
  155. MMSYSERR_WRITEERROR ,"registry write error",
  156. MMSYSERR_DELETEERROR ,"registry delete error",
  157. MMSYSERR_VALNOTFOUND ,"registry value not found",
  158. MMSYSERR_NODRIVERCB ,"Never got a 32 bit callback from driver",
  159. #endif // WINVER >= 0x400
  160. WAVERR_BADFORMAT ,"wave:unsupported wave format",
  161. WAVERR_STILLPLAYING ,"wave:still something playing",
  162. WAVERR_UNPREPARED ,"wave:header not prepared",
  163. WAVERR_SYNC ,"wave:device is synchronous",
  164. MIDIERR_UNPREPARED ,"midi:header not prepared",
  165. MIDIERR_STILLPLAYING ,"midi:still something playing",
  166. //MIDIERR_NOMAP ,"midi:no configured instruments",
  167. MIDIERR_NOTREADY ,"midi:hardware is still busy",
  168. MIDIERR_NODEVICE ,"midi:port no longer connected",
  169. MIDIERR_INVALIDSETUP ,"midi:invalid MIF",
  170. #ifdef CHICAGO
  171. MIDIERR_BADOPENMODE ,"midi:operation unsupported w/ open mode",
  172. #endif
  173. TIMERR_NOCANDO ,"timer: request not completed",
  174. JOYERR_PARMS ,"joy:bad parameters",
  175. JOYERR_NOCANDO ,"joy:request not completed",
  176. JOYERR_UNPLUGGED ,"joystick is unplugged",
  177. MCIERR_INVALID_DEVICE_ID ,"MCIERR_INVALID_DEVICE_ID",
  178. MCIERR_UNRECOGNIZED_KEYWORD ,"MCIERR_UNRECOGNIZED_KEYWORD",
  179. MCIERR_UNRECOGNIZED_COMMAND ,"MCIERR_UNRECOGNIZED_COMMAND",
  180. MCIERR_HARDWARE ,"MCIERR_HARDWARE",
  181. MCIERR_INVALID_DEVICE_NAME ,"MCIERR_INVALID_DEVICE_NAME",
  182. MCIERR_OUT_OF_MEMORY ,"MCIERR_OUT_OF_MEMORY",
  183. MCIERR_DEVICE_OPEN ,"MCIERR_DEVICE_OPEN",
  184. MCIERR_CANNOT_LOAD_DRIVER ,"MCIERR_CANNOT_LOAD_DRIVER",
  185. MCIERR_MISSING_COMMAND_STRING ,"MCIERR_MISSING_COMMAND_STRING",
  186. MCIERR_PARAM_OVERFLOW ,"MCIERR_PARAM_OVERFLOW",
  187. MCIERR_MISSING_STRING_ARGUMENT ,"MCIERR_MISSING_STRING_ARGUMENT",
  188. MCIERR_BAD_INTEGER ,"MCIERR_BAD_INTEGER",
  189. MCIERR_PARSER_INTERNAL ,"MCIERR_PARSER_INTERNAL",
  190. MCIERR_DRIVER_INTERNAL ,"MCIERR_DRIVER_INTERNAL",
  191. MCIERR_MISSING_PARAMETER ,"MCIERR_MISSING_PARAMETER",
  192. MCIERR_UNSUPPORTED_FUNCTION ,"MCIERR_UNSUPPORTED_FUNCTION",
  193. MCIERR_FILE_NOT_FOUND ,"MCIERR_FILE_NOT_FOUND",
  194. MCIERR_DEVICE_NOT_READY ,"MCIERR_DEVICE_NOT_READY",
  195. MCIERR_INTERNAL ,"MCIERR_INTERNAL",
  196. MCIERR_DRIVER ,"MCIERR_DRIVER",
  197. MCIERR_CANNOT_USE_ALL ,"MCIERR_CANNOT_USE_ALL",
  198. MCIERR_MULTIPLE ,"MCIERR_MULTIPLE",
  199. MCIERR_EXTENSION_NOT_FOUND ,"MCIERR_EXTENSION_NOT_FOUND",
  200. MCIERR_OUTOFRANGE ,"MCIERR_OUTOFRANGE",
  201. MCIERR_FLAGS_NOT_COMPATIBLE ,"MCIERR_FLAGS_NOT_COMPATIBLE",
  202. MCIERR_FILE_NOT_SAVED ,"MCIERR_FILE_NOT_SAVED",
  203. MCIERR_DEVICE_TYPE_REQUIRED ,"MCIERR_DEVICE_TYPE_REQUIRED",
  204. MCIERR_DEVICE_LOCKED ,"MCIERR_DEVICE_LOCKED",
  205. MCIERR_DUPLICATE_ALIAS ,"MCIERR_DUPLICATE_ALIAS",
  206. MCIERR_BAD_CONSTANT ,"MCIERR_BAD_CONSTANT",
  207. MCIERR_MUST_USE_SHAREABLE ,"MCIERR_MUST_USE_SHAREABLE",
  208. MCIERR_MISSING_DEVICE_NAME ,"MCIERR_MISSING_DEVICE_NAME",
  209. MCIERR_BAD_TIME_FORMAT ,"MCIERR_BAD_TIME_FORMAT",
  210. MCIERR_NO_CLOSING_QUOTE ,"MCIERR_NO_CLOSING_QUOTE",
  211. MCIERR_DUPLICATE_FLAGS ,"MCIERR_DUPLICATE_FLAGS",
  212. MCIERR_INVALID_FILE ,"MCIERR_INVALID_FILE",
  213. MCIERR_NULL_PARAMETER_BLOCK ,"MCIERR_NULL_PARAMETER_BLOCK",
  214. MCIERR_UNNAMED_RESOURCE ,"MCIERR_UNNAMED_RESOURCE",
  215. MCIERR_NEW_REQUIRES_ALIAS ,"MCIERR_NEW_REQUIRES_ALIAS",
  216. MCIERR_NOTIFY_ON_AUTO_OPEN ,"MCIERR_NOTIFY_ON_AUTO_OPEN",
  217. MCIERR_NO_ELEMENT_ALLOWED ,"MCIERR_NO_ELEMENT_ALLOWED",
  218. MCIERR_NONAPPLICABLE_FUNCTION ,"MCIERR_NONAPPLICABLE_FUNCTION",
  219. MCIERR_ILLEGAL_FOR_AUTO_OPEN ,"MCIERR_ILLEGAL_FOR_AUTO_OPEN",
  220. MCIERR_FILENAME_REQUIRED ,"MCIERR_FILENAME_REQUIRED",
  221. MCIERR_EXTRA_CHARACTERS ,"MCIERR_EXTRA_CHARACTERS",
  222. MCIERR_DEVICE_NOT_INSTALLED ,"MCIERR_DEVICE_NOT_INSTALLED",
  223. MCIERR_GET_CD ,"MCIERR_GET_CD",
  224. MCIERR_SET_CD ,"MCIERR_SET_CD",
  225. MCIERR_SET_DRIVE ,"MCIERR_SET_DRIVE",
  226. MCIERR_DEVICE_LENGTH ,"MCIERR_DEVICE_LENGTH",
  227. MCIERR_DEVICE_ORD_LENGTH ,"MCIERR_DEVICE_ORD_LENGTH",
  228. MCIERR_NO_INTEGER ,"MCIERR_NO_INTEGER",
  229. MCIERR_WAVE_OUTPUTSINUSE ,"MCIERR_WAVE_OUTPUTSINUSE",
  230. MCIERR_WAVE_SETOUTPUTINUSE ,"MCIERR_WAVE_SETOUTPUTINUSE",
  231. MCIERR_WAVE_INPUTSINUSE ,"MCIERR_WAVE_INPUTSINUSE",
  232. MCIERR_WAVE_SETINPUTINUSE ,"MCIERR_WAVE_SETINPUTINUSE",
  233. MCIERR_WAVE_OUTPUTUNSPECIFIED ,"MCIERR_WAVE_OUTPUTUNSPECIFIED",
  234. MCIERR_WAVE_INPUTUNSPECIFIED ,"MCIERR_WAVE_INPUTUNSPECIFIED",
  235. MCIERR_WAVE_OUTPUTSUNSUITABLE ,"MCIERR_WAVE_OUTPUTSUNSUITABLE",
  236. MCIERR_WAVE_SETOUTPUTUNSUITABLE ,"MCIERR_WAVE_SETOUTPUTUNSUITABLE",
  237. MCIERR_WAVE_INPUTSUNSUITABLE ,"MCIERR_WAVE_INPUTSUNSUITABLE",
  238. MCIERR_WAVE_SETINPUTUNSUITABLE ,"MCIERR_WAVE_SETINPUTUNSUITABLE",
  239. MCIERR_SEQ_DIV_INCOMPATIBLE ,"MCIERR_SEQ_DIV_INCOMPATIBLE",
  240. MCIERR_SEQ_PORT_INUSE ,"MCIERR_SEQ_PORT_INUSE",
  241. MCIERR_SEQ_PORT_NONEXISTENT ,"MCIERR_SEQ_PORT_NONEXISTENT",
  242. MCIERR_SEQ_PORT_MAPNODEVICE ,"MCIERR_SEQ_PORT_MAPNODEVICE",
  243. MCIERR_SEQ_PORT_MISCERROR ,"MCIERR_SEQ_PORT_MISCERROR",
  244. MCIERR_SEQ_TIMER ,"MCIERR_SEQ_TIMER",
  245. MCIERR_SEQ_PORTUNSPECIFIED ,"MCIERR_SEQ_PORTUNSPECIFIED",
  246. MCIERR_SEQ_NOMIDIPRESENT ,"MCIERR_SEQ_NOMIDIPRESENT",
  247. MCIERR_NO_WINDOW ,"MCIERR_NO_WINDOW",
  248. MCIERR_CREATEWINDOW ,"MCIERR_CREATEWINDOW",
  249. MCIERR_FILE_READ ,"MCIERR_FILE_READ",
  250. MCIERR_FILE_WRITE ,"MCIERR_FILE_WRITE",
  251. #ifdef CHICAGO
  252. MCIERR_NO_IDENTITY ,"MCIERR_NO_IDENTITY",
  253. MIXERR_INVALLINE ,"Invalid Mixer Line",
  254. MIXERR_INVALCONTROL ,"Invalid Mixer Control",
  255. MIXERR_INVALVALUE ,"Invalid Mixer Value",
  256. #endif // CHICAGO
  257. #endif // DEBUG
  258. 0xFFFFFFFE , "unknown error %d"
  259. };
  260. struct _mmdebug {
  261. int Level;
  262. int Mask;
  263. int StopOnRip;
  264. DWORD TakeFault;
  265. struct _mmerrors *paErrs;
  266. BOOL Initialized;
  267. HANDLE hOut;
  268. } mmdebug = {0, 0xFF, 0, 0xFF, aMMErr};
  269. /*+ AuxFault
  270. *
  271. *-=================================================================*/
  272. UINT WINAPI AuxFault (
  273. DWORD dwFaultMask)
  274. {
  275. LPUINT pData = NULL;
  276. if (dwFaultMask & mmdebug.TakeFault)
  277. return *pData;
  278. return 0;
  279. }
  280. /*+ AuxOut - write a string to designated debug out
  281. *
  282. *-=================================================================*/
  283. void WINAPI AuxOut (
  284. LPTSTR psz)
  285. {
  286. #ifdef WIN32
  287. if (mmdebug.hOut)
  288. {
  289. UINT cb = lstrlen(psz);
  290. DWORD dw;
  291. if (INVALID_HANDLE_VALUE != mmdebug.hOut)
  292. WriteFile (mmdebug.hOut, psz, cb, &dw, NULL);
  293. }
  294. else
  295. #endif
  296. {
  297. #ifdef DbgLog
  298. DbgOutString (psz); // from \quartz\sdk\classes\base\debug.cpp
  299. #else
  300. OutputDebugString (psz);
  301. #endif
  302. }
  303. }
  304. /*+ AuxDebug - create a formatted string and output to debug terminal
  305. *
  306. *-=================================================================*/
  307. int FAR _cdecl AuxDebugEx (
  308. int iLevel,
  309. LPTSTR lpFormat,
  310. ...)
  311. {
  312. #ifdef WIN32
  313. char szBuf[1024];
  314. #else
  315. static char szBuf[1024];
  316. #endif
  317. int cb;
  318. va_list va;
  319. LPSTR psz;
  320. // mask the iLevel passed with mmdebug.Mask. if this ends up
  321. // clearing the high bits then iLevel has a shot being smaller
  322. // than mmdebug.Level. if not, then the second test will always
  323. // fail. Thus mmdebug.Mask has bits set to DISABLE that category.
  324. //
  325. // note that we always pass messages that have an iLevel < 0.
  326. // this level corresponds to Asserts & Rips so we always want to see them.
  327. //
  328. if (iLevel < 0 || mmdebug.Level >= (iLevel & mmdebug.Mask))
  329. {
  330. va_start (va, lpFormat);
  331. cb = wvsprintfA (szBuf, lpFormat, va);
  332. va_end (va);
  333. // eat leading ..\..\ which we get from __FILE__ since
  334. // george's wierd generic makefile stuff.
  335. //
  336. psz = szBuf;
  337. while (psz[0] == '.' && psz[1] == '.' && psz[2] == '\\')
  338. psz += 3;
  339. // if we begin with a drive letter, strip off all but filename
  340. //
  341. if (psz[0] && psz[1] == ':')
  342. {
  343. UINT ii = 2;
  344. for (ii = 2; psz[ii] != 0; ++ii)
  345. if (psz[ii] == '\\')
  346. psz += ii+1, ii = 0;
  347. }
  348. // write to standard out if we have a handle. otherwise write to
  349. // the debugger
  350. //
  351. #ifdef MODULE_DEBUG_PREFIX
  352. if (psz != szBuf)
  353. AuxOut (MODULE_DEBUG_PREFIX);
  354. #endif
  355. AuxOut (psz);
  356. }
  357. return cb;
  358. }
  359. /*+ AuxRip
  360. *
  361. *-=================================================================*/
  362. void FAR _cdecl AuxRip (
  363. LPTSTR lpFormat,
  364. ...)
  365. {
  366. #ifdef WIN32
  367. char szBuf[1024];
  368. #else
  369. static char szBuf[1024];
  370. #endif
  371. va_list va;
  372. LPSTR psz;
  373. va_start (va, lpFormat);
  374. wvsprintfA (szBuf, lpFormat, va);
  375. va_end (va);
  376. // eat leading ..\..\ which we get from __FILE__ since
  377. // george's wierd generic makefile stuff.
  378. //
  379. psz = szBuf;
  380. while (psz[0] == '.' && psz[1] == '.' && psz[2] == '\\')
  381. psz += 3;
  382. AuxOut ("RIP: ");
  383. AuxOut (psz);
  384. AuxOut ("\r\n");
  385. if (mmdebug.StopOnRip)
  386. {
  387. #if !defined _WIN32 || defined _X86_
  388. _asm {int 3};
  389. #else
  390. DebugBreak();
  391. #endif
  392. }
  393. }
  394. /*+ AuxDebugDump -
  395. *
  396. *-=================================================================*/
  397. VOID WINAPI AuxDebugDump (
  398. int iLevel,
  399. LPVOID lpvData,
  400. int nCount)
  401. {
  402. LPBYTE lpData = (LPBYTE)lpvData;
  403. char szBuf[128];
  404. LPSTR psz;
  405. int cb;
  406. int ix;
  407. BYTE abRow[8];
  408. if ((mmdebug.Level < (iLevel & mmdebug.Mask)) || nCount <= 0)
  409. return;
  410. do {
  411. cb = wsprintf (szBuf, "\t%08X: ", lpData);
  412. psz = szBuf + cb;
  413. for (ix = 0; ix < 8; ++ix)
  414. {
  415. LPBYTE lpb = lpData;
  416. abRow[ix] = '.';
  417. if (IsBadReadPtr (lpData + ix, 1))
  418. lstrcpy (psz, ".. ");
  419. else
  420. {
  421. wsprintf (psz, "%02X ", lpData[ix]);
  422. if (lpData[ix] >= 32 && lpData[ix] < 127)
  423. abRow[ix] = lpData[ix];
  424. }
  425. psz += 3;
  426. }
  427. for (ix = 0; ix < 8; ++ix)
  428. *psz++ = abRow[ix];
  429. lstrcpy (psz, "\r\n");
  430. #ifdef MODULE_DEBUG_PREFIX
  431. AuxOut (MODULE_DEBUG_PREFIX);
  432. #endif
  433. AuxOut (szBuf);
  434. } while (lpData += 8, (nCount -= 8) > 0);
  435. return;
  436. }
  437. /*+ AuxMMErrText
  438. *
  439. *-=================================================================*/
  440. LPCTSTR WINAPI AuxMMErrText (
  441. DWORD mmr)
  442. {
  443. UINT uRemain = sizeof(aMMErr)/sizeof(aMMErr[0]);
  444. UINT uUpper = uRemain-1;
  445. UINT uLower = 0;
  446. static char szTemp[50];
  447. if (mmr <= aMMErr[uUpper].mmr)
  448. {
  449. // binary search for mmr match, if match
  450. // return string pointer
  451. //
  452. while (--uRemain)
  453. {
  454. UINT ii = (uLower + uUpper) >> 1;
  455. if (aMMErr[ii].mmr < mmr)
  456. {
  457. if (uLower == ii)
  458. break;
  459. uLower = ii;
  460. }
  461. else if (aMMErr[ii].mmr > mmr)
  462. {
  463. if (uUpper == ii)
  464. break;
  465. uUpper = ii;
  466. }
  467. else
  468. {
  469. return aMMErr[ii].psz;
  470. break;
  471. }
  472. }
  473. // we can only get to here if no match was found for
  474. // the error id.
  475. //
  476. if ( ! uRemain)
  477. {
  478. int ix;
  479. INLINE_BREAK;
  480. for (ix = 0; ix < sizeof(aMMErr)/sizeof(aMMErr[0])-1; ++ix)
  481. {
  482. assert (aMMErr[ix].mmr < aMMErr[ix+1].mmr);
  483. }
  484. wsprintf (szTemp, "error %d 0x%X", mmr, mmr);
  485. return szTemp;
  486. }
  487. }
  488. wsprintf (szTemp, aMMErr[uUpper].psz, mmr);
  489. return szTemp;
  490. }
  491. /*+ DebugSetOutputLevel
  492. *
  493. *-=================================================================*/
  494. BOOL WINAPI DebugSetOutputLevel (
  495. int nLevel,
  496. int nMask)
  497. {
  498. int nOldLevel = mmdebug.Level;
  499. if (!mmdebug.Initialized)
  500. {
  501. #ifdef WIN32
  502. TCHAR szFile[MAX_PATH];
  503. mmdebug.TakeFault = GetProfileInt("Debug", "FaultMask", 1);
  504. GetProfileString("Debug", "MMDebugTo", "", szFile, sizeof(szFile));
  505. #if 0
  506. if (!lstrcmpi(szFile, "Console"))
  507. {
  508. mmdebug.hOut = GetStdHandle (STD_OUTPUT_HANDLE);
  509. if (!mmdebug.hOut || mmdebug.hOut == INVALID_HANDLE_VALUE)
  510. {
  511. AllocConsole ();
  512. mmdebug.hOut = GetStdHandle (STD_OUTPUT_HANDLE);
  513. if (mmdebug.hOut == INVALID_HANDLE_VALUE)
  514. mmdebug.hOut = NULL;
  515. }
  516. SetConsoleTitle (MODULE_DEBUG_PREFIX " Debug Output");
  517. }
  518. else
  519. #endif
  520. if (szFile[0] &&
  521. lstrcmpi(szFile, "Debug") &&
  522. lstrcmpi(szFile, "Debugger") &&
  523. lstrcmpi(szFile, "Deb"))
  524. {
  525. mmdebug.hOut = CreateFile(szFile, GENERIC_WRITE,
  526. FILE_SHARE_READ,
  527. NULL, OPEN_ALWAYS,
  528. FILE_ATTRIBUTE_NORMAL,
  529. NULL);
  530. if (INVALID_HANDLE_VALUE != mmdebug.hOut)
  531. SetFilePointer (mmdebug.hOut, 0, NULL, FILE_END);
  532. }
  533. #endif
  534. mmdebug.Initialized = TRUE;
  535. }
  536. mmdebug.Level = (nLevel & 0xFF);
  537. mmdebug.Mask = (nMask | 0xFF);
  538. return nOldLevel;
  539. }
  540. #endif // _INC_MMDEBUG_CODE_
  541. #endif // DEBUG || _DEBUG
  542. #ifdef __cplusplus
  543. }
  544. #endif // _cplusplus