home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CRCDOS.ARJ / CHANDLER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-28  |  3.5 KB  |  104 lines

  1. /*********************************************************************/
  2. /* Module name: chandler.c                                           */
  3. /* Date: 10 Oct 87; 25 Nov 87                                        */
  4. /* Environment: Turbo C 1.0                                          */
  5. /* Author: Synchronistic Software (Was it JUST a coincidence?)       */
  6. /* Notice: Public Domain: The following conditions apply to use:     */
  7. /*         1) No fee shall be charged for distribution.              */
  8. /*         2) Modifications may be made, but authorship information  */
  9. /*            for all contributing authors shall be retained.        */
  10. /*         3) This code may not be included as part of a commercial  */
  11. /*            package.                                               */
  12. /* This program is provided AS IS without any warranty, expressed or */
  13. /* implied, including, but not limited to, fitness for a particular  */
  14. /* purpose.                                                          */
  15. /*********************************************************************/
  16. static char    *__ATH__ =
  17. "@(#)chandler() v1.1 (25Nov87): Public Domain (P) 1987 Synchronistic Software";
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. int        __CriticalError;    /* Set to 1 when routine entered */
  23. int        __CritErrIGNORE = 0;    /* Ignores errors when true */
  24.  
  25. /* REFERENCE: Armbrust, Steven; and Forgeron, Ted. Programmer's */
  26. /* Reference Manual for IBM Personal Computers. Homewood, Illinois: */
  27. /* Dow Jones-Irwin, 1986. */
  28. static char    *error_type[] = {
  29.     /* 0x00 */ "attempt to write to a write-protected disk$",
  30.     /* 0x01 */ "undefined unit/drive$",
  31.     /* 0x02 */ "drive not ready$",
  32.     /* 0x03 */ "unknown command$",
  33.     /* 0x04 */ "CRC data error occurred$",
  34.     /* 0x05 */ "bad request structure length$",
  35.     /* 0x06 */ "seek error occurred$",
  36.     /* 0x07 */ "unknown medial type$",
  37.     /* 0x08 */ "requested sector not located$",
  38.     /* 0x09 */ "printer out of paper$",
  39.     /* 0x0a */ "general write fault occurred$",
  40.     /* 0x0b */ "general read fault occurred$",
  41.     /* 0x0c */ "general failure occurred$"
  42. };
  43.  
  44. static struct dev_header {
  45.     unsigned char    junk1[4];
  46.     unsigned int    attrib;
  47.     unsigned char    junk2[4];
  48.     char        name[8];
  49. };
  50.  
  51. #define OUTSTR(msg)    bdosptr( 0x09, msg, 0x00 )
  52. #define OUTCH(ch)    bdos( 0x02, ch, 0x00 )
  53.  
  54. #pragma warn -par
  55. int chandler( int errval, int ax, int bp, int si )
  56. {
  57.     static char            buf[25];
  58.     static struct dev_header    far *header;
  59.     static unsigned char        drive;
  60.     register int            i;
  61.  
  62.     __CriticalError = 1;
  63.     header = MK_FP( bp, si );
  64.     drive = ax & 0x00ff;
  65.  
  66.     if (__CritErrIGNORE) {
  67.         if ( (ax & 0x8000) && !(header->attrib & 0x8000) ) {
  68.             OUTSTR( "Cannot access FAT!  Aborting.\n\r$" );
  69.             hardresume( 2 );
  70.         }
  71.         hardretn( -1 );
  72.     }
  73.  
  74.     OUTSTR( "Critical Error: $" );
  75.     if (errval <= 0x0c) {
  76.         OUTSTR( error_type[errval] );
  77.     } else {
  78.         sprintf( buf, "unknown error 0x%02x$", errval );
  79.         OUTSTR( buf );
  80.     }
  81.  
  82.     if (ax & 0x8000) {    /* Not a disk error (may be a FAT error) */
  83.         if (header->attrib & 0x8000) {    /* Character device error */
  84.             OUTSTR( " (device $" );
  85.             for (i = 0; i < 8; i++)
  86.                 OUTCH( header->name[i] );
  87.             OUTSTR( ")$" );
  88.         } else {    /* FAT error */
  89.             sprintf( buf, " (drive %c)$", 'A' + drive );
  90.             OUTSTR( buf );
  91.             OUTSTR( "; cannot access FAT, aborting\n\r$" );
  92.             hardresume( 2 );
  93.         }
  94.     } else {    /* Disk error */
  95.         sprintf( buf, " (drive %c)$", 'A' + drive );
  96.         OUTSTR( buf );
  97.     }
  98.     OUTSTR( "\n\r$" );
  99.  
  100.     /* Try to fail the system call.  If DOS doesn't like this it aborts. */
  101.     hardretn( -1 );
  102. }
  103. #pragma warn .par
  104.