1984-11-29 14:22:02 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
1991-09-19 10:38:40 +00:00
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG _NSIG
|
|
|
|
#endif
|
|
|
|
|
1985-01-21 12:47:04 +00:00
|
|
|
/* $Header$ */
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
/* Trap handling */
|
|
|
|
int _trpline; /* BASIC return label */
|
|
|
|
jmp_buf trpbuf;
|
|
|
|
|
|
|
|
_trpset(nr)
|
|
|
|
int nr;
|
|
|
|
{
|
|
|
|
/*debug printf("trap set to %d\n",nr);*/
|
|
|
|
_trpline=nr;
|
|
|
|
}
|
1993-11-17 16:27:44 +00:00
|
|
|
void
|
1984-11-29 14:22:02 +00:00
|
|
|
_trpfatal(i)
|
|
|
|
int i;
|
|
|
|
{
|
|
|
|
extern int _errsym,_erlsym;
|
|
|
|
|
|
|
|
_errsym= i;
|
|
|
|
_setline();
|
|
|
|
if( _trpline == 0)
|
|
|
|
printf("LINE %d: FATAL ERROR: trap %d\n",_erlsym,i);
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("trap occurred %d return %d\n",i,_trpline);
|
|
|
|
#endif
|
|
|
|
_trap();
|
|
|
|
}
|
|
|
|
|
|
|
|
_ini_trp()
|
|
|
|
{
|
|
|
|
/* initialize trap routines */
|
1993-11-17 16:27:44 +00:00
|
|
|
int i;
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
for(i=0;i<NSIG;i++)
|
|
|
|
signal(i,_trpfatal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_settrap(nr)
|
|
|
|
int nr;
|
|
|
|
{
|
|
|
|
_trpline=nr;
|
|
|
|
}
|
|
|
|
_trap()
|
|
|
|
{
|
|
|
|
int line;
|
|
|
|
|
|
|
|
if( _trpline==0) exit(-1);
|
|
|
|
line=_trpline;
|
|
|
|
_trpline=0; /* should be reset by user */
|
|
|
|
_ini_trp();
|
|
|
|
longjmp(trpbuf,line);
|
|
|
|
}
|