2 * Copyright (C) 1984-2021 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;
38 extern long jump_sline_fraction;
40 extern int less_is_more;
43 * Interrupt signal handler.
45 #if MSDOS_COMPILER!=WIN32C
53 LSIGNAL(SIGINT, SIG_ACK);
55 LSIGNAL(SIGINT, u_interrupt);
57 #if MSDOS_COMPILER==DJGPPC
59 * If a keyboard has been hit, it must be Ctrl-C
60 * (as opposed to Ctrl-Break), so consume it.
61 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
69 set_filter_pattern(NULL, 0);
72 intread(); /* May longjmp */
78 * "Stop" (^Z) signal handler.
85 LSIGNAL(SIGTSTP, stop);
94 #define SIG_LESSWINDOW SIGWINCH
97 #define SIG_LESSWINDOW SIGWIND
101 #ifdef SIG_LESSWINDOW
103 * "Window" change handler
110 LSIGNAL(SIG_LESSWINDOW, winch);
117 #if MSDOS_COMPILER==WIN32C
119 * Handle CTRL-C and CTRL-BREAK keys.
121 #define WIN32_LEAN_AND_MEAN
125 wbreak_handler(dwCtrlType)
131 case CTRL_BREAK_EVENT:
134 set_filter_pattern(NULL, 0);
152 * Set up the signal handlers.
161 * Set signal handlers.
163 #if MSDOS_COMPILER==WIN32C
164 SetConsoleCtrlHandler(wbreak_handler, TRUE);
166 (void) LSIGNAL(SIGINT, u_interrupt);
169 (void) LSIGNAL(SIGTSTP, secure ? SIG_IGN : stop);
172 (void) LSIGNAL(SIGWINCH, winch);
175 (void) LSIGNAL(SIGWIND, winch);
178 (void) LSIGNAL(SIGQUIT, SIG_IGN);
181 (void) LSIGNAL(SIGTERM, terminate);
186 * Restore signals to defaults.
188 #if MSDOS_COMPILER==WIN32C
189 SetConsoleCtrlHandler(wbreak_handler, FALSE);
191 (void) LSIGNAL(SIGINT, SIG_DFL);
194 (void) LSIGNAL(SIGTSTP, SIG_DFL);
197 (void) LSIGNAL(SIGWINCH, SIG_IGN);
200 (void) LSIGNAL(SIGWIND, SIG_IGN);
203 (void) LSIGNAL(SIGQUIT, SIG_DFL);
206 (void) LSIGNAL(SIGTERM, SIG_DFL);
212 * Process any signals we have received.
213 * A received signal cause a bit to be set in "sigs".
220 if ((tsignals = sigs) == 0)
225 if (tsignals & S_STOP)
228 * Clean up the terminal.
231 LSIGNAL(SIGTTOU, SIG_IGN);
238 LSIGNAL(SIGTTOU, SIG_DFL);
240 LSIGNAL(SIGTSTP, SIG_DFL);
241 kill(getpid(), SIGTSTP);
244 * Hopefully we'll be back later and resume here...
245 * Reset the terminal and arrange to repaint the
246 * screen when we get back to the main command loop.
248 LSIGNAL(SIGTSTP, stop);
256 if (tsignals & S_WINCH)
258 int old_width, old_height;
260 * Re-execute scrsize() to read the new window size.
262 old_width = sc_width;
263 old_height = sc_height;
265 if (sc_width != old_width || sc_height != old_height)
267 wscroll = (sc_height + 1) / 2;
274 if (tsignals & S_INTERRUPT)
277 quit(QUIT_INTERRUPT);