home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0109.zip / Timur / errors.c < prev    next >
Text File  |  1993-06-07  |  3KB  |  99 lines

  1. /* ERRORS.C - Error handler
  2.  
  3. Copyright (c) 1992-1993 Timur Tabi
  4. Copyright (c) 1992-1993 Fasa Corporation
  5.  
  6. The following trademarks are the property of Fasa Corporation:
  7. BattleTech, CityTech, AeroTech, MechWarrior, BattleMech, and 'Mech.
  8. The use of these trademarks should not be construed as a challenge to these marks.
  9.  
  10. */
  11.  
  12. #define INCL_WINWINDOWMGR
  13. #define INCL_WINERRORS
  14. #define INCL_WINDIALOGS
  15. #define INCL_GPIERRORS
  16. #define INCL_DOSMISC
  17. #include <os2.h>
  18. #include <stdio.h>
  19.  
  20. #define ERRORS_C
  21. #include "header.h"
  22. #include "errors.h"
  23. #include "window.h"
  24. #include "errormsg.h"
  25.  
  26. static char * FindMsg(ERROR ec) {
  27. /* This function takes an error code and returns the error message associated with it.
  28.    It returns a pointer to "UNKNOWN" if it can't find the error code in its databases.
  29. */
  30.   static char szUnknown[]="UNKNOWN";
  31.   int i=0;
  32.  
  33.   do
  34.     if (amsg[i].ec == ec) return amsg[i].szMsg;
  35.   while (amsg[++i].ec);
  36.  
  37.   return szUnknown;
  38. }
  39. ERROR ErrorBox(ERROR ec) {
  40. /* This function displays a message box that corresponds to error code 'ec'
  41.    (ec & 0xFF000000) returns the base error code for the module to which 'ec' belongs
  42.    (ec & 0xFFFF0000) returns the base error code for the function to which 'ec' belongs
  43. */
  44.   char szMsg[100];
  45.  
  46.   if (!ec) return 0;
  47.  
  48.   sprintf(szMsg,"Module: %s\nFunction: %s\n%s",FindMsg(ec & 0xFF000000),FindMsg(ec & 0xFFFF0000),FindMsg(ec));
  49.   WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,szMsg,NULL,0,MB_OK | MB_ICONEXCLAMATION);
  50.   return ec;
  51. }
  52.  
  53. APIRET ErrorDosError(APIRET rc) {
  54. /* This function displays a message box appropriate to the Dos error code.  If 'rc' equals
  55.    zero, then this function simply exists.  The return code is always the same as the
  56.    parameter.
  57. */
  58.   ULONG ulClass,ulAction,ulLocus;
  59.   char sz[128];
  60.  
  61.   if (rc) {
  62.     DosErrClass(rc,&ulClass,&ulAction,&ulLocus);
  63.     sprintf(sz,"Code: %lu\nClass: %lu\nAction: %lu\nLocus: %lu",rc,ulClass,ulAction,ulLocus);
  64.     WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,sz,"DOS Error!",0,MB_OK | MB_ICONEXCLAMATION);
  65.   }
  66.   return rc;
  67. }
  68.  
  69. void ErrorWinError(void) {
  70.   char sz[64];
  71.   ERROR eid=WinGetLastError(hab);
  72.  
  73.   if (!eid) return;
  74.   sprintf(sz,"Error ID: %u Severity: %u",ERRORIDERROR(eid),ERRORIDSEV(eid));
  75.   WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,sz,NULL,0,MB_OK | MB_ICONEXCLAMATION);
  76. }
  77.  
  78. /*
  79. void ErrorWinError(void) {
  80.   PERRINFO perriErrorInfo;
  81.   PSZ       pszOffSet,pszErrMsg;
  82.  
  83.   perriErrorInfo = WinGetErrorInfo(habMain);
  84.  
  85.   if (perriErrorInfo != NULL) {
  86.    pszOffSet = ((PSZ) perriErrorInfo) + perriErrorInfo->offaoffszMsg;
  87.    pszErrMsg = ((PSZ) perriErrorInfo) + *((PSHORT)pszOffSet);
  88.    WinMessageBox(HWND_DESKTOP,
  89.                  HWND_DESKTOP,
  90.                  pszErrMsg,
  91.                  "PM Error",
  92.                  0,
  93.                  MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL);
  94.  
  95.    WinFreeErrorInfo(perriErrorInfo);
  96. }
  97. */
  98.  
  99.