home *** CD-ROM | disk | FTP | other *** search
- /*Program 9_1 - Control Break Handler
- by Stephen R. Davis, 1987
-
- Use the Turbo C provided ctrlbrk() routine to establish
- our own control break handler. We will put ourselves into
- an infinite loop. Entering control break will enter us into
- infinite loop. One more time and we exit. This is an
- example of the longjmp as well as the installation of multiple
- Control-Break handlers.
- */
-
- #include <stdio.h>
- #include <dos.h>
- #include <setjmp.h>
-
- /*prototype definitions*/
- int break1 (void);
- int break2 (void);
-
- /*global data definitions*/
- jmp_buf save;
-
- /*Break1 - intercept the first control break*/
- int break1 (void)
- {
- printf ("First break entered!\n");
- longjmp (save, 1);
- }
-
- /*Break2 - intercept the second control break*/
- int break2 (void)
- {
- printf ("Second break entered!\n");
- longjmp (save, 2);
- }
-
- /*Main - main program to exercise the break handler*/
- main ()
- {
- int value;
-
- value = setjmp (save);
- switch (value) {
- case 0:
- ctrlbrk (break1);
- printf ("Entering first loop\n");
- for (;;)
- printf (" Infinite loop #1\n");
- case 1:
- ctrlbrk (break2);
- printf ("Entering second loop\n");
- for (;;)
- printf (" Infinite loop #2\n");
- default:
- printf ("That's all folks\n");
- }
- }