Category : C Source Code
Archive   : POLY3DRS.ZIP
Filename : CTRL-BRK.C

 
Output of file : CTRL-BRK.C contained in archive : POLY3DRS.ZIP
/*****************************************************************************
* Module to trap ctrl-brk/hardware error and handle them gracefully. *
* Note the usage of GraphGen.c module is assumed. *
* *
* Written by: Gershon Elber Ver 1.0, Jan. 1989 *
*****************************************************************************/

#ifdef __MSDOS__
#include
#include
#else
#include
#endif /* __MSDOS__ */

#include
#include "program.h"
#include "ctrl-brk.h"

#ifdef __MSDOS__
static void far *OldCtrlBrk; /* Save here old int 1bh to be able to restore. */
#endif /* __MSDOS__ */

static int WasCtrlBrkSetUp = FALSE; /* TRUE if SetUpCtrlBrk rtn was called. */
int WasCtrlBrk;

#ifdef __MSDOS__

/*****************************************************************************
* Routine TrapCtrlBrk gain control if Control break was typed: *
*****************************************************************************/
static void interrupt TrapCtrlBrk(void)
{
WasCtrlBrk = TRUE;
}

#endif /* __MSDOS__ */

/*****************************************************************************
* Routine TrapCtrlC gain control if Control C was typed (DOS level): *
*****************************************************************************/
static int TrapCtrlC(void)
{
WasCtrlBrk = TRUE;

#ifndef __MSDOS__
printf("\n*** Break ***\n");
#endif /* __MSDOS__ */

return -1; /* Resume execution. */
}

/*****************************************************************************
* Routine SetUpCtrlBrk must be called once by main program: *
*****************************************************************************/
void SetUpCtrlBrk(void)
{
if (WasCtrlBrkSetUp) return; /* No need to to it twice! */

#ifdef __MSDOS__
OldCtrlBrk = getvect(BIOS_CTRL_BRK);
setvect(BIOS_CTRL_BRK, TrapCtrlBrk);

ctrlbrk(TrapCtrlC);
#else
signal(SIGINT, TrapCtrlC);
signal(SIGQUIT, TrapCtrlC);
#endif /* __MSDOS__ */

WasCtrlBrkSetUp = TRUE;
}

/*****************************************************************************
* Routine RestoreCtrlBrk must be called before the program quit: *
*****************************************************************************/
void RestoreCtrlBrk(void)
{
#ifdef __MSDOS__
if (WasCtrlBrkSetUp)
setvect(BIOS_CTRL_BRK, (void interrupt (*)()) OldCtrlBrk);
#endif /* __MSDOS__ */

WasCtrlBrkSetUp = FALSE;
}

#ifdef __MSDOS__

/*****************************************************************************
* Routine TrapHardWareError gain control if hardware fails - int 24. *
*****************************************************************************/
static int TrapHardWareError(int errval, int ax, int bp, int si)
{
return IGNORE;
}

#endif /* __MSDOS__ */

/*****************************************************************************
* Routine SetUpHardError must be called once by main program: *
* harderr set interrupt vector 0x024 to point to TrapHardWareError. *
*****************************************************************************/
void SetUpHardErr(void)
{
#ifdef __MSDOS__
harderr(TrapHardWareError);
#endif /* __MSDOS__ */
}


  3 Responses to “Category : C Source Code
Archive   : POLY3DRS.ZIP
Filename : CTRL-BRK.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/