2 * Copyright (C) 1984-2012 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 * "Window" change handler
94 LSIGNAL(SIGWINCH, winch);
102 * "Window" change handler
109 LSIGNAL(SIGWIND, winch);
117 #if MSDOS_COMPILER==WIN32C
119 * Handle CTRL-C and CTRL-BREAK keys.
124 wbreak_handler(dwCtrlType)
130 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);
171 * Restore signals to defaults.
173 (void) LSIGNAL(SIGINT, SIG_DFL);
174 #if MSDOS_COMPILER==WIN32C
175 SetConsoleCtrlHandler(wbreak_handler, FALSE);
178 (void) LSIGNAL(SIGTSTP, SIG_DFL);
181 (void) LSIGNAL(SIGWINCH, SIG_IGN);
184 (void) LSIGNAL(SIGWIND, SIG_IGN);
187 (void) LSIGNAL(SIGQUIT, SIG_DFL);
193 * Process any signals we have received.
194 * A received signal cause a bit to be set in "sigs".
199 register int tsignals;
201 if ((tsignals = sigs) == 0)
206 if (tsignals & S_STOP)
209 * Clean up the terminal.
212 LSIGNAL(SIGTTOU, SIG_IGN);
219 LSIGNAL(SIGTTOU, SIG_DFL);
221 LSIGNAL(SIGTSTP, SIG_DFL);
222 kill(getpid(), SIGTSTP);
225 * Hopefully we'll be back later and resume here...
226 * Reset the terminal and arrange to repaint the
227 * screen when we get back to the main command loop.
229 LSIGNAL(SIGTSTP, stop);
237 if (tsignals & S_WINCH)
239 int old_width, old_height;
241 * Re-execute scrsize() to read the new window size.
243 old_width = sc_width;
244 old_height = sc_height;
246 if (sc_width != old_width || sc_height != old_height)
248 wscroll = (sc_height + 1) / 2;
255 if (tsignals & S_INTERRUPT)
258 quit(QUIT_INTERRUPT);