| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: error.c 182 2005-05-28 17:54:26Z root $
|
|---|
| 5 |
|
|---|
| 6 | Error reporting
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2004, 2005 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 12 Aug 04 SHL Comments
|
|---|
| 12 | 23 May 05 SHL Move saymsg here
|
|---|
| 13 | 24 May 05 SHL Rename General_Error to more accurate Win_Error
|
|---|
| 14 | 24 May 05 SHL Rename saymsg to more accurate Misc_Error
|
|---|
| 15 | 24 May 05 SHL Rework Win_Error args and clean up logic
|
|---|
| 16 | 27 May 05 SHL Rework to use common showMsg
|
|---|
| 17 |
|
|---|
| 18 | ***********************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #define INCL_DOS
|
|---|
| 21 | #define INCL_DOSERRORS
|
|---|
| 22 | #define INCL_WIN
|
|---|
| 23 |
|
|---|
| 24 | #include <os2.h>
|
|---|
| 25 | #include <stdlib.h>
|
|---|
| 26 | #include <stdio.h>
|
|---|
| 27 | #include <string.h>
|
|---|
| 28 | #include <stdarg.h>
|
|---|
| 29 |
|
|---|
| 30 | #include "fm3dll.h"
|
|---|
| 31 | #include "fm3str.h"
|
|---|
| 32 |
|
|---|
| 33 | #pragma data_seg(DATA1)
|
|---|
| 34 | #pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg,showMsg)
|
|---|
| 35 |
|
|---|
| 36 | static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg);
|
|---|
| 37 |
|
|---|
| 38 | //== Win_Error: report Win...() error ===
|
|---|
| 39 |
|
|---|
| 40 | VOID Win_Error(HWND hwndErr, HWND hwndOwner, PSZ pszFileName, ULONG ulLineNo, CHAR *pszFmt,...)
|
|---|
| 41 | {
|
|---|
| 42 | PERRINFO pErrInfoBlk; /* Pointer to ERRINFO structure filled
|
|---|
| 43 | by WinGetErrorInfo */
|
|---|
| 44 | PSZ pszOffset; /* Pointer to current error message returned
|
|---|
| 45 | by WinGetErrorInfo */
|
|---|
| 46 | CHAR szMsg[4096];
|
|---|
| 47 | PSZ psz;
|
|---|
| 48 | HAB hab;
|
|---|
| 49 | va_list va;
|
|---|
| 50 |
|
|---|
| 51 | if (hwndErr == NULLHANDLE)
|
|---|
| 52 | hab = (HAB)0;
|
|---|
| 53 | else
|
|---|
| 54 | hab = WinQueryAnchorBlock(hwndErr);
|
|---|
| 55 |
|
|---|
| 56 | // Format callers message
|
|---|
| 57 | va_start(va, pszFmt);
|
|---|
| 58 | vsprintf(szMsg, pszFmt, va);
|
|---|
| 59 | va_end(va);
|
|---|
| 60 |
|
|---|
| 61 | // Append file name and line number
|
|---|
| 62 | sprintf(szMsg + strlen(szMsg),
|
|---|
| 63 | GetPString(IDS_GENERR1TEXT),
|
|---|
| 64 | pszFileName, ulLineNo, " ");
|
|---|
| 65 |
|
|---|
| 66 | // Get last PM error for the current thread
|
|---|
| 67 | pErrInfoBlk = WinGetErrorInfo(hab);
|
|---|
| 68 | // fixme to report
|
|---|
| 69 | if (pErrInfoBlk != NULL)
|
|---|
| 70 | {
|
|---|
| 71 | if (!hwndOwner)
|
|---|
| 72 | hwndOwner = HWND_DESKTOP;
|
|---|
| 73 | /* Find message offset in array of message offsets
|
|---|
| 74 | Assume 1 message - fixme?
|
|---|
| 75 | */
|
|---|
| 76 | pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk -> offaoffszMsg;
|
|---|
| 77 | /* Address error message in array of messages and
|
|---|
| 78 | append error message to source code linenumber
|
|---|
| 79 | */
|
|---|
| 80 | psz = szMsg + strlen(szMsg);
|
|---|
| 81 | sprintf(psz, "#0x%04x \"", ERRORIDERROR(pErrInfoBlk -> idError));
|
|---|
| 82 | psz += strlen(psz);
|
|---|
| 83 | strcpy(psz, ((PSZ)pErrInfoBlk) + *(PSHORT)pszOffset);
|
|---|
| 84 | psz += strlen(psz);
|
|---|
| 85 | strcpy(psz, "\"");
|
|---|
| 86 | WinFreeErrorInfo(pErrInfoBlk); // Free resource segment
|
|---|
| 87 |
|
|---|
| 88 | showMsg(MB_ENTER | MB_ICONEXCLAMATION,
|
|---|
| 89 | hwndOwner,
|
|---|
| 90 | GetPString(IDS_GENERR2TEXT), // Titlebar message
|
|---|
| 91 | szMsg); // Formatted message
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | } // Win_Error
|
|---|
| 95 |
|
|---|
| 96 | //== Dos_Error: report Dos...() error ===
|
|---|
| 97 |
|
|---|
| 98 | INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PSZ pszFileName,
|
|---|
| 99 | ULONG ulLineNo, CHAR *pszFmt,...)
|
|---|
| 100 | {
|
|---|
| 101 | CHAR szMsg[4096];
|
|---|
| 102 | ULONG Class = 17; // Error class - fixme to not init?
|
|---|
| 103 | ULONG action = 9; // Error action
|
|---|
| 104 | ULONG Locus = 7; // Error location
|
|---|
| 105 | ULONG ulMsgLen;
|
|---|
| 106 | CHAR *pszMsgStart;
|
|---|
| 107 | CHAR *psz;
|
|---|
| 108 | va_list va;
|
|---|
| 109 |
|
|---|
| 110 | if (!ulRC)
|
|---|
| 111 | return MBID_ENTER; // Should not have been called
|
|---|
| 112 |
|
|---|
| 113 | // Format caller's message
|
|---|
| 114 | va_start(va, pszFmt);
|
|---|
| 115 | vsprintf(szMsg, pszFmt, va);
|
|---|
| 116 | va_end(va);
|
|---|
| 117 |
|
|---|
| 118 | DosErrClass(ulRC, &Class, &action, &Locus);
|
|---|
| 119 |
|
|---|
| 120 | sprintf(szMsg + strlen(szMsg),
|
|---|
| 121 | GetPString(IDS_DOSERR1TEXT),
|
|---|
| 122 | pszFileName,
|
|---|
| 123 | ulLineNo,
|
|---|
| 124 | ulRC,
|
|---|
| 125 | GetPString(IDS_ERRCLASS1TEXT + (Class - 1)),
|
|---|
| 126 | GetPString(IDS_ERRACTION1TEXT + (action - 1)),
|
|---|
| 127 | GetPString(IDS_ERRLOCUS1TEXT + (Locus - 1)));
|
|---|
| 128 | pszMsgStart = szMsg + strlen(szMsg) + 1;
|
|---|
| 129 | // Get message leaving space for NL separator
|
|---|
| 130 | if (!DosGetMessage(NULL, 0L, (PCHAR)pszMsgStart + 1, 1024, ulRC, "OSO001.MSG", &ulMsgLen) ||
|
|---|
| 131 | !DosGetMessage(NULL, 0L, (PCHAR)pszMsgStart + 1, 1024, ulRC, "OSO001H.MSG", &ulMsgLen))
|
|---|
| 132 | {
|
|---|
| 133 | // Got message
|
|---|
| 134 | pszMsgStart[ulMsgLen + 1] = 0; // Terminate
|
|---|
| 135 | *(pszMsgStart - 1) = '\n'; // Stuff NL before message text
|
|---|
| 136 | *pszMsgStart = '\"'; // Prefix message text with quote
|
|---|
| 137 |
|
|---|
| 138 | psz = pszMsgStart + ulMsgLen; // Point at last char
|
|---|
| 139 | // Chop trailing NL CR TAB
|
|---|
| 140 | while (*psz &&
|
|---|
| 141 | (*psz == '\r' || *psz == '\n' || *psz == ' ' || *psz == '\t'))
|
|---|
| 142 | {
|
|---|
| 143 | *psz-- = 0;
|
|---|
| 144 | }
|
|---|
| 145 | strcat(psz, "\""); // Append trailing quote
|
|---|
| 146 |
|
|---|
| 147 | // Convert CR and NL combos to single space
|
|---|
| 148 | psz = pszMsgStart;
|
|---|
| 149 | while (*psz)
|
|---|
| 150 | {
|
|---|
| 151 | if (*psz == '\n' || *psz == '\r')
|
|---|
| 152 | {
|
|---|
| 153 | while (*(psz + 1) == '\n' || *(psz + 1) == '\r')
|
|---|
| 154 | memmove(psz, psz + 1, strlen(psz));
|
|---|
| 155 | *psz = ' ';
|
|---|
| 156 | }
|
|---|
| 157 | else
|
|---|
| 158 | psz++;
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | return showMsg(mb_type | MB_ICONEXCLAMATION,
|
|---|
| 163 | hwndOwner,
|
|---|
| 164 | GetPString(IDS_DOSERR2TEXT), // Title
|
|---|
| 165 | szMsg);
|
|---|
| 166 |
|
|---|
| 167 | } // Dos_Error
|
|---|
| 168 |
|
|---|
| 169 | // fixme to be rename to Misc_Error
|
|---|
| 170 |
|
|---|
| 171 | //=== saymsg: report misc error ===
|
|---|
| 172 |
|
|---|
| 173 | APIRET saymsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszFmt,...)
|
|---|
| 174 | {
|
|---|
| 175 | CHAR szMsg[4096];
|
|---|
| 176 | va_list va;
|
|---|
| 177 |
|
|---|
| 178 | va_start(va, pszFmt);
|
|---|
| 179 | vsprintf(szMsg, pszFmt, va);
|
|---|
| 180 | va_end(va);
|
|---|
| 181 |
|
|---|
| 182 | return showMsg(mb_type,
|
|---|
| 183 | hwnd,
|
|---|
| 184 | pszTitle,
|
|---|
| 185 | szMsg);
|
|---|
| 186 | } // saymsg
|
|---|
| 187 |
|
|---|
| 188 | //=== showMsg: report misc error ===
|
|---|
| 189 |
|
|---|
| 190 | static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg)
|
|---|
| 191 | {
|
|---|
| 192 | fputs(pszMsg, stderr);
|
|---|
| 193 | fputc('\n', stderr);
|
|---|
| 194 | fflush(stderr);
|
|---|
| 195 |
|
|---|
| 196 | if (!hwnd)
|
|---|
| 197 | hwnd = HWND_DESKTOP;
|
|---|
| 198 |
|
|---|
| 199 | return WinMessageBox(HWND_DESKTOP, // Parent
|
|---|
| 200 | hwnd, // Owner
|
|---|
| 201 | pszMsg,
|
|---|
| 202 | pszTitle,
|
|---|
| 203 | 0, // help id
|
|---|
| 204 | mb_type | MB_MOVEABLE);
|
|---|
| 205 | } // showMsg
|
|---|