Article View: net.micro.amiga
Article #4961Capturing ^C
From: t.skrobala
Date: Thu, 06 Nov 1986 13:37
Date: Thu, 06 Nov 1986 13:37
75 lines
2419 bytes
2419 bytes
...Throw me a line...
Is there a way to capture ^C signals on Amiga in a manner analagous to
UNIX signal()? I'd like to be able to abort recalcitrant programs with
^C, but do some cleanup before exiting. Thus I'd like a function to be
called when ^C is typed. My reading of the ROM Kernel Manual suggests
that SigExcept() is the key, but, in the example below, my onintr()
function only gets called once (with d0 set to 0), when SetExcept() is
called, and never thereafter; ^C's are ignored. If I explicitly call
signal(task, SIGBREAKF_CTRL_C), onintr() *does* get called. If I don't
call SetExcept(), ^C produces an immediate exit (after I hit RETURN to
satisfy the read()).
I know that it's possible to check for ^C with SetSignal() after
every read(), but I'm hoping that there's a less burdensome way
to detect the exception.
I am using Manx Aztec C with 1.1 Amiga software.
Thanks,
Tom Skrobala AT&T Information Systems ihnp4!ariel!tas
--------------------------------------------------------------
#include <exec/types.h>
#include <exec/tasks.h>
#include <libraries/dos.h>
#include <stdio.h>
#include <functions.h>
long exceptID ;
long hadIntr ;
#asm
public _onintr
_onintr:
or.l d0,_exceptID
add.l #1,_hadIntr
rts
#endasm
extern onintr() ;
main()
{
struct Task *task ;
long oldSignals ;
char buf[10] ;
int n ;
exceptID = 0 ;
hadIntr = 0 ;
task = FindTask( NULL ) ;
printf( "task=0x%lx\n", task ) ;
task->tc_ExceptCode = (APTR)onintr ;
oldSignals = SetExcept( SIGBREAKF_CTRL_C, SIGBREAKF_CTRL_C ) ;
while( n = read( 0, buf, 10 ), buf[0] != 'x' )
{
if( exceptID || hadIntr )
{
printf( "received %ld signal(s) 0x%lx\n",
hadIntr, exceptID ) ;
exceptID = 0 ;
hadIntr = 0 ;
}
printf( "received n=%d, %c\n", n, buf[0] ) ;
if( n < 0 )
printf( "received err=%ld\n", IoErr() ) ;
}
printf( "out of loop\n" ) ;
}
Technical Details
Message-ID:
<2210@mtuxo.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cuae2!ihnp4!drutx!mtuxo!tasShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cuae2!ihnp4!drutx!mtuxo!tas From: tas@mtuxo.UUCP (t.skrobala) Newsgroups: net.micro.amiga,comp.sys.amiga Subject: Capturing ^C Message-ID: <2210@mtuxo.UUCP> Date: Thu, 6-Nov-86 08:37:56 EST Article-I.D.: mtuxo.2210 Posted: Thu Nov 6 08:37:56 1986 Date-Received: Fri, 7-Nov-86 22:44:05 EST Distribution: na Organization: AT&T Information Systems Labs, Holmdel NJ Lines: 75