www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/25/09:46:48

Date: Thu, 25 Jun 1998 16:45:55 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Carsten Svaneborg <zqex AT fys-hp-1 DOT risoea DOT dka>
cc: djgpp AT delorie DOT com
Subject: Re: ctrl-c
In-Reply-To: <3592325D.7C2EF151@fys-hp-1.risoea.dka>
Message-ID: <Pine.SUN.3.91.980625163946.28316B-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019