Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses handle non-tty cases more gracefully.
details: https://anonhg.NetBSD.org/src/rev/5dc075a368a1
branches: trunk
changeset: 533292:5dc075a368a1
user: itojun <itojun%NetBSD.org@localhost>
date: Wed Jun 26 18:23:28 2002 +0000
description:
handle non-tty cases more gracefully.
diffstat:
lib/libcurses/curses_private.h | 3 +-
lib/libcurses/screen.c | 5 ++-
lib/libcurses/tty.c | 55 ++++++++++++++++++++++++++++++++++++++---
3 files changed, 55 insertions(+), 8 deletions(-)
diffs (244 lines):
diff -r de289aa9fa91 -r 5dc075a368a1 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h Wed Jun 26 18:13:59 2002 +0000
+++ b/lib/libcurses/curses_private.h Wed Jun 26 18:23:28 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses_private.h,v 1.21 2002/06/26 18:14:03 christos Exp $ */
+/* $NetBSD: curses_private.h,v 1.22 2002/06/26 18:23:28 itojun Exp $ */
/*-
* Copyright (c) 1998-2000 Brett Lymn
@@ -233,6 +233,7 @@
char pad_char;
char ttytype[128];
int endwin;
+ int notty;
};
diff -r de289aa9fa91 -r 5dc075a368a1 lib/libcurses/screen.c
--- a/lib/libcurses/screen.c Wed Jun 26 18:13:59 2002 +0000
+++ b/lib/libcurses/screen.c Wed Jun 26 18:23:28 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.c,v 1.5 2002/01/02 10:38:29 blymn Exp $ */
+/* $NetBSD: screen.c,v 1.6 2002/06/26 18:23:30 itojun Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
#else
-__RCSID("$NetBSD: screen.c,v 1.5 2002/01/02 10:38:29 blymn Exp $");
+__RCSID("$NetBSD: screen.c,v 1.6 2002/06/26 18:23:30 itojun Exp $");
#endif
#endif /* not lint */
@@ -137,6 +137,7 @@
new_screen->curscr = NULL;
new_screen->__virtscr = NULL;
new_screen->curwin = 0;
+ new_screen->notty = FALSE;
if (_cursesi_gettmode(new_screen) == ERR)
goto error_exit;
diff -r de289aa9fa91 -r 5dc075a368a1 lib/libcurses/tty.c
--- a/lib/libcurses/tty.c Wed Jun 26 18:13:59 2002 +0000
+++ b/lib/libcurses/tty.c Wed Jun 26 18:23:28 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.c,v 1.28 2002/01/02 10:38:29 blymn Exp $ */
+/* $NetBSD: tty.c,v 1.29 2002/06/26 18:23:31 itojun Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95";
#else
-__RCSID("$NetBSD: tty.c,v 1.28 2002/01/02 10:38:29 blymn Exp $");
+__RCSID("$NetBSD: tty.c,v 1.29 2002/06/26 18:23:31 itojun Exp $");
#endif
#endif /* not lint */
@@ -81,7 +81,10 @@
int
baudrate(void)
{
- return cfgetospeed(&_cursesi_screen->baset);
+ if (_cursesi_screen->notty == TRUE)
+ return 0;
+
+ return cfgetospeed(&_cursesi_screen->baset);
}
/*
@@ -109,8 +112,16 @@
{
screen->useraw = 0;
- if (tcgetattr(fileno(screen->infd), &screen->orig_termios))
- return (ERR);
+ if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) {
+ /* if the input fd is not a tty try the output */
+ if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) {
+ /* not a tty ... we will disable tty related stuff */
+ screen->notty = TRUE;
+ __GT = 0;
+ __NONL = 0;
+ return (OK);
+ }
+ }
screen->baset = screen->orig_termios;
screen->baset.c_oflag &= ~OXTABS;
@@ -164,6 +175,8 @@
_cursesi_screen->useraw = __pfast = __rawmode = 1;
_cursesi_screen->curt = &_cursesi_screen->rawt;
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT | TCSADRAIN : TCSADRAIN,
_cursesi_screen->curt) ? ERR : OK);
@@ -177,6 +190,8 @@
__restartwin();
_cursesi_screen->useraw = __pfast = __rawmode = 0;
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->curt = &_cursesi_screen->baset;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT | TCSADRAIN : TCSADRAIN,
@@ -191,6 +206,8 @@
__restartwin();
__rawmode = 1;
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->curt = _cursesi_screen->useraw ?
&_cursesi_screen->rawt : &_cursesi_screen->cbreakt;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
@@ -206,6 +223,8 @@
__restartwin();
__rawmode = 0;
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->curt = _cursesi_screen->useraw ?
&_cursesi_screen->rawt : &_cursesi_screen->baset;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
@@ -220,6 +239,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->rawt.c_cc[VMIN] = 1;
_cursesi_screen->rawt.c_cc[VTIME] = 0;
_cursesi_screen->cbreakt.c_cc[VMIN] = 1;
@@ -238,6 +259,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->rawt.c_cc[VMIN] = 0;
_cursesi_screen->rawt.c_cc[VTIME] = 0;
_cursesi_screen->cbreakt.c_cc[VMIN] = 0;
@@ -256,6 +279,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return;
_cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
_cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
}
@@ -267,6 +292,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return;
_cursesi_screen->rawt.c_cc[VMIN] = _cursesi_screen->ovmin;
_cursesi_screen->rawt.c_cc[VTIME] = _cursesi_screen->ovtime;
_cursesi_screen->cbreakt.c_cc[VMIN] = _cursesi_screen->ovmin;
@@ -282,6 +309,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
_cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
_cursesi_screen->rawt.c_cc[VMIN] = 0;
@@ -303,6 +332,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->rawt.c_cc[VMIN] = 1;
_cursesi_screen->rawt.c_cc[VTIME] = 0;
_cursesi_screen->cbreakt.c_cc[VMIN] = 1;
@@ -344,6 +375,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->rawt.c_iflag |= ICRNL;
_cursesi_screen->rawt.c_oflag |= ONLCR;
_cursesi_screen->cbreakt.c_iflag |= ICRNL;
@@ -364,6 +397,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
_cursesi_screen->rawt.c_iflag &= ~ICRNL;
_cursesi_screen->rawt.c_oflag &= ~ONLCR;
_cursesi_screen->cbreakt.c_iflag &= ~ICRNL;
@@ -384,6 +419,8 @@
if (_cursesi_screen->endwin)
__restartwin();
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
if (bf) {
_cursesi_screen->rawt.c_lflag &= ~NOFLSH;
_cursesi_screen->cbreakt.c_lflag &= ~NOFLSH;
@@ -460,6 +497,8 @@
int
savetty(void)
{
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
return (tcgetattr(fileno(_cursesi_screen->infd),
&_cursesi_screen->savedtty) ? ERR : OK);
}
@@ -467,6 +506,8 @@
int
resetty(void)
{
+ if (_cursesi_screen->notty == TRUE)
+ return OK;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT | TCSADRAIN : TCSADRAIN,
&_cursesi_screen->savedtty) ? ERR : OK);
@@ -480,6 +521,8 @@
char
erasechar(void)
{
+ if (_cursesi_screen->notty == TRUE)
+ return 0;
return _cursesi_screen->baset.c_cc[VERASE];
}
@@ -490,5 +533,7 @@
char
killchar(void)
{
+ if (_cursesi_screen->notty == TRUE)
+ return 0;
return _cursesi_screen->baset.c_cc[VKILL];
}
Home |
Main Index |
Thread Index |
Old Index