Changeset 121 for trunk/dll/error.c
- Timestamp:
- Dec 5, 2004, 1:16:38 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/error.c
r2 r121 1 2 /*********************************************************************** 3 4 $Id$ 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 1 15 #define INCL_DOS 2 16 #define INCL_DOSERRORS … … 8 22 #include <string.h> 9 23 #include <stdarg.h> 24 10 25 #include "fm3dll.h" 11 26 #include "fm3str.h" … … 14 29 #pragma alloc_text(FMINPUT,General_Error,Dos_Error) 15 30 31 // fixme to have MiscError instead of saymsg 16 32 17 VOID General_Error(HAB hab,HWND hwnd, PSZ ErrModule,LONG ErrLine,CHAR *s,...) { 33 // fixme to be Win_Error 34 // fixme to pass hwndError rather hab 18 35 36 VOID General_Error(HAB hab,HWND hwndOwner, PSZ ErrModule,LONG ErrLine,CHAR *s,...) 37 { 19 38 PERRINFO pErrInfoBlk; /* Pointer to ERRINFO structure that is filled 20 39 by WinGetErrorInfo */ 21 40 PSZ pszOffset; /* Pointer to the current error message returned 22 41 by WinGetErrorInfo */ 23 CHAR ErrBuffer[4096]; /* The wholeerror message that is displayed to42 CHAR ErrBuffer[4096]; /* The error message that is displayed to 24 43 the user via WinMessageBox */ 44 PSZ psz; 25 45 va_list ap; 26 46 47 // Format callers message 27 48 va_start(ap,s); 28 49 vsprintf(ErrBuffer,s,ap); 29 50 va_end(ap); 30 sprintf(&ErrBuffer[strlen(ErrBuffer)], 51 52 // Append file name and line number 53 sprintf(ErrBuffer + strlen(ErrBuffer), 31 54 GetPString(IDS_GENERR1TEXT), 32 ErrModule, 33 ErrLine, 34 " "); 35 /* Get last error for the current thread. */ 55 ErrModule, ErrLine, " "); 56 57 /* Get last PM error for the current thread */ 36 58 pErrInfoBlk = WinGetErrorInfo(hab); 37 if(pErrInfoBlk != (PERRINFO)NULL) { 38 if(!hwnd) 39 hwnd = HWND_DESKTOP; 40 /* Find offset in array of message offsets */ 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 */ 41 65 pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg; 42 66 /* Address error message in array of messages and 43 append error message to source code linenumber */ 44 sprintf(&ErrBuffer[strlen(ErrBuffer)],"#0x%04x \"", 45 ERRORIDERROR(pErrInfoBlk->idError)); 46 strcat(ErrBuffer,(((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset))); 47 strcat(ErrBuffer,"\""); 48 WinFreeErrorInfo(pErrInfoBlk); /* Free resource segment */ 49 WinMessageBox(HWND_DESKTOP, /* Parent window is DESKTOP */ 50 hwnd, /* Owner window is DESKTOP */ 51 (PSZ)ErrBuffer, /* General_Error message */ 52 /* Title bar message */ 53 GetPString(IDS_GENERR2TEXT), 54 0, /* Message identifier */ 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 */ 55 82 MB_ENTER | MB_ICONEXCLAMATION | MB_MOVEABLE); 56 83 } … … 58 85 59 86 60 INT Dos_Error(INT type,ULONG Error,HWND hwnd , PSZ ErrModule,61 LONG ErrLine,CHAR *s,...) {62 87 INT Dos_Error(INT type,ULONG Error,HWND hwndOwner, PSZ ErrModule, 88 LONG ErrLine,CHAR *s,...) 89 { 63 90 CHAR MsgBuffer[4096]; /* The whole error message that 64 91 is displayed to … … 68 95 ULONG Locus = 7; /* Error location */ 69 96 ULONG len; 70 CHAR *p,*pp; 97 CHAR *pszMsgStart; 98 CHAR *psz; 71 99 va_list ap; 72 100 73 101 if(Error != 0) { 74 strset(MsgBuffer,0); 75 if(!hwnd) 76 hwnd = HWND_DESKTOP; 102 strset(MsgBuffer,0); // fixme? 103 if(!hwndOwner) 104 hwndOwner = HWND_DESKTOP; 105 106 // Format caller's message 77 107 va_start(ap,s); 78 108 vsprintf(MsgBuffer,s,ap); 79 109 va_end(ap); 110 80 111 DosErrClass(Error,&Class,&action,&Locus); 112 81 113 sprintf(&MsgBuffer[strlen(MsgBuffer)], 82 114 GetPString(IDS_DOSERR1TEXT), … … 87 119 GetPString(IDS_ERRACTION1TEXT + (action - 1)), 88 120 GetPString(IDS_ERRLOCUS1TEXT + (Locus - 1))); 89 p = MsgBuffer + strlen(MsgBuffer) + 1; 90 if(!DosGetMessage(NULL,0L,(PCHAR)p + 1,1024,Error,"OSO001.MSG",&len) || 91 !DosGetMessage(NULL,0L,(PCHAR)p + 1,1024,Error,"OSO001H.MSG",&len)) { 92 p[len + 1] = 0; 93 *(p - 1) = '\n'; 94 *p = '\"'; 95 pp = p + len; 96 while(*pp && (*pp == '\r' || *pp == '\n' || *pp == ' ' || *pp == '\t')) { 97 *pp = 0; 98 pp--; 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--; 99 136 } 100 strcat(p,"\""); 101 pp = p; 102 while(*pp) { 103 if(*pp == '\n' || *pp == '\r') { 104 while(*(pp + 1) == '\n' || *(pp + 1) == '\r') 105 memmove(pp,pp + 1,strlen(pp)); 106 *pp = ' '; 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 = ' '; 107 145 } 108 146 else 109 p p++;147 psz++; 110 148 } 111 149 } 112 return WinMessageBox(HWND_DESKTOP, /* Parent window is DESKTOP */ 113 hwnd, /* Owner window */ 114 (PSZ)MsgBuffer, /* DOS API error message */ 115 /* Title bar message */ 116 GetPString(IDS_DOSERR2TEXT), 117 0, /* Message identifier */ 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 */ 118 155 type | MB_ICONEXCLAMATION | MB_MOVEABLE); 119 156 } 120 157 return MBID_ENTER; 121 158 } 122
Note:
See TracChangeset
for help on using the changeset viewer.