source: trunk/dll/error.c@ 143

Last change on this file since 143 was 137, checked in by root, 20 years ago

Move saymsg here

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