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