2 * Copyright (C) 1984-2002 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information about less, or for information on how to
8 * contact the author, 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 extern int sc_width, sc_height;
32 extern int screen_trashed;
40 * Interrupt signal handler.
48 LSIGNAL(SIGINT, SIG_ACK);
50 LSIGNAL(SIGINT, u_interrupt);
52 #if MSDOS_COMPILER==DJGPPC
54 * If a keyboard has been hit, it must be Ctrl-C
55 * (as opposed to Ctrl-Break), so consume it.
56 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
69 * "Stop" (^Z) signal handler.
76 LSIGNAL(SIGTSTP, stop);
85 * "Window" change handler
92 LSIGNAL(SIGWINCH, winch);
100 * "Window" change handler
107 LSIGNAL(SIGWIND, winch);
115 #if MSDOS_COMPILER==WIN32C
117 * Handle CTRL-C and CTRL-BREAK keys.
122 wbreak_handler(dwCtrlType)
128 case CTRL_BREAK_EVENT:
139 * Set up the signal handlers.
148 * Set signal handlers.
150 (void) LSIGNAL(SIGINT, u_interrupt);
151 #if MSDOS_COMPILER==WIN32C
152 SetConsoleCtrlHandler(wbreak_handler, TRUE);
155 (void) LSIGNAL(SIGTSTP, stop);
158 (void) LSIGNAL(SIGWINCH, winch);
161 (void) LSIGNAL(SIGWIND, winch);
164 (void) LSIGNAL(SIGQUIT, SIG_IGN);
170 * Restore signals to defaults.
172 (void) LSIGNAL(SIGINT, SIG_DFL);
173 #if MSDOS_COMPILER==WIN32C
174 SetConsoleCtrlHandler(wbreak_handler, FALSE);
177 (void) LSIGNAL(SIGTSTP, SIG_DFL);
180 (void) LSIGNAL(SIGWINCH, SIG_IGN);
183 (void) LSIGNAL(SIGWIND, SIG_IGN);
186 (void) LSIGNAL(SIGQUIT, SIG_DFL);
192 * Process any signals we have received.
193 * A received signal cause a bit to be set in "sigs".
198 register int tsignals;
200 if ((tsignals = sigs) == 0)
205 if (tsignals & S_STOP)
208 * Clean up the terminal.
211 LSIGNAL(SIGTTOU, SIG_IGN);
218 LSIGNAL(SIGTTOU, SIG_DFL);
220 LSIGNAL(SIGTSTP, SIG_DFL);
221 kill(getpid(), SIGTSTP);
224 * Hopefully we'll be back later and resume here...
225 * Reset the terminal and arrange to repaint the
226 * screen when we get back to the main command loop.
228 LSIGNAL(SIGTSTP, stop);
236 if (tsignals & S_WINCH)
238 int old_width, old_height;
240 * Re-execute scrsize() to read the new window size.
242 old_width = sc_width;
243 old_height = sc_height;
245 if (sc_width != old_width || sc_height != old_height)
247 wscroll = (sc_height + 1) / 2;
252 if (tsignals & S_INTERRUPT)
256 * {{ You may wish to replace the bell() with
257 * error("Interrupt", NULL_PARG); }}
261 * If we were interrupted while in the "calculating
262 * line numbers" loop, turn off line numbers.
270 error("Line numbers turned off", NULL_PARG);