2 * Copyright (C) 1984-2007 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
;
37 extern long jump_sline_fraction
;
40 * 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.)
67 * "Stop" (^Z) signal handler.
74 LSIGNAL(SIGTSTP
, stop
);
83 * "Window" change handler
90 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
);
165 * Restore signals to defaults.
167 (void) LSIGNAL(SIGINT
, SIG_DFL
);
168 #if MSDOS_COMPILER==WIN32C
169 SetConsoleCtrlHandler(wbreak_handler
, FALSE
);
172 (void) LSIGNAL(SIGTSTP
, SIG_DFL
);
175 (void) LSIGNAL(SIGWINCH
, SIG_IGN
);
178 (void) LSIGNAL(SIGWIND
, SIG_IGN
);
181 (void) LSIGNAL(SIGQUIT
, SIG_DFL
);
187 * Process any signals we have received.
188 * A received signal cause a bit to be set in "sigs".
193 register int tsignals
;
195 if ((tsignals
= sigs
) == 0)
200 if (tsignals
& S_STOP
)
203 * Clean up the terminal.
206 LSIGNAL(SIGTTOU
, SIG_IGN
);
213 LSIGNAL(SIGTTOU
, SIG_DFL
);
215 LSIGNAL(SIGTSTP
, SIG_DFL
);
216 kill(getpid(), SIGTSTP
);
219 * Hopefully we'll be back later and resume here...
220 * Reset the terminal and arrange to repaint the
221 * screen when we get back to the main command loop.
223 LSIGNAL(SIGTSTP
, stop
);
231 if (tsignals
& S_WINCH
)
233 int old_width
, old_height
;
235 * Re-execute scrsize() to read the new window size.
237 old_width
= sc_width
;
238 old_height
= sc_height
;
240 if (sc_width
!= old_width
|| sc_height
!= old_height
)
242 wscroll
= (sc_height
+ 1) / 2;
248 if (tsignals
& S_INTERRUPT
)
254 * {{ You may wish to replace the bell() with
255 * error("Interrupt", NULL_PARG); }}
259 * If we were interrupted while in the "calculating
260 * line numbers" loop, turn off line numbers.
268 error("Line numbers turned off", NULL_PARG
);