home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / RCUTILS.ZIP / ERRDIAG.C < prev    next >
C/C++ Source or Header  |  1992-09-28  |  2KB  |  69 lines

  1. /* errdiag.c */
  2. /* Written by Rick Curry */
  3. /* Adapted from errdiag.c code written by Eric Sassaman (ericsa@microsoft) */
  4. /* simple VioPopUp only version */
  5.  
  6. #define INCL_DOSPROCESS
  7. #define INCL_DOSQUEUES
  8. #define INCL_VIO
  9. #define INCL_DOSMISC
  10. #include <os2.h>
  11. #include <stdio.h>
  12.  
  13. #define BASE_ERR 1
  14. #define NET_ERR 2
  15.  
  16. static USHORT fWait = VP_WAIT | VP_OPAQUE;
  17. char errTxt[128]; /* short version of error text (not explanation text) */
  18.  
  19. static int bseerr(int errNumber, int errType);
  20. void errDiag(int errNumber, char *file, int line);
  21.  
  22. static int bseerr(int errNumber, int errType)
  23. {
  24.   USHORT err;
  25.   char chBuf[256];
  26.   USHORT cbMsg;
  27.   char *szMsgFileName;
  28.  
  29.   szMsgFileName = (errType == NET_ERR ? "net.msg" : "oso001.msg");
  30.   err = DosGetMessage(NULL, 0, errTxt, sizeof(chBuf), errNumber,
  31.       szMsgFileName, &cbMsg);
  32.   errTxt[cbMsg] = 0;  /* null terminate the message string */
  33.   if (err)
  34.     return(1);
  35.   puts(errTxt);
  36.   szMsgFileName = (errType == NET_ERR ? "neth.msg" : "oso001h.msg");
  37.   err = DosGetMessage(NULL, 0, chBuf, sizeof(chBuf), errNumber,
  38.       szMsgFileName, &cbMsg);
  39.   chBuf[cbMsg] = 0;  /* null terminate the message string */
  40.   if (err)
  41.     return(1);
  42.   puts(chBuf);
  43.   return(0);
  44. } /* bseerr */
  45.  
  46.  
  47. void errDiag(int errNumber, char *file, int line)
  48. {
  49.   char szMsg[128];
  50.   USHORT err;
  51.   int errType; /* either NET_ERR or BASE_ERR */
  52.  
  53.   if (errNumber >= 2100 && errNumber <=2999)
  54.     errType = NET_ERR;
  55.   else
  56.     errType = BASE_ERR;
  57.   VioPopUp(&fWait, 0);
  58.   sprintf(szMsg, "Error %d has occurred in file %s on line %d.\n", errNumber, file, line);
  59.   puts(szMsg);
  60.   err = bseerr(errNumber, errType);
  61.   if (err)  /* if bseerr() fails, just return */
  62.     return;
  63.  
  64.   puts("Hit return to continue...");
  65.   getchar();
  66.   VioEndPopUp(0);
  67.   return;
  68. } /* errDiag */
  69.