home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / DRAWFN3S.ZIP / CTRL-BRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-06  |  2.9 KB  |  81 lines

  1. /*****************************************************************************
  2. * Module to trap ctrl-brk/hardware error and handle them gracefully.         *
  3. * Note the usage of GraphGen.c module is assumed.                 *
  4. *                                         *
  5. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Jan. 1989    *
  6. *****************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <setjmp.h>
  11. #include <graphics.h>
  12. #include "Ctrl-Brk.h"
  13.  
  14. static void far *OldCtrlBrk; /* Save here old int 1bh to be able to restore. */
  15. static int WasCtrlBrkSetUp = FALSE;  /* TRUE if SetUpCtrlBrk rtn was called. */
  16. int WasCtrlBrk;
  17.  
  18. static void interrupt TrapCtrlBrk(void);
  19. static int TrapCtrlC(void);
  20.  
  21. /*****************************************************************************
  22. * Routine TrapCtrlBrk gain control if Control break was typed:             *
  23. *****************************************************************************/
  24. static void interrupt TrapCtrlBrk(void)
  25. {
  26.     WasCtrlBrk = TRUE;
  27. }
  28.  
  29. /*****************************************************************************
  30. * Routine TrapCtrlC gain control if Control C was typed (DOS level):         *
  31. *****************************************************************************/
  32. static int TrapCtrlC(void)
  33. {
  34.     WasCtrlBrk = TRUE;
  35.  
  36.     return -1;                        /* Resume execution. */
  37. }
  38.  
  39. /*****************************************************************************
  40. * Routine SetUpCtrlBrk must be called once by main program:             *
  41. *****************************************************************************/
  42. void SetUpCtrlBrk(void)
  43. {
  44.     if (WasCtrlBrkSetUp) return;          /* No need to to it twice! */
  45.  
  46.     OldCtrlBrk = getvect(BIOS_CTRL_BRK);
  47.     setvect(BIOS_CTRL_BRK, TrapCtrlBrk);
  48.  
  49.     ctrlbrk(TrapCtrlC);
  50.  
  51.     WasCtrlBrkSetUp = TRUE;
  52. }
  53.  
  54. /*****************************************************************************
  55. * Routine RestoreCtrlBrk must be called before the program quit:         *
  56. *****************************************************************************/
  57. void RestoreCtrlBrk(void)
  58. {
  59.     if (WasCtrlBrkSetUp)
  60.     setvect(BIOS_CTRL_BRK, (void interrupt (*)()) OldCtrlBrk);
  61.  
  62.     WasCtrlBrkSetUp = FALSE;
  63. }
  64.  
  65. /*****************************************************************************
  66. * Routine TrapHardWareError gain control if hardware fails - int 24.         *
  67. *****************************************************************************/
  68. static int TrapHardWareError(int errval, int ax, int bp, int si)
  69. {
  70.     return IGNORE;
  71. }
  72.  
  73. /*****************************************************************************
  74. * Routine SetUpHardError must be called once by main program:             *
  75. * harderr set interrupt vector 0x024 to point to TrapHardWareError.         *
  76. *****************************************************************************/
  77. void SetUpHardErr(void)
  78. {
  79.     harderr(TrapHardWareError);
  80. }
  81.