]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/signal.c
2 static char rcsid
[] = "$Id: signal.c,v 1.2 1993/08/02 17:20:21 mycroft Exp $";
6 #include "header.h" /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
7 #define BIT(a) (1<<((a)-1))
8 extern char savefilename
[],wizard
,predostuff
,nosignal
;
9 static s2choose() /* text to be displayed if ^C during intro screen */
11 cursor(1,24); lprcat("Press "); setbold(); lprcat("return"); resetbold();
12 lprcat(" to continue: "); lflush();
16 cntlc() /* what to do for a ^C */
18 if (nosignal
) return; /* don't do anything if inhibited */
19 signal(SIGQUIT
,SIG_IGN
); signal(SIGINT
,SIG_IGN
);
20 quit(); if (predostuff
==1) s2choose(); else showplayer();
22 signal(SIGQUIT
,cntlc
); signal(SIGINT
,cntlc
);
26 * subroutine to save the game if a hangup signal
31 savegame(savefilename
); wizard
=1; died(-257); /* hangup signal */
36 tstop() /* control Y */
38 if (nosignal
) return; /* nothing if inhibited */
39 lcreat((char*)0); clearvt100(); lflush(); signal(SIGTSTP
,SIG_DFL
);
41 /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/
42 sigsetmask(sigblock(0)& ~BIT(SIGTSTP
));
44 kill(getpid(),SIGTSTP
);
46 setupvt100(); signal(SIGTSTP
,tstop
);
47 if (predostuff
==1) s2choose(); else drawscreen();
48 showplayer(); lflush();
53 * subroutine to issue the needed signal traps called from main()
55 static void sigpanic();
56 static void sigill() { sigpanic(SIGILL
); }
57 static void sigtrap() { sigpanic(SIGTRAP
); }
58 static void sigiot() { sigpanic(SIGIOT
); }
59 static void sigemt() { sigpanic(SIGEMT
); }
60 static void sigfpe() { sigpanic(SIGFPE
); }
61 static void sigbus() { sigpanic(SIGBUS
); }
62 static void sigsegv() { sigpanic(SIGSEGV
); }
63 static void sigsys() { sigpanic(SIGSYS
); }
64 static void sigpipe() { sigpanic(SIGPIPE
); }
65 static void sigterm() { sigpanic(SIGTERM
); }
68 signal(SIGQUIT
, cntlc
); signal(SIGINT
, cntlc
);
69 signal(SIGKILL
, SIG_IGN
); signal(SIGHUP
, sgam
);
70 signal(SIGILL
, sigill
); signal(SIGTRAP
, sigtrap
);
71 signal(SIGIOT
, sigiot
); signal(SIGEMT
, sigemt
);
72 signal(SIGFPE
, sigfpe
); signal(SIGBUS
, sigbus
);
73 signal(SIGSEGV
, sigsegv
); signal(SIGSYS
, sigsys
);
74 signal(SIGPIPE
, sigpipe
); signal(SIGTERM
, sigterm
);
76 signal(SIGTSTP
,tstop
); signal(SIGSTOP
,tstop
);
80 #ifdef BSD /* for BSD UNIX? */
82 static char *signame
[NSIG
] = { "",
83 "SIGHUP", /* 1 hangup */
84 "SIGINT", /* 2 interrupt */
85 "SIGQUIT", /* 3 quit */
86 "SIGILL", /* 4 illegal instruction (not reset when caught) */
87 "SIGTRAP", /* 5 trace trap (not reset when caught) */
88 "SIGIOT", /* 6 IOT instruction */
89 "SIGEMT", /* 7 EMT instruction */
90 "SIGFPE", /* 8 floating point exception */
91 "SIGKILL", /* 9 kill (cannot be caught or ignored) */
92 "SIGBUS", /* 10 bus error */
93 "SIGSEGV", /* 11 segmentation violation */
94 "SIGSYS", /* 12 bad argument to system call */
95 "SIGPIPE", /* 13 write on a pipe with no one to read it */
96 "SIGALRM", /* 14 alarm clock */
97 "SIGTERM", /* 15 software termination signal from kill */
98 "SIGURG", /* 16 urgent condition on IO channel */
99 "SIGSTOP", /* 17 sendable stop signal not from tty */
100 "SIGTSTP", /* 18 stop signal from tty */
101 "SIGCONT", /* 19 continue a stopped process */
102 "SIGCHLD", /* 20 to parent on child stop or exit */
103 "SIGTTIN", /* 21 to readers pgrp upon background tty read */
104 "SIGTTOU", /* 22 like TTIN for output if (tp->t_local<OSTOP) */
105 "SIGIO", /* 23 input/output possible signal */
106 "SIGXCPU", /* 24 exceeded CPU time limit */
107 "SIGXFSZ", /* 25 exceeded file size limit */
108 "SIGVTALRM",/* 26 virtual time alarm */
109 "SIGPROF", /* 27 profiling time alarm */
112 #else BSD /* for system V? */
114 static char *signame
[NSIG
] = { "",
115 "SIGHUP", /* 1 hangup */
116 "SIGINT", /* 2 interrupt */
117 "SIGQUIT", /* 3 quit */
118 "SIGILL", /* 4 illegal instruction (not reset when caught) */
119 "SIGTRAP", /* 5 trace trap (not reset when caught) */
120 "SIGIOT", /* 6 IOT instruction */
121 "SIGEMT", /* 7 EMT instruction */
122 "SIGFPE", /* 8 floating point exception */
123 "SIGKILL", /* 9 kill (cannot be caught or ignored) */
124 "SIGBUS", /* 10 bus error */
125 "SIGSEGV", /* 11 segmentation violation */
126 "SIGSYS", /* 12 bad argument to system call */
127 "SIGPIPE", /* 13 write on a pipe with no one to read it */
128 "SIGALRM", /* 14 alarm clock */
129 "SIGTERM", /* 15 software termination signal from kill */
130 "SIGUSR1", /* 16 user defines signal 1 */
131 "SIGUSR2", /* 17 user defines signal 2 */
132 "SIGCLD", /* 18 child death */
133 "SIGPWR", /* 19 power fail */
134 "","","","","","","","","","","","" };
139 * routine to process a fatal error signal
147 sprintf(buf
,"\nLarn - Panic! Signal %d received [%s]",sig
,signame
[sig
]);
148 write(2,buf
,strlen(buf
)); sleep(2);
150 savegame(savefilename
);
151 kill(getpid(),sig
); /* this will terminate us */