2 * Copyright (C) 1984-2004 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 about less, or for information on how to
8 * contact the author, 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;
39 * Interrupt signal handler.
47 LSIGNAL(SIGINT, SIG_ACK);
49 LSIGNAL(SIGINT, u_interrupt);
51 #if MSDOS_COMPILER==DJGPPC
53 * If a keyboard has been hit, it must be Ctrl-C
54 * (as opposed to Ctrl-Break), so consume it.
55 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
66 * "Stop" (^Z) signal handler.
73 LSIGNAL(SIGTSTP, stop);
82 * "Window" change handler
89 LSIGNAL(SIGWINCH, winch);
97 * "Window" change handler
104 LSIGNAL(SIGWIND, winch);
112 #if MSDOS_COMPILER==WIN32C
114 * Handle CTRL-C and CTRL-BREAK keys.
119 wbreak_handler(dwCtrlType)
125 case CTRL_BREAK_EVENT:
136 * Set up the signal handlers.
145 * Set signal handlers.
147 (void) LSIGNAL(SIGINT, u_interrupt);
148 #if MSDOS_COMPILER==WIN32C
149 SetConsoleCtrlHandler(wbreak_handler, TRUE);
152 (void) LSIGNAL(SIGTSTP, stop);
155 (void) LSIGNAL(SIGWINCH, winch);
158 (void) LSIGNAL(SIGWIND, winch);
161 (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;
249 if (tsignals & S_INTERRUPT)
255 * {{ You may wish to replace the bell() with
256 * error("Interrupt", NULL_PARG); }}
260 * If we were interrupted while in the "calculating
261 * line numbers" loop, turn off line numbers.
269 error("Line numbers turned off", NULL_PARG);