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