2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* break.c */
|
|
|
|
/* FreeDOS */
|
|
|
|
/* */
|
|
|
|
/* Control Break detection and handling */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1999 */
|
|
|
|
/* Steffen Kaiser */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
#include "globals.h"
|
2002-10-22 04:40:19 +02:00
|
|
|
#include "proto.h"
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
2001-11-18 15:01:12 +01:00
|
|
|
static BYTE *RcsId =
|
|
|
|
"$Id$";
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
|
|
|
|
2004-04-14 11:20:08 +02:00
|
|
|
#define CB_FLG *(UBYTE FAR*)MK_FP(0x0, 0x471)
|
2000-05-06 21:34:20 +02:00
|
|
|
#define CB_MSK 0x80
|
|
|
|
|
2004-04-14 11:20:08 +02:00
|
|
|
/* Check for ^Break/^C.
|
|
|
|
* Three sources are available:
|
|
|
|
* 1) flag at 40:71 bit 7
|
|
|
|
* 2) CON stream (if STDIN is redirected somewhere else)
|
|
|
|
* 3) input stream (most likely STDIN)
|
|
|
|
* Actions:
|
|
|
|
* 1) echo ^C
|
|
|
|
* 2) clear the STDIN stream
|
|
|
|
* 3) decrease the InDOS flag as the kernel drops back to user space
|
|
|
|
* 4) invoke INT-23 and never come back
|
2000-05-06 21:34:20 +02:00
|
|
|
*/
|
2004-04-14 11:20:08 +02:00
|
|
|
unsigned char check_handle_break(struct dhdr FAR **pdev, int sft_out)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2004-04-14 11:20:08 +02:00
|
|
|
unsigned char c = CTL_C;
|
|
|
|
if (CB_FLG & CB_MSK)
|
2003-09-09 19:43:43 +02:00
|
|
|
CB_FLG &= ~CB_MSK; /* reset the ^Break flag */
|
2004-04-14 11:20:08 +02:00
|
|
|
else
|
|
|
|
c = (unsigned char)ndread(&syscon);
|
|
|
|
if (c == CTL_C)
|
|
|
|
{
|
|
|
|
sft_out = -1;
|
|
|
|
pdev = &syscon;
|
2003-09-09 19:43:43 +02:00
|
|
|
}
|
2004-04-14 11:20:08 +02:00
|
|
|
else if (*pdev != syscon)
|
|
|
|
c = (unsigned char)ndread(pdev);
|
|
|
|
if (c == CTL_C)
|
|
|
|
{
|
|
|
|
con_flush(pdev);
|
|
|
|
echo_ctl_c(pdev, sft_out);
|
|
|
|
if (!ErrorMode) /* within int21_handler, InDOS is not incremented */
|
|
|
|
if (InDOS)
|
|
|
|
--InDOS; /* fail-safe */
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2004-04-14 11:20:08 +02:00
|
|
|
spawn_int23(); /* invoke user INT-23 and never come back */
|
|
|
|
}
|
|
|
|
return c;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|