|
|
1.1 root 1: /*********************************************************************
2: * COPYRIGHT NOTICE *
3: **********************************************************************
4: * This software is copyright (C) 1982 by Pavel Curtis *
5: * *
6: * Permission is granted to reproduce and distribute *
7: * this file by any means so long as no fee is charged *
8: * above a nominal handling fee and so long as this *
9: * notice is always included in the copies. *
10: * *
11: * Other rights are reserved except as explicitly granted *
12: * by written permission of the author. *
13: * Pavel Curtis *
14: * Computer Science Dept. *
15: * 405 Upson Hall *
16: * Cornell University *
17: * Ithaca, NY 14853 *
18: * *
19: * Ph- (607) 256-4934 *
20: * *
21: * Pavel.Cornell@Udel-Relay (ARPAnet) *
22: * decvax!cornell!pavel (UUCPnet) *
23: *********************************************************************/
24:
25: /*
26: * fixterm.c
27: *
28: * Routines:
29: * fixterm()
30: * resetterm()
31: * saveterm()
32: * gettmode()
33: * setterm()
34: * baudrate()
35: * erasechar()
36: * killchar()
37: * flushinp()
38: * savetty()
39: * resetty()
40: *
41: * $Log: RCS/lib_fixterm.v $
42: * Revision 2.2 92/29/11 15:27:58 munk
43: * Conditional usage of termio
44: *
45: * Revision 2.1 82/10/25 14:47:22 pavel
46: * Added Copyright Notice
47: *
48: * Revision 2.0 82/10/24 15:17:36 pavel
49: * Beta-one Test Release
50: *
51: * Revision 1.3 82/08/23 22:30:27 pavel
52: * The REAL Alpha-one Release Version
53: *
54: * Revision 1.2 82/08/19 19:11:21 pavel
55: * Alpha Test Release One
56: *
57: * Revision 1.1 82/08/12 18:40:30 pavel
58: * Initial revision
59: *
60: *
61: */
62:
63: #ifdef RCSHDR
64: static char RCSid[] =
65: "$Header: RCS/lib_fixterm.v Revision 2.1 82/10/25 14:47:22 pavel Exp$";
66: #endif
67:
68: #include "curses.h"
69: #include "curses.priv.h"
70: #include "term.h"
71: #ifdef COHERENT
72: #ifdef USE_TERMIO
73: #include <termio.h>
74: #else
75: #include <sgtty.h>
76: #endif
77: #else
78: #include <sys/ioctl.h>
79: #endif
80:
81:
82: /*
83: * fixterm()
84: * resetterm()
85: *
86: * fixterm() establishes the tty modes contained in cur_term->Nttyb.
87: * resetterm() establishes those in cur_term->Ottyb.
88: *
89: */
90:
91: fixterm()
92: {
93: #ifdef TRACE
94: if (_tracing)
95: _tracef("fixterm() called");
96: #endif
97: #ifdef USE_TERMIO
98: ioctl(cur_term->Filedes, TCSETA, &cur_term->Ntermio);
99: #else
100: stty(cur_term->Filedes, &cur_term->Nttyb);
101: #endif
102: }
103:
104:
105: resetterm()
106: {
107: #ifdef TRACE
108: if (_tracing)
109: _tracef("resetterm() called");
110: #endif
111: #ifdef USE_TERMIO
112: ioctl(cur_term->Filedes, TCSETA, &cur_term->Otermio);
113: #else
114: stty(cur_term->Filedes, &cur_term->Ottyb);
115: #endif
116: }
117:
118:
119: saveterm()
120: {
121: #ifdef TRACE
122: if (_tracing)
123: _tracef("saveterm() called");
124: #endif
125: #ifdef USE_TERMIO
126: ioctl(cur_term->Filedes, TCGETA, &cur_term->Ntermio);
127: #else
128: gtty(cur_term->Filedes, &cur_term->Nttyb);
129: #endif
130: }
131:
132:
133: /*
134: * gettmode()
135: * setterm(type)
136: *
137: * These are kept around for backward compatibilty. gettmode() does
138: * nothing. setterm() results in a proper call to setupterm()
139: *
140: */
141: gettmode()
142: {
143: #ifdef TRACE
144: if (_tracing)
145: _tracef("gettmode() called");
146: #endif
147: }
148:
149:
150: setterm(type)
151: char *type;
152: {
153: #ifdef TRACE
154: if (_tracing)
155: _tracef("setterm() called");
156: #endif
157: setupterm(type, 1, 0);
158: }
159:
160:
161: /*
162: * erasechar()
163: *
164: * Return erase character as given in cur_term->Ottyb.
165: *
166: */
167: char
168: erasechar()
169: {
170: #ifdef TRACE
171: if (_tracing)
172: _tracef("erasechar() called");
173: #endif
174: #ifdef USE_TERMIO
175: return(cur_term->Otermio.c_cc[VERASE]);
176: #else
177: return(cur_term->Ottyb.sg_erase);
178: #endif
179: }
180:
181:
182: /*
183: * killchar()
184: *
185: * Return kill character as given in cur_term->Ottyb.
186: *
187: */
188: char
189: killchar()
190: {
191: #ifdef TRACE
192: if (_tracing)
193: _tracef("killchar() called");
194: #endif
195: #ifdef USE_TERMIO
196: return(cur_term->Otermio.c_cc[VKILL]);
197: #else
198: return(cur_term->Ottyb.sg_kill);
199: #endif
200: }
201:
202:
203: /*
204: * flushinp()
205: *
206: * Flush any input on cur_term->Filedes
207: *
208: */
209: flushinp()
210: {
211: #ifdef TRACE
212: if (_tracing)
213: _tracef("flushinp() called");
214: #endif
215: #ifdef USE_TERMIO
216: ioctl(cur_term->Filedes, TCFLSH, 0);
217: #else
218: ioctl(cur_term->Filedes, TIOCFLUSH, 0);
219: #endif
220:
221: if (SP)
222: SP->_backcnt = 0;
223: }
224:
225:
226: /*
227: * int
228: * baudrate()
229: *
230: * Returns the current terminal's baud rate.
231: *
232: */
233: static int speeds[] =
234: {
235: 0, 50, 75, 110, 134, 150, 200, 300, 600,
236: 1200, 1800, 2400, 4800, 9600, 19200, 38400
237: };
238:
239: int
240: baudrate()
241: {
242: int speed;
243:
244: #ifdef TRACE
245: if (_tracing)
246: _tracef("baudrate() called");
247: #endif
248: #ifdef USE_TERMIO
249: speed = cur_term->Ntermio.c_cflag & CBAUD;
250: #else
251: speed = cur_term->Nttyb.sg_ospeed;
252: #endif
253: return speeds[speed];
254: }
255:
256:
257: /*
258: ** savetty() and resetty()
259: **
260: ** Kept around for compatibility.
261: **
262: */
263:
264: #ifdef USE_TERMIO
265: static struct termio myTermio;
266: #else
267: static struct sgttyb sgbuf;
268: #endif
269:
270: savetty()
271: {
272: #ifdef TRACE
273: if (_tracing)
274: _tracef("savetty() called");
275: #endif
276:
277: #ifdef USE_TERMIO
278: ioctl(cur_term->Filedes, TCGETA, &myTermio);
279: #else
280: gtty(cur_term->Filedes, &sgbuf);
281: #endif
282: }
283:
284:
285: resetty()
286: {
287: #ifdef TRACE
288: if (_tracing)
289: _tracef("resetty() called");
290: #endif
291:
292: #ifdef USE_TERMIO
293: ioctl(cur_term->Filedes, TCSETA, &myTermio);
294: #else
295: stty(cur_term->Filedes, &sgbuf);
296: #endif
297: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.