home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / TDE32.ZIP / CRITERR.C < prev    next >
C/C++ Source or Header  |  1993-11-13  |  15KB  |  481 lines

  1. /*
  2.  * I haven't tested the signals in UNIX, yet..., Frank.
  3.  *
  4.  * Instead of the Abort, Retry, Ignore thing, let's try to handle critical
  5.  * errors within tde.  Give the user some indication of the critical error
  6.  * and then find out what the user wants to do.
  7.  *
  8.  * If we are in a unix environment, lets map signals to our DOS critical
  9.  * error handler.
  10.  *
  11.  * IMPORTANT:  This is a replacement for the standard DOS critical error
  12.  * handler.  Since DOS is not re-entrant, do not call any functions that,
  13.  * directly or indirectly, call DOS functions.  We are in some DOS function
  14.  * when a critical error occurs.  Using BIOS and direct hardware I/O
  15.  * functions, however, is allowed.
  16.  *
  17.  * The prototype for the critical error handler is
  18.  *
  19.  *            int  FAR crit_err_handler( void )
  20.  *
  21.  * The handler is explicitly declared as "FAR", because the assembly
  22.  * routine is hard coded for a "FAR" function.  See the bottom of
  23.  * int24.asm for more info.
  24.  *
  25.  * See (incidentally, these are the current references for MSDOS 6.0):
  26.  *
  27.  *   Microsoft Knowledge Base, "Action Taken on Abort, Retry, Ignore, Fail",
  28.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q67586,
  29.  *    Publication Date:  March 24, 1993.
  30.  *
  31.  *   Microsoft Knowledge Base, "Extended Error Code Information",
  32.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q74463,
  33.  *    Publication Date:  March 24, 1993.
  34.  *
  35.  *   Programmer's Reference Manual, Microsoft Corporation, Redmond,
  36.  *    Washington, 1986, Document No. 410630014-320-003-1285, pp. 1-20 thru
  37.  *    1-21, pp. 1-34 thru 1-38, p 1-99, pp. 1-121 thru 1-124, pp. 1-216 thru
  38.  *    1-218, pp. 2-1 thru 2-30.
  39.  *
  40.  *   Ray Duncan, _Advanced MS-DOS_, Microsoft Press, Redmond, Washington,
  41.  *    1986, ISBN 0-914845-77-2, pp 89-97, pp 130-133.
  42.  *
  43.  *
  44.  * New editor name:  TDE, the Thomson-Davis Editor.
  45.  * Author:           Frank Davis
  46.  * Date:             June 5, 1991, version 1.0
  47.  * Date:             July 29, 1991, version 1.1
  48.  * Date:             October 5, 1991, version 1.2
  49.  * Date:             January 20, 1992, version 1.3
  50.  * Date:             February 17, 1992, version 1.4
  51.  * Date:             April 1, 1992, version 1.5
  52.  * Date:             June 5, 1992, version 2.0
  53.  * Date:             October 31, 1992, version 2.1
  54.  * Date:             April 1, 1993, version 2.2
  55.  * Date:             June 5, 1993, version 3.0
  56.  * Date:             August 29, 1993, version 3.1
  57.  * Date:             November 13, 1993, version 3.2
  58.  *
  59.  * This code is released into the public domain, Frank Davis.
  60.  *    You may distribute it freely.
  61.  */
  62.  
  63. #include "tdestr.h"
  64. #include "common.h"
  65. #include "tdefunc.h"
  66. #include "criterr.h"
  67.  
  68. #if defined( __UNIX__ )
  69.  #include <signal.h>
  70. #endif
  71.  
  72. /*
  73.  * Save the area of the screen that will display the Critical
  74.  * Error info.  CEH_WIDTH and CEH_HEIGHT are the dimensions of critical
  75.  * error screen in criterr.h.   CEH_OFFSET is the offset into the screen
  76.  * refresh buffer.  Let the compiler calculate the offset, 'cause the offset
  77.  * don't change anyway.
  78.  */
  79. #define CEH_ROW         5
  80. #define CEH_COL         6
  81. #define CEH_WIDTH       69
  82. #define CEH_HEIGHT      15
  83.  
  84. #define CEH_OFFSET      ((CEH_ROW * 160) + (CEH_COL * 2))
  85.  
  86. #define NEXT_LINE       160
  87.  
  88.  
  89. #if defined( __UNIX__ )
  90. /*
  91.  **********************************************************************
  92.  ******************************  PART 1  ******************************
  93.  **********************************************************************
  94.  *
  95.  * Let's try to make unix have the look and feel of a PC.
  96.  */
  97.  
  98. /*
  99.  * buffer for ceh info screen.  make this a chtype array
  100.  */
  101. chtype ceh_buffer[CEH_HEIGHT][CEH_WIDTH];   /* chtype is defined in curses.h */
  102.  
  103. /*
  104.  * Name:    crit_err_handler
  105.  * Purpose: Show user something is wrong and get a response
  106.  * Date:    November 13, 1993
  107.  */
  108. void  crit_err_handler( int sig )
  109. {
  110. int  attr;
  111. int  rc;
  112. int  c;
  113.  
  114.    attr = g_display.help_color;
  115.    save_area( (chtype *)ceh_buffer );
  116.    show_error_screen( CEH_ROW, CEH_COL );
  117.    switch (sig) {
  118.       case SIGABRT :
  119.          s_output( sigabrt_1,  8, 23, attr );
  120.          s_output( sigabrt_2,  9, 23, attr );
  121.          s_output( sigabrt_3, 10, 23, attr );
  122.          break;
  123.       case SIGALRM :
  124.          s_output( sigalrm_1,  8, 23, attr );
  125.          s_output( sigalrm_2,  9, 23, attr );
  126.          break;
  127.       case SIGCHLD :
  128.          s_output( sigchld_1,  8, 23, attr );
  129.          s_output( sigchld_2,  9, 23, attr );
  130.          s_output( sigchld_3, 10, 23, attr );
  131.          s_output( sigchld_4, 11, 23, attr );
  132.          break;
  133.       case SIGCONT :
  134.          s_output( sigcont_1,  8, 23, attr );
  135.          s_output( sigcont_2,  9, 23, attr );
  136.          s_output( sigcont_3, 10, 23, attr );
  137.          s_output( sigcont_4, 11, 23, attr );
  138.          break;
  139.       case SIGFPE :
  140.          s_output( sigfpe_1,  8, 23, attr );
  141.          s_output( sigfpe_2,  9, 23, attr );
  142.          s_output( sigfpe_3, 10, 23, attr );
  143.          break;
  144.       case SIGHUP :
  145.          s_output( sighup_1,  8, 23, attr );
  146.          s_output( sighup_2,  9, 23, attr );
  147.          s_output( sighup_3, 10, 23, attr );
  148.          break;
  149.       case SIGILL :
  150.          s_output( sigill_1,  8, 23, attr );
  151.          s_output( sigill_2,  9, 23, attr );
  152.          s_output( sigill_3, 10, 23, attr );
  153.          break;
  154.       case SIGINT :
  155.          s_output( sigint_1,  8, 23, attr );
  156.          s_output( sigint_2,  9, 23, attr );
  157.          s_output( sigint_3, 10, 23, attr );
  158.          break;
  159.       case SIGIO :
  160.          s_output( sigio_1,  8, 23, attr );
  161.          s_output( sigio_2,  9, 23, attr );
  162.          s_output( sigio_3, 10, 23, attr );
  163.          break;
  164. /*
  165.  * SIGIOT and SIGABRT share same signal in linux????, Frank
  166.  *
  167.       case SIGIOT :
  168.          s_output( sigiot_1,  8, 23, attr );
  169.          s_output( sigiot_2,  9, 23, attr );
  170.          s_output( sigiot_3, 10, 23, attr );
  171.          break;
  172. */
  173.       case SIGKILL :
  174.          s_output( sigkill_1,  8, 23, attr );
  175.          s_output( sigkill_2,  9, 23, attr );
  176.          s_output( sigkill_3, 10, 23, attr );
  177.          break;
  178.       case SIGPIPE :
  179.          s_output( sigpipe_1,  8, 23, attr );
  180.          s_output( sigpipe_2,  9, 23, attr );
  181.          s_output( sigpipe_3, 10, 23, attr );
  182.          break;
  183. /*
  184.  * SIGPOLL, SIGIO, and SIGURG share the same signal in linux???, Frank
  185.  *
  186.       case SIGPOLL :
  187.          s_output( sigpoll_1,  8, 23, attr );
  188.          s_output( sigpoll_2,  9, 23, attr );
  189.          break;
  190.  */
  191.       /*
  192.        * is TDE supposed to catch profiler signals?
  193.       case SIGPROF :
  194.          break;
  195.       */
  196.       case SIGPWR :
  197.          s_output( sigpwr_1,  8, 23, attr );
  198.          s_output( sigpwr_2,  9, 23, attr );
  199.          s_output( sigpwr_3, 10, 23, attr );
  200.          break;
  201.       case SIGQUIT :
  202.          s_output( sigquit_1,  8, 23, attr );
  203.          s_output( sigquit_2,  9, 23, attr );
  204.          s_output( sigquit_3, 10, 23, attr );
  205.          break;
  206.       case SIGSEGV :
  207.          s_output( sigsegv_1,  8, 23, attr );
  208.          s_output( sigsegv_2,  9, 23, attr );
  209.          s_output( sigsegv_3, 10, 23, attr );
  210.          break;
  211.       case SIGSTOP :
  212.          s_output( sigstop_1,  8, 23, attr );
  213.          s_output( sigstop_2,  9, 23, attr );
  214.          s_output( sigstop_3, 10, 23, attr );
  215.          break;
  216.       case SIGTERM :
  217.          s_output( sigterm_1,  8, 23, attr );
  218.          s_output( sigterm_2,  9, 23, attr );
  219.          s_output( sigterm_3, 10, 23, attr );
  220.          break;
  221.       case SIGTRAP :
  222.          s_output( sigtrap_1,  8, 23, attr );
  223.          s_output( sigtrap_2,  9, 23, attr );
  224.          s_output( sigtrap_3, 10, 23, attr );
  225.          break;
  226.       case SIGTSTP :
  227.          s_output( sigtstp_1,  8, 23, attr );
  228.          s_output( sigtstp_2,  9, 23, attr );
  229.          s_output( sigtstp_3, 10, 23, attr );
  230.          break;
  231.       case SIGTTIN :
  232.          s_output( sigttin_1,  8, 23, attr );
  233.          s_output( sigttin_2,  9, 23, attr );
  234.          s_output( sigttin_3, 10, 23, attr );
  235.          break;
  236.       case SIGTTOU :
  237.          s_output( sigttou_1,  8, 23, attr );
  238.          s_output( sigttou_2,  9, 23, attr );
  239.          s_output( sigttou_3, 10, 23, attr );
  240.          break;
  241. /*
  242.  * SIGPOLL, SIGIO, and SIGURG share the same signal in linux???, Frank
  243.  *
  244.       case SIGURG  :
  245.          s_output( sigurg_1,  8, 23, attr );
  246.          s_output( sigurg_2,  9, 23, attr );
  247.          s_output( sigurg_3, 10, 23, attr );
  248.          break;
  249.  */
  250.       case SIGUSR1 :
  251.          s_output( sigusr1_1,  8, 23, attr );
  252.          s_output( sigusr1_2,  9, 23, attr );
  253.          s_output( sigusr1_3, 10, 23, attr );
  254.          break;
  255.       case SIGUSR2 :
  256.          s_output( sigusr2_1,  8, 23, attr );
  257.          s_output( sigusr2_2,  9, 23, attr );
  258.          s_output( sigusr2_3, 10, 23, attr );
  259.          break;
  260.       case SIGVTALRM :
  261.          s_output( sigvtalrm_1,  8, 23, attr );
  262.          s_output( sigvtalrm_2,  9, 23, attr );
  263.          break;
  264.       case SIGWINCH :
  265.          s_output( sigwinch_1,  8, 23, attr );
  266.          s_output( sigwinch_2,  9, 23, attr );
  267.          s_output( sigwinch_3, 10, 23, attr );
  268.          break;
  269.       case SIGXCPU :
  270.          s_output( sigxcpu_1,  8, 23, attr );
  271.          s_output( sigxcpu_2,  9, 23, attr );
  272.          s_output( sigxcpu_3, 10, 23, attr );
  273.          break;
  274.       case SIGXFSZ :
  275.          s_output( sigxfsz_1,  8, 23, attr );
  276.          s_output( sigxfsz_2,  9, 23, attr );
  277.          s_output( sigxfsz_3, 10, 23, attr );
  278.          break;
  279.       default :
  280.          break;
  281.    }
  282.  
  283.    xygoto( 60, 17 );
  284.    do
  285.       c = getanswerkey( );
  286.    while (c != L_FAIL  &&  c != L_RETRY  &&  c != L_ABORT);
  287.    switch ( c ) {
  288.       case L_ABORT :
  289.          rc = ABORT;
  290.          break;
  291.       case L_FAIL :
  292.          rc = FAIL;
  293.          break;
  294.       case L_RETRY :
  295.       default :
  296.          rc = RETRY;
  297.          break;
  298.    }
  299.    restore_area( (chtype *)ceh_buffer );
  300. }
  301.  
  302.  
  303. /*
  304.  * Name:    show_error_screen
  305.  * Purpose: Display error screen in window
  306.  * Date:    November 13, 1993
  307.  * Passed:  row: line to display ceh screen
  308.  *          col: column to begin display ceh screen
  309.  */
  310. void show_error_screen( int row, int col )
  311. {
  312. char **p;
  313.  
  314.  
  315.    for (p=criterr_screen; *p != NULL; p++, row++)
  316.       s_output( *p, row, col, g_display.help_color );
  317. }
  318.  
  319.  
  320. /*
  321.  * Name:    save_area
  322.  * Purpose: save a region of the screen
  323.  * Date:    November 13, 1993
  324.  * Passed:  dest: pointer to buffer for contents of screen under ceh
  325.  * Notes:   the source is the screen and the destination is the buffer.
  326.  */
  327. void save_area( chtype *dest )
  328. {
  329. int hgt;
  330. int wid;
  331. int i;
  332.  
  333.    i = 0;
  334.    for (hgt=CEH_HEIGHT; hgt; hgt--)
  335.       for (wid=CEH_WIDTH; wid; wid--)
  336.          dest[i++] = mvinch( hgt + CEH_ROW, wid + CEH_COL );
  337. }
  338.  
  339.  
  340. /*
  341.  * Name:    restore_area
  342.  * Purpose: restore a region of the screen
  343.  * Date:    November 13, 1993
  344.  * Passed:  source: pointer to buffer for contents of screen under ceh
  345.  * Notes:   the source is the buffer and the destination is the screen.
  346.  */
  347. void restore_area( chtype *source )
  348. {
  349. int hgt;
  350. int wid;
  351. register int i;
  352.  
  353.    i = 0;
  354.    for (hgt=CEH_HEIGHT; hgt; hgt--)
  355.       for (wid=CEH_WIDTH; wid; wid--)
  356.          mvaddch( hgt + CEH_ROW, wid + CEH_COL, source[i++] );
  357. }
  358.  
  359. #else
  360.  
  361. /*
  362.  **********************************************************************
  363.  ******************************  PART 2  ******************************
  364.  **********************************************************************
  365.  *
  366.  * DOS critical error handler.
  367.  */
  368.  
  369. /*
  370.  * buffer for ceh info screen.  make this an int array because we
  371.  * need to save character and attribute.
  372.  */
  373. int ceh_buffer[CEH_HEIGHT][CEH_WIDTH];
  374.  
  375.  
  376. /*
  377.  * Name:    crit_err_handler
  378.  * Purpose: Show user something is wrong and get a response
  379.  * Date:    April 1, 1992
  380.  */
  381. int  FAR crit_err_handler( void )
  382. {
  383. int  rc;
  384. int  c;
  385.  
  386.    save_area( (char FAR *)ceh_buffer );
  387.    show_error_screen( CEH_ROW, CEH_COL );
  388.    xygoto( 60, 17 );
  389.    do
  390.       c = getanswerkey( );
  391.    while (c != L_FAIL  &&  c != L_RETRY  &&  c != L_ABORT);
  392.    switch ( c ) {
  393.       case L_ABORT :
  394.          rc = ABORT;
  395.          break;
  396.       case L_FAIL  :
  397.          rc = FAIL;
  398.          break;
  399.       case L_RETRY :
  400.       default :
  401.          rc = RETRY;
  402.          break;
  403.    }
  404.    restore_area( (char FAR *)ceh_buffer );
  405.    return( rc );
  406. }
  407.  
  408.  
  409. /*
  410.  * Name:    show_error_screen
  411.  * Purpose: Display error screen in window
  412.  * Date:    April 1, 1992
  413.  * Passed:  row: line to display ceh screen
  414.  *          col: column to begin display ceh screen
  415.  */
  416. void show_error_screen( int row, int col )
  417. {
  418. char **p;
  419.  
  420.    for (p=criterr_screen; *p != NULL; p++, row++)
  421.       s_output( *p, row, col, g_display.help_color );
  422.    s_output( error_code[ceh.code],    8, 23, g_display.help_color );
  423.    s_output( operation[ceh.rw],       9, 23, g_display.help_color );
  424.    if (ceh.dattr == 0)
  425.       c_output( ceh.drive + 'a',     23, 10, g_display.help_color );
  426.    else
  427.       s_output( critt1,              10, 23, g_display.help_color );
  428.    s_output( ext_err[ceh.extended],  11, 23, g_display.help_color );
  429.    s_output( error_class[ceh.class], 12, 23, g_display.help_color );
  430.    s_output( locus[ceh.locus],       13, 23, g_display.help_color );
  431.    s_output( device_type[ceh.dattr], 14, 23, g_display.help_color );
  432.    s_output( ceh.dattr == 0 ? critt1 : ceh.dname,
  433.                                      15, 23, g_display.help_color );
  434. }
  435.  
  436.  
  437. /*
  438.  * Name:    save_area
  439.  * Purpose: save a region of the screen
  440.  * Date:    April 1, 1992
  441.  * Passed:  dest: pointer to buffer for contents of screen under ceh
  442.  * Notes:   this function does not check for snow.  the source is the screen
  443.  *             and the destination is the buffer.
  444.  */
  445. void save_area( char FAR *dest )
  446. {
  447.  
  448. char FAR *source;
  449. register int hgt;
  450.  
  451.    source = (char FAR *)g_display.display_address + CEH_OFFSET;
  452.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  453.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  454.       source += NEXT_LINE;
  455.       dest += (CEH_WIDTH*2);
  456.    }
  457. }
  458.  
  459.  
  460. /*
  461.  * Name:    restore_area
  462.  * Purpose: restore a region of the screen
  463.  * Date:    April 1, 1992
  464.  * Passed:  source: pointer to buffer for contents of screen under ceh
  465.  * Notes:   this function does not check for snow.  the source is the buffer
  466.  *             and the destination is the screen.
  467.  */
  468. void restore_area( char FAR *source )
  469. {
  470. char FAR *dest;
  471. register int hgt;
  472.  
  473.    dest = (char FAR *)g_display.display_address + CEH_OFFSET;
  474.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  475.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  476.       dest += NEXT_LINE;
  477.       source += (CEH_WIDTH*2);
  478.    }
  479. }
  480. #endif
  481.