home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / cxl / error / cxlhderr.c
Encoding:
C/C++ Source or Header  |  1989-11-07  |  8.8 KB  |  241 lines

  1. /*
  2. **      Another hard error handler for the CXL windowing library.
  3. **
  4. **      Place call to _harderr after call to video_init.
  5. **
  6. **      Syntax:     _harderr(CXL_error_handler);
  7. **
  8. **      From:       Ian Journeaux, EASYL SOFTWARE
  9. **                  CIS: 76214,1427
  10. **                  or the CXL Support BBS: (512)590-0460
  11. **
  12. */
  13.  
  14.  
  15.  
  16. #include    <bios.h>
  17. #include    <conio.h>
  18. #include    <dos.h>
  19. #include    <malloc.h>
  20. #include    <process.h>
  21. #include    <stdio.h>
  22. #include    <stdlib.h>
  23. #include    <string.h>
  24. #include    "cxldef.h"
  25. #include    "cxlkey.h"
  26. #include    "cxlmou.h"
  27. #include    "cxlstr.h"
  28. #include    "cxlvid.h"
  29. #include    "cxlwin.h"
  30. #include    "cxlxwin.h"
  31.  
  32. /* Type definitions */
  33.  
  34. /* Prototypes */
  35. void get_devname( void );
  36.  
  37. /*---------------------------------------------------------------------------*/
  38. /* Extended Error table */
  39. static char *exterror[]=
  40.     { "Successful call", "Invalid service number", "File not found",
  41.       "Path not found", "Too many files open", "Access denied",
  42.       "Invalid file handle", "Memory control blocks destroyed",
  43.       "Insufficient memory", "Invalid memory-block address",
  44.       "Invalid environment", "Invalid format", "Invalid access code",
  45.       "Invalid data", "Reserved for future use", "Invalid drive",
  46.       "Attempt to remove current directory", "Not same device",
  47.       "No more files", "Disk is write protected", "Unknown unit",
  48.       "Device not ready", "Unknown command", "CRC data error",
  49.       "Unknown command", "CRC data error", "Bad request-structure length",
  50.       "Seek error", "Not a dos disk", "Sector not found",
  51.       "Printer out of paper", "Write fault", "Read fault", "General Failure",
  52.       "Sharing violation", "Lock violation", "Disk change invalid",
  53.       "File control block unavailable", "Network busy",
  54.       "Reserved", "Handle end-of-file not completed",
  55.       "Reserved", "Reserved", "Reserved", "Reserved", "Reserved", "Reserved",
  56.       "Reserved", "Reserved", "Reserved", "Reserved", "Reserved",
  57.       "Network support unavailable", "Remote computer unavailable",
  58.       "Network request not supported", "Remote computer not listening",
  59.       "Duplicate name on network", "Network name not found", "Network busy",
  60.       "Network device no longer exists", "Network BIOS command limit exceeded",
  61.       "Network adapter hardware error", "Incorrect response from network",
  62.       "Unexpected network error", "Incompatible remote adapter",
  63.       "Print queue full", "Queue not full", "Not enough space to print file",
  64.       "Network name was deleted", "Access denied by network",
  65.       "Network device type incorrect", "Network name not found",
  66.       "Network name limit exceeded", "Network BIOS session limit exceeded",
  67.       "Temporarily paused", "Network request not accepted",
  68.       "Print/disk redirection paused", "File already exists",
  69.       "Cannot make directory", "Fail on INT 24h", "Too many redirections",
  70.       "Duplicate redirection", "Invalid password", "Invalid parameter",
  71.       "Network write fault", "Function not supported on network",
  72.       "Required system component not installed",  NULL };
  73.  
  74. /*---------------------------------------------------------------------------*/
  75. /* Class table */
  76. static char *class[]=
  77.     { "Out of storage space or I/O channels", "Temporary situation (file or record lock)",
  78.       "Authorization (access denied)", "Internal system error", "Hardware failure",
  79.       "System failure (or bad config.sys)", "Application program error", "Item not found",
  80.       "Bad format", "Resource currently locked", "Media error",
  81.       "Item already exists", "Unknown", NULL };
  82.  
  83. /*---------------------------------------------------------------------------*/
  84. /* Action table */
  85. static char *action[]=
  86.     { "Retry the operation", "Delay and then retry", "Re-enter user input",
  87.       "Abort application after closing files", "Abort immediately",
  88.         "Ignore the error", "Retry after correcting error", NULL };
  89.  
  90. /*---------------------------------------------------------------------------*/
  91. /* Locus table */
  92. static char *locus[]=
  93.     { "Unknown source", "Block device (disk error)", "Network error",
  94.         "Serial device error (timeout)", "System memory error", NULL };
  95.  
  96. /*---------------------------------------------------------------------------*/
  97. /* Location of disk error */
  98. static char *location[]=
  99.     { "DOS error", "FAT error", "Directory error", "File error", NULL };
  100.  
  101. /*---------------------------------------------------------------------------*/
  102. /* Tpye of disk error */
  103. static char *read_write[]=
  104.     { "Read error", "Write error", NULL };
  105.  
  106. /*---------------------------------------------------------------------------*/
  107. /* Drive Letters */
  108. static char *drive_letter[]=
  109.     { "A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:",
  110.       "M:", "N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:",
  111.       "Y:", "Z:",   NULL };
  112.  
  113. /*---------------------------------------------------------------------------*/
  114. static struct
  115. {
  116.     unsigned deverr;
  117.     unsigned errcode;
  118.     unsigned far *devhdr;  /* Pointer to HEADER structure. READ ONLY!       */
  119. } near _hflags;
  120.  
  121. struct DOSERROR error;
  122.  
  123. #define HEADER struct _device_header
  124. extern HEADER
  125. {
  126.      long     far *devptr;
  127.      unsigned far *attrib;
  128.      unsigned far *stratptr;
  129.      unsigned far *intrptr;
  130.      char     far *devname;
  131. };
  132.  
  133. unsigned int critical_error;
  134. char device_name[8];
  135.  
  136. void far CXL_error_handler(unsigned deverr, unsigned errcode, unsigned far *devhdr)
  137. {
  138.     int i;
  139.     int status;
  140.     int done = 0;
  141.     unsigned int fail;
  142.     unsigned int retry;
  143.     unsigned int ignore;
  144.     unsigned int disk;
  145.     unsigned int drive;
  146.     unsigned int disk_error;
  147.     unsigned int disk_error_type;
  148.     unsigned int disk_error_location;
  149.     unsigned int di_low, di_high;
  150.     unsigned far *headptr;
  151.     HEADER header;
  152.  
  153.     _hflags.deverr  = deverr;
  154.     _hflags.errcode = errcode;
  155.     _hflags.devhdr  = devhdr;
  156.  
  157.     disk_error = (deverr & 0x8000) >> 15;
  158.     ignore     = (deverr & 0x2000) >> 13;
  159.     retry      = (deverr & 0x1000) >> 12;
  160.     fail       = (deverr & 0x0800) >> 11;
  161.     drive      = (deverr & 0x00FF);
  162.     disk_error_location = (deverr & 0x0600) >> 9;
  163.     disk_error_type = (deverr & 0x0100) >> 8;
  164.     dosexterr(&error);
  165.  
  166.     if((error.exterror < 0) || (error.exterror > 90)) {
  167.         error.exterror = 1;
  168.     }
  169.     if((error.class < 1) || (error.class > 13)) {
  170.         error.class = 13;
  171.     }
  172.     if((error.locus < 1) || (error.locus > 5)) {
  173.         error.locus = 1;
  174.     }
  175.     if((error.action < 1) || (error.action > 7)) {
  176.         error.action = 1;
  177.     }
  178.  
  179.     if(!wopen(6,10,15,70,1,YELLOW|_RED,YELLOW|_RED)) error_exit();
  180.     wtitle("[ CRITICAL ERROR ]",TCENTER,YELLOW|BLINK|_RED);
  181.     whline(6, 0, 60, 0, YELLOW|_RED);
  182.  
  183.     wprintf("\033R%c\033C%cError Code     : %s", 1, 1, exterror[error.exterror]);
  184.     wprintf("\033R%c\033C%cClass of Error : %s", 2, 1, class[error.class-1]);
  185.     wprintf("\033R%c\033C%cLocation       : %s", 3, 1, locus[error.locus-1]);
  186.     if(disk_error == 0) {
  187.         wprintf("\033R%c\033C%c%s on drive %s  %s", 4, 18, read_write[disk_error_type], drive_letter[drive], location[disk_error_location]);
  188.     } else {
  189.         get_devname();
  190.         wprintf("\033R%c\033C%cDevice: %s", 4, 18, device_name);
  191.     }
  192.  
  193.     wprintf("\033R%c\033C%cRecommended Action : %s", 5, 1, action[error.action-1]);
  194.     if(error.action == 6) {
  195.         i = 'I';
  196.     } else if ((error.action == 4)||(error.action == 5)) {
  197.         i = 'A';
  198.     } else {
  199.         i = 'R';
  200.     }
  201.     wsetesc(0);
  202.     wmenubeg(14,16,14,65,5,YELLOW|_RED,YELLOW|_RED,NULL);
  203.     wmenuitem( 0, 0 , "Retry",  'R', 'R', 0, NULL, 0, 0);
  204.     wmenuitem( 0, 13, "Abort",  'A', 'A', 0, NULL, 0, 0);
  205.     wmenuitem( 0, 26, "Ignore", 'I', 'I', 0, NULL, 0, 0);
  206.     wmenuitem( 0, 39, "Fail",   'F', 'F', 0, NULL, 0, 0);
  207.     wmenuend(i, M_HORZ, 0, 0, LMAGENTA|_BLACK, WHITE|_BLACK, LGREY|_BLACK, RED|BLINK|_LGREY);
  208.     i = wmenuget();
  209.  
  210.     switch (i)
  211.     {
  212.         case 'R':   critical_error = _HARDERR_RETRY;
  213.                     break;
  214.  
  215.         case 'A':   critical_error = _HARDERR_ABORT;
  216.                     cls();
  217.                     break;
  218.  
  219.         case 'I':   critical_error = _HARDERR_IGNORE;
  220.                     break;
  221.  
  222.         case 'F':   critical_error = _HARDERR_FAIL;
  223.                     break;
  224.     }
  225.  
  226.     wclose();
  227.     _hardresume(critical_error);
  228. }
  229.  
  230. void get_devname( void )
  231. /* Returns the name of the device on which the error occured.               */
  232. /* For example, PRN is returned if writing to a printer which               */
  233. /* is out of paper.                                                         */
  234. {
  235.     int i;
  236.     for(i=0; i < 8; i++) {
  237.         device_name[i] = ((char *) &(_hflags.devhdr[5]))[i];
  238.     }
  239. }
  240.  
  241.