Annotation of mstools/samples/mcitest/debug.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  *  debug.c
                      3:  *
                      4:  *  debugging menu support
                      5:  *
                      6:  *  Debug level info is in WIN.INI in the [debug] section:
                      7:  *
                      8:  *      [debug]
                      9:  *      App=0               level for App
                     10:  *
                     11:  */
                     12: 
                     13: #include <stdio.h>
                     14: #include <windows.h>
                     15: #include "mcitest.h"
                     16: #include <stdarg.h>
                     17: 
                     18: #if DBG
                     19: 
1.1.1.2 ! root       20: #define DEFAULTDEBUGLEVEL 1
1.1       root       21: int   __iDebugLevel = DEFAULTDEBUGLEVEL;
                     22: 
                     23: void dDbgSetDebugMenuLevel(int i)
                     24: {
                     25:     HMENU hMenu;
                     26:     UINT m;
                     27: 
                     28:     if ((i < 0) || (i > 4)) i = 4;
                     29:     hMenu = GetMenu(hwndMainDlg);
                     30:     for (m=IDM_DEBUG0; m<=IDM_DEBUG4; m++) {
                     31:         CheckMenuItem(hMenu, m, MF_UNCHECKED);
                     32:     }
                     33:     CheckMenuItem(hMenu, (UINT)(i + IDM_DEBUG0), MF_CHECKED);
                     34:     __iDebugLevel = i;
1.1.1.2 ! root       35:     dprintf3((TEXT("Debug level set to %d"), i));
1.1       root       36: }
                     37: 
                     38: /***************************************************************************
                     39: 
                     40:     @doc INTERNAL
                     41: 
                     42:     @api void | dDbgOut | This function sends output to the current
                     43:         debug output device.
                     44: 
                     45:     @parm LPSTR | lpszFormat | Pointer to a printf style format string.
                     46:     @parm ??? | ... | Args.
                     47: 
                     48:     @rdesc There is no return value.
                     49: 
                     50: ****************************************************************************/
                     51: 
1.1.1.2 ! root       52: void dDbgOut(LPTSTR lpszFormat, ...)
1.1       root       53: {
                     54:     int i;
1.1.1.2 ! root       55:     TCHAR buf[256];
1.1       root       56:     va_list va;
                     57: 
1.1.1.2 ! root       58:     i = wsprintf(buf, TEXT("%s: "), aszAppName);
1.1       root       59: 
                     60:     va_start(va, lpszFormat);
1.1.1.2 ! root       61:     i += wvsprintf(buf+i, lpszFormat, va);
1.1       root       62:     va_end(va);
                     63: 
1.1.1.2 ! root       64:     buf[i++] = TEXT('\n');
1.1       root       65:     buf[i] = 0;
                     66: 
                     67:     OutputDebugString(buf);
                     68: }
                     69: 
                     70: /***************************************************************************
                     71: 
                     72:     @doc INTERNAL
                     73: 
                     74:     @api int | dDbgGetLevel | This function gets the current debug level
                     75:         for a module.
                     76: 
                     77:     @parm LPSTR | lpszModule | The name of the module.
                     78: 
                     79:     @rdesc The return value is the current debug level.
                     80: 
                     81:     @comm The information is kept in the [debug] section of WIN.INI
                     82: 
                     83: ****************************************************************************/
                     84: 
1.1.1.2 ! root       85: int dDbgGetLevel(LPTSTR lpszAppName)
1.1       root       86: {
1.1.1.2 ! root       87:     return GetProfileInt(TEXT("mmdebug"), lpszAppName, DEFAULTDEBUGLEVEL);
1.1       root       88: }
                     89: 
                     90: /***************************************************************************
                     91: 
                     92:     @doc INTERNAL
                     93: 
                     94:     @api int | dDbgSaveLevel | This function saves the current debug level
                     95:         for a module.
                     96: 
                     97:     @parm LPSTR | lpszModule | The name of the module.
                     98:     @parm int | iLevel | The value to save.
                     99: 
                    100:     @rdesc There is no return value.
                    101: 
                    102:     @comm The information is kept in the [debug] section of WIN.INI
                    103: 
                    104: ****************************************************************************/
                    105: 
1.1.1.2 ! root      106: void dDbgSaveLevel(LPTSTR lpszAppName, int iLevel)
1.1       root      107: {
1.1.1.2 ! root      108:     TCHAR buf[80];
1.1       root      109: 
1.1.1.2 ! root      110:     wsprintf(buf, TEXT("%d"), iLevel);
        !           111:     WriteProfileString(TEXT("debug"), lpszAppName, buf);
1.1       root      112: }
                    113: 
                    114: /***************************************************************************
                    115: 
                    116:     @doc INTERNAL
                    117: 
                    118:     @api void | dDbgAssert | This function shows an assert message box.
                    119: 
                    120:     @parm LPSTR | exp | Pointer to the expression string.
                    121:     @parm LPSTR | file | Pointer to the file name.
                    122:     @parm int | line | The line number.
                    123: 
                    124:     @rdesc There is no return value.
                    125: 
                    126:     @comm We try to use the current active window as the parent. If
                    127:         this fails we use the desktop window.  The box is system
                    128:         modal to avoid any trouble.
                    129: 
                    130: ****************************************************************************/
                    131: 
1.1.1.2 ! root      132: void dDbgAssert(LPTSTR exp, LPTSTR file, int line)
1.1       root      133: {
1.1.1.2 ! root      134:     TCHAR bufTmp[256];
1.1       root      135:     int iResponse;
                    136:     HWND hWnd;
                    137: 
1.1.1.2 ! root      138:     wsprintf(bufTmp,
        !           139:         TEXT("Expression: %s\nFile: %s, Line: %d\n\nAbort:  Exit Process\nRetry:  Enter Debugger\nIgnore: Continue"),
1.1       root      140:         exp, file, line);
                    141: 
                    142:     // try to use the active window, but NULL is ok if there
                    143:     // isn't one.
                    144: 
                    145:     hWnd = GetActiveWindow();
                    146: 
                    147:     iResponse = MessageBox(hWnd,
                    148:                            bufTmp,
1.1.1.2 ! root      149:                            TEXT("Assertion Failure"),
1.1       root      150:                            MB_TASKMODAL
                    151:                             | MB_ICONEXCLAMATION
                    152:                             | MB_DEFBUTTON3
                    153:                             | MB_ABORTRETRYIGNORE);
                    154: 
                    155:     switch (iResponse) {
                    156:         case 0:
1.1.1.2 ! root      157:             dprintf1((TEXT("Assert message box failed")));
        !           158:             dprintf2((TEXT("  Expression: %s"), exp));
        !           159:             dprintf2((TEXT("  File: %s,  Line: %d"), file, line));
1.1       root      160:             break;
                    161:         case IDABORT:
                    162:             ExitProcess(1);
                    163:             break;
                    164:         case IDRETRY:
                    165:             DebugBreak();
                    166:             break;
                    167:         case IDIGNORE:
                    168:             break;
                    169:     }
                    170: }
                    171: 
                    172: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.