2 * Copyright (C) 1984-2022 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.
12 * Routines dealing with signals.
14 * A signal usually merely causes a bit to be set in the "signals" word.
15 * At some convenient time, the mainline code checks to see if any
16 * signals need processing by calling psignal().
17 * If we happen to be reading from a file [in iread()] at the time
18 * the signal is received, we call intread to interrupt the iread.
25 * "sigs" contains bits indicating signals which need to be processed.
29 extern int sc_width, sc_height;
30 extern int screen_trashed;
35 extern int quit_on_intr;
37 extern long jump_sline_fraction;
40 * Interrupt signal handler.
42 #if MSDOS_COMPILER!=WIN32C
50 LSIGNAL(SIGINT, SIG_ACK);
52 LSIGNAL(SIGINT, u_interrupt);
54 #if MSDOS_COMPILER==DJGPPC
56 * If a keyboard has been hit, it must be Ctrl-C
57 * (as opposed to Ctrl-Break), so consume it.
58 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
64 set_filter_pattern(NULL, 0);
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:
129 set_filter_pattern(NULL, 0);
147 * Set up the signal handlers.
156 * Set signal handlers.
158 #if MSDOS_COMPILER==WIN32C
159 SetConsoleCtrlHandler(wbreak_handler, TRUE);
161 (void) LSIGNAL(SIGINT, u_interrupt);
164 (void) LSIGNAL(SIGTSTP, secure ? SIG_IGN : stop);
167 (void) LSIGNAL(SIGWINCH, winch);
170 (void) LSIGNAL(SIGWIND, winch);
173 (void) LSIGNAL(SIGQUIT, SIG_IGN);
176 (void) LSIGNAL(SIGTERM, terminate);
181 * Restore signals to defaults.
183 #if MSDOS_COMPILER==WIN32C
184 SetConsoleCtrlHandler(wbreak_handler, FALSE);
186 (void) LSIGNAL(SIGINT, SIG_DFL);
189 (void) LSIGNAL(SIGTSTP, SIG_DFL);
192 (void) LSIGNAL(SIGWINCH, SIG_IGN);
195 (void) LSIGNAL(SIGWIND, SIG_IGN);
198 (void) LSIGNAL(SIGQUIT, SIG_DFL);
201 (void) LSIGNAL(SIGTERM, SIG_DFL);
207 * Process any signals we have received.
208 * A received signal cause a bit to be set in "sigs".
215 if ((tsignals = sigs) == 0)
220 if (tsignals & S_STOP)
223 * Clean up the terminal.
226 LSIGNAL(SIGTTOU, SIG_IGN);
233 LSIGNAL(SIGTTOU, SIG_DFL);
235 LSIGNAL(SIGTSTP, SIG_DFL);
236 kill(getpid(), SIGTSTP);
239 * Hopefully we'll be back later and resume here...
240 * Reset the terminal and arrange to repaint the
241 * screen when we get back to the main command loop.
243 LSIGNAL(SIGTSTP, stop);
251 if (tsignals & S_WINCH)
253 int old_width, old_height;
255 * Re-execute scrsize() to read the new window size.
257 old_width = sc_width;
258 old_height = sc_height;
260 if (sc_width != old_width || sc_height != old_height)
262 wscroll = (sc_height + 1) / 2;
269 if (tsignals & S_INTERRUPT)
272 quit(QUIT_INTERRUPT);