home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / IRITS.ZIP / CTRL-BRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  3.3 KB  |  111 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                Ver 1.1, Mar. 1990   *
  6. *****************************************************************************/
  7.  
  8. #ifdef __MSDOS__
  9. #include <dos.h>
  10. #include <graphics.h>
  11. #else
  12. #include <signal.h>
  13. #endif /* __MSDOS__ */
  14.  
  15. #include <stdio.h>
  16. #include "program.h"
  17. #include "ctrl-brk.h"
  18.  
  19. #ifndef __MSDOS__
  20. #include "xgraphic.h"
  21. #endif /* __MSDOS__ */
  22.  
  23. #ifdef __MSDOS__
  24. static void far *OldCtrlBrk; /* Save here old int 1bh to be able to restore. */
  25. #endif /* __MSDOS__ */
  26.  
  27. static int WasCtrlBrkSetUp = FALSE;  /* TRUE if SetUpCtrlBrk rtn was called. */
  28. int WasCtrlBrk;
  29.  
  30. #ifdef __MSDOS__
  31.  
  32. /*****************************************************************************
  33. * Routine TrapCtrlBrk gain control if Control break was typed:             *
  34. *****************************************************************************/
  35. static void interrupt TrapCtrlBrk(void)
  36. {
  37.     WasCtrlBrk = TRUE;
  38. }
  39.  
  40. #endif /* __MSDOS__ */
  41.  
  42. /*****************************************************************************
  43. * Routine TrapCtrlC gain control if Control C was typed (DOS level):         *
  44. *****************************************************************************/
  45. static int TrapCtrlC(void)
  46. {
  47.     WasCtrlBrk = TRUE;
  48.  
  49. #ifndef __MSDOS__
  50.     printf("\n*** Break ***\n");
  51. #endif /* __MSDOS__ */
  52.  
  53.     return -1;                        /* Resume execution. */
  54. }
  55.  
  56. /*****************************************************************************
  57. * Routine SetUpCtrlBrk must be called once by main program:             *
  58. *****************************************************************************/
  59. void SetUpCtrlBrk(void)
  60. {
  61.     if (WasCtrlBrkSetUp) return;          /* No need to to it twice! */
  62.  
  63. #ifdef __MSDOS__
  64.     OldCtrlBrk = getvect(BIOS_CTRL_BRK);
  65.     setvect(BIOS_CTRL_BRK, TrapCtrlBrk);
  66.  
  67.     ctrlbrk(TrapCtrlC);
  68. #else
  69.     signal(SIGINT, TrapCtrlC);
  70.     signal(SIGQUIT, TrapCtrlC);
  71. #endif /* __MSDOS__ */
  72.  
  73.     WasCtrlBrkSetUp = TRUE;
  74. }
  75.  
  76. /*****************************************************************************
  77. * Routine RestoreCtrlBrk must be called before the program quit:         *
  78. *****************************************************************************/
  79. void RestoreCtrlBrk(void)
  80. {
  81. #ifdef __MSDOS__
  82.     if (WasCtrlBrkSetUp)
  83.     setvect(BIOS_CTRL_BRK, (void interrupt (*)()) OldCtrlBrk);
  84. #endif /* __MSDOS__ */
  85.  
  86.     WasCtrlBrkSetUp = FALSE;
  87. }
  88.  
  89. #ifdef __MSDOS__
  90.  
  91. /*****************************************************************************
  92. * Routine TrapHardWareError gain control if hardware fails - int 24.         *
  93. *****************************************************************************/
  94. static int TrapHardWareError(int errval, int ax, int bp, int si)
  95. {
  96.     return IGNORE;
  97. }
  98.  
  99. #endif /* __MSDOS__ */
  100.  
  101. /*****************************************************************************
  102. * Routine SetUpHardError must be called once by main program:             *
  103. * harderr set interrupt vector 0x024 to point to TrapHardWareError.         *
  104. *****************************************************************************/ 
  105. void SetUpHardErr(void)
  106. {
  107. #ifdef __MSDOS__
  108.     harderr(TrapHardWareError);
  109. #endif /* __MSDOS__ */
  110. }
  111.