1 | /* $Header: /afs/dev.mit.edu/source/repository/third/tcsh/ed.term.c,v 1.1.1.2 1998-10-03 21:09:48 danw Exp $ */ |
---|
2 | /* |
---|
3 | * ed.term.c: Low level terminal interface |
---|
4 | */ |
---|
5 | /*- |
---|
6 | * Copyright (c) 1980, 1991 The Regents of the University of California. |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions |
---|
11 | * are met: |
---|
12 | * 1. Redistributions of source code must retain the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer. |
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer in the |
---|
16 | * documentation and/or other materials provided with the distribution. |
---|
17 | * 3. All advertising materials mentioning features or use of this software |
---|
18 | * must display the following acknowledgement: |
---|
19 | * This product includes software developed by the University of |
---|
20 | * California, Berkeley and its contributors. |
---|
21 | * 4. Neither the name of the University nor the names of its contributors |
---|
22 | * may be used to endorse or promote products derived from this software |
---|
23 | * without specific prior written permission. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
35 | * SUCH DAMAGE. |
---|
36 | */ |
---|
37 | #include "sh.h" |
---|
38 | #ifndef WINNT |
---|
39 | |
---|
40 | RCSID("$Id: ed.term.c,v 1.1.1.2 1998-10-03 21:09:48 danw Exp $") |
---|
41 | |
---|
42 | #include "ed.h" |
---|
43 | #include "ed.term.h" |
---|
44 | |
---|
45 | int didsetty = 0; |
---|
46 | ttyperm_t ttylist = { |
---|
47 | { |
---|
48 | #if defined(POSIX) || defined(TERMIO) |
---|
49 | { "iflag:", ICRNL, (INLCR|IGNCR) }, |
---|
50 | { "oflag:", (OPOST|ONLCR), ONLRET }, |
---|
51 | { "cflag:", 0, 0 }, |
---|
52 | { "lflag:", (ISIG|ICANON|ECHO|ECHOE|ECHOCTL|IEXTEN), |
---|
53 | (NOFLSH|ECHONL|EXTPROC|FLUSHO|IDEFAULT) }, |
---|
54 | #else /* GSTTY */ |
---|
55 | { "nrmal:", (ECHO|CRMOD|ANYP), (CBREAK|RAW|LCASE|VTDELAY|ALLDELAY) }, |
---|
56 | { "local:", (LCRTBS|LCRTERA|LCRTKIL), (LPRTERA|LFLUSHO) }, |
---|
57 | #endif /* POSIX || TERMIO */ |
---|
58 | { "chars:", 0, 0 }, |
---|
59 | }, |
---|
60 | { |
---|
61 | #if defined(POSIX) || defined(TERMIO) |
---|
62 | { "iflag:", (INLCR|ICRNL), IGNCR }, |
---|
63 | { "oflag:", (OPOST|ONLCR), ONLRET }, |
---|
64 | { "cflag:", 0, 0 }, |
---|
65 | { "lflag:", ISIG, |
---|
66 | (NOFLSH|ICANON|ECHO|ECHOK|ECHONL|EXTPROC|IEXTEN|FLUSHO| |
---|
67 | IDEFAULT) }, |
---|
68 | #else /* GSTTY */ |
---|
69 | { "nrmal:", (CBREAK|CRMOD|ANYP), (RAW|ECHO|LCASE|VTDELAY|ALLDELAY) }, |
---|
70 | { "local:", (LCRTBS|LCRTERA|LCRTKIL), (LPRTERA|LFLUSHO) }, |
---|
71 | #endif /* POSIX || TERMIO */ |
---|
72 | { "chars:", (C_SH(C_MIN)|C_SH(C_TIME)|C_SH(C_SWTCH)|C_SH(C_DSWTCH)| |
---|
73 | C_SH(C_WERASE)|C_SH(C_REPRINT)|C_SH(C_SUSP)|C_SH(C_DSUSP)| |
---|
74 | C_SH(C_EOF)|C_SH(C_EOL)|C_SH(C_DISCARD)|C_SH(C_PGOFF)| |
---|
75 | C_SH(C_KILL2)|C_SH(C_PAGE)|C_SH(C_STATUS)|C_SH(C_LNEXT)), |
---|
76 | 0 } |
---|
77 | }, |
---|
78 | { |
---|
79 | #if defined(POSIX) || defined(TERMIO) |
---|
80 | { "iflag:", 0, IXON | IXOFF }, |
---|
81 | { "oflag:", 0, 0 }, |
---|
82 | { "cflag:", 0, 0 }, |
---|
83 | { "lflag:", 0, ISIG | IEXTEN }, |
---|
84 | #else /* GSTTY */ |
---|
85 | { "nrmal:", RAW, CBREAK }, |
---|
86 | { "local:", 0, 0 }, |
---|
87 | #endif /* POSIX || TERMIO */ |
---|
88 | { "chars:", 0, 0 }, |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | static struct tcshmodes { |
---|
93 | char *m_name; |
---|
94 | #ifdef SOLARIS2 |
---|
95 | unsigned long m_value; |
---|
96 | #else /* !SOLARIS2 */ |
---|
97 | int m_value; |
---|
98 | #endif /* SOLARIS2 */ |
---|
99 | int m_type; |
---|
100 | } modelist[] = { |
---|
101 | #if defined(POSIX) || defined(TERMIO) |
---|
102 | |
---|
103 | # ifdef IGNBRK |
---|
104 | { "ignbrk", IGNBRK, M_INPUT }, |
---|
105 | # endif /* IGNBRK */ |
---|
106 | # ifdef BRKINT |
---|
107 | { "brkint", BRKINT, M_INPUT }, |
---|
108 | # endif /* BRKINT */ |
---|
109 | # ifdef IGNPAR |
---|
110 | { "ignpar", IGNPAR, M_INPUT }, |
---|
111 | # endif /* IGNPAR */ |
---|
112 | # ifdef PARMRK |
---|
113 | { "parmrk", PARMRK, M_INPUT }, |
---|
114 | # endif /* PARMRK */ |
---|
115 | # ifdef INPCK |
---|
116 | { "inpck", INPCK, M_INPUT }, |
---|
117 | # endif /* INPCK */ |
---|
118 | # ifdef ISTRIP |
---|
119 | { "istrip", ISTRIP, M_INPUT }, |
---|
120 | # endif /* ISTRIP */ |
---|
121 | # ifdef INLCR |
---|
122 | { "inlcr", INLCR, M_INPUT }, |
---|
123 | # endif /* INLCR */ |
---|
124 | # ifdef IGNCR |
---|
125 | { "igncr", IGNCR, M_INPUT }, |
---|
126 | # endif /* IGNCR */ |
---|
127 | # ifdef ICRNL |
---|
128 | { "icrnl", ICRNL, M_INPUT }, |
---|
129 | # endif /* ICRNL */ |
---|
130 | # ifdef IUCLC |
---|
131 | { "iuclc", IUCLC, M_INPUT }, |
---|
132 | # endif /* IUCLC */ |
---|
133 | # ifdef IXON |
---|
134 | { "ixon", IXON, M_INPUT }, |
---|
135 | # endif /* IXON */ |
---|
136 | # ifdef IXANY |
---|
137 | { "ixany", IXANY, M_INPUT }, |
---|
138 | # endif /* IXANY */ |
---|
139 | # ifdef IXOFF |
---|
140 | { "ixoff", IXOFF, M_INPUT }, |
---|
141 | # endif /* IXOFF */ |
---|
142 | # ifdef IMAXBEL |
---|
143 | { "imaxbel",IMAXBEL,M_INPUT }, |
---|
144 | # endif /* IMAXBEL */ |
---|
145 | # ifdef IDELETE |
---|
146 | { "idelete",IDELETE,M_INPUT }, |
---|
147 | # endif /* IDELETE */ |
---|
148 | |
---|
149 | # ifdef OPOST |
---|
150 | { "opost", OPOST, M_OUTPUT }, |
---|
151 | # endif /* OPOST */ |
---|
152 | # ifdef OLCUC |
---|
153 | { "olcuc", OLCUC, M_OUTPUT }, |
---|
154 | # endif /* OLCUC */ |
---|
155 | # ifdef ONLCR |
---|
156 | { "onlcr", ONLCR, M_OUTPUT }, |
---|
157 | # endif /* ONLCR */ |
---|
158 | # ifdef OCRNL |
---|
159 | { "ocrnl", OCRNL, M_OUTPUT }, |
---|
160 | # endif /* OCRNL */ |
---|
161 | # ifdef ONOCR |
---|
162 | { "onocr", ONOCR, M_OUTPUT }, |
---|
163 | # endif /* ONOCR */ |
---|
164 | # ifdef ONOEOT |
---|
165 | { "onoeot", ONOEOT, M_OUTPUT }, |
---|
166 | # endif /* ONOEOT */ |
---|
167 | # ifdef ONLRET |
---|
168 | { "onlret", ONLRET, M_OUTPUT }, |
---|
169 | # endif /* ONLRET */ |
---|
170 | # ifdef OFILL |
---|
171 | { "ofill", OFILL, M_OUTPUT }, |
---|
172 | # endif /* OFILL */ |
---|
173 | # ifdef OFDEL |
---|
174 | { "ofdel", OFDEL, M_OUTPUT }, |
---|
175 | # endif /* OFDEL */ |
---|
176 | # ifdef NLDLY |
---|
177 | { "nldly", NLDLY, M_OUTPUT }, |
---|
178 | # endif /* NLDLY */ |
---|
179 | # ifdef CRDLY |
---|
180 | { "crdly", CRDLY, M_OUTPUT }, |
---|
181 | # endif /* CRDLY */ |
---|
182 | # ifdef TABDLY |
---|
183 | { "tabdly", TABDLY, M_OUTPUT }, |
---|
184 | # endif /* TABDLY */ |
---|
185 | # ifdef XTABS |
---|
186 | { "xtabs", XTABS, M_OUTPUT }, |
---|
187 | # endif /* XTABS */ |
---|
188 | # ifdef BSDLY |
---|
189 | { "bsdly", BSDLY, M_OUTPUT }, |
---|
190 | # endif /* BSDLY */ |
---|
191 | # ifdef VTDLY |
---|
192 | { "vtdly", VTDLY, M_OUTPUT }, |
---|
193 | # endif /* VTDLY */ |
---|
194 | # ifdef FFDLY |
---|
195 | { "ffdly", FFDLY, M_OUTPUT }, |
---|
196 | # endif /* FFDLY */ |
---|
197 | # ifdef PAGEOUT |
---|
198 | { "pageout",PAGEOUT,M_OUTPUT }, |
---|
199 | # endif /* PAGEOUT */ |
---|
200 | # ifdef WRAP |
---|
201 | { "wrap", WRAP, M_OUTPUT }, |
---|
202 | # endif /* WRAP */ |
---|
203 | |
---|
204 | # ifdef CIGNORE |
---|
205 | { "cignore",CIGNORE,M_CONTROL }, |
---|
206 | # endif /* CBAUD */ |
---|
207 | # ifdef CBAUD |
---|
208 | { "cbaud", CBAUD, M_CONTROL }, |
---|
209 | # endif /* CBAUD */ |
---|
210 | # ifdef CSTOPB |
---|
211 | { "cstopb", CSTOPB, M_CONTROL }, |
---|
212 | # endif /* CSTOPB */ |
---|
213 | # ifdef CREAD |
---|
214 | { "cread", CREAD, M_CONTROL }, |
---|
215 | # endif /* CREAD */ |
---|
216 | # ifdef PARENB |
---|
217 | { "parenb", PARENB, M_CONTROL }, |
---|
218 | # endif /* PARENB */ |
---|
219 | # ifdef PARODD |
---|
220 | { "parodd", PARODD, M_CONTROL }, |
---|
221 | # endif /* PARODD */ |
---|
222 | # ifdef HUPCL |
---|
223 | { "hupcl", HUPCL, M_CONTROL }, |
---|
224 | # endif /* HUPCL */ |
---|
225 | # ifdef CLOCAL |
---|
226 | { "clocal", CLOCAL, M_CONTROL }, |
---|
227 | # endif /* CLOCAL */ |
---|
228 | # ifdef LOBLK |
---|
229 | { "loblk", LOBLK, M_CONTROL }, |
---|
230 | # endif /* LOBLK */ |
---|
231 | # ifdef CIBAUD |
---|
232 | { "cibaud", CIBAUD, M_CONTROL }, |
---|
233 | # endif /* CIBAUD */ |
---|
234 | # ifdef CRTSCTS |
---|
235 | # ifdef CCTS_OFLOW |
---|
236 | { "ccts_oflow",CCTS_OFLOW,M_CONTROL }, |
---|
237 | # else |
---|
238 | { "crtscts",CRTSCTS,M_CONTROL }, |
---|
239 | # endif /* CCTS_OFLOW */ |
---|
240 | # endif /* CRTSCTS */ |
---|
241 | # ifdef CRTS_IFLOW |
---|
242 | { "crts_iflow",CRTS_IFLOW,M_CONTROL }, |
---|
243 | # endif /* CRTS_IFLOW */ |
---|
244 | # ifdef MDMBUF |
---|
245 | { "mdmbuf", MDMBUF, M_CONTROL }, |
---|
246 | # endif /* MDMBUF */ |
---|
247 | # ifdef RCV1EN |
---|
248 | { "rcv1en", RCV1EN, M_CONTROL }, |
---|
249 | # endif /* RCV1EN */ |
---|
250 | # ifdef XMT1EN |
---|
251 | { "xmt1en", XMT1EN, M_CONTROL }, |
---|
252 | # endif /* XMT1EN */ |
---|
253 | |
---|
254 | # ifdef ISIG |
---|
255 | { "isig", ISIG, M_LINED }, |
---|
256 | # endif /* ISIG */ |
---|
257 | # ifdef ICANON |
---|
258 | { "icanon", ICANON, M_LINED }, |
---|
259 | # endif /* ICANON */ |
---|
260 | # ifdef XCASE |
---|
261 | { "xcase", XCASE, M_LINED }, |
---|
262 | # endif /* XCASE */ |
---|
263 | # ifdef ECHO |
---|
264 | { "echo", ECHO, M_LINED }, |
---|
265 | # endif /* ECHO */ |
---|
266 | # ifdef ECHOE |
---|
267 | { "echoe", ECHOE, M_LINED }, |
---|
268 | # endif /* ECHOE */ |
---|
269 | # ifdef ECHOK |
---|
270 | { "echok", ECHOK, M_LINED }, |
---|
271 | # endif /* ECHOK */ |
---|
272 | # ifdef ECHONL |
---|
273 | { "echonl", ECHONL, M_LINED }, |
---|
274 | # endif /* ECHONL */ |
---|
275 | # ifdef NOFLSH |
---|
276 | { "noflsh", NOFLSH, M_LINED }, |
---|
277 | # endif /* NOFLSH */ |
---|
278 | # ifdef TOSTOP |
---|
279 | { "tostop", TOSTOP, M_LINED }, |
---|
280 | # endif /* TOSTOP */ |
---|
281 | # ifdef ECHOCTL |
---|
282 | { "echoctl",ECHOCTL,M_LINED }, |
---|
283 | # endif /* ECHOCTL */ |
---|
284 | # ifdef ECHOPRT |
---|
285 | { "echoprt",ECHOPRT,M_LINED }, |
---|
286 | # endif /* ECHOPRT */ |
---|
287 | # ifdef ECHOKE |
---|
288 | { "echoke", ECHOKE, M_LINED }, |
---|
289 | # endif /* ECHOKE */ |
---|
290 | # ifdef DEFECHO |
---|
291 | { "defecho",DEFECHO,M_LINED }, |
---|
292 | # endif /* DEFECHO */ |
---|
293 | # ifdef FLUSHO |
---|
294 | { "flusho", FLUSHO, M_LINED }, |
---|
295 | # endif /* FLUSHO */ |
---|
296 | # ifdef PENDIN |
---|
297 | { "pendin", PENDIN, M_LINED }, |
---|
298 | # endif /* PENDIN */ |
---|
299 | # ifdef IEXTEN |
---|
300 | { "iexten", IEXTEN, M_LINED }, |
---|
301 | # endif /* IEXTEN */ |
---|
302 | # ifdef NOKERNINFO |
---|
303 | { "nokerninfo",NOKERNINFO,M_LINED }, |
---|
304 | # endif /* NOKERNINFO */ |
---|
305 | # ifdef ALTWERASE |
---|
306 | { "altwerase",ALTWERASE,M_LINED }, |
---|
307 | # endif /* ALTWERASE */ |
---|
308 | # ifdef EXTPROC |
---|
309 | { "extproc",EXTPROC,M_LINED }, |
---|
310 | # endif /* EXTPROC */ |
---|
311 | # ifdef IDEFAULT |
---|
312 | { "idefault",IDEFAULT,M_LINED }, |
---|
313 | # endif /* IDEFAULT */ |
---|
314 | |
---|
315 | #else /* GSTTY */ |
---|
316 | |
---|
317 | # ifdef TANDEM |
---|
318 | { "tandem", TANDEM, M_CONTROL }, |
---|
319 | # endif /* TANDEM */ |
---|
320 | # ifdef CBREAK |
---|
321 | { "cbreak", CBREAK, M_CONTROL }, |
---|
322 | # endif /* CBREAK */ |
---|
323 | # ifdef LCASE |
---|
324 | { "lcase", LCASE, M_CONTROL }, |
---|
325 | # endif /* LCASE */ |
---|
326 | # ifdef ECHO |
---|
327 | { "echo", ECHO, M_CONTROL }, |
---|
328 | # endif /* ECHO */ |
---|
329 | # ifdef CRMOD |
---|
330 | { "crmod", CRMOD, M_CONTROL }, |
---|
331 | # endif /* CRMOD */ |
---|
332 | # ifdef RAW |
---|
333 | { "raw", RAW, M_CONTROL }, |
---|
334 | # endif /* RAW */ |
---|
335 | # ifdef ODDP |
---|
336 | { "oddp", ODDP, M_CONTROL }, |
---|
337 | # endif /* ODDP */ |
---|
338 | # ifdef EVENP |
---|
339 | { "evenp", EVENP, M_CONTROL }, |
---|
340 | # endif /* EVENP */ |
---|
341 | # ifdef ANYP |
---|
342 | { "anyp", ANYP, M_CONTROL }, |
---|
343 | # endif /* ANYP */ |
---|
344 | # ifdef NLDELAY |
---|
345 | { "nldelay",NLDELAY,M_CONTROL }, |
---|
346 | # endif /* NLDELAY */ |
---|
347 | # ifdef TBDELAY |
---|
348 | { "tbdelay",TBDELAY,M_CONTROL }, |
---|
349 | # endif /* TBDELAY */ |
---|
350 | # ifdef XTABS |
---|
351 | { "xtabs", XTABS, M_CONTROL }, |
---|
352 | # endif /* XTABS */ |
---|
353 | # ifdef CRDELAY |
---|
354 | { "crdelay",CRDELAY,M_CONTROL }, |
---|
355 | # endif /* CRDELAY */ |
---|
356 | # ifdef VTDELAY |
---|
357 | { "vtdelay",VTDELAY,M_CONTROL }, |
---|
358 | # endif /* VTDELAY */ |
---|
359 | # ifdef BSDELAY |
---|
360 | { "bsdelay",BSDELAY,M_CONTROL }, |
---|
361 | # endif /* BSDELAY */ |
---|
362 | # ifdef CRTBS |
---|
363 | { "crtbs", CRTBS, M_CONTROL }, |
---|
364 | # endif /* CRTBS */ |
---|
365 | # ifdef PRTERA |
---|
366 | { "prtera", PRTERA, M_CONTROL }, |
---|
367 | # endif /* PRTERA */ |
---|
368 | # ifdef CRTERA |
---|
369 | { "crtera", CRTERA, M_CONTROL }, |
---|
370 | # endif /* CRTERA */ |
---|
371 | # ifdef TILDE |
---|
372 | { "tilde", TILDE, M_CONTROL }, |
---|
373 | # endif /* TILDE */ |
---|
374 | # ifdef MDMBUF |
---|
375 | { "mdmbuf", MDMBUF, M_CONTROL }, |
---|
376 | # endif /* MDMBUF */ |
---|
377 | # ifdef LITOUT |
---|
378 | { "litout", LITOUT, M_CONTROL }, |
---|
379 | # endif /* LITOUT */ |
---|
380 | # ifdef TOSTOP |
---|
381 | { "tostop", TOSTOP, M_CONTROL }, |
---|
382 | # endif /* TOSTOP */ |
---|
383 | # ifdef FLUSHO |
---|
384 | { "flusho", FLUSHO, M_CONTROL }, |
---|
385 | # endif /* FLUSHO */ |
---|
386 | # ifdef NOHANG |
---|
387 | { "nohang", NOHANG, M_CONTROL }, |
---|
388 | # endif /* NOHANG */ |
---|
389 | # ifdef L001000 |
---|
390 | { "l001000",L001000,M_CONTROL }, |
---|
391 | # endif /* L001000 */ |
---|
392 | # ifdef CRTKIL |
---|
393 | { "crtkil", CRTKIL, M_CONTROL }, |
---|
394 | # endif /* CRTKIL */ |
---|
395 | # ifdef PASS8 |
---|
396 | { "pass8", PASS8, M_CONTROL }, |
---|
397 | # endif /* PASS8 */ |
---|
398 | # ifdef CTLECH |
---|
399 | { "ctlech", CTLECH, M_CONTROL }, |
---|
400 | # endif /* CTLECH */ |
---|
401 | # ifdef PENDIN |
---|
402 | { "pendin", PENDIN, M_CONTROL }, |
---|
403 | # endif /* PENDIN */ |
---|
404 | # ifdef DECCTQ |
---|
405 | { "decctq", DECCTQ, M_CONTROL }, |
---|
406 | # endif /* DECCTQ */ |
---|
407 | # ifdef NOFLSH |
---|
408 | { "noflsh", NOFLSH, M_CONTROL }, |
---|
409 | # endif /* NOFLSH */ |
---|
410 | |
---|
411 | # ifdef LCRTBS |
---|
412 | { "lcrtbs", LCRTBS, M_LOCAL }, |
---|
413 | # endif /* LCRTBS */ |
---|
414 | # ifdef LPRTERA |
---|
415 | { "lprtera",LPRTERA,M_LOCAL }, |
---|
416 | # endif /* LPRTERA */ |
---|
417 | # ifdef LCRTERA |
---|
418 | { "lcrtera",LCRTERA,M_LOCAL }, |
---|
419 | # endif /* LCRTERA */ |
---|
420 | # ifdef LTILDE |
---|
421 | { "ltilde", LTILDE, M_LOCAL }, |
---|
422 | # endif /* LTILDE */ |
---|
423 | # ifdef LMDMBUF |
---|
424 | { "lmdmbuf",LMDMBUF,M_LOCAL }, |
---|
425 | # endif /* LMDMBUF */ |
---|
426 | # ifdef LLITOUT |
---|
427 | { "llitout",LLITOUT,M_LOCAL }, |
---|
428 | # endif /* LLITOUT */ |
---|
429 | # ifdef LTOSTOP |
---|
430 | { "ltostop",LTOSTOP,M_LOCAL }, |
---|
431 | # endif /* LTOSTOP */ |
---|
432 | # ifdef LFLUSHO |
---|
433 | { "lflusho",LFLUSHO,M_LOCAL }, |
---|
434 | # endif /* LFLUSHO */ |
---|
435 | # ifdef LNOHANG |
---|
436 | { "lnohang",LNOHANG,M_LOCAL }, |
---|
437 | # endif /* LNOHANG */ |
---|
438 | # ifdef LCRTKIL |
---|
439 | { "lcrtkil",LCRTKIL,M_LOCAL }, |
---|
440 | # endif /* LCRTKIL */ |
---|
441 | # ifdef LPASS8 |
---|
442 | { "lpass8", LPASS8, M_LOCAL }, |
---|
443 | # endif /* LPASS8 */ |
---|
444 | # ifdef LCTLECH |
---|
445 | { "lctlech",LCTLECH,M_LOCAL }, |
---|
446 | # endif /* LCTLECH */ |
---|
447 | # ifdef LPENDIN |
---|
448 | { "lpendin",LPENDIN,M_LOCAL }, |
---|
449 | # endif /* LPENDIN */ |
---|
450 | # ifdef LDECCTQ |
---|
451 | { "ldecctq",LDECCTQ,M_LOCAL }, |
---|
452 | # endif /* LDECCTQ */ |
---|
453 | # ifdef LNOFLSH |
---|
454 | { "lnoflsh",LNOFLSH,M_LOCAL }, |
---|
455 | # endif /* LNOFLSH */ |
---|
456 | |
---|
457 | #endif /* POSIX || TERMIO */ |
---|
458 | # if defined(VINTR) || defined(TIOCGETC) |
---|
459 | { "intr", C_SH(C_INTR), M_CHAR }, |
---|
460 | # endif /* VINTR */ |
---|
461 | # if defined(VQUIT) || defined(TIOCGETC) |
---|
462 | { "quit", C_SH(C_QUIT), M_CHAR }, |
---|
463 | # endif /* VQUIT */ |
---|
464 | # if defined(VERASE) || defined(TIOCGETP) |
---|
465 | { "erase", C_SH(C_ERASE), M_CHAR }, |
---|
466 | # endif /* VERASE */ |
---|
467 | # if defined(VKILL) || defined(TIOCGETP) |
---|
468 | { "kill", C_SH(C_KILL), M_CHAR }, |
---|
469 | # endif /* VKILL */ |
---|
470 | # if defined(VEOF) || defined(TIOCGETC) |
---|
471 | { "eof", C_SH(C_EOF), M_CHAR }, |
---|
472 | # endif /* VEOF */ |
---|
473 | # if defined(VEOL) |
---|
474 | { "eol", C_SH(C_EOL), M_CHAR }, |
---|
475 | # endif /* VEOL */ |
---|
476 | # if defined(VEOL2) |
---|
477 | { "eol2", C_SH(C_EOL2), M_CHAR }, |
---|
478 | # endif /* VEOL2 */ |
---|
479 | # if defined(VSWTCH) |
---|
480 | { "swtch", C_SH(C_SWTCH), M_CHAR }, |
---|
481 | # endif /* VSWTCH */ |
---|
482 | # if defined(VDSWTCH) |
---|
483 | { "dswtch", C_SH(C_DSWTCH), M_CHAR }, |
---|
484 | # endif /* VDSWTCH */ |
---|
485 | # if defined(VERASE2) |
---|
486 | { "erase2", C_SH(C_ERASE2), M_CHAR }, |
---|
487 | # endif /* VERASE2 */ |
---|
488 | # if defined(VSTART) || defined(TIOCGETC) |
---|
489 | { "start", C_SH(C_START), M_CHAR }, |
---|
490 | # endif /* VSTART */ |
---|
491 | # if defined(VSTOP) || defined(TIOCGETC) |
---|
492 | { "stop", C_SH(C_STOP), M_CHAR }, |
---|
493 | # endif /* VSTOP */ |
---|
494 | # if defined(VWERASE) || defined(TIOCGLTC) |
---|
495 | { "werase", C_SH(C_WERASE), M_CHAR }, |
---|
496 | # endif /* VWERASE */ |
---|
497 | # if defined(VSUSP) || defined(TIOCGLTC) |
---|
498 | { "susp", C_SH(C_SUSP), M_CHAR }, |
---|
499 | # endif /* VSUSP */ |
---|
500 | # if defined(VDSUSP) || defined(TIOCGLTC) |
---|
501 | { "dsusp", C_SH(C_DSUSP), M_CHAR }, |
---|
502 | # endif /* VDSUSP */ |
---|
503 | # if defined(VREPRINT) || defined(TIOCGLTC) |
---|
504 | { "reprint", C_SH(C_REPRINT),M_CHAR }, |
---|
505 | # endif /* WREPRINT */ |
---|
506 | # if defined(VDISCARD) || defined(TIOCGLTC) |
---|
507 | { "discard", C_SH(C_DISCARD),M_CHAR }, |
---|
508 | # endif /* VDISCARD */ |
---|
509 | # if defined(VLNEXT) || defined(TIOCGLTC) |
---|
510 | { "lnext", C_SH(C_LNEXT), M_CHAR }, |
---|
511 | # endif /* VLNEXT */ |
---|
512 | # if defined(VSTATUS) || defined(TIOCGPAGE) |
---|
513 | { "status", C_SH(C_STATUS), M_CHAR }, |
---|
514 | # endif /* VSTATUS */ |
---|
515 | # if defined(VPAGE) || defined(TIOCGPAGE) |
---|
516 | { "page", C_SH(C_PAGE), M_CHAR }, |
---|
517 | # endif /* VPAGE */ |
---|
518 | # if defined(VPGOFF) || defined(TIOCGPAGE) |
---|
519 | { "pgoff", C_SH(C_PGOFF), M_CHAR }, |
---|
520 | # endif /* VPGOFF */ |
---|
521 | # if defined(VKILL2) |
---|
522 | { "kill2", C_SH(C_KILL2), M_CHAR }, |
---|
523 | # endif /* VKILL2 */ |
---|
524 | # if defined(VBRK) || defined(TIOCGETC) |
---|
525 | { "brk", C_SH(C_BRK), M_CHAR }, |
---|
526 | # endif /* VBRK */ |
---|
527 | # if defined(VMIN) |
---|
528 | { "min", C_SH(C_MIN), M_CHAR }, |
---|
529 | # endif /* VMIN */ |
---|
530 | # if defined(VTIME) |
---|
531 | { "time", C_SH(C_TIME), M_CHAR }, |
---|
532 | # endif /* VTIME */ |
---|
533 | { NULL, 0, -1 }, |
---|
534 | }; |
---|
535 | |
---|
536 | /* Retry a system call */ |
---|
537 | #define RETRY(x) \ |
---|
538 | for (;;) \ |
---|
539 | if ((x) == -1) { \ |
---|
540 | if (errno != EINTR) \ |
---|
541 | return -1; \ |
---|
542 | else \ |
---|
543 | continue; \ |
---|
544 | } \ |
---|
545 | else \ |
---|
546 | break \ |
---|
547 | |
---|
548 | /*ARGSUSED*/ |
---|
549 | void |
---|
550 | dosetty(v, t) |
---|
551 | Char **v; |
---|
552 | struct command *t; |
---|
553 | { |
---|
554 | struct tcshmodes *m; |
---|
555 | char x, *d; |
---|
556 | int aflag = 0; |
---|
557 | Char *s; |
---|
558 | int z = EX_IO; |
---|
559 | char cmdname[BUFSIZE]; |
---|
560 | |
---|
561 | USE(t); |
---|
562 | setname(strcpy(cmdname, short2str(*v++))); |
---|
563 | |
---|
564 | while (v && *v && v[0][0] == '-' && v[0][2] == '\0') |
---|
565 | switch (v[0][1]) { |
---|
566 | case 'a': |
---|
567 | aflag++; |
---|
568 | v++; |
---|
569 | break; |
---|
570 | case 'd': |
---|
571 | v++; |
---|
572 | z = ED_IO; |
---|
573 | break; |
---|
574 | case 'x': |
---|
575 | v++; |
---|
576 | z = EX_IO; |
---|
577 | break; |
---|
578 | case 'q': |
---|
579 | v++; |
---|
580 | z = QU_IO; |
---|
581 | break; |
---|
582 | default: |
---|
583 | stderror(ERR_NAME | ERR_SYSTEM, short2str(v[0]), |
---|
584 | CGETS(8, 1, "Unknown switch")); |
---|
585 | break; |
---|
586 | } |
---|
587 | |
---|
588 | didsetty = 1; |
---|
589 | if (!v || !*v) { |
---|
590 | int i = -1; |
---|
591 | int len = 0, st = 0, cu; |
---|
592 | for (m = modelist; m->m_name; m++) { |
---|
593 | if (m->m_type != i) { |
---|
594 | xprintf("%s%s", i != -1 ? "\n" : "", |
---|
595 | ttylist[z][m->m_type].t_name); |
---|
596 | i = m->m_type; |
---|
597 | st = len = strlen(ttylist[z][m->m_type].t_name); |
---|
598 | } |
---|
599 | |
---|
600 | x = (ttylist[z][i].t_setmask & m->m_value) ? '+' : '\0'; |
---|
601 | x = (ttylist[z][i].t_clrmask & m->m_value) ? '-' : x; |
---|
602 | |
---|
603 | if (x != '\0' || aflag) { |
---|
604 | cu = strlen(m->m_name) + (x != '\0') + 1; |
---|
605 | if (len + cu >= T_Cols) { |
---|
606 | xprintf("\n%*s", st, ""); |
---|
607 | len = st + cu; |
---|
608 | } |
---|
609 | else |
---|
610 | len += cu; |
---|
611 | if (x != '\0') |
---|
612 | xprintf("%c%s ", x, m->m_name); |
---|
613 | else |
---|
614 | xprintf("%s ", m->m_name); |
---|
615 | } |
---|
616 | } |
---|
617 | xputchar('\n'); |
---|
618 | return; |
---|
619 | } |
---|
620 | while (v && (s = *v++)) { |
---|
621 | switch (*s) { |
---|
622 | case '+': |
---|
623 | case '-': |
---|
624 | x = *s++; |
---|
625 | break; |
---|
626 | default: |
---|
627 | x = '\0'; |
---|
628 | break; |
---|
629 | } |
---|
630 | d = short2str(s); |
---|
631 | for (m = modelist; m->m_name; m++) |
---|
632 | if (strcmp(m->m_name, d) == 0) |
---|
633 | break; |
---|
634 | if (!m->m_name) |
---|
635 | stderror(ERR_NAME | ERR_SYSTEM, d, CGETS(8, 2, "Invalid argument")); |
---|
636 | |
---|
637 | switch (x) { |
---|
638 | case '+': |
---|
639 | ttylist[z][m->m_type].t_setmask |= m->m_value; |
---|
640 | ttylist[z][m->m_type].t_clrmask &= ~m->m_value; |
---|
641 | break; |
---|
642 | case '-': |
---|
643 | ttylist[z][m->m_type].t_setmask &= ~m->m_value; |
---|
644 | ttylist[z][m->m_type].t_clrmask |= m->m_value; |
---|
645 | break; |
---|
646 | default: |
---|
647 | ttylist[z][m->m_type].t_setmask &= ~m->m_value; |
---|
648 | ttylist[z][m->m_type].t_clrmask &= ~m->m_value; |
---|
649 | break; |
---|
650 | } |
---|
651 | } |
---|
652 | } /* end dosetty */ |
---|
653 | |
---|
654 | int |
---|
655 | tty_getty(fd, td) |
---|
656 | int fd; |
---|
657 | ttydata_t *td; |
---|
658 | { |
---|
659 | #ifdef POSIX |
---|
660 | RETRY(tcgetattr(fd, &td->d_t)); |
---|
661 | #else /* TERMIO || GSTTY */ |
---|
662 | # ifdef TERMIO |
---|
663 | RETRY(ioctl(fd, TCGETA, (ioctl_t) &td->d_t)); |
---|
664 | # else /* GSTTY */ |
---|
665 | # ifdef TIOCGETP |
---|
666 | if (ioctl(fd, TIOCGETP, (ioctl_t) &td->d_t) == -1) |
---|
667 | return -1; |
---|
668 | # endif /* TIOCGETP */ |
---|
669 | # ifdef TIOCGETC |
---|
670 | if (ioctl(fd, TIOCGETC, (ioctl_t) &td->d_tc) == -1) |
---|
671 | return -1; |
---|
672 | # endif /* TIOCGETC */ |
---|
673 | # ifdef TIOCGPAGE |
---|
674 | if (ioctl(fd, TIOCGPAGE, (ioctl_t) &td->d_pc) == -1) |
---|
675 | return -1; |
---|
676 | # endif /* TIOCGPAGE */ |
---|
677 | # ifdef TIOCLGET |
---|
678 | if (ioctl(fd, TIOCLGET, (ioctl_t) &td->d_lb) == -1) |
---|
679 | return -1; |
---|
680 | # endif /* TIOCLGET */ |
---|
681 | # endif /* TERMIO */ |
---|
682 | #endif /* POSIX */ |
---|
683 | |
---|
684 | #ifdef TIOCGLTC |
---|
685 | if (ioctl(fd, TIOCGLTC, (ioctl_t) &td->d_ltc) == -1) |
---|
686 | return -1; |
---|
687 | #endif /* TIOCGLTC */ |
---|
688 | |
---|
689 | return 0; |
---|
690 | } |
---|
691 | |
---|
692 | int |
---|
693 | tty_setty(fd, td) |
---|
694 | int fd; |
---|
695 | ttydata_t *td; |
---|
696 | { |
---|
697 | #ifdef POSIX |
---|
698 | RETRY(tcsetattr(fd, TCSADRAIN, &td->d_t)); |
---|
699 | #else |
---|
700 | # ifdef TERMIO |
---|
701 | RETRY(ioctl(fd, TCSETAW, (ioctl_t) &td->d_t)); |
---|
702 | # else |
---|
703 | # ifdef TIOCSETN |
---|
704 | if (ioctl(fd, TIOCSETN, (ioctl_t) &td->d_t) == -1) |
---|
705 | return -1; |
---|
706 | # endif /* TIOCSETN */ |
---|
707 | # ifdef TIOCGETC |
---|
708 | if (ioctl(fd, TIOCSETC, (ioctl_t) &td->d_tc) == -1) |
---|
709 | return -1; |
---|
710 | # endif /* TIOCGETC */ |
---|
711 | # ifdef TIOCGPAGE |
---|
712 | if (ioctl(fd, TIOCSPAGE, (ioctl_t) &td->d_pc) == -1) |
---|
713 | return -1; |
---|
714 | # endif /* TIOCGPAGE */ |
---|
715 | # ifdef TIOCLGET |
---|
716 | if (ioctl(fd, TIOCLSET, (ioctl_t) &td->d_lb) == -1) |
---|
717 | return -1; |
---|
718 | # endif /* TIOCLGET */ |
---|
719 | # endif /* TERMIO */ |
---|
720 | #endif /* POSIX */ |
---|
721 | |
---|
722 | #ifdef TIOCGLTC |
---|
723 | if (ioctl(fd, TIOCSLTC, (ioctl_t) &td->d_ltc) == -1) |
---|
724 | return -1; |
---|
725 | #endif /* TIOCGLTC */ |
---|
726 | |
---|
727 | return 0; |
---|
728 | } |
---|
729 | |
---|
730 | void |
---|
731 | tty_getchar(td, s) |
---|
732 | ttydata_t *td; |
---|
733 | unsigned char *s; |
---|
734 | { |
---|
735 | #ifdef TIOCGLTC |
---|
736 | { |
---|
737 | struct ltchars *n = &td->d_ltc; |
---|
738 | |
---|
739 | s[C_SUSP] = n->t_suspc; |
---|
740 | s[C_DSUSP] = n->t_dsuspc; |
---|
741 | s[C_REPRINT] = n->t_rprntc; |
---|
742 | s[C_DISCARD] = n->t_flushc; |
---|
743 | s[C_WERASE] = n->t_werasc; |
---|
744 | s[C_LNEXT] = n->t_lnextc; |
---|
745 | } |
---|
746 | #endif /* TIOCGLTC */ |
---|
747 | |
---|
748 | #if defined(POSIX) || defined(TERMIO) |
---|
749 | { |
---|
750 | # ifdef POSIX |
---|
751 | struct termios *n = &td->d_t; |
---|
752 | # else |
---|
753 | struct termio *n = &td->d_t; |
---|
754 | # endif /* POSIX */ |
---|
755 | |
---|
756 | # ifdef VINTR |
---|
757 | s[C_INTR] = n->c_cc[VINTR]; |
---|
758 | # endif /* VINTR */ |
---|
759 | # ifdef VQUIT |
---|
760 | s[C_QUIT] = n->c_cc[VQUIT]; |
---|
761 | # endif /* VQUIT */ |
---|
762 | # ifdef VERASE |
---|
763 | s[C_ERASE] = n->c_cc[VERASE]; |
---|
764 | # endif /* VERASE */ |
---|
765 | # ifdef VKILL |
---|
766 | s[C_KILL] = n->c_cc[VKILL]; |
---|
767 | # endif /* VKILL */ |
---|
768 | # ifdef VEOF |
---|
769 | s[C_EOF] = n->c_cc[VEOF]; |
---|
770 | # endif /* VEOF */ |
---|
771 | # ifdef VEOL |
---|
772 | s[C_EOL] = n->c_cc[VEOL]; |
---|
773 | # endif /* VEOL */ |
---|
774 | # ifdef VEOL2 |
---|
775 | s[C_EOL2] = n->c_cc[VEOL2]; |
---|
776 | # endif /* VEOL2 */ |
---|
777 | # ifdef VSWTCH |
---|
778 | s[C_SWTCH] = n->c_cc[VSWTCH]; |
---|
779 | # endif /* VSWTCH */ |
---|
780 | # ifdef VDSWTCH |
---|
781 | s[C_DSWTCH] = n->c_cc[VDSWTCH]; |
---|
782 | # endif /* VDSWTCH */ |
---|
783 | # ifdef VERASE2 |
---|
784 | s[C_ERASE2] = n->c_cc[VERASE2]; |
---|
785 | # endif /* VERASE2 */ |
---|
786 | # ifdef VSTART |
---|
787 | s[C_START] = n->c_cc[VSTART]; |
---|
788 | # endif /* VSTART */ |
---|
789 | # ifdef VSTOP |
---|
790 | s[C_STOP] = n->c_cc[VSTOP]; |
---|
791 | # endif /* VSTOP */ |
---|
792 | # ifdef VWERASE |
---|
793 | s[C_WERASE] = n->c_cc[VWERASE]; |
---|
794 | # endif /* VWERASE */ |
---|
795 | # ifdef VSUSP |
---|
796 | s[C_SUSP] = n->c_cc[VSUSP]; |
---|
797 | # endif /* VSUSP */ |
---|
798 | # ifdef VDSUSP |
---|
799 | s[C_DSUSP] = n->c_cc[VDSUSP]; |
---|
800 | # endif /* VDSUSP */ |
---|
801 | # ifdef VREPRINT |
---|
802 | s[C_REPRINT] = n->c_cc[VREPRINT]; |
---|
803 | # endif /* WREPRINT */ |
---|
804 | # ifdef VDISCARD |
---|
805 | s[C_DISCARD] = n->c_cc[VDISCARD]; |
---|
806 | # endif /* VDISCARD */ |
---|
807 | # ifdef VLNEXT |
---|
808 | s[C_LNEXT] = n->c_cc[VLNEXT]; |
---|
809 | # endif /* VLNEXT */ |
---|
810 | # ifdef VSTATUS |
---|
811 | s[C_STATUS] = n->c_cc[VSTATUS]; |
---|
812 | # endif /* VSTATUS */ |
---|
813 | # ifdef VPAGE |
---|
814 | s[C_PAGE] = n->c_cc[VPAGE]; |
---|
815 | # endif /* VPAGE */ |
---|
816 | # ifdef VPGOFF |
---|
817 | s[C_PGOFF] = n->c_cc[VPGOFF]; |
---|
818 | # endif /* VPGOFF */ |
---|
819 | # ifdef VKILL2 |
---|
820 | s[C_KILL2] = n->c_cc[VKILL2]; |
---|
821 | # endif /* KILL2 */ |
---|
822 | # ifdef VMIN |
---|
823 | s[C_MIN] = n->c_cc[VMIN]; |
---|
824 | # endif /* VMIN */ |
---|
825 | # ifdef VTIME |
---|
826 | s[C_TIME] = n->c_cc[VTIME]; |
---|
827 | # endif /* VTIME */ |
---|
828 | } |
---|
829 | |
---|
830 | #else /* SGTTY */ |
---|
831 | |
---|
832 | # ifdef TIOCGPAGE |
---|
833 | { |
---|
834 | struct ttypagestat *n = &td->d_pc; |
---|
835 | |
---|
836 | s[C_STATUS] = n->tps_statc; |
---|
837 | s[C_PAGE] = n->tps_pagec; |
---|
838 | s[C_PGOFF] = n->tps_pgoffc; |
---|
839 | } |
---|
840 | # endif /* TIOCGPAGE */ |
---|
841 | |
---|
842 | # ifdef TIOCGETC |
---|
843 | { |
---|
844 | struct tchars *n = &td->d_tc; |
---|
845 | |
---|
846 | s[C_INTR] = n->t_intrc; |
---|
847 | s[C_QUIT] = n->t_quitc; |
---|
848 | s[C_START] = n->t_startc; |
---|
849 | s[C_STOP] = n->t_stopc; |
---|
850 | s[C_EOF] = n->t_eofc; |
---|
851 | s[C_BRK] = n->t_brkc; |
---|
852 | } |
---|
853 | # endif /* TIOCGETC */ |
---|
854 | |
---|
855 | # ifdef TIOCGETP |
---|
856 | { |
---|
857 | struct sgttyb *n = &td->d_t; |
---|
858 | |
---|
859 | s[C_ERASE] = n->sg_erase; |
---|
860 | s[C_KILL] = n->sg_kill; |
---|
861 | } |
---|
862 | # endif /* TIOCGETP */ |
---|
863 | #endif /* !POSIX || TERMIO */ |
---|
864 | |
---|
865 | } /* tty_getchar */ |
---|
866 | |
---|
867 | |
---|
868 | void |
---|
869 | tty_setchar(td, s) |
---|
870 | ttydata_t *td; |
---|
871 | unsigned char *s; |
---|
872 | { |
---|
873 | #ifdef TIOCGLTC |
---|
874 | { |
---|
875 | struct ltchars *n = &td->d_ltc; |
---|
876 | |
---|
877 | n->t_suspc = s[C_SUSP]; |
---|
878 | n->t_dsuspc = s[C_DSUSP]; |
---|
879 | n->t_rprntc = s[C_REPRINT]; |
---|
880 | n->t_flushc = s[C_DISCARD]; |
---|
881 | n->t_werasc = s[C_WERASE]; |
---|
882 | n->t_lnextc = s[C_LNEXT]; |
---|
883 | } |
---|
884 | #endif /* TIOCGLTC */ |
---|
885 | |
---|
886 | #if defined(POSIX) || defined(TERMIO) |
---|
887 | { |
---|
888 | # ifdef POSIX |
---|
889 | struct termios *n = &td->d_t; |
---|
890 | # else |
---|
891 | struct termio *n = &td->d_t; |
---|
892 | # endif /* POSIX */ |
---|
893 | |
---|
894 | # ifdef VINTR |
---|
895 | n->c_cc[VINTR] = s[C_INTR]; |
---|
896 | # endif /* VINTR */ |
---|
897 | # ifdef VQUIT |
---|
898 | n->c_cc[VQUIT] = s[C_QUIT]; |
---|
899 | # endif /* VQUIT */ |
---|
900 | # ifdef VERASE |
---|
901 | n->c_cc[VERASE] = s[C_ERASE]; |
---|
902 | # endif /* VERASE */ |
---|
903 | # ifdef VKILL |
---|
904 | n->c_cc[VKILL] = s[C_KILL]; |
---|
905 | # endif /* VKILL */ |
---|
906 | # ifdef VEOF |
---|
907 | n->c_cc[VEOF] = s[C_EOF]; |
---|
908 | # endif /* VEOF */ |
---|
909 | # ifdef VEOL |
---|
910 | n->c_cc[VEOL] = s[C_EOL]; |
---|
911 | # endif /* VEOL */ |
---|
912 | # ifdef VEOL2 |
---|
913 | n->c_cc[VEOL2] = s[C_EOL2]; |
---|
914 | # endif /* VEOL2 */ |
---|
915 | # ifdef VSWTCH |
---|
916 | n->c_cc[VSWTCH] = s[C_SWTCH]; |
---|
917 | # endif /* VSWTCH */ |
---|
918 | # ifdef VDSWTCH |
---|
919 | n->c_cc[VDSWTCH] = s[C_DSWTCH]; |
---|
920 | # endif /* VDSWTCH */ |
---|
921 | # ifdef VERASE2 |
---|
922 | n->c_cc[VERASE2] = s[C_ERASE2]; |
---|
923 | # endif /* VERASE2 */ |
---|
924 | # ifdef VSTART |
---|
925 | n->c_cc[VSTART] = s[C_START]; |
---|
926 | # endif /* VSTART */ |
---|
927 | # ifdef VSTOP |
---|
928 | n->c_cc[VSTOP] = s[C_STOP]; |
---|
929 | # endif /* VSTOP */ |
---|
930 | # ifdef VWERASE |
---|
931 | n->c_cc[VWERASE] = s[C_WERASE]; |
---|
932 | # endif /* VWERASE */ |
---|
933 | # ifdef VSUSP |
---|
934 | n->c_cc[VSUSP] = s[C_SUSP]; |
---|
935 | # endif /* VSUSP */ |
---|
936 | # ifdef VDSUSP |
---|
937 | n->c_cc[VDSUSP] = s[C_DSUSP]; |
---|
938 | # endif /* VDSUSP */ |
---|
939 | # ifdef VREPRINT |
---|
940 | n->c_cc[VREPRINT] = s[C_REPRINT]; |
---|
941 | # endif /* WREPRINT */ |
---|
942 | # ifdef VDISCARD |
---|
943 | n->c_cc[VDISCARD] = s[C_DISCARD]; |
---|
944 | # endif /* VDISCARD */ |
---|
945 | # ifdef VLNEXT |
---|
946 | n->c_cc[VLNEXT] = s[C_LNEXT]; |
---|
947 | # endif /* VLNEXT */ |
---|
948 | # ifdef VSTATUS |
---|
949 | n->c_cc[VSTATUS] = s[C_STATUS]; |
---|
950 | # endif /* VSTATUS */ |
---|
951 | # ifdef VPAGE |
---|
952 | n->c_cc[VPAGE] = s[C_PAGE]; |
---|
953 | # endif /* VPAGE */ |
---|
954 | # ifdef VPGOFF |
---|
955 | n->c_cc[VPGOFF] = s[C_PGOFF]; |
---|
956 | # endif /* VPGOFF */ |
---|
957 | # ifdef VKILL2 |
---|
958 | n->c_cc[VKILL2] = s[C_KILL2]; |
---|
959 | # endif /* VKILL2 */ |
---|
960 | # ifdef VMIN |
---|
961 | n->c_cc[VMIN] = s[C_MIN]; |
---|
962 | # endif /* VMIN */ |
---|
963 | # ifdef VTIME |
---|
964 | n->c_cc[VTIME] = s[C_TIME]; |
---|
965 | # endif /* VTIME */ |
---|
966 | } |
---|
967 | |
---|
968 | #else /* GSTTY */ |
---|
969 | |
---|
970 | # ifdef TIOCGPAGE |
---|
971 | { |
---|
972 | struct ttypagestat *n = &td->d_pc; |
---|
973 | |
---|
974 | n->tps_length = 0; |
---|
975 | n->tps_lpos = 0; |
---|
976 | n->tps_statc = s[C_STATUS]; |
---|
977 | n->tps_pagec = s[C_PAGE]; |
---|
978 | n->tps_pgoffc = s[C_PGOFF]; |
---|
979 | n->tps_flag = 0; |
---|
980 | } |
---|
981 | # endif /* TIOCGPAGE */ |
---|
982 | |
---|
983 | # ifdef TIOCGETC |
---|
984 | { |
---|
985 | struct tchars *n = &td->d_tc; |
---|
986 | n->t_intrc = s[C_INTR]; |
---|
987 | n->t_quitc = s[C_QUIT]; |
---|
988 | n->t_startc = s[C_START]; |
---|
989 | n->t_stopc = s[C_STOP]; |
---|
990 | n->t_eofc = s[C_EOF]; |
---|
991 | n->t_brkc = s[C_BRK]; |
---|
992 | } |
---|
993 | # endif /* TIOCGETC */ |
---|
994 | |
---|
995 | # ifdef TIOCGETP |
---|
996 | { |
---|
997 | struct sgttyb *n = &td->d_t; |
---|
998 | |
---|
999 | n->sg_erase = s[C_ERASE]; |
---|
1000 | n->sg_kill = s[C_KILL]; |
---|
1001 | } |
---|
1002 | # endif /* TIOCGETP */ |
---|
1003 | #endif /* !POSIX || TERMIO */ |
---|
1004 | |
---|
1005 | } /* tty_setchar */ |
---|
1006 | |
---|
1007 | speed_t |
---|
1008 | tty_getspeed(td) |
---|
1009 | ttydata_t *td; |
---|
1010 | { |
---|
1011 | speed_t spd; |
---|
1012 | |
---|
1013 | #ifdef POSIX |
---|
1014 | if ((spd = cfgetispeed(&td->d_t)) == 0) |
---|
1015 | spd = cfgetospeed(&td->d_t); |
---|
1016 | #else /* ! POSIX */ |
---|
1017 | # ifdef TERMIO |
---|
1018 | # ifdef CBAUD |
---|
1019 | spd = td->d_t.c_cflag & CBAUD; |
---|
1020 | # else |
---|
1021 | spd = 0; |
---|
1022 | # endif |
---|
1023 | # else /* SGTTY */ |
---|
1024 | spd = td->d_t.sg_ispeed; |
---|
1025 | # endif /* TERMIO */ |
---|
1026 | #endif /* POSIX */ |
---|
1027 | |
---|
1028 | return spd; |
---|
1029 | } /* end tty_getspeed */ |
---|
1030 | |
---|
1031 | int |
---|
1032 | tty_gettabs(td) |
---|
1033 | ttydata_t *td; |
---|
1034 | { |
---|
1035 | #if defined(POSIX) || defined(TERMIO) |
---|
1036 | return ((td->d_t.c_oflag & TAB3) == TAB3) ? 0 : 1; |
---|
1037 | #else /* SGTTY */ |
---|
1038 | return (td->d_t.sg_flags & XTABS) == XTABS ? 0 : 1; |
---|
1039 | #endif /* POSIX || TERMIO */ |
---|
1040 | } /* end tty_gettabs */ |
---|
1041 | |
---|
1042 | int |
---|
1043 | tty_geteightbit(td) |
---|
1044 | ttydata_t *td; |
---|
1045 | { |
---|
1046 | #if defined(POSIX) || defined(TERMIO) |
---|
1047 | return (td->d_t.c_cflag & CSIZE) == CS8; |
---|
1048 | #else /* SGTTY */ |
---|
1049 | return td->d_lb & (LPASS8 | LLITOUT); |
---|
1050 | #endif /* POSIX || TERMIO */ |
---|
1051 | } /* end tty_geteightbit */ |
---|
1052 | |
---|
1053 | int |
---|
1054 | tty_cooked_mode(td) |
---|
1055 | ttydata_t *td; |
---|
1056 | { |
---|
1057 | #if defined(POSIX) || defined(TERMIO) |
---|
1058 | return (td->d_t.c_lflag & ICANON); |
---|
1059 | #else /* SGTTY */ |
---|
1060 | return !(td->d_t.sg_flags & (RAW | CBREAK)); |
---|
1061 | #endif /* POSIX || TERMIO */ |
---|
1062 | } /* end tty_cooked_mode */ |
---|
1063 | |
---|
1064 | #ifdef _IBMR2 |
---|
1065 | void |
---|
1066 | tty_setdisc(fd, dis) |
---|
1067 | int fd; |
---|
1068 | int dis; |
---|
1069 | { |
---|
1070 | static bool edit_discipline = 0; |
---|
1071 | static union txname tx_disc; |
---|
1072 | extern char strPOSIX[]; |
---|
1073 | |
---|
1074 | switch (dis) { |
---|
1075 | case EX_IO: |
---|
1076 | if (edit_discipline) { |
---|
1077 | if (ioctl(fd, TXSETLD, (ioctl_t) & tx_disc) == -1) |
---|
1078 | return; |
---|
1079 | edit_discipline = 0; |
---|
1080 | } |
---|
1081 | return; |
---|
1082 | |
---|
1083 | case ED_IO: |
---|
1084 | tx_disc.tx_which = 0; |
---|
1085 | if (ioctl(fd, TXGETLD, (ioctl_t) & tx_disc) == -1) |
---|
1086 | return; |
---|
1087 | if (strcmp(tx_disc.tx_name, strPOSIX) != 0) { |
---|
1088 | edit_discipline = 1; |
---|
1089 | if (ioctl(fd, TXSETLD, (ioctl_t) strPOSIX) == -1) |
---|
1090 | return; |
---|
1091 | } |
---|
1092 | return; |
---|
1093 | |
---|
1094 | default: |
---|
1095 | return; |
---|
1096 | } |
---|
1097 | } /* end tty_setdisc */ |
---|
1098 | #endif /* _IBMR2 */ |
---|
1099 | |
---|
1100 | #ifdef DEBUG_TTY |
---|
1101 | static void |
---|
1102 | tty_printchar(s) |
---|
1103 | unsigned char *s; |
---|
1104 | { |
---|
1105 | struct tcshmodes *m; |
---|
1106 | int i; |
---|
1107 | |
---|
1108 | for (i = 0; i < C_NCC; i++) { |
---|
1109 | for (m = modelist; m->m_name; m++) |
---|
1110 | if (m->m_type == M_CHAR && C_SH(i) == m->m_value) |
---|
1111 | break; |
---|
1112 | if (m->m_name) |
---|
1113 | xprintf("%s ^%c ", m->m_name, s[i] + 'A' - 1); |
---|
1114 | if (i % 5 == 0) |
---|
1115 | xputchar('\n'); |
---|
1116 | } |
---|
1117 | xputchar('\n'); |
---|
1118 | } |
---|
1119 | #endif /* DEBUG_TTY */ |
---|
1120 | #else /* WINNT */ |
---|
1121 | int |
---|
1122 | tty_cooked_mode(td) |
---|
1123 | void *td; |
---|
1124 | { |
---|
1125 | return do_nt_check_cooked_mode(); |
---|
1126 | } |
---|
1127 | #endif /* !WINNT */ |
---|