🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1784

Re: Need help:Ctrl-C and Ctrl-Break

#1784
From: Alex Matulich
Date: Fri, 03 Aug 1990 17:14
39 lines
1730 bytes
In article <9627@tekigm2.MEN.TEK.COM> dennisw@tekigm2.MEN.TEK.COM (Dennis G Ward) writes:
>I've got a truly great program underway, but I can't stand to let the
>user break out of it with Ctrl-C or Ctrl-Break, and I need keyboard
>input.  What's the trick(s)?

The most PORTABLE way to do it (and it works well too) is to use the
signal() function in the standard library, like so:

---------------------------------------
#include <signal.h>

void ctrlctrap(i)
int i;
{
signal(SIGINT, ctrlctrap);  /* make sure next ctrl-break comes back here */
}


void main()
{
signal(SIGINT, ctrlctrap);  /* activate ctrl-c/ctrl-break trap handler */

etc....
--------------------------------------

Every time ctrl-c or ctrl break is pressed, the funtion ctrlctrap() will
be invoked, and will reset the pointer for the next ctrl-c to call
ctrlctrap() again.

This has worked on every ANSI compiler I have tried it on (Lattice,
Microsoft, unix compilers, etc.)


-- 
     ///  Alex Matulich
    ///  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
\\\///  alex@bilver.UUCP    ...uunet!tarpit!bilver!alex
 \XX/  From BitNet try: IN%"bilver!alex@uunet.uu.net"
Technical Details
Message-ID: <870@bilver.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uwm.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!crdgw1!ge-dab!tarpit!bilver!alex
References: <1990Jul30.182430.7493@uokmax.uucp> <9627@tekigm2.MEN.TEK.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uwm.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!crdgw1!ge-dab!tarpit!bilver!alex
From: alex@bilver.UUCP (Alex Matulich)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Need help:Ctrl-C and Ctrl-Break
Keywords: signal, control break
Message-ID: <870@bilver.UUCP>
Date: 3 Aug 90 17:14:48 GMT
References: <1990Jul30.182430.7493@uokmax.uucp> <9627@tekigm2.MEN.TEK.COM>
Organization: William J. Vermillion, Winter Park, FL
Lines: 39