home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8108 < prev    next >
Encoding:
Text File  |  1992-07-26  |  4.2 KB  |  93 lines

  1. Path: sparky!uunet!munnari.oz.au!csource!speednut
  2. From: speednut@csource.oz.au (mark jose)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: REQUEST FOR INFO: DISABLING ^C
  5. Message-ID: <iJ7NqB6w165w@csource.oz.au>
  6. Date: Sun, 26 Jul 92 15:55:41 +1000
  7. Reply-To: speednut@csource.oz.au
  8. Organization: Unique Computing Pty Ltd, Melbourne, Australia
  9. Lines: 82
  10.  
  11. Original Message From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
  12. Subject: Re: REQUEST FOR INFO: DISABLING ^C
  13.  
  14. > fredc@ibmpcug.co.uk (Fred Curtis) writes:
  15. >
  16. > >I want to disable the ^C interrupt.  I can trap it and ignore it
  17. > >by reseting the DOS interrupt vector, but it still prints "^C" on
  18. > >the screen.
  19.  
  20. Sorry for this late post, but I just read this group. Below is the code I
  21. use to catch the ^C interrupt (directly).
  22.  
  23. The code below actually sets a flag "abortflag" to trigger other parts of the
  24. program that it's time to quite. If you want to disable the Ctrl-Break
  25. altogether then just make "FatalAbort()" do nothing.
  26.  
  27. Hope this helps.
  28.  
  29.  
  30. /*---------------------------------------------------------------------------*/
  31. /* Handles the capturing of Control-C and Control-Break to allow for normal  */
  32. /* exitting during program execution.                                        */
  33. /*                                                                           */
  34. /* Donated to the Public Domain. USE IT AT ***YOUR*** PERIL!!!!!!!!!!!!!!!!  */
  35. /*---------------------------------------------------------------------------*/
  36. #include <dos.h>             /* Required for getvect/setvect  - Turbo C      */
  37.  
  38.  
  39. #ifdefined MSOFT        /* Using a Microsoft C compiler (QUICK-C?) */
  40.    #define  enable   _enable
  41.    #define  disable  _disable
  42.    #define  setvect  _dos_setvect
  43.    #define  getvect  _dos_getvect
  44. #endif
  45.  
  46. /*---------------------------------------------------------------------------*/
  47. /* Local function prototypes and variables.                                  */
  48. /*---------------------------------------------------------------------------*/
  49. static void interrupt far FatalAbort(void);   /* The abort interrupt routine */
  50. static void (interrupt far *OldBreak)(void);  /* The old abort interrupt     */
  51.  
  52. /*---------------------------------------------------------------------------*/
  53. /* Global variables.                                                         */
  54. /*---------------------------------------------------------------------------*/
  55. int localabort;                           /* The abort flag.                 */
  56.  
  57. /*---------------------------------------------------------------------------*/
  58. /* Set up the new interrupt routines for Ctrl-C and Ctrl-Break.              */
  59. /*---------------------------------------------------------------------------*/
  60. void cdecl SetBreakOut(void)
  61.   {
  62.    disable();                             /* Turn off interrupts (for now)   */
  63.    localabort = 0;                        /* Set the abort flag.             */
  64.    OldBreak = getvect(0x1B);              /* Save the old interrupt control. */
  65.    setvect(0x1B, FatalAbort);             /* Set fatal abort vector (1)      */
  66.    setvect(0x23, FatalAbort);             /* Set fatal abort vector (2)      */
  67.    enable();                              /* Turn interrupts back on - flush!*/
  68.   }
  69.  
  70. /*---------------------------------------------------------------------------*/
  71. /* Restore the old interrupt back in its old vector.                         */
  72. /*---------------------------------------------------------------------------*/
  73. void cdecl RestoreBreak(void)
  74.   {
  75.    setvect(0x1B, OldBreak);              /* Restore old interrupt.           */
  76.   }
  77.  
  78. /*---------------------------------------------------------------------------*/
  79. /* Interrupt will trap Ctrl-C and Ctrl-Break. Just change abortflag to 1 &   */
  80. /* the program will pick it up and deal with it.                             */
  81. /*---------------------------------------------------------------------------*/
  82. static void interrupt far FatalAbort(void)
  83.    {
  84.     localabort = 1;                      /* Just set the flag and that's it! */
  85.    }
  86.  
  87. Above done in Turbo C 2.0
  88.  
  89. .........................................................
  90. mark jose
  91. speednut@csource.oz.au  Unique Computing Pty Ltd, Melbourne, Australia
  92. The opinions expressed above are that of the author only.
  93.