2 * Copyright (C) 1984-2004 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;
37 extern int quit_on_intr;
41 * Interrupt signal handler.
49 LSIGNAL(SIGINT, SIG_ACK);
51 LSIGNAL(SIGINT, u_interrupt);
53 #if MSDOS_COMPILER==DJGPPC
55 * If a keyboard has been hit, it must be Ctrl-C
56 * (as opposed to Ctrl-Break), so consume it.
57 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
70 * "Stop" (^Z) signal handler.
77 LSIGNAL(SIGTSTP, stop);
86 * "Window" change handler
93 LSIGNAL(SIGWINCH, winch);
101 * "Window" change handler
108 LSIGNAL(SIGWIND, winch);
116 #if MSDOS_COMPILER==WIN32C
118 * Handle CTRL-C and CTRL-BREAK keys.
123 wbreak_handler(dwCtrlType)
129 case CTRL_BREAK_EVENT:
140 * Set up the signal handlers.
149 * Set signal handlers.
151 (void) LSIGNAL(SIGINT, u_interrupt);
152 #if MSDOS_COMPILER==WIN32C
153 SetConsoleCtrlHandler(wbreak_handler, TRUE);
156 (void) LSIGNAL(SIGTSTP, stop);
159 (void) LSIGNAL(SIGWINCH, winch);
162 (void) LSIGNAL(SIGWIND, winch);
165 (void) LSIGNAL(SIGQUIT, SIG_IGN);
171 * Restore signals to defaults.
173 (void) LSIGNAL(SIGINT, SIG_DFL);
174 #if MSDOS_COMPILER==WIN32C
175 SetConsoleCtrlHandler(wbreak_handler, FALSE);
178 (void) LSIGNAL(SIGTSTP, SIG_DFL);
181 (void) LSIGNAL(SIGWINCH, SIG_IGN);
184 (void) LSIGNAL(SIGWIND, SIG_IGN);
187 (void) LSIGNAL(SIGQUIT, SIG_DFL);
193 * Process any signals we have received.
194 * A received signal cause a bit to be set in "sigs".
199 register int tsignals;
201 if ((tsignals = sigs) == 0)
206 if (tsignals & S_STOP)
209 * Clean up the terminal.
212 LSIGNAL(SIGTTOU, SIG_IGN);
219 LSIGNAL(SIGTTOU, SIG_DFL);
221 LSIGNAL(SIGTSTP, SIG_DFL);
222 kill(getpid(), SIGTSTP);
225 * Hopefully we'll be back later and resume here...
226 * Reset the terminal and arrange to repaint the
227 * screen when we get back to the main command loop.
229 LSIGNAL(SIGTSTP, stop);
237 if (tsignals & S_WINCH)
239 int old_width, old_height;
241 * Re-execute scrsize() to read the new window size.
243 old_width = sc_width;
244 old_height = sc_height;
246 if (sc_width != old_width || sc_height != old_height)
248 wscroll = (sc_height + 1) / 2;
253 if (tsignals & S_INTERRUPT)
259 * {{ You may wish to replace the bell() with
260 * error("Interrupt", NULL_PARG); }}
264 * If we were interrupted while in the "calculating
265 * line numbers" loop, turn off line numbers.
273 error("Line numbers turned off", NULL_PARG);