/*****************************************************************************
* Module to trap ctrl-brk/hardware error and handle them gracefully.	     *
*									     *
* Written by:  Gershon Elber				Ver 1.1, Mar. 1990   *
*****************************************************************************/

#include <signal.h>
#include <stdio.h>
#include "program.h"
#include "inptprsg.h"
#include "ctrl-brk.h"

/*****************************************************************************
* Routine TrapCtrlC gain control if Control C was typed (DOS level):	     *
*****************************************************************************/
static void TrapCtrlC(int Type)
{
    printf("\n*** Break ***\n");
    fflush(stdout);
    SetUpCtrlBrk();

    FlushToEndOfExpr(FALSE);
    longjmp(GlblLongJumpBuffer, 1);
}

/*****************************************************************************
* Routine SetUpCtrlBrk must be called once by main program:		     *
*****************************************************************************/
void SetUpCtrlBrk(void)
{
    signal(SIGINT, TrapCtrlC);
#if defined(__UNIX__) || defined(OS2GCC)
    signal(SIGQUIT, TrapCtrlC);
    signal(SIGKILL, IritExit0);
#endif /* __UNIX__ || OS2GCC */
}
