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.
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.
48 LSIGNAL(SIGINT, SIG_ACK);
50 LSIGNAL(SIGINT, u_interrupt);
52 #if MSDOS_COMPILER==DJGPPC
54 * If a keyboard has been hit, it must be Ctrl-C
55 * (as opposed to Ctrl-Break), so consume it.
56 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
62 intread(); /* May longjmp */
67 * "Stop" (^Z) signal handler.
74 LSIGNAL(SIGTSTP, stop);
83 #define SIG_LESSWINDOW SIGWINCH
86 #define SIG_LESSWINDOW SIGWIND
92 * "Window" change handler
99 LSIGNAL(SIG_LESSWINDOW, winch);
106 #if MSDOS_COMPILER==WIN32C
108 * Handle CTRL-C and CTRL-BREAK keys.
113 wbreak_handler(dwCtrlType)
119 case CTRL_BREAK_EVENT:
137 * Set up the signal handlers.
146 * Set signal handlers.
148 (void) LSIGNAL(SIGINT, u_interrupt);
149 #if MSDOS_COMPILER==WIN32C
150 SetConsoleCtrlHandler(wbreak_handler, TRUE);
153 (void) LSIGNAL(SIGTSTP, stop);
156 (void) LSIGNAL(SIGWINCH, winch);
159 (void) LSIGNAL(SIGWIND, winch);
162 (void) LSIGNAL(SIGQUIT, SIG_IGN);
165 (void) LSIGNAL(SIGTERM, terminate);
170 * Restore signals to defaults.
172 (void) LSIGNAL(SIGINT, SIG_DFL);
173 #if MSDOS_COMPILER==WIN32C
174 SetConsoleCtrlHandler(wbreak_handler, FALSE);
177 (void) LSIGNAL(SIGTSTP, SIG_DFL);
180 (void) LSIGNAL(SIGWINCH, SIG_IGN);
183 (void) LSIGNAL(SIGWIND, SIG_IGN);
186 (void) LSIGNAL(SIGQUIT, SIG_DFL);
189 (void) LSIGNAL(SIGTERM, SIG_DFL);
195 * Process any signals we have received.
196 * A received signal cause a bit to be set in "sigs".
203 if ((tsignals = sigs) == 0)
208 if (tsignals & S_STOP)
211 * Clean up the terminal.
214 LSIGNAL(SIGTTOU, SIG_IGN);
221 LSIGNAL(SIGTTOU, SIG_DFL);
223 LSIGNAL(SIGTSTP, SIG_DFL);
224 kill(getpid(), SIGTSTP);
227 * Hopefully we'll be back later and resume here...
228 * Reset the terminal and arrange to repaint the
229 * screen when we get back to the main command loop.
231 LSIGNAL(SIGTSTP, stop);
239 if (tsignals & S_WINCH)
241 int old_width, old_height;
243 * Re-execute scrsize() to read the new window size.
245 old_width = sc_width;
246 old_height = sc_height;
248 if (sc_width != old_width || sc_height != old_height)
250 wscroll = (sc_height + 1) / 2;
257 if (tsignals & S_INTERRUPT)
260 quit(QUIT_INTERRUPT);