
/*
 *  BREAK.C
 *
 *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
 *
 *  Internal routine to check for ^C.	NOTE, ^C is cleared before we
 *  write ^C\n because write itself calls chkabort().
 */

#include <exec/types.h>
#include <exec/tasks.h>
#include <exec/execbase.h>
#include <libraries/dos.h>
#include <stdio.h>
#include <stdlib.h>

typedef int (*fptr)();

static int brk();

extern struct ExecBase *SysBase;
static int (*_BrkFunc)() = brk;

void
chkabort()
{
    struct Task *task = SysBase->ThisTask;

    if (task->tc_SigRecvd & SIGBREAKF_CTRL_C) {
	SetSignal(0, SIGBREAKF_CTRL_C);
	if ((*_BrkFunc)()) {
	    write(2, "^C\n", 3);
	    exit(EXIT_FAILURE);
	}
    }
}

static int
brk()
{
    return(1);
}

fptr
onbreak(func)
fptr func;
{
    fptr old = _BrkFunc;

    if (func == NULL) {
	_BrkFunc = brk;
    } else {
	_BrkFunc = func;
    }
    return(old);
}

