home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name qyerror -- Return error text and DOS error information.
- *
- * Synopsis ercode = qyerror(percode,ppmsg,pclass,paction,plocus);
- *
- * int ercode Error code from operation of QYERROR
- * (0 if o.k., 1 if DOS 2.x)
- * int *percode On entry: error code from DOS.
- * (If this is DOS version 3.0 or greater,
- * the error code from the DOS function
- * that failed most recently is returned.)
- * char **ppmsg Pointer to variable to receive address
- * of error message (NIL if unknown error
- * code).
- * int *pclass Returned error class (0 if DOS 2.x).
- * int *paction Returned recommended action (0 if DOS 2.x).
- * int *plocus Returned error locus (0 if DOS 2.x).
- *
- * Description This function returns a pointer to a string containing
- * an error message matching a DOS error code.
- *
- * If this is DOS version 3.00 or greater, additional
- * information is provided about the results of the DOS
- * function call that most recently failed. (For this
- * reason, QYERROR is normally only used after a DOS call
- * fails.) The error code from that call is returned in
- * *percode; the error class, recommended action, and error
- * locus are likewise returned.
- *
- * If this is DOS version 2.x, the value ("ercode") of the
- * function is 1 (since detailed error information is not
- * available). However, if *percode is a valid error code,
- * the address of the proper error message is returned in
- * *ppmsg.
- *
- * This function is not "destructive": it can be called
- * more than once without affecting the results.
- *
- * Returns ercode Error code from operation of QYERROR
- * (0 if o.k., 1 if DOS 2.x)
- * *percode If this is DOS version 3.0 or greater,
- * the error code from the DOS function
- * that failed most recently is returned.
- * *ppmsg Pointer to variable to receive address
- * of error message (NIL if unknown error
- * code).
- * *pclass Error class (0 if DOS 2.x).
- * *paction Recommended action (0 if DOS 2.x).
- * *plocus Error locus (0 if DOS 2.x).
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bquery.h>
-
- /* Globally available error messages corresponding to DOS error */
- /* codes. */
-
- MSG_PAIR b_ermsgs[] =
- {
- 0,"No error",
- 1,"Invalid function number",
- 2,"File not found",
- 3,"Path not found",
- 4,"Too many open files (no handles)",
- 5,"Access denied",
- 6,"Invalid handle number",
- 7,"Memory control block destroyed",
- 8,"Insufficient memory",
- 9,"Invalid memory block address",
- 10,"Invalid environment",
- 11,"Invalid format",
- 12,"Invalid access code",
- 13,"Invalid data",
- 15,"Invalid drive number specified",
- 16,"Cannot remove current directory",
- 17,"Device names are different",
- 18,"No more matching files found",
- 19,"Diskette is write-protected",
- 20,"Unknown unit",
- 21,"Drive not ready",
- 22,"Unknown command",
- 23,"Data error (CRC error)",
- 24,"Bad request structure length",
- 25,"Seek error",
- 26,"Unknown media type",
- 27,"Sector not found",
- 28,"Printer out of paper",
- 29,"Write fault",
- 30,"Read fault",
- 31,"General failure",
- 32,"Sharing violation",
- 33,"Lock violation",
- 34,"Invalid disk change",
- 35,"No more file control blocks left",
- 80,"File exists",
- 82,"Cannot make",
- 83,"Fail on INT 24h"
- };
-
- #define NUM_MSGS (sizeof(b_ermsgs)/sizeof(b_ermsgs[0]))
-
- int qyerror(percode,ppmsg,pclass,paction,plocus)
- int *percode;
- char **ppmsg;
- int *pclass,*paction,*plocus;
- {
- int minor;
- DOSREG dos_reg;
- int result;
- register int i;
-
- if (qydosver(&minor) < 3) /* Note: this DOS function */
- { /* never fails on DOS 2.00 or */
- /* greater, so it won't affect */
- /* function 0x59. */
- *pclass =
- *paction =
- *plocus = 0;
- result = 1; /* Report error since DOS */
- /* function 0x59 isn't */
- /* available. */
- }
- else
- {
- dos_reg.ax = 0x5900; /* DOS function 0x59. */
- dos_reg.bx = 0x0000;
- dos(&dos_reg);
-
- *percode = dos_reg.ax;
- *pclass = uthibyte(dos_reg.bx);
- *paction = utlobyte(dos_reg.bx);
- *plocus = uthibyte(dos_reg.cx);
-
- result = 0; /* Success. */
- }
-
- *ppmsg = NIL;
- for (i = 0; i < NUM_MSGS; i++)
- if (b_ermsgs[i].msgnum == *percode)
- {
- *ppmsg = b_ermsgs[i].pmsg;/* Return address of error */
- break; /* message. */
- }
-
- return result;
- }