2 * Copyright (C) 1984-2011 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;
38 extern int less_is_more;
39 extern long jump_sline_fraction;
42 * Interrupt signal handler.
51 LSIGNAL(SIGINT, SIG_ACK);
53 LSIGNAL(SIGINT, u_interrupt);
55 #if MSDOS_COMPILER==DJGPPC
57 * If a keyboard has been hit, it must be Ctrl-C
58 * (as opposed to Ctrl-Break), so consume it.
59 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
67 intread(); /* May longjmp */
72 * "Stop" (^Z) signal handler.
79 LSIGNAL(SIGTSTP, stop);
88 * "Window" change handler
95 LSIGNAL(SIGWINCH, winch);
103 * "Window" change handler
110 LSIGNAL(SIGWIND, winch);
118 #if MSDOS_COMPILER==WIN32C
120 * Handle CTRL-C and CTRL-BREAK keys.
125 wbreak_handler(dwCtrlType)
131 case CTRL_BREAK_EVENT:
142 * Set up the signal handlers.
151 * Set signal handlers.
153 (void) LSIGNAL(SIGINT, u_interrupt);
154 #if MSDOS_COMPILER==WIN32C
155 SetConsoleCtrlHandler(wbreak_handler, TRUE);
158 (void) LSIGNAL(SIGTSTP, stop);
161 (void) LSIGNAL(SIGWINCH, winch);
164 (void) LSIGNAL(SIGWIND, winch);
167 (void) LSIGNAL(SIGQUIT, SIG_IGN);
172 * Restore signals to defaults.
174 (void) LSIGNAL(SIGINT, SIG_DFL);
175 #if MSDOS_COMPILER==WIN32C
176 SetConsoleCtrlHandler(wbreak_handler, FALSE);
179 (void) LSIGNAL(SIGTSTP, SIG_DFL);
182 (void) LSIGNAL(SIGWINCH, SIG_IGN);
185 (void) LSIGNAL(SIGWIND, SIG_IGN);
188 (void) LSIGNAL(SIGQUIT, SIG_DFL);
194 * Process any signals we have received.
195 * A received signal cause a bit to be set in "sigs".
200 register int tsignals;
202 if ((tsignals = sigs) == 0)
207 if (tsignals & S_STOP)
210 * Clean up the terminal.
213 LSIGNAL(SIGTTOU, SIG_IGN);
220 LSIGNAL(SIGTTOU, SIG_DFL);
222 LSIGNAL(SIGTSTP, SIG_DFL);
223 kill(getpid(), SIGTSTP);
226 * Hopefully we'll be back later and resume here...
227 * Reset the terminal and arrange to repaint the
228 * screen when we get back to the main command loop.
230 LSIGNAL(SIGTSTP, stop);
238 if (tsignals & S_WINCH)
240 int old_width, old_height;
242 * Re-execute scrsize() to read the new window size.
244 old_width = sc_width;
245 old_height = sc_height;
247 if (sc_width != old_width || sc_height != old_height)
249 wscroll = (sc_height + 1) / 2;
256 if (tsignals & S_INTERRUPT)
259 quit(QUIT_INTERRUPT);