| @@ -1,15 +1,229 @@ | | | @@ -1,15 +1,229 @@ |
1 | $NetBSD: patch-ab,v 1.5 2013/07/18 12:07:24 joerg Exp $ | | 1 | $NetBSD: patch-ab,v 1.6 2014/09/12 03:54:13 dholland Exp $ |
2 | | | 2 | |
3 | --- termio.c.orig 2013-07-17 14:36:18.000000000 +0000 | | 3 | Rip out struct sgttyb and termio and other prehistoric stuff. Use only |
| | | 4 | termios, except leave the OS2 and MINIX cases alone. The latter |
| | | 5 | probably should be removed too, but let's wait to hear from some Minix |
| | | 6 | users. |
| | | 7 | |
| | | 8 | Also, make the termios code that was already here actually work. |
| | | 9 | |
| | | 10 | --- termio.c.orig 2014-09-12 03:38:15.000000000 +0000 |
4 | +++ termio.c | | 11 | +++ termio.c |
5 | @@ -14,6 +14,10 @@ | | 12 | @@ -12,9 +12,6 @@ |
| | | 13 | #include <errno.h> |
| | | 14 | #include <stdio.h> |
6 | #include <signal.h> | | 15 | #include <signal.h> |
7 | #ifdef BSD | | 16 | -#ifdef BSD |
8 | #include <sys/ioctl.h> | | 17 | -#include <sys/ioctl.h> |
9 | +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) | | 18 | -#else |
10 | +#include <sys/ioctl_compat.h> | | 19 | #ifdef OS2 |
| | | 20 | #ifndef __EMX__ |
| | | 21 | #define INCL_NOPM |
| | | 22 | @@ -28,15 +25,10 @@ |
| | | 23 | #include <sgtty.h> |
| | | 24 | #define O_NDELAY O_NONBLOCK |
| | | 25 | #else |
| | | 26 | -#ifdef __GLIBC__ |
| | | 27 | +#include <sys/ioctl.h> |
| | | 28 | #include <termios.h> |
| | | 29 | -#else |
| | | 30 | -#include <termio.h> |
| | | 31 | -#endif /* __GLIBC__ */ |
| | | 32 | #endif /* MINIX */ |
| | | 33 | #endif /* OS2 */ |
| | | 34 | -#endif /* BSD */ |
| | | 35 | -#include <errno.h> |
| | | 36 | #include <fcntl.h> |
| | | 37 | #include "def.h" |
| | | 38 | int kbdflgs; /* saved keyboard fd flags */ |
| | | 39 | @@ -44,10 +36,6 @@ int kbdpoll; /* in O_NDELAY mode |
| | | 40 | int kbdqp; /* there is a char in kbdq */ |
| | | 41 | char kbdq; /* char we've already read */ |
| | | 42 | |
| | | 43 | -#ifdef BSD |
| | | 44 | -struct sgttyb otermb; |
| | | 45 | -struct sgttyb ntermb; |
| | | 46 | -#else |
| | | 47 | #ifdef OS2 |
| | | 48 | #ifndef __EMX__ |
| | | 49 | KBDINFO kbst, kbst_std; |
| | | 50 | @@ -58,21 +46,12 @@ struct sgttyb otermio; /* original term |
| | | 51 | struct sgttyb ntermio; /* charactoristics to use inside */ |
| | | 52 | struct tchars tchars, tcharsorig; |
| | | 53 | #else |
| | | 54 | -#ifdef __GLIBC__ |
| | | 55 | -#include <sys/ioctl.h> |
11 | +#include <termios.h> | | 56 | +#include <termios.h> |
| | | 57 | struct termios otermio; |
| | | 58 | struct termios ntermio; |
| | | 59 | -#else |
| | | 60 | -struct termio otermio; /* original terminal characteristics */ |
| | | 61 | -struct termio ntermio; /* charactoristics to use inside */ |
| | | 62 | -#endif /* __GLIBC__ */ |
| | | 63 | #endif /* MINIX */ |
| | | 64 | #endif /* OS2 */ |
| | | 65 | -#endif /* BSD */ |
| | | 66 | |
| | | 67 | -#ifndef OS2 |
| | | 68 | -//extern errno; /* System error number -- Necessary when compiling in BSD 1.13 */ |
| | | 69 | -#endif |
| | | 70 | |
| | | 71 | int nrow; /* Terminal size, rows. */ |
| | | 72 | int ncol; /* Terminal size, columns. */ |
| | | 73 | @@ -86,42 +65,37 @@ int ncol; /* Terminal size, columns. |
| | | 74 | void |
| | | 75 | ttopen () |
| | | 76 | { |
| | | 77 | -#ifdef BSD |
| | | 78 | -#ifdef ULTRIX |
| | | 79 | +#if !defined(OS2) && !defined(MINIX) |
| | | 80 | + |
| | | 81 | +#if defined(TIOCGWINSZ) |
| | | 82 | struct winsize ttysize; |
| | | 83 | -#else |
| | | 84 | +#elif defined(TIOCGSIZE) |
| | | 85 | struct ttysize ttysize; |
| | | 86 | #endif |
| | | 87 | |
| | | 88 | - ioctl (0, TIOCGETP, &otermb); /* save settings */ |
| | | 89 | - ntermb = otermb; /* setup new settings */ |
| | | 90 | - ntermb.sg_flags &= ~ECHO; |
| | | 91 | - ntermb.sg_flags |= RAW; |
| | | 92 | - ioctl (0, TIOCSETP, &ntermb); /* and activate them */ |
| | | 93 | - kbdpoll = FALSE; |
| | | 94 | - |
| | | 95 | /* on all screens we are not sure of the initial position |
| | | 96 | of the cursor */ |
| | | 97 | ttrow = 999; |
| | | 98 | ttcol = 999; |
| | | 99 | -#ifdef ULTRIX |
| | | 100 | +#if defined(TIOCGWINSZ) |
| | | 101 | if (ioctl (0, TIOCGWINSZ, &ttysize) == 0) |
| | | 102 | { |
| | | 103 | nrow = ttysize.ws_row; |
| | | 104 | ncol = ttysize.ws_col; |
| | | 105 | -#else |
| | | 106 | + } else |
| | | 107 | +#elif defined(TIOCGSIZE) |
| | | 108 | if (ioctl (0, TIOCGSIZE, &ttysize) == 0) |
| | | 109 | { |
| | | 110 | nrow = ttysize.ts_lines; |
| | | 111 | ncol = ttysize.ts_cols; |
| | | 112 | + } else |
| | | 113 | #endif /* ULTRIX */ |
| | | 114 | - } |
| | | 115 | - else |
| | | 116 | { |
| | | 117 | nrow = NROW; |
| | | 118 | ncol = NCOL; |
| | | 119 | } |
| | | 120 | -#else |
| | | 121 | +#endif /* not OS2 or MINIX */ |
| | | 122 | + |
| | | 123 | #ifdef OS2 |
| | | 124 | setmode (1, O_BINARY); |
| | | 125 | #else |
| | | 126 | @@ -137,33 +111,23 @@ ttopen () |
| | | 127 | tchars.t_stopc = tchars.t_eofc = tchars.t_brkc = -1; |
| | | 128 | ioctl (0, TIOCSETC, &tchars); |
| | | 129 | #else |
| | | 130 | -#ifdef __GLIBC__ |
| | | 131 | tcgetattr(0,&otermio); |
| | | 132 | -#else |
| | | 133 | - ioctl (0, TCGETA, &otermio);/* save old settings */ |
| | | 134 | - ntermio.c_line = otermio.c_line; |
| | | 135 | -#endif |
| | | 136 | +#if 0 /* horribly wrong -- never do this! */ |
| | | 137 | ntermio.c_iflag = 0; /* setup new settings */ |
| | | 138 | ntermio.c_oflag = 0; |
| | | 139 | ntermio.c_cflag = otermio.c_cflag; |
| | | 140 | ntermio.c_lflag = 0; |
| | | 141 | +#else |
| | | 142 | + ntermio = otermio; |
| | | 143 | + ntermio.c_lflag &= ~(ECHO|ECHONL|ECHOCTL|ISIG|ICANON); |
12 | +#endif | | 144 | +#endif |
| | | 145 | ntermio.c_cc[VMIN] = 1; |
| | | 146 | ntermio.c_cc[VTIME] = 0; |
| | | 147 | -#ifdef __GLIBC__ |
| | | 148 | tcsetattr(0,TCSANOW,&ntermio); |
| | | 149 | -#else |
| | | 150 | - ioctl (0, TCSETAW, &ntermio); /* and activate them */ |
| | | 151 | -#endif |
| | | 152 | #endif /* MINIX */ |
| | | 153 | kbdflgs = fcntl (0, F_GETFL, 0); |
| | | 154 | kbdpoll = FALSE; |
| | | 155 | #endif /* OS2 */ |
| | | 156 | - /* on all screens we are not sure of the initial position of the cursor */ |
| | | 157 | - ttrow = 999; |
| | | 158 | - ttcol = 999; |
| | | 159 | - nrow = NROW; |
| | | 160 | - ncol = NCOL; |
| | | 161 | -#endif /* BSD */ |
| | | 162 | } |
| | | 163 | |
| | | 164 | /* |
| | | 165 | @@ -174,10 +138,6 @@ ttopen () |
| | | 166 | void |
| | | 167 | ttclose () |
| | | 168 | { |
| | | 169 | -#ifdef BSD |
| | | 170 | - if (ioctl (0, TIOCSETP, &otermb) == -1) /* restore terminal settings */ |
| | | 171 | - printf ("closing ioctl on dev 0 failure, error = %d\n", errno); |
| | | 172 | -#else |
| | | 173 | #ifdef OS2 |
| | | 174 | setmode (1, O_TEXT); |
13 | #else | | 175 | #else |
| | | 176 | @@ -186,17 +146,12 @@ ttclose () |
| | | 177 | ioctl (0, TIOCSETC, &tcharsorig) == -1) |
| | | 178 | printf ("closing ioctl on dev 0 failure, error = %d\n", errno); |
| | | 179 | #else |
| | | 180 | -#ifdef __GLIBC__ |
| | | 181 | if( tcsetattr(0,TCSANOW,&otermio) == -1) |
| | | 182 | -#else |
| | | 183 | - if (ioctl (0, TCSETAW, &otermio) == -1) /* restore terminal settings */ |
| | | 184 | -#endif |
| | | 185 | printf ("closing ioctl on dev 0 failure, error = %d\n", errno); |
| | | 186 | #endif /* MINIX */ |
| | | 187 | if (fcntl (0, F_SETFL, kbdflgs) == -1) |
| | | 188 | printf ("closing fcntl on dev 0 failure, error = %d\n", errno); |
| | | 189 | #endif /* OS2 */ |
| | | 190 | -#endif /* BSD */ |
| | | 191 | } |
| | | 192 | |
14 | #ifdef OS2 | | 193 | #ifdef OS2 |
15 | #ifndef __EMX__ | | 194 | @@ -235,7 +190,7 @@ ttcooked (void) |
| | | 195 | #endif |
| | | 196 | } |
| | | 197 | |
| | | 198 | -#endif |
| | | 199 | +#endif /* OS2 */ |
| | | 200 | |
| | | 201 | /* |
| | | 202 | * Write a character to the display. On VMS, terminal output is buffered, and |
| | | 203 | @@ -336,7 +291,7 @@ int ttgetc () |
| | | 204 | kbdqp = FALSE; |
| | | 205 | else |
| | | 206 | { |
| | | 207 | -#ifdef BSD |
| | | 208 | +#if defined(FIONREAD) |
| | | 209 | int count; |
| | | 210 | |
| | | 211 | if (kbdpoll && (ioctl (0, FIONREAD, &count), count == 0)) |
| | | 212 | @@ -372,7 +327,7 @@ int ttkeyready () |
| | | 213 | #else |
| | | 214 | if (!kbdqp) |
| | | 215 | { |
| | | 216 | -#ifdef BSD |
| | | 217 | +#if defined(FIONREAD) |
| | | 218 | int count; |
| | | 219 | |
| | | 220 | if (!kbdpoll && (ioctl (0, FIONREAD, &count), count == 0)) |
| | | 221 | @@ -389,7 +344,7 @@ int ttkeyready () |
| | | 222 | kbdpoll = TRUE; /* fix in 1.13 */ |
| | | 223 | kbdqp = (1 == read (0, &kbdq, 1)); |
| | | 224 | #endif /* MINIX */ |
| | | 225 | -#endif /* BSD */ |
| | | 226 | +#endif /* FIONREAD */ |
| | | 227 | |
| | | 228 | } |
| | | 229 | return (kbdqp); |