bruceb@amiga.UUCP (Bruce Barrett) (02/12/86)
Ok, this is how a (Lattice) C program detects Control-C, or Control-D
keypresses, ... or ... BREAK task#, C ; BREAK task#, D ; BREAK task#, ALL
This is taken from the C manual errata shipped with V1.1 developers kits.
I presume it is (c) copyright 1985, 1986 Commodore-Amiga, Inc.
page 6-7: Following the paragraph that begins "The program exit....", add:
Programs can also be terminated by task interruption, if desired.
If the external int location Enable_Abort contains a nonzero
value, a check for the characters Ctrl-C and Ctrl-D is made
whenever a call to one of the level-1 I/O functions is processed.
page 6-7 at the and of section 6.2.4 add:
Detection of Ctrl-C and Ctrl-D is provided in the I/O library. If
the external integer location Enable_Abort is set to non-zero, a
check for these conditions is performed every time a level-1 I/O
call is made. If either of these keys were pressed, the
appropriate character is echoed to stdout, all level-1 files are
closed, and the program terminates. Programs that do not use
level-1 I/O or that wish to check more frequently may call the
function Chk_Abort(), which will return zero if neither of the
keys were pressed, or the signal value if either key was pressed.
Note that if Enable_Abort is non-zero a successful call to
Chk_Abort (either key had been pressed) will result in program
termination as described above.
If either of these keys has been typed, the appropriate character
is echoed to the console window, all level-1 files are closed,
and the program is terminated. Programs that do not use level-1
I/O or that need to check more frequently for interruption may
call the function Chk_Abort(), which will return zero if neither
of the interrupt characters were typed, or the appropriate signal
value (which will be non-zero; see AmigaDOS documentation)
otherwise. Note that control does not return to the caller
unless Enable_Abort is zero; if it is non-zero, the program is
simply terminated as described above. By default, Enable_Abort
is zero; it must be forced to a non-zero value in order to
activate the interrupt checking.
To check for ^C/^D every time a level-1 I/O call is made. Exit
if found:
Enable_Abort = 1;
To check for ^C/^D (for example within a loop) and if found, have
C handle exiting for you:
Enable_Abort = 1;
Chk_Abort();
To check for ^C/^D (for example within a loop) and if found, NOT
have C exit for you:
Enable_Abort = 0;
If (0 != Chk_Abort()) {
do_my_cleanup();
exit(1);
}
------- Bruce Barrett ---------