Mail Archives: djgpp/1998/06/25/09:46:48
On Thu, 25 Jun 1998, Carsten Svaneborg wrote:
> Eli Zaretskii wrote:
> > Use the library function `signal' to install a signal handler for the
> > SIGINT signal. In the handler, call that particular function you want to
> > be called.
> How precisely do you do this?
> Could you sketch a piece of code that trapped and handled some signal.
You should really look up the description of the function `signal' in the
library reference (type "info libc alpha signal" from the DOS prompt). A
*really* sketchy fragment will be like this (UNTESTED!):
#include <signal.h>
...
void ctrl_c_handler (int signo)
{
static int ctrl_c_count = 0;
if (signo == SIGINT)
ctrl_c_count++;
}
...
int main (void)
{
...
signal (SIGINT, ctrl_c_handler);
...
}
Note that SIGINT is also generated by Ctrl-BREAK. If you need to
distinguish these two, you will need to peek at the keyboard buffer
inside the handler (when Ctrl-BREAK is pressed, the buffer is empty, or
holds the key pressed before that, which isn't Ctrl-C).
Again, please look in the library docs for the details. This issue is
too complex to be described in a message.
- Raw text -