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