Path: blob/main/editors/beav/files/patch-termio.c
18157 views
--- termio.c.orig 2013-12-12 17:16:34.000000000 +01001+++ termio.c 2013-12-12 17:17:40.000000000 +01002@@ -8,11 +8,16 @@34#ifdef UNIX /* System V */56+#if defined(__GLIBC__) || \7+ defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)8+#define TERMIOS 19+#endif10+11#include <unistd.h>12#include <errno.h>13#include <stdio.h>14#include <signal.h>15-#ifdef BSD16+#if defined(BSD) && !defined(TERMIOS)17#include <sys/ioctl.h>18#else19#ifdef OS220@@ -28,7 +33,8 @@21#include <sgtty.h>22#define O_NDELAY O_NONBLOCK23#else24-#ifdef __GLIBC__25+#ifdef TERMIOS26+#include <sys/ioctl.h>27#include <termios.h>28#else29#include <termio.h>30@@ -44,7 +50,7 @@ int kbdpoll; /* in O_NDELAY mode31int kbdqp; /* there is a char in kbdq */32char kbdq; /* char we've already read */3334-#ifdef BSD35+#if defined(BSD) && !defined(TERMIOS)36struct sgttyb otermb;37struct sgttyb ntermb;38#else39@@ -58,7 +64,7 @@ struct sgttyb otermio; /* original term40struct sgttyb ntermio; /* charactoristics to use inside */41struct tchars tchars, tcharsorig;42#else43-#ifdef __GLIBC__44+#ifdef TERMIOS45#include <sys/ioctl.h>46struct termios otermio;47struct termios ntermio;48@@ -86,8 +92,8 @@ int ncol; /* Terminal size, columns.49void50ttopen ()51{52-#ifdef BSD53-#ifdef ULTRIX54+#if defined(BSD) && !defined(TERMIOS)55+#ifdef TIOCGWINSZ56struct winsize ttysize;57#else58struct ttysize ttysize;59@@ -104,7 +110,7 @@ ttopen ()60of the cursor */61ttrow = 999;62ttcol = 999;63-#ifdef ULTRIX64+#ifdef TIOCGWINSZ65if (ioctl (0, TIOCGWINSZ, &ttysize) == 0)66{67nrow = ttysize.ws_row;68@@ -137,8 +143,13 @@ ttopen ()69tchars.t_stopc = tchars.t_eofc = tchars.t_brkc = -1;70ioctl (0, TIOCSETC, &tchars);71#else72-#ifdef __GLIBC__73+#ifdef TERMIOS74+#ifdef TIOCGWINSZ75+ struct winsize ttysize;76+#endif77tcgetattr(0,&otermio);78+ ntermio.c_ispeed = otermio.c_ispeed;79+ ntermio.c_ospeed = otermio.c_ospeed;80#else81ioctl (0, TCGETA, &otermio);/* save old settings */82ntermio.c_line = otermio.c_line;83@@ -149,7 +160,7 @@ ttopen ()84ntermio.c_lflag = 0;85ntermio.c_cc[VMIN] = 1;86ntermio.c_cc[VTIME] = 0;87-#ifdef __GLIBC__88+#ifdef TERMIOS89tcsetattr(0,TCSANOW,&ntermio);90#else91ioctl (0, TCSETAW, &ntermio); /* and activate them */92@@ -161,8 +172,17 @@ ttopen ()93/* on all screens we are not sure of the initial position of the cursor */94ttrow = 999;95ttcol = 999;96- nrow = NROW;97- ncol = NCOL;98+#if defined(TERMIOS) && defined(TIOCGWINSZ)99+ if (ioctl (0, TIOCGWINSZ, &ttysize) == 0)100+ {101+ nrow = ttysize.ws_row;102+ ncol = ttysize.ws_col;103+ } else104+#endif105+ {106+ nrow = NROW;107+ ncol = NCOL;108+ }109#endif /* BSD */110}111112@@ -174,7 +194,7 @@ ttopen ()113void114ttclose ()115{116-#ifdef BSD117+#if defined(BSD) && !defined(TERMIOS)118if (ioctl (0, TIOCSETP, &otermb) == -1) /* restore terminal settings */119printf ("closing ioctl on dev 0 failure, error = %d\n", errno);120#else121@@ -186,7 +206,7 @@ ttclose ()122ioctl (0, TIOCSETC, &tcharsorig) == -1)123printf ("closing ioctl on dev 0 failure, error = %d\n", errno);124#else125-#ifdef __GLIBC__126+#ifdef TERMIOS127if( tcsetattr(0,TCSANOW,&otermio) == -1)128#else129if (ioctl (0, TCSETAW, &otermio) == -1) /* restore terminal settings */130131132