Репозитории ALT
Группа :: Работа с файлами
Пакет: less
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: less-378-alt-tty.patch
Скачать
Скачать
--- less-378/screen.c.orig 2002-09-30 21:57:15 +0400
+++ less-378/screen.c 2002-10-02 13:14:32 +0400
@@ -237,6 +237,18 @@ extern int hilite_search;
extern char *tgetstr();
extern char *tgoto();
+static int screen_fd(void)
+{
+ static int fd = -1;
+ if (fd == -1)
+ {
+ for (fd = STDIN_FILENO; fd <= STDERR_FILENO; ++fd)
+ if (isatty(fd))
+ break;
+ }
+
+ return (fd <= STDERR_FILENO) ? fd : -1;
+}
/*
* Change terminal to "raw mode", or restore to "normal" mode.
@@ -268,7 +280,7 @@ raw_mode(on)
/*
* Get terminal modes.
*/
- tcgetattr(tty, &s);
+ tcgetattr(screen_fd(), &s);
/*
* Save modes and set certain variables dependent on modes.
@@ -426,7 +438,7 @@ raw_mode(on)
#if HAVE_FSYNC
fsync(tty);
#endif
- tcsetattr(tty, TCSADRAIN, &s);
+ tcsetattr(screen_fd(), TCSADRAIN, &s);
#if MUST_SET_LINE_DISCIPLINE
if (!on)
{
@@ -436,7 +448,7 @@ raw_mode(on)
* is therefore not restored, yet. Restore the old
* line discipline by hand.
*/
- ioctl(tty, TIOCSETD, &save_term.c_line);
+ ioctl(screen_fd(), TIOCSETD, &save_term.c_line);
}
#endif
}
@@ -452,7 +464,7 @@ raw_mode(on)
/*
* Get terminal modes.
*/
- ioctl(tty, TCGETA, &s);
+ ioctl(screen_fd(), TCGETA, &s);
/*
* Save modes and set certain variables dependent on modes.
@@ -488,7 +500,7 @@ raw_mode(on)
*/
s = save_term;
}
- ioctl(tty, TCSETAW, &s);
+ ioctl(screen_fd(), TCSETAW, &s);
}
#else
#ifdef TIOCGETP
@@ -502,7 +514,7 @@ raw_mode(on)
/*
* Get terminal modes.
*/
- ioctl(tty, TIOCGETP, &s);
+ ioctl(screen_fd(), TIOCGETP, &s);
/*
* Save modes and set certain variables dependent on modes.
@@ -531,7 +543,7 @@ raw_mode(on)
*/
s = save_term;
}
- ioctl(tty, TIOCSETN, &s);
+ ioctl(screen_fd(), TIOCSETN, &s);
}
#else
#ifdef _OSK
@@ -741,7 +753,7 @@ scrsize()
#ifdef TIOCGWINSZ
{
struct winsize w;
- if (ioctl(2, TIOCGWINSZ, &w) == 0)
+ if (ioctl(screen_fd(), TIOCGWINSZ, &w) == 0)
{
if (w.ws_row > 0)
sys_height = w.ws_row;
@@ -753,7 +765,7 @@ scrsize()
#ifdef WIOCGETD
{
struct uwdata w;
- if (ioctl(2, WIOCGETD, &w) == 0)
+ if (ioctl(screen_fd(), WIOCGETD, &w) == 0)
{
if (w.uw_height > 0)
sys_height = w.uw_height / w.uw_vs;