2 * Copyright (C) 1984-2014 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 * "Window" change handler
90 LSIGNAL(SIGWINCH, winch);
98 * "Window" change handler
105 LSIGNAL(SIGWIND, winch);
113 #if MSDOS_COMPILER==WIN32C
115 * Handle CTRL-C and CTRL-BREAK keys.
120 wbreak_handler(dwCtrlType)
126 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);
167 * Restore signals to defaults.
169 (void) LSIGNAL(SIGINT, SIG_DFL);
170 #if MSDOS_COMPILER==WIN32C
171 SetConsoleCtrlHandler(wbreak_handler, FALSE);
174 (void) LSIGNAL(SIGTSTP, SIG_DFL);
177 (void) LSIGNAL(SIGWINCH, SIG_IGN);
180 (void) LSIGNAL(SIGWIND, SIG_IGN);
183 (void) LSIGNAL(SIGQUIT, SIG_DFL);
189 * Process any signals we have received.
190 * A received signal cause a bit to be set in "sigs".
195 register int tsignals;
197 if ((tsignals = sigs) == 0)
202 if (tsignals & S_STOP)
205 * Clean up the terminal.
208 LSIGNAL(SIGTTOU, SIG_IGN);
215 LSIGNAL(SIGTTOU, SIG_DFL);
217 LSIGNAL(SIGTSTP, SIG_DFL);
218 kill(getpid(), SIGTSTP);
221 * Hopefully we'll be back later and resume here...
222 * Reset the terminal and arrange to repaint the
223 * screen when we get back to the main command loop.
225 LSIGNAL(SIGTSTP, stop);
233 if (tsignals & S_WINCH)
235 int old_width, old_height;
237 * Re-execute scrsize() to read the new window size.
239 old_width = sc_width;
240 old_height = sc_height;
242 if (sc_width != old_width || sc_height != old_height)
244 wscroll = (sc_height + 1) / 2;
251 if (tsignals & S_INTERRUPT)
254 quit(QUIT_INTERRUPT);