home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / QYERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  4.6 KB  |  150 lines

  1. /**
  2. *
  3. * Name        qyerror -- Return error text and DOS error information.
  4. *
  5. * Synopsis    ercode = qyerror(percode,ppmsg,pclass,paction,plocus);
  6. *
  7. *        int ercode      Error code from operation of QYERROR
  8. *                  (0 if o.k., 1 if DOS 2.x)
  9. *        int *percode      On entry:  error code from DOS.
  10. *                  (If this is DOS version 3.0 or greater,
  11. *                  the error code from the DOS function
  12. *                  that failed most recently is returned.)
  13. *        char **ppmsg      Pointer to variable to receive address
  14. *                  of error message (NIL if unknown error
  15. *                  code).
  16. *        int *pclass      Returned error class (0 if DOS 2.x).
  17. *        int *paction      Returned recommended action (0 if DOS 2.x).
  18. *        int *plocus      Returned error locus (0 if DOS 2.x).
  19. *
  20. * Description    This function returns a pointer to a string containing
  21. *        an error message matching a DOS error code.
  22. *
  23. *        If this is DOS version 3.00 or greater, additional
  24. *        information is provided about the results of the DOS
  25. *        function call that most recently failed.  (For this
  26. *        reason, QYERROR is normally only used after a DOS call
  27. *        fails.)  The error code from that call is returned in
  28. *        *percode; the error class, recommended action, and error
  29. *        locus are likewise returned.
  30. *
  31. *        If this is DOS version 2.x, the value ("ercode") of the
  32. *        function is 1 (since detailed error information is not
  33. *        available).  However, if *percode is a valid error code,
  34. *        the address of the proper error message is returned in
  35. *        *ppmsg.
  36. *
  37. *        This function is not "destructive":  it can be called
  38. *        more than once without affecting the results.
  39. *
  40. * Returns    ercode          Error code from operation of QYERROR
  41. *                  (0 if o.k., 1 if DOS 2.x)
  42. *        *percode      If this is DOS version 3.0 or greater,
  43. *                  the error code from the DOS function
  44. *                  that failed most recently is returned.
  45. *        *ppmsg          Pointer to variable to receive address
  46. *                  of error message (NIL if unknown error
  47. *                  code).
  48. *        *pclass       Error class (0 if DOS 2.x).
  49. *        *paction      Recommended action (0 if DOS 2.x).
  50. *        *plocus       Error locus (0 if DOS 2.x).
  51. *
  52. * Version    3.0  (C)Copyright Blaise Computing Inc.  1986
  53. *
  54. **/
  55.  
  56. #include <bquery.h>
  57.  
  58.     /* Globally available error messages corresponding to DOS error   */
  59.     /* codes.                                  */
  60.  
  61. MSG_PAIR b_ermsgs[] =
  62. {
  63.      0,"No error",
  64.      1,"Invalid function number",
  65.      2,"File not found",
  66.      3,"Path not found",
  67.      4,"Too many open files (no handles)",
  68.      5,"Access denied",
  69.      6,"Invalid handle number",
  70.      7,"Memory control block destroyed",
  71.      8,"Insufficient memory",
  72.      9,"Invalid memory block address",
  73.     10,"Invalid environment",
  74.     11,"Invalid format",
  75.     12,"Invalid access code",
  76.     13,"Invalid data",
  77.     15,"Invalid drive number specified",
  78.     16,"Cannot remove current directory",
  79.     17,"Device names are different",
  80.     18,"No more matching files found",
  81.     19,"Diskette is write-protected",
  82.     20,"Unknown unit",
  83.     21,"Drive not ready",
  84.     22,"Unknown command",
  85.     23,"Data error (CRC error)",
  86.     24,"Bad request structure length",
  87.     25,"Seek error",
  88.     26,"Unknown media type",
  89.     27,"Sector not found",
  90.     28,"Printer out of paper",
  91.     29,"Write fault",
  92.     30,"Read fault",
  93.     31,"General failure",
  94.     32,"Sharing violation",
  95.     33,"Lock violation",
  96.     34,"Invalid disk change",
  97.     35,"No more file control blocks left",
  98.     80,"File exists",
  99.     82,"Cannot make",
  100.     83,"Fail on INT 24h"
  101. };
  102.  
  103. #define NUM_MSGS    (sizeof(b_ermsgs)/sizeof(b_ermsgs[0]))
  104.  
  105. int qyerror(percode,ppmsg,pclass,paction,plocus)
  106. int  *percode;
  107. char **ppmsg;
  108. int  *pclass,*paction,*plocus;
  109. {
  110.     int      minor;
  111.     DOSREG     dos_reg;
  112.     int      result;
  113.     register int i;
  114.  
  115.     if (qydosver(&minor) < 3)          /* Note:    this DOS function     */
  116.     {                      /* never fails on DOS 2.00 or   */
  117.                       /* greater, so it won't affect  */
  118.                       /* function 0x59.           */
  119.     *pclass  =
  120.     *paction =
  121.     *plocus  = 0;
  122.     result     = 1;              /* Report error since DOS       */
  123.                       /* function 0x59 isn't          */
  124.                       /* available.              */
  125.     }
  126.     else
  127.     {
  128.     dos_reg.ax = 0x5900;          /* DOS function 0x59.          */
  129.     dos_reg.bx = 0x0000;
  130.     dos(&dos_reg);
  131.  
  132.     *percode = dos_reg.ax;
  133.     *pclass  = uthibyte(dos_reg.bx);
  134.     *paction = utlobyte(dos_reg.bx);
  135.     *plocus  = uthibyte(dos_reg.cx);
  136.  
  137.     result     = 0;              /* Success.              */
  138.     }
  139.  
  140.     *ppmsg = NIL;
  141.     for (i = 0; i < NUM_MSGS; i++)
  142.     if (b_ermsgs[i].msgnum == *percode)
  143.     {
  144.         *ppmsg = b_ermsgs[i].pmsg;/* Return address of error      */
  145.         break;              /* message.              */
  146.     }
  147.  
  148.     return result;
  149. }
  150.