home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / tde221.zip / CRITERR.C < prev    next >
C/C++ Source or Header  |  1993-04-01  |  6KB  |  190 lines

  1. /*
  2.  * Instead of the Abort, Retry, Ignore thing, let's try to handle critical
  3.  * errors within tde.  Give the user some indication of the critical error
  4.  * and then find out what the user wants to do.
  5.  *
  6.  * IMPORTANT:  This is a replacement for the standard DOS critical error
  7.  * handler.  Since DOS is not re-entrant, do not call any functions that,
  8.  * directly or indirectly, call DOS functions.  We are in some DOS function
  9.  * when a critical error occurs.  Using BIOS and direct hardware I/O
  10.  * functions, however, is allowed.
  11.  *
  12.  * The prototype for the critical error handler is
  13.  *
  14.  *            int  far crit_err_handler( void )
  15.  *
  16.  * The handler is explicitly declared as "far", because the assembly
  17.  * routine is hard coded for a "far" function.  See the bottom of
  18.  * int24.asm for more info.
  19.  *
  20.  * See (incidentally, these are the current references for MSDOS 6.0):
  21.  *
  22.  *   Microsoft Knowledge Base, "Action Taken on Abort, Retry, Ignore, Fail",
  23.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q67586,
  24.  *    Publication Date:  March 24, 1993.
  25.  *
  26.  *   Microsoft Knowledge Base, "Extended Error Code Information",
  27.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q74463,
  28.  *    Publication Date:  March 24, 1993.
  29.  *
  30.  *   Programmer's Reference Manual, Microsoft Corporation, Redmond,
  31.  *    Washington, 1986, Document No. 410630014-320-003-1285, pp. 1-20 thru
  32.  *    1-21, pp. 1-34 thru 1-38, p 1-99, pp. 1-121 thru 1-124, pp. 1-216 thru
  33.  *    1-218, pp. 2-1 thru 2-30.
  34.  *
  35.  *   Ray Duncan, _Advanced MS-DOS_, Microsoft Press, Redmond, Washington,
  36.  *    1986, ISBN 0-914845-77-2, pp 89-97, pp 130-133.
  37.  *
  38.  *
  39.  * New editor name:  TDE, the Thomson-Davis Editor.
  40.  * Author:           Frank Davis
  41.  * Date:             June 5, 1991, version 1.0
  42.  * Date:             July 29, 1991, version 1.1
  43.  * Date:             October 5, 1991, version 1.2
  44.  * Date:             January 20, 1992, version 1.3
  45.  * Date:             February 17, 1992, version 1.4
  46.  * Date:             April 1, 1992, version 1.5
  47.  * Date:             June 5, 1992, version 2.0
  48.  * Date:             October 31, 1992, version 2.1
  49.  * Date:             April 1, 1993, version 2.2
  50.  *
  51.  * This code is released into the public domain, Frank Davis.
  52.  *    You may distribute it freely.
  53.  */
  54.  
  55. #include "tdestr.h"
  56. #include "common.h"
  57. #include "tdefunc.h"
  58. #include "criterr.h"
  59.  
  60. /*
  61.  * Save the area of the screen that will display the Critical
  62.  * Error info.  CEH_WIDTH and CEH_HEIGHT are the dimensions of critical
  63.  * error screen in criterr.h.   CEH_OFFSET is the offset into the screen
  64.  * refresh buffer.  Let the compiler calculate the offset, 'cause the offset
  65.  * don't change anyway.
  66.  */
  67. #define CEH_ROW         5
  68. #define CEH_COL         6
  69. #define CEH_WIDTH       69
  70. #define CEH_HEIGHT      15
  71.  
  72. #define CEH_OFFSET      ((CEH_ROW * 160) + (CEH_COL * 2))
  73.  
  74. #define NEXT_LINE       160
  75.  
  76.  
  77. /*
  78.  * buffer for ceh info screen.  make this an int array because we
  79.  * need to save character and attribute.
  80.  */
  81. int ceh_buffer[CEH_HEIGHT][CEH_WIDTH];
  82.  
  83.  
  84. /*
  85.  * Name:    crit_err_handler
  86.  * Purpose: Show user something is wrong and get a response
  87.  * Date:    April 1, 1992
  88.  */
  89. int  far crit_err_handler( void )
  90. {
  91. int  rc;
  92. int  c;
  93.  
  94.    save_area( (char far *)ceh_buffer );
  95.    show_error_screen( CEH_ROW, CEH_COL );
  96.    xygoto( 60, 17 );
  97.    do
  98.       c = getkey( );
  99.    while (c != 'Q' && c != 'q' && c != 'R' && c != 'r' && c != 'A' && c != 'a');
  100.    switch ( c ) {
  101.       case 'A':
  102.       case 'a':
  103.          rc = ABORT;
  104.          break;
  105.       case 'Q':
  106.       case 'q':
  107.          rc = FAIL;
  108.          break;
  109.       case 'R':
  110.       case 'r':
  111.       default :
  112.          rc = RETRY;
  113.          break;
  114.    }
  115.    restore_area( (char far *)ceh_buffer );
  116.    return( rc );
  117. }
  118.  
  119.  
  120. /*
  121.  * Name:    show_error_screen
  122.  * Purpose: Display error screen in window
  123.  * Date:    April 1, 1992
  124.  * Passed:  row: line to display ceh screen
  125.  *          col: column to begin display ceh screen
  126.  */
  127. void show_error_screen( int row, int col )
  128. {
  129. char **p;
  130.  
  131.    for (p=criterr_screen; *p != NULL; p++, row++)
  132.       s_output( *p, row, col, g_display.help_color );
  133.    s_output( error_code[ceh.code],    8, 23, g_display.help_color );
  134.    s_output( operation[ceh.rw],       9, 23, g_display.help_color );
  135.    if (ceh.dattr == 0)
  136.       c_output( ceh.drive + 'a',     23, 10, g_display.help_color );
  137.    else
  138.       s_output( critt1,              10, 23, g_display.help_color );
  139.    s_output( ext_err[ceh.extended],  11, 23, g_display.help_color );
  140.    s_output( error_class[ceh.class], 12, 23, g_display.help_color );
  141.    s_output( locus[ceh.locus],       13, 23, g_display.help_color );
  142.    s_output( device_type[ceh.dattr], 14, 23, g_display.help_color );
  143.    s_output( ceh.dattr == 0 ? critt1 : ceh.dname,
  144.                                      15, 23, g_display.help_color );
  145. }
  146.  
  147.  
  148. /*
  149.  * Name:    save_area
  150.  * Purpose: save a region of the screen
  151.  * Date:    April 1, 1992
  152.  * Passed:  dest: pointer to buffer for contents of screen under ceh
  153.  * Notes:   this function does not check for snow.  the source is the screen
  154.  *             and the destination is the buffer.
  155.  */
  156. void save_area( char far *dest )
  157. {
  158. char far *source;
  159. register int hgt;
  160.  
  161.    source = (char far *)g_display.display_address + CEH_OFFSET;
  162.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  163.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  164.       source += NEXT_LINE;
  165.       dest += (CEH_WIDTH*2);
  166.    }
  167. }
  168.  
  169.  
  170. /*
  171.  * Name:    restore_area
  172.  * Purpose: restore a region of the screen
  173.  * Date:    April 1, 1992
  174.  * Passed:  source: pointer to buffer for contents of screen under ceh
  175.  * Notes:   this function does not check for snow.  the source is the buffer
  176.  *             and the destination is the screen.
  177.  */
  178. void restore_area( char far *source )
  179. {
  180. char far *dest;
  181. register int hgt;
  182.  
  183.    dest = (char far *)g_display.display_address + CEH_OFFSET;
  184.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  185.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  186.       dest += NEXT_LINE;
  187.       source += (CEH_WIDTH*2);
  188.    }
  189. }
  190.