Changeset 144 for trunk/dll/error.c
- Timestamp:
- May 25, 2005, 4:00:21 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/error.c
r137 r144 11 11 12 Aug 04 SHL Comments 12 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 13 16 14 17 ***********************************************************************/ … … 28 31 29 32 #pragma data_seg(DATA1) 30 #pragma alloc_text(FMINPUT, General_Error,Dos_Error,saymsg)33 #pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg) 31 34 32 // fixme to be Win_Error33 35 // fixme to pass hwndError rather hab 34 36 35 VOID General_Error(HAB hab,HWND hwndOwner, PSZ ErrModule,LONG ErrLine,CHAR *s,...) 37 //== Win_Error: report Win...() error === 38 39 VOID Win_Error(HWND hwndErr, HWND hwndOwner, PSZ pszFileName, ULONG ulLineNo, CHAR *pszFmt,...) 36 40 { 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; 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); 45 55 46 56 // Format callers message 47 va_start( ap,s);48 vsprintf( ErrBuffer,s,ap);49 va_end( ap);57 va_start(va, pszFmt); 58 vsprintf(szErrBuffer, pszFmt, va); 59 va_end(va); 50 60 51 61 // Append file name and line number 52 sprintf( ErrBuffer + strlen(ErrBuffer),53 54 ErrModule, ErrLine, " ");62 sprintf(szErrBuffer + strlen(szErrBuffer), 63 GetPString(IDS_GENERR1TEXT), 64 pszFileName, ulLineNo, " "); 55 65 56 66 /* Get last PM error for the current thread */ 57 67 pErrInfoBlk = WinGetErrorInfo(hab); 58 if(pErrInfoBlk != NULL) { 59 if(!hwndOwner) 68 if (pErrInfoBlk != NULL) 69 { 70 if (!hwndOwner) 60 71 hwndOwner = HWND_DESKTOP; 61 72 /* Find message offset in array of message offsets 62 73 Assume 1 message - fixme? 63 74 */ 64 pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;75 pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk -> offaoffszMsg; 65 76 /* Address error message in array of messages and 66 77 append error message to source code linenumber 67 78 */ 68 psz = ErrBuffer + strlen(ErrBuffer);69 sprintf(psz, "#0x%04x \"", ERRORIDERROR(pErrInfoBlk->idError));79 psz = szErrBuffer + strlen(szErrBuffer); 80 sprintf(psz, "#0x%04x \"", ERRORIDERROR(pErrInfoBlk -> idError)); 70 81 psz += strlen(psz); 71 strcpy(psz, ((PSZ)pErrInfoBlk) + *(PSHORT)pszOffset);82 strcpy(psz, ((PSZ) pErrInfoBlk) + *(PSHORT) pszOffset); 72 83 psz += strlen(psz); 73 strcpy(psz, "\"");84 strcpy(psz, "\""); 74 85 WinFreeErrorInfo(pErrInfoBlk); /* Free resource segment */ 75 86 76 WinMessageBox(HWND_DESKTOP, /* Parent window*/77 hwndOwner, /* Owner window*/78 ErrBuffer,/* Formatted message */79 80 0,/* Message identifier */81 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); 82 93 } 83 }84 94 95 } // Win_Error 85 96 86 INT Dos_Error(INT type,ULONG Error,HWND hwndOwner, PSZ ErrModule, 87 LONG ErrLine,CHAR *s,...) 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,...) 88 101 { 89 CHAR MsgBuffer[4096];/* The whole error message that90 91 92 ULONG Class = 17; /* Error class*/93 ULONG action = 9;/* Error action */94 ULONG Locus = 7;/* Error location */95 ULONG len;96 CHAR 97 CHAR 98 va_list ap;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; 99 112 100 if(Error != 0) { 101 strset(MsgBuffer,0); // fixme? 102 if(!hwndOwner) 103 hwndOwner = HWND_DESKTOP; 113 if (!ulRC) 114 return MBID_ENTER; // Should not have been called 104 115 105 // Format caller's message 106 va_start(ap,s); 107 vsprintf(MsgBuffer,s,ap); 108 va_end(ap); 116 if (!hwndOwner) 117 hwndOwner = HWND_DESKTOP; 109 118 110 DosErrClass(Error,&Class,&action,&Locus); 119 // Format caller's message 120 va_start(va, pszFmt); 121 vsprintf(szMsgBuffer, pszFmt, va); 122 va_end(va); 111 123 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 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')) 124 147 { 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--; 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 = ' '; 135 161 } 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 } 162 else 163 psz++; 148 164 } 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 165 } 156 return MBID_ENTER;157 }158 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); 159 173 160 // fixme to have Misc_Error instead of saymsg 174 } // Dos_Error 161 175 162 APIRET saymsg (APIRET type,HWND hwnd,CHAR *title,CHAR *string,...) 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,...) 163 181 { 164 CHAR *buffer; 165 va_list ap; 166 APIRET ret; 182 CHAR szBuffer[4096]; 183 va_list va; 167 184 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) 185 va_start(va, pszFmt); 186 vsprintf(szBuffer, pszFmt, va); 187 va_end(va); 188 189 if (!hwnd) 182 190 hwnd = HWND_DESKTOP; 183 ret = WinMessageBox(HWND_DESKTOP,hwnd,buffer,title, 184 0,type | MB_MOVEABLE); 185 free(buffer); 186 return ret; 187 } 191 192 return WinMessageBox(HWND_DESKTOP, hwnd, szBuffer, pszTitle, 193 0, mb_type | MB_MOVEABLE); 194 } // saymsg
Note:
See TracChangeset
for help on using the changeset viewer.