Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/editors/beav/files/patch-termio.c
16461 views
1
--- termio.c.orig 2013-12-12 17:16:34.000000000 +0100
2
+++ termio.c 2013-12-12 17:17:40.000000000 +0100
3
@@ -8,11 +8,16 @@
4
5
#ifdef UNIX /* System V */
6
7
+#if defined(__GLIBC__) || \
8
+ defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
9
+#define TERMIOS 1
10
+#endif
11
+
12
#include <unistd.h>
13
#include <errno.h>
14
#include <stdio.h>
15
#include <signal.h>
16
-#ifdef BSD
17
+#if defined(BSD) && !defined(TERMIOS)
18
#include <sys/ioctl.h>
19
#else
20
#ifdef OS2
21
@@ -28,7 +33,8 @@
22
#include <sgtty.h>
23
#define O_NDELAY O_NONBLOCK
24
#else
25
-#ifdef __GLIBC__
26
+#ifdef TERMIOS
27
+#include <sys/ioctl.h>
28
#include <termios.h>
29
#else
30
#include <termio.h>
31
@@ -44,7 +50,7 @@ int kbdpoll; /* in O_NDELAY mode
32
int kbdqp; /* there is a char in kbdq */
33
char kbdq; /* char we've already read */
34
35
-#ifdef BSD
36
+#if defined(BSD) && !defined(TERMIOS)
37
struct sgttyb otermb;
38
struct sgttyb ntermb;
39
#else
40
@@ -58,7 +64,7 @@ struct sgttyb otermio; /* original term
41
struct sgttyb ntermio; /* charactoristics to use inside */
42
struct tchars tchars, tcharsorig;
43
#else
44
-#ifdef __GLIBC__
45
+#ifdef TERMIOS
46
#include <sys/ioctl.h>
47
struct termios otermio;
48
struct termios ntermio;
49
@@ -86,8 +92,8 @@ int ncol; /* Terminal size, columns.
50
void
51
ttopen ()
52
{
53
-#ifdef BSD
54
-#ifdef ULTRIX
55
+#if defined(BSD) && !defined(TERMIOS)
56
+#ifdef TIOCGWINSZ
57
struct winsize ttysize;
58
#else
59
struct ttysize ttysize;
60
@@ -104,7 +110,7 @@ ttopen ()
61
of the cursor */
62
ttrow = 999;
63
ttcol = 999;
64
-#ifdef ULTRIX
65
+#ifdef TIOCGWINSZ
66
if (ioctl (0, TIOCGWINSZ, &ttysize) == 0)
67
{
68
nrow = ttysize.ws_row;
69
@@ -137,8 +143,13 @@ ttopen ()
70
tchars.t_stopc = tchars.t_eofc = tchars.t_brkc = -1;
71
ioctl (0, TIOCSETC, &tchars);
72
#else
73
-#ifdef __GLIBC__
74
+#ifdef TERMIOS
75
+#ifdef TIOCGWINSZ
76
+ struct winsize ttysize;
77
+#endif
78
tcgetattr(0,&otermio);
79
+ ntermio.c_ispeed = otermio.c_ispeed;
80
+ ntermio.c_ospeed = otermio.c_ospeed;
81
#else
82
ioctl (0, TCGETA, &otermio);/* save old settings */
83
ntermio.c_line = otermio.c_line;
84
@@ -149,7 +160,7 @@ ttopen ()
85
ntermio.c_lflag = 0;
86
ntermio.c_cc[VMIN] = 1;
87
ntermio.c_cc[VTIME] = 0;
88
-#ifdef __GLIBC__
89
+#ifdef TERMIOS
90
tcsetattr(0,TCSANOW,&ntermio);
91
#else
92
ioctl (0, TCSETAW, &ntermio); /* and activate them */
93
@@ -161,8 +172,17 @@ ttopen ()
94
/* on all screens we are not sure of the initial position of the cursor */
95
ttrow = 999;
96
ttcol = 999;
97
- nrow = NROW;
98
- ncol = NCOL;
99
+#if defined(TERMIOS) && defined(TIOCGWINSZ)
100
+ if (ioctl (0, TIOCGWINSZ, &ttysize) == 0)
101
+ {
102
+ nrow = ttysize.ws_row;
103
+ ncol = ttysize.ws_col;
104
+ } else
105
+#endif
106
+ {
107
+ nrow = NROW;
108
+ ncol = NCOL;
109
+ }
110
#endif /* BSD */
111
}
112
113
@@ -174,7 +194,7 @@ ttopen ()
114
void
115
ttclose ()
116
{
117
-#ifdef BSD
118
+#if defined(BSD) && !defined(TERMIOS)
119
if (ioctl (0, TIOCSETP, &otermb) == -1) /* restore terminal settings */
120
printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
121
#else
122
@@ -186,7 +206,7 @@ ttclose ()
123
ioctl (0, TIOCSETC, &tcharsorig) == -1)
124
printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
125
#else
126
-#ifdef __GLIBC__
127
+#ifdef TERMIOS
128
if( tcsetattr(0,TCSANOW,&otermio) == -1)
129
#else
130
if (ioctl (0, TCSETAW, &otermio) == -1) /* restore terminal settings */
131
132