home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 2.ddi / TOOLS.2 / EXAMPLES / CTLBRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.7 KB  |  105 lines

  1. /*
  2. *    CTLBRK.C    Demonstrate implementation and use of a
  3. *            control-break handler.
  4. *
  5. *  The purpose of CTLBRK is to show a working example of
  6. *  implementation and use of a control-break (int 0x23) handler.
  7. *
  8. *  This program displays a prompt on the screen, and then invites
  9. *  the user to press CTRL-C or CTRL-BREAK.  The control-break
  10. *  handler will be triggered when the user presses the key, and
  11. *  will display a message.
  12. *
  13. *  The command line format is as follows:
  14. *
  15. *    ctlbrk
  16. *
  17. *  Version    6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
  18. *
  19. */
  20.  
  21.  
  22. #include <stdio.h>
  23.  
  24. #include <bfiles.h>
  25. #include <bintrupt.h>
  26. #include <bscreens.h>
  27. #include <bvideo.h>
  28.  
  29.         /* Vector 0x23 is the one to intercept.         */
  30. #define CBREAK_VEC 0x23
  31.  
  32.         /* Size of the CTRL-BREAK interrupt handler stack.  */
  33. #define STKSIZE 1500
  34.  
  35.         /* Declaration of the CTRL-BREAK handler.        */
  36. void cbreak (ALLREG *,ISRCTRL *,ISRMSG *);
  37.  
  38. int main()
  39. {
  40.         /* ISR control block for the handler.            */
  41.     ISRCTRL     cbrk_ctl;
  42.  
  43.         /* Allocate stack space for handler execution.        */
  44.     static char  cbrk_stack[STKSIZE];
  45.  
  46.     int      err;
  47.     char     resp[2];
  48.  
  49.         /* String uniquely identifying this interrupt        */
  50.         /* handler.                        */
  51.     static char cbrk_ident[] = "CTLBRK 03/31/89";
  52.  
  53.         /* Install Ctrl-Break handler, then prompt user to  */
  54.         /* try it.                        */
  55.     err = isinstal (CBREAK_VEC, cbreak, cbrk_ident,
  56.             &cbrk_ctl, cbrk_stack, STKSIZE, 1);
  57.     if (err != 0)
  58.     return (err);
  59.  
  60.     printf ("Press CTRL-C or CTRL-BREAK to try interrupt handler,\n");
  61.     fflush (stdout);
  62.     flprompt ("or press ENTER to quit: ", resp, sizeof (resp));
  63.  
  64.         /* We do not have to re-install the previous        */
  65.         /* INT 0x23 handler because DOS does so         */
  66.         /* automatically on program termination.        */
  67.  
  68.     return (0);
  69. }
  70.  
  71.  
  72.  
  73. /**
  74. *
  75. * Name        cbreak -- Interrupt service routine for Ctrl-Break
  76. *
  77. * Description    This function is installed as a handler for interrupt
  78. *        type 0x23.  It displays a message using BIOS or direct
  79. *        I/O (using no DOS functions) and then returns to DOS via
  80. *        a "RETF", thus causing the program to be aborted.
  81. *
  82. **/
  83.  
  84. void cbreak (pregs, pisrblk, pmsg)
  85. ALLREG    *pregs;
  86. ISRCTRL *pisrblk;
  87. ISRMSG    *pmsg;
  88. {
  89.     int mode, columns, act_page;
  90.     int row, col, junk;
  91.  
  92.         /* Get rid of compiler warning messages.        */
  93.     junk = *((int *) pregs);
  94.     junk = *((int *) pmsg);
  95.     junk = *((int *) pisrblk);
  96.  
  97.     scmode (&mode, &columns, &act_page);
  98.     scpage (act_page);
  99.     sccurst (&row, &col, &junk, &junk);
  100.     vidspmsg (row, col, -1, -1, "<<Ctrl-C detected>>");
  101.  
  102.     pmsg->working_flags |= CF_FLAG;
  103.     pmsg->exit_style     = IEXIT_RETF;
  104. }
  105.