1 /* $NetBSD: signal.c,v 1.4 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
14 * Routines dealing with signals.
16 * A signal usually merely causes a bit to be set in the "signals" word.
17 * At some convenient time, the mainline code checks to see if any
18 * signals need processing by calling psignal().
19 * If we happen to be reading from a file [in iread()] at the time
20 * the signal is received, we call intread to interrupt the iread.
27 * "sigs" contains bits indicating signals which need to be processed.
31 static RETSIGTYPE u_interrupt
__P((int));
32 static RETSIGTYPE stop
__P((int));
33 #if MSDOS_COMPILER==WIN32C
34 static BOOL WINAPI wbreak_handler
__P((DWORD
));
37 extern int sc_width
, sc_height
;
38 extern int screen_trashed
;
43 extern int quit_on_intr
;
44 extern long jump_sline_fraction
;
47 * Interrupt signal handler.
56 LSIGNAL(SIGINT
, SIG_ACK
);
58 LSIGNAL(SIGINT
, u_interrupt
);
60 #if MSDOS_COMPILER==DJGPPC
62 * If a keyboard has been hit, it must be Ctrl-C
63 * (as opposed to Ctrl-Break), so consume it.
64 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
70 intread(); /* May longjmp */
75 * "Stop" (^Z) signal handler.
82 LSIGNAL(SIGTSTP
, stop
);
91 * "Window" change handler
98 LSIGNAL(SIGWINCH
, winch
);
106 * "Window" change handler
113 LSIGNAL(SIGWIND
, winch
);
121 #if MSDOS_COMPILER==WIN32C
123 * Handle CTRL-C and CTRL-BREAK keys.
128 wbreak_handler(dwCtrlType
)
134 case CTRL_BREAK_EVENT
:
145 * Set up the signal handlers.
154 * Set signal handlers.
156 (void) LSIGNAL(SIGINT
, u_interrupt
);
157 #if MSDOS_COMPILER==WIN32C
158 SetConsoleCtrlHandler(wbreak_handler
, TRUE
);
161 (void) LSIGNAL(SIGTSTP
, stop
);
164 (void) LSIGNAL(SIGWINCH
, winch
);
167 (void) LSIGNAL(SIGWIND
, winch
);
170 (void) LSIGNAL(SIGQUIT
, SIG_IGN
);
175 * Restore signals to defaults.
177 (void) LSIGNAL(SIGINT
, SIG_DFL
);
178 #if MSDOS_COMPILER==WIN32C
179 SetConsoleCtrlHandler(wbreak_handler
, FALSE
);
182 (void) LSIGNAL(SIGTSTP
, SIG_DFL
);
185 (void) LSIGNAL(SIGWINCH
, SIG_IGN
);
188 (void) LSIGNAL(SIGWIND
, SIG_IGN
);
191 (void) LSIGNAL(SIGQUIT
, SIG_DFL
);
197 * Process any signals we have received.
198 * A received signal cause a bit to be set in "sigs".
203 register int tsignals
;
205 if ((tsignals
= sigs
) == 0)
210 if (tsignals
& S_STOP
)
213 * Clean up the terminal.
216 LSIGNAL(SIGTTOU
, SIG_IGN
);
223 LSIGNAL(SIGTTOU
, SIG_DFL
);
225 LSIGNAL(SIGTSTP
, SIG_DFL
);
226 kill(getpid(), SIGTSTP
);
229 * Hopefully we'll be back later and resume here...
230 * Reset the terminal and arrange to repaint the
231 * screen when we get back to the main command loop.
233 LSIGNAL(SIGTSTP
, stop
);
241 if (tsignals
& S_WINCH
)
243 int old_width
, old_height
;
245 * Re-execute scrsize() to read the new window size.
247 old_width
= sc_width
;
248 old_height
= sc_height
;
250 if (sc_width
!= old_width
|| sc_height
!= old_height
)
252 wscroll
= (sc_height
+ 1) / 2;
259 if (tsignals
& S_INTERRUPT
)
262 quit(QUIT_INTERRUPT
);