Article View: comp.os.msdos.programmer
Article #507REQUEST FOR INFO: DISABLING ^C
From: mark jose
Date: Sun, 26 Jul 1992 05:55
Date: Sun, 26 Jul 1992 05:55
82 lines
4397 bytes
4397 bytes
Original Message From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
Subject: Re: REQUEST FOR INFO: DISABLING ^C
> fredc@ibmpcug.co.uk (Fred Curtis) writes:
>
> >I want to disable the ^C interrupt. I can trap it and ignore it
> >by reseting the DOS interrupt vector, but it still prints "^C" on
> >the screen.
Sorry for this late post, but I just read this group. Below is the code I
use to catch the ^C interrupt (directly).
The code below actually sets a flag "abortflag" to trigger other parts of the
program that it's time to quite. If you want to disable the Ctrl-Break
altogether then just make "FatalAbort()" do nothing.
Hope this helps.
/*---------------------------------------------------------------------------*/
/* Handles the capturing of Control-C and Control-Break to allow for normal */
/* exitting during program execution. */
/* */
/* Donated to the Public Domain. USE IT AT ***YOUR*** PERIL!!!!!!!!!!!!!!!! */
/*---------------------------------------------------------------------------*/
#include <dos.h> /* Required for getvect/setvect - Turbo C */
#ifdefined MSOFT /* Using a Microsoft C compiler (QUICK-C?) */
#define enable _enable
#define disable _disable
#define setvect _dos_setvect
#define getvect _dos_getvect
#endif
/*---------------------------------------------------------------------------*/
/* Local function prototypes and variables. */
/*---------------------------------------------------------------------------*/
static void interrupt far FatalAbort(void); /* The abort interrupt routine */
static void (interrupt far *OldBreak)(void); /* The old abort interrupt */
/*---------------------------------------------------------------------------*/
/* Global variables. */
/*---------------------------------------------------------------------------*/
int localabort; /* The abort flag. */
/*---------------------------------------------------------------------------*/
/* Set up the new interrupt routines for Ctrl-C and Ctrl-Break. */
/*---------------------------------------------------------------------------*/
void cdecl SetBreakOut(void)
{
disable(); /* Turn off interrupts (for now) */
localabort = 0; /* Set the abort flag. */
OldBreak = getvect(0x1B); /* Save the old interrupt control. */
setvect(0x1B, FatalAbort); /* Set fatal abort vector (1) */
setvect(0x23, FatalAbort); /* Set fatal abort vector (2) */
enable(); /* Turn interrupts back on - flush!*/
}
/*---------------------------------------------------------------------------*/
/* Restore the old interrupt back in its old vector. */
/*---------------------------------------------------------------------------*/
void cdecl RestoreBreak(void)
{
setvect(0x1B, OldBreak); /* Restore old interrupt. */
}
/*---------------------------------------------------------------------------*/
/* Interrupt will trap Ctrl-C and Ctrl-Break. Just change abortflag to 1 & */
/* the program will pick it up and deal with it. */
/*---------------------------------------------------------------------------*/
static void interrupt far FatalAbort(void)
{
localabort = 1; /* Just set the flag and that's it! */
}
Above done in Turbo C 2.0
.........................................................
mark jose
speednut@csource.oz.au Unique Computing Pty Ltd, Melbourne, Australia
The opinions expressed above are that of the author only.
Technical Details
Message-ID:
<iJ7NqB6w165w@csource.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!csource!speednutShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!csource!speednut From: speednut@csource.oz.au (mark jose) Newsgroups: comp.os.msdos.programmer Subject: REQUEST FOR INFO: DISABLING ^C Message-ID: <iJ7NqB6w165w@csource.oz.au> Date: Sun, 26 Jul 92 15:55:41 +1000 Reply-To: speednut@csource.oz.au Organization: Unique Computing Pty Ltd, Melbourne, Australia Lines: 82