2 * Copyright (C) 1984-2019 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;
36 extern long jump_sline_fraction;
39 * Interrupt signal handler.
41 #if MSDOS_COMPILER!=WIN32C
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.)
63 intread(); /* May longjmp */
69 * "Stop" (^Z) signal handler.
76 LSIGNAL(SIGTSTP, stop);
85 #define SIG_LESSWINDOW SIGWINCH
88 #define SIG_LESSWINDOW SIGWIND
94 * "Window" change handler
101 LSIGNAL(SIG_LESSWINDOW, winch);
108 #if MSDOS_COMPILER==WIN32C
110 * Handle CTRL-C and CTRL-BREAK keys.
112 #define WIN32_LEAN_AND_MEAN
116 wbreak_handler(dwCtrlType)
122 case CTRL_BREAK_EVENT:
140 * Set up the signal handlers.
149 * Set signal handlers.
151 #if MSDOS_COMPILER==WIN32C
152 SetConsoleCtrlHandler(wbreak_handler, TRUE);
154 (void) LSIGNAL(SIGINT, u_interrupt);
157 (void) LSIGNAL(SIGTSTP, stop);
160 (void) LSIGNAL(SIGWINCH, winch);
163 (void) LSIGNAL(SIGWIND, winch);
166 (void) LSIGNAL(SIGQUIT, SIG_IGN);
169 (void) LSIGNAL(SIGTERM, terminate);
174 * Restore signals to defaults.
176 #if MSDOS_COMPILER==WIN32C
177 SetConsoleCtrlHandler(wbreak_handler, FALSE);
179 (void) LSIGNAL(SIGINT, SIG_DFL);
182 (void) LSIGNAL(SIGTSTP, SIG_DFL);
185 (void) LSIGNAL(SIGWINCH, SIG_IGN);
188 (void) LSIGNAL(SIGWIND, SIG_IGN);
191 (void) LSIGNAL(SIGQUIT, SIG_DFL);
194 (void) LSIGNAL(SIGTERM, SIG_DFL);
200 * Process any signals we have received.
201 * A received signal cause a bit to be set in "sigs".
208 if ((tsignals = sigs) == 0)
213 if (tsignals & S_STOP)
216 * Clean up the terminal.
219 LSIGNAL(SIGTTOU, SIG_IGN);
226 LSIGNAL(SIGTTOU, SIG_DFL);
228 LSIGNAL(SIGTSTP, SIG_DFL);
229 kill(getpid(), SIGTSTP);
232 * Hopefully we'll be back later and resume here...
233 * Reset the terminal and arrange to repaint the
234 * screen when we get back to the main command loop.
236 LSIGNAL(SIGTSTP, stop);
244 if (tsignals & S_WINCH)
246 int old_width, old_height;
248 * Re-execute scrsize() to read the new window size.
250 old_width = sc_width;
251 old_height = sc_height;
253 if (sc_width != old_width || sc_height != old_height)
255 wscroll = (sc_height + 1) / 2;
262 if (tsignals & S_INTERRUPT)
265 quit(QUIT_INTERRUPT);