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.

125 lines
2.5 KiB

  1. /* Debug.c
  2. *
  3. * Debug functions for compression manager
  4. */
  5. #include <windows.h>
  6. #include <stdarg.h>
  7. #include <win32.h>
  8. #ifdef DEBUG // See comments in NTAVI.H about DEBUG
  9. #ifdef _WIN32
  10. #include <profile.key>
  11. /*
  12. * read a UINT from the profile, or return default if
  13. * not found.
  14. */
  15. UINT mmGetProfileIntA(LPSTR appname, LPSTR valuename, INT uDefault)
  16. {
  17. CHAR achName[MAX_PATH];
  18. HKEY hkey;
  19. DWORD dwType;
  20. INT value = uDefault;
  21. DWORD dwData;
  22. int cbData;
  23. lstrcpyA(achName, KEYNAMEA);
  24. lstrcatA(achName, appname);
  25. if (RegOpenKeyA(ROOTKEY, achName, &hkey) == ERROR_SUCCESS) {
  26. cbData = sizeof(dwData);
  27. if (RegQueryValueExA(
  28. hkey,
  29. valuename,
  30. NULL,
  31. &dwType,
  32. (PBYTE) &dwData,
  33. &cbData) == ERROR_SUCCESS) {
  34. if (dwType == REG_DWORD || dwType == REG_BINARY) {
  35. value = (INT)dwData;
  36. #ifdef USESTRINGSALSO
  37. } else if (dwType == REG_SZ) {
  38. value = atoi((LPSTR) &dwData);
  39. #endif
  40. }
  41. }
  42. RegCloseKey(hkey);
  43. }
  44. return((UINT)value);
  45. }
  46. #endif
  47. /* _Assert(fExpr, szFile, iLine)
  48. *
  49. * If <fExpr> is TRUE, then do nothing. If <fExpr> is FALSE, then display
  50. * an "assertion failed" message box allowing the user to abort the program,
  51. * enter the debugger (the "Retry" button), or igore the error.
  52. *
  53. * <szFile> is the name of the source file; <iLine> is the line number
  54. * containing the _Assert() call.
  55. */
  56. #pragma optimize("", off)
  57. BOOL FAR PASCAL
  58. _Assert(BOOL fExpr, LPSTR szFile, int iLine)
  59. {
  60. #ifdef _WIN32
  61. char ach[300];
  62. #else
  63. static char ach[300]; // debug output (avoid stack overflow)
  64. #endif
  65. int id;
  66. int iExitCode;
  67. void FAR PASCAL DebugBreak(void);
  68. /* check if assertion failed */
  69. if (fExpr)
  70. return fExpr;
  71. /* display error message */
  72. wsprintfA(ach, "File %s, line %d", (LPSTR) szFile, iLine);
  73. MessageBeep(MB_ICONHAND);
  74. id = MessageBoxA(NULL, ach, "Assertion Failed",
  75. MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  76. /* abort, debug, or ignore */
  77. switch (id)
  78. {
  79. case IDABORT:
  80. /* kill this application */
  81. iExitCode = 0;
  82. #ifndef _WIN32
  83. _asm
  84. {
  85. mov ah, 4Ch
  86. mov al, BYTE PTR iExitCode
  87. int 21h
  88. }
  89. #endif // WIN16
  90. break;
  91. case IDRETRY:
  92. /* break into the debugger */
  93. DebugBreak();
  94. break;
  95. case IDIGNORE:
  96. /* ignore the assertion failure */
  97. break;
  98. }
  99. return FALSE;
  100. }
  101. #pragma optimize("", on)
  102. #endif