2 * Copyright (C) 1984-2020 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, see the README file.
13 * Routines dealing with signals.
15 * A signal usually merely causes a bit to be set in the "signals" word.
16 * At some convenient time, the mainline code checks to see if any
17 * signals need processing by calling psignal().
18 * If we happen to be reading from a file [in iread()] at the time
19 * the signal is received, we call intread to interrupt the iread.
26 * "sigs" contains bits indicating signals which need to be processed.
30 extern int sc_width, sc_height;
31 extern int screen_trashed;
36 extern int quit_on_intr;
37 extern int less_is_more;
38 extern long jump_sline_fraction;
41 * Interrupt signal handler.
43 #if MSDOS_COMPILER!=WIN32C
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 */
73 * "Stop" (^Z) signal handler.
80 LSIGNAL(SIGTSTP, stop);
89 #define SIG_LESSWINDOW SIGWINCH
92 #define SIG_LESSWINDOW SIGWIND
98 * "Window" change handler
105 LSIGNAL(SIG_LESSWINDOW, winch);
112 #if MSDOS_COMPILER==WIN32C
114 * Handle CTRL-C and CTRL-BREAK keys.
116 #define WIN32_LEAN_AND_MEAN
120 wbreak_handler(dwCtrlType)
126 case CTRL_BREAK_EVENT:
144 * Set up the signal handlers.
153 * Set signal handlers.
155 #if MSDOS_COMPILER==WIN32C
156 SetConsoleCtrlHandler(wbreak_handler, TRUE);
158 (void) LSIGNAL(SIGINT, u_interrupt);
161 (void) LSIGNAL(SIGTSTP, stop);
164 (void) LSIGNAL(SIGWINCH, winch);
167 (void) LSIGNAL(SIGWIND, winch);
170 (void) LSIGNAL(SIGQUIT, SIG_IGN);
173 (void) LSIGNAL(SIGTERM, terminate);
178 * Restore signals to defaults.
180 #if MSDOS_COMPILER==WIN32C
181 SetConsoleCtrlHandler(wbreak_handler, FALSE);
183 (void) LSIGNAL(SIGINT, SIG_DFL);
186 (void) LSIGNAL(SIGTSTP, SIG_DFL);
189 (void) LSIGNAL(SIGWINCH, SIG_IGN);
192 (void) LSIGNAL(SIGWIND, SIG_IGN);
195 (void) LSIGNAL(SIGQUIT, SIG_DFL);
198 (void) LSIGNAL(SIGTERM, SIG_DFL);
204 * Process any signals we have received.
205 * A received signal cause a bit to be set in "sigs".
212 if ((tsignals = sigs) == 0)
217 if (tsignals & S_STOP)
220 * Clean up the terminal.
223 LSIGNAL(SIGTTOU, SIG_IGN);
230 LSIGNAL(SIGTTOU, SIG_DFL);
232 LSIGNAL(SIGTSTP, SIG_DFL);
233 kill(getpid(), SIGTSTP);
236 * Hopefully we'll be back later and resume here...
237 * Reset the terminal and arrange to repaint the
238 * screen when we get back to the main command loop.
240 LSIGNAL(SIGTSTP, stop);
248 if (tsignals & S_WINCH)
250 int old_width, old_height;
252 * Re-execute scrsize() to read the new window size.
254 old_width = sc_width;
255 old_height = sc_height;
257 if (sc_width != old_width || sc_height != old_height)
259 wscroll = (sc_height + 1) / 2;
266 if (tsignals & S_INTERRUPT)
269 quit(QUIT_INTERRUPT);