]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/signal.c
2 static char rcsid
[] = "$NetBSD: signal.c,v 1.5 1995/12/21 11:27:51 mycroft Exp $";
6 #include "header.h" /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
9 #define BIT(a) (1<<((a)-1))
10 extern char savefilename
[],wizard
,predostuff
,nosignal
;
11 static s2choose() /* text to be displayed if ^C during intro screen */
13 cursor(1,24); lprcat("Press "); setbold(); lprcat("return"); resetbold();
14 lprcat(" to continue: "); lflush();
18 cntlc() /* what to do for a ^C */
20 if (nosignal
) return; /* don't do anything if inhibited */
21 signal(SIGQUIT
,SIG_IGN
); signal(SIGINT
,SIG_IGN
);
22 quit(); if (predostuff
==1) s2choose(); else showplayer();
24 signal(SIGQUIT
,cntlc
); signal(SIGINT
,cntlc
);
28 * subroutine to save the game if a hangup signal
33 savegame(savefilename
); wizard
=1; died(-257); /* hangup signal */
38 tstop() /* control Y */
40 if (nosignal
) return; /* nothing if inhibited */
41 lcreat((char*)0); clearvt100(); lflush(); signal(SIGTSTP
,SIG_DFL
);
43 /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/
44 sigsetmask(sigblock(0)& ~BIT(SIGTSTP
));
46 kill(getpid(),SIGTSTP
);
48 setupvt100(); signal(SIGTSTP
,tstop
);
49 if (predostuff
==1) s2choose(); else drawscreen();
50 showplayer(); lflush();
55 * subroutine to issue the needed signal traps called from main()
57 static void sigpanic();
60 signal(SIGQUIT
, cntlc
); signal(SIGINT
, cntlc
);
61 signal(SIGKILL
, SIG_IGN
); signal(SIGHUP
, sgam
);
62 signal(SIGILL
, sigpanic
); signal(SIGTRAP
, sigpanic
);
63 signal(SIGIOT
, sigpanic
); signal(SIGEMT
, sigpanic
);
64 signal(SIGFPE
, sigpanic
); signal(SIGBUS
, sigpanic
);
65 signal(SIGSEGV
, sigpanic
); signal(SIGSYS
, sigpanic
);
66 signal(SIGPIPE
, sigpanic
); signal(SIGTERM
, sigpanic
);
68 signal(SIGTSTP
,tstop
); signal(SIGSTOP
,tstop
);
73 * routine to process a fatal error signal
81 sprintf(buf
,"\nLarn - Panic! Signal %d received [SIG%s]",sig
,sys_signame
[sig
]);
82 write(2,buf
,strlen(buf
)); sleep(2);
84 savegame(savefilename
);
85 kill(getpid(),sig
); /* this will terminate us */