2 * Copyright (C) 1984-2017 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.
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.)
66 intread(); /* May longjmp */
71 * "Stop" (^Z) signal handler.
78 LSIGNAL(SIGTSTP, stop);
87 #define SIG_LESSWINDOW SIGWINCH
90 #define SIG_LESSWINDOW SIGWIND
96 * "Window" change handler
103 LSIGNAL(SIG_LESSWINDOW, winch);
110 #if MSDOS_COMPILER==WIN32C
112 * Handle CTRL-C and CTRL-BREAK keys.
117 wbreak_handler(dwCtrlType)
123 case CTRL_BREAK_EVENT:
141 * Set up the signal handlers.
150 * Set signal handlers.
152 (void) LSIGNAL(SIGINT, u_interrupt);
153 #if MSDOS_COMPILER==WIN32C
154 SetConsoleCtrlHandler(wbreak_handler, TRUE);
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 (void) LSIGNAL(SIGINT, SIG_DFL);
177 #if MSDOS_COMPILER==WIN32C
178 SetConsoleCtrlHandler(wbreak_handler, FALSE);
181 (void) LSIGNAL(SIGTSTP, SIG_DFL);
184 (void) LSIGNAL(SIGWINCH, SIG_IGN);
187 (void) LSIGNAL(SIGWIND, SIG_IGN);
190 (void) LSIGNAL(SIGQUIT, SIG_DFL);
193 (void) LSIGNAL(SIGTERM, SIG_DFL);
199 * Process any signals we have received.
200 * A received signal cause a bit to be set in "sigs".
207 if ((tsignals = sigs) == 0)
212 if (tsignals & S_STOP)
215 * Clean up the terminal.
218 LSIGNAL(SIGTTOU, SIG_IGN);
225 LSIGNAL(SIGTTOU, SIG_DFL);
227 LSIGNAL(SIGTSTP, SIG_DFL);
228 kill(getpid(), SIGTSTP);
231 * Hopefully we'll be back later and resume here...
232 * Reset the terminal and arrange to repaint the
233 * screen when we get back to the main command loop.
235 LSIGNAL(SIGTSTP, stop);
243 if (tsignals & S_WINCH)
245 int old_width, old_height;
247 * Re-execute scrsize() to read the new window size.
249 old_width = sc_width;
250 old_height = sc_height;
252 if (sc_width != old_width || sc_height != old_height)
254 wscroll = (sc_height + 1) / 2;
261 if (tsignals & S_INTERRUPT)
264 quit(QUIT_INTERRUPT);