2 * Copyright (C) 1984-2002 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
;
38 * Interrupt signal handler.
46 LSIGNAL(SIGINT
, SIG_ACK
);
48 LSIGNAL(SIGINT
, u_interrupt
);
50 #if MSDOS_COMPILER==DJGPPC
52 * If a keyboard has been hit, it must be Ctrl-C
53 * (as opposed to Ctrl-Break), so consume it.
54 * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.)
65 * "Stop" (^Z) signal handler.
72 LSIGNAL(SIGTSTP
, stop
);
81 * "Window" change handler
88 LSIGNAL(SIGWINCH
, winch
);
96 * "Window" change handler
103 LSIGNAL(SIGWIND
, winch
);
111 #if MSDOS_COMPILER==WIN32C
113 * Handle CTRL-C and CTRL-BREAK keys.
118 wbreak_handler(dwCtrlType
)
124 case CTRL_BREAK_EVENT
:
135 * Set up the signal handlers.
144 * Set signal handlers.
146 (void) LSIGNAL(SIGINT
, u_interrupt
);
147 #if MSDOS_COMPILER==WIN32C
148 SetConsoleCtrlHandler(wbreak_handler
, TRUE
);
151 (void) LSIGNAL(SIGTSTP
, stop
);
154 (void) LSIGNAL(SIGWINCH
, winch
);
157 (void) LSIGNAL(SIGWIND
, winch
);
160 (void) LSIGNAL(SIGQUIT
, SIG_IGN
);
166 * Restore signals to defaults.
168 (void) LSIGNAL(SIGINT
, SIG_DFL
);
169 #if MSDOS_COMPILER==WIN32C
170 SetConsoleCtrlHandler(wbreak_handler
, FALSE
);
173 (void) LSIGNAL(SIGTSTP
, SIG_DFL
);
176 (void) LSIGNAL(SIGWINCH
, SIG_IGN
);
179 (void) LSIGNAL(SIGWIND
, SIG_IGN
);
182 (void) LSIGNAL(SIGQUIT
, SIG_DFL
);
188 * Process any signals we have received.
189 * A received signal cause a bit to be set in "sigs".
194 register int tsignals
;
196 if ((tsignals
= sigs
) == 0)
201 if (tsignals
& S_STOP
)
204 * Clean up the terminal.
207 LSIGNAL(SIGTTOU
, SIG_IGN
);
214 LSIGNAL(SIGTTOU
, SIG_DFL
);
216 LSIGNAL(SIGTSTP
, SIG_DFL
);
217 kill(getpid(), SIGTSTP
);
220 * Hopefully we'll be back later and resume here...
221 * Reset the terminal and arrange to repaint the
222 * screen when we get back to the main command loop.
224 LSIGNAL(SIGTSTP
, stop
);
232 if (tsignals
& S_WINCH
)
234 int old_width
, old_height
;
236 * Re-execute scrsize() to read the new window size.
238 old_width
= sc_width
;
239 old_height
= sc_height
;
241 if (sc_width
!= old_width
|| sc_height
!= old_height
)
243 wscroll
= (sc_height
+ 1) / 2;
248 if (tsignals
& S_INTERRUPT
)
252 * {{ You may wish to replace the bell() with
253 * error("Interrupt", NULL_PARG); }}
257 * If we were interrupted while in the "calculating
258 * line numbers" loop, turn off line numbers.
266 error("Line numbers turned off", NULL_PARG
);