home *** CD-ROM | disk | FTP | other *** search
- /*
- * CTLBRK.C Demonstrate implementation and use of a
- * control-break handler.
- *
- * The purpose of CTLBRK is to show a working example of
- * implementation and use of a control-break (int 0x23) handler.
- *
- * This program displays a prompt on the screen, and then invites
- * the user to press CTRL-C or CTRL-BREAK. The control-break
- * handler will be triggered when the user presses the key, and
- * will display a message.
- *
- * The command line format is as follows:
- *
- * ctlbrk
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
- *
- */
-
-
- #include <stdio.h>
-
- #include <bfiles.h>
- #include <bintrupt.h>
- #include <bscreens.h>
- #include <bvideo.h>
-
- /* Vector 0x23 is the one to intercept. */
- #define CBREAK_VEC 0x23
-
- /* Size of the CTRL-BREAK interrupt handler stack. */
- #define STKSIZE 1500
-
- /* Declaration of the CTRL-BREAK handler. */
- void cbreak (ALLREG *,ISRCTRL *,ISRMSG *);
-
- int main()
- {
- /* ISR control block for the handler. */
- ISRCTRL cbrk_ctl;
-
- /* Allocate stack space for handler execution. */
- static char cbrk_stack[STKSIZE];
-
- int err;
- char resp[2];
-
- /* String uniquely identifying this interrupt */
- /* handler. */
- static char cbrk_ident[] = "CTLBRK 03/31/89";
-
- /* Install Ctrl-Break handler, then prompt user to */
- /* try it. */
- err = isinstal (CBREAK_VEC, cbreak, cbrk_ident,
- &cbrk_ctl, cbrk_stack, STKSIZE, 1);
- if (err != 0)
- return (err);
-
- printf ("Press CTRL-C or CTRL-BREAK to try interrupt handler,\n");
- fflush (stdout);
- flprompt ("or press ENTER to quit: ", resp, sizeof (resp));
-
- /* We do not have to re-install the previous */
- /* INT 0x23 handler because DOS does so */
- /* automatically on program termination. */
-
- return (0);
- }
-
-
-
- /**
- *
- * Name cbreak -- Interrupt service routine for Ctrl-Break
- *
- * Description This function is installed as a handler for interrupt
- * type 0x23. It displays a message using BIOS or direct
- * I/O (using no DOS functions) and then returns to DOS via
- * a "RETF", thus causing the program to be aborted.
- *
- **/
-
- void cbreak (pregs, pisrblk, pmsg)
- ALLREG *pregs;
- ISRCTRL *pisrblk;
- ISRMSG *pmsg;
- {
- int mode, columns, act_page;
- int row, col, junk;
-
- /* Get rid of compiler warning messages. */
- junk = *((int *) pregs);
- junk = *((int *) pmsg);
- junk = *((int *) pisrblk);
-
- scmode (&mode, &columns, &act_page);
- scpage (act_page);
- sccurst (&row, &col, &junk, &junk);
- vidspmsg (row, col, -1, -1, "<<Ctrl-C detected>>");
-
- pmsg->working_flags |= CF_FLAG;
- pmsg->exit_style = IEXIT_RETF;
- }