Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 127 lines (110 sloc) 2.888 kb
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
1 /* tcapsysv.h */
2
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
3 #ifdef FEATURE_RCSID
4 char id_tcapsysv[] = "$Id: tcapsysv.h,v 2.12 2003/01/26 19:41:36 steve Exp $";
5 #endif
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
6
7 #include <termio.h>
8 #include <signal.h>
9 #include <unistd.h>
10
11 /* HPUX does a "#define ttysize winsize". Elvis doesn't like that. */
12 #undef ttysize
13
14 static struct termio oldtermio; /* original tty mode */
15 static struct termio newtermio; /* cbreak/noecho tty mode */
16
17 /* signal catching function */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
18 static void catchsig(signo)
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
19 int signo;
20 {
21 caught |= (1<<signo);
22 }
23
24
25 /* remember the original tty state */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
26 static void ttyinit2()
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
27 {
28 /* get the old tty state */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
29 ioctl(ttykbd, TCGETA, &oldtermio);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
30 }
31
32 /* switch back to the original tty state */
33 void ttynormal()
34 {
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
35 ioctl(ttykbd, TCSETAW, &oldtermio);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
36 }
37
38 /* switch to the tty state that elvis runs in */
39 void ttyraw(erasekey)
40 char *erasekey; /* where to store the ERASE key */
41 {
42 /* arrange for signals to be caught or ignored */
43 signal(SIGINT, catchsig);
44 #ifdef SIGWINCH
45 signal(SIGWINCH, catchsig);
46 #endif
47 signal(SIGQUIT, SIG_IGN);
48
49 ospeed = (oldtermio.c_cflag & CBAUD);
50 *erasekey = oldtermio.c_cc[VERASE];
51 newtermio = oldtermio;
52 # ifdef IXANY
53 newtermio.c_iflag &= (IXON|IXOFF|IXANY|ISTRIP|IGNBRK);
54 # else
55 newtermio.c_iflag &= (IXON|IXOFF|ISTRIP|IGNBRK);
56 # endif
57 newtermio.c_oflag &= ~OPOST;
58 newtermio.c_lflag &= ISIG;
59 newtermio.c_cc[VINTR] = ELVCTRL('C'); /* always use ^C for interrupts */
60 newtermio.c_cc[VMIN] = 1;
61 newtermio.c_cc[VTIME] = 0;
62 # ifdef VSWTCH
63 newtermio.c_cc[VSWTCH] = 0;
64 # endif
65 # ifdef VSWTC
66 newtermio.c_cc[VSWTC] = 0;
67 # endif
68 # ifdef VSUSP
69 # if VSUSP < NCC
70 newtermio.c_cc[VSUSP] = 0;
71 # endif
72 # endif
73 # ifdef VDSUSP
74 newtermio.c_cc[VSUSP] = 0;
75 # endif
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
76 ioctl(ttykbd, TCSETAW, &newtermio);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
77 }
78
79 /* For System-V, we use VMIN/VTIME to implement the timeout. For no
80 * timeout, VMIN should be 1 and VTIME should be 0; for timeout, VMIN
81 * should be 0 and VTIME should be the timeout value.
82 */
83 int ttyread(buf, len, timeout)
84 char *buf; /* where to store the input characters */
85 int len; /* maximum number of characters to read */
86 int timeout;/* timeout (or 0 for none) */
87 {
88 struct termio t, oldt;
89 int bytes; /* number of bytes actually read */
90
91 /* reset the "caught" variable */
92 caught = 0;
93
94 /* make sure the signal handler is still in place */
95 signal(SIGINT, catchsig);
96 #ifdef SIGWINCH
97 signal(SIGWINCH, catchsig);
98 #endif
99
100 /* arrange for timeout, and disable special keys */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
101 ioctl(ttykbd, TCGETA, &t);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
102 oldt = t;
103 if (timeout)
104 {
105 t.c_cc[VMIN] = 0;
106 t.c_cc[VTIME] = timeout;
107 }
108 else
109 {
110 t.c_cc[VMIN] = 1;
111 t.c_cc[VTIME] = 0;
112 }
113 t.c_cc[VINTR] = t.c_cc[VQUIT] = 0;
114 #ifdef VSTART
115 t.c_cc[VSTART] = t.c_cc[VSTOP] = 0;
116 #endif
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
117 ioctl(ttykbd, TCSETA, &t);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
118
119 /* Perform the read. */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
120 bytes = read(ttykbd, buf, (unsigned)len);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
121
122 /* set the tty back to ordinary raw mode */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
123 ioctl(ttykbd, TCSETA, &oldt);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
124
125 /* return the number of bytes read */
126 return bytes;
127 }
Something went wrong with that request. Please try again.