Thread View: net.micro.amiga
3 messages
3 total messages
Started by t.skrobala
Thu, 06 Nov 1986 13:37
Capturing ^C
Author: 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" ) ;
}
Re: Capturing ^C
Author: James M Synge
Date: Fri, 07 Nov 1986 13:10
Date: Fri, 07 Nov 1986 13:10
34 lines
2297 bytes
2297 bytes
In article <2210@mtuxo.UUCP>, tas@mtuxo.UUCP (t.skrobala) writes: > 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. I've tried writing an exception handler and had some problems. One thing I notice you're not dealing with in your assembly section is the fact that you don't know what state your registers are in, except D0 and A0, which contain the signal mask and address of your ExceptData. SO, when your code is adding 1 to hadIntr, you don't know where that 1 is being added. It is some offset from (A4), but, since A4 is in an unknown state, we don't know where that is. > If I don't > call SetExcept(), ^C produces an immediate exit (after I hit RETURN to > satisfy the read()). This is because the Manx io routines check for ^C every time (unless you set an external variable whose name I cann't remember). > Thanks, > Tom Skrobala AT&T Information Systems ihnp4!ariel!tas My pleasure, -- --------------------------------------------------------------------------- James M Synge, Department of Atmospheric Sciences, University of Washington VOX: 1 206 543 0308 (Work) 1 206 455 2025 (Home) UUCP: uw-beaver!geops!uw-atm!james ARPA: geops!uw-atm!james@beaver.cs.washington.edu
Re: Capturing ^C
Author: Paul Higginbottom
Date: Sat, 08 Nov 1986 17:32
Date: Sat, 08 Nov 1986 17:32
86 lines
3529 bytes
3529 bytes
In article <46@uw-atm.UUCP> james@uw-atm.UUCP (James M Synge) writes:
>In article <2210@mtuxo.UUCP>, tas@mtuxo.UUCP (t.skrobala) writes:
>> 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.
>
>I've tried writing an exception handler and had some problems. One thing
>I notice you're not dealing with in your assembly section is the fact that
>you don't know what state your registers are in, except D0 and A0, which
>contain the signal mask and address of your ExceptData. SO, when your
>code is adding 1 to hadIntr, you don't know where that 1 is being
>added. It is some offset from (A4), but, since A4 is in an unknown state,
>we don't know where that is.
>
This is not really true. The "rules" of the OS dictate that routines
leave registers untouched except d0/d1/a0/a1 which are used for passing
args and results and cannot be guaranteed to be munged during some call.
Thus, a4 should always be in a healthy state for a program's assembler
sections to access any variables in the C or assembler parts. The
linker converts:
move.w _stuff,d0
into
move.w (a4)_stuff,d0
(please excuse assembler inaccuracies, I do as little as possible)
>> If I don't
>> call SetExcept(), ^C produces an immediate exit (after I hit RETURN to
>> satisfy the read()).
>
>This is because the Manx io routines check for ^C every time (unless you
>set an external variable whose name I cann't remember).
>
The variable is Enable_Abort, and to disable Manx's checking of CTRL-C
during sys and std i/o - you need to set it to 0. E.g:
main()
{
extern short Enable_Abort;
Enable_Abort = 0; /* no more ctrl-c aborts */
...
}
However, you can STILL check for CTRL-C's conveniently via the Chk_Abort()
function provided in the Manx system. E.g:
...
extern long Chk_Abort();
... some i/o loop ...
{
if (Chk_Abort())
{
break; /* leave the loop */
}
....
}
... cleanup here ...
>> Thanks,
>> Tom Skrobala AT&T Information Systems ihnp4!ariel!tas
>
>My pleasure,
>--
>---------------------------------------------------------------------------
>James M Synge, Department of Atmospheric Sciences, University of Washington
>VOX: 1 206 543 0308 (Work) 1 206 455 2025 (Home)
>UUCP: uw-beaver!geops!uw-atm!james
>ARPA: geops!uw-atm!james@beaver.cs.washington.edu
Mine too,
Paul Higginbottom, my house, Exton, PA.
Disclaimer: I work for myself, and my opinions are my own.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads