1 /* $Header: /src/pub/tcsh/ed.term.c,v 1.25 2000/11/11 23:03:34 christos Exp $ */
3 * ed.term.c: Low level terminal interface
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
40 RCSID("$Id: ed.term.c,v 1.25 2000/11/11 23:03:34 christos Exp $")
48 #if defined(POSIX) || defined(TERMIO)
49 { "iflag:", ICRNL, (INLCR|IGNCR) },
50 { "oflag:", (OPOST|ONLCR), ONLRET },
52 { "lflag:", (ISIG|ICANON|ECHO|ECHOE|ECHOCTL|IEXTEN),
53 (NOFLSH|ECHONL|EXTPROC|FLUSHO|IDEFAULT) },
55 { "nrmal:", (ECHO|CRMOD|ANYP), (CBREAK|RAW|LCASE|VTDELAY|ALLDELAY) },
56 { "local:", (LCRTBS|LCRTERA|LCRTKIL), (LPRTERA|LFLUSHO) },
57 #endif /* POSIX || TERMIO */
61 #if defined(POSIX) || defined(TERMIO)
62 { "iflag:", (INLCR|ICRNL), IGNCR },
63 { "oflag:", (OPOST|ONLCR), ONLRET },
66 (NOFLSH|ICANON|ECHO|ECHOK|ECHONL|EXTPROC|IEXTEN|FLUSHO|
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)),
79 #if defined(POSIX) || defined(TERMIO)
80 { "iflag:", 0, IXON | IXOFF },
83 { "lflag:", 0, ISIG | IEXTEN },
85 { "nrmal:", RAW, CBREAK },
87 #endif /* POSIX || TERMIO */
92 static struct tcshmodes {
95 unsigned long m_value;
101 #if defined(POSIX) || defined(TERMIO)
104 { "ignbrk", IGNBRK, M_INPUT },
107 { "brkint", BRKINT, M_INPUT },
110 { "ignpar", IGNPAR, M_INPUT },
113 { "parmrk", PARMRK, M_INPUT },
116 { "inpck", INPCK, M_INPUT },
119 { "istrip", ISTRIP, M_INPUT },
122 { "inlcr", INLCR, M_INPUT },
125 { "igncr", IGNCR, M_INPUT },
128 { "icrnl", ICRNL, M_INPUT },
131 { "iuclc", IUCLC, M_INPUT },
134 { "ixon", IXON, M_INPUT },
137 { "ixany", IXANY, M_INPUT },
140 { "ixoff", IXOFF, M_INPUT },
143 { "imaxbel",IMAXBEL,M_INPUT },
144 # endif /* IMAXBEL */
146 { "idelete",IDELETE,M_INPUT },
147 # endif /* IDELETE */
150 { "opost", OPOST, M_OUTPUT },
153 { "olcuc", OLCUC, M_OUTPUT },
156 { "onlcr", ONLCR, M_OUTPUT },
159 { "ocrnl", OCRNL, M_OUTPUT },
162 { "onocr", ONOCR, M_OUTPUT },
165 { "onoeot", ONOEOT, M_OUTPUT },
168 { "onlret", ONLRET, M_OUTPUT },
171 { "ofill", OFILL, M_OUTPUT },
174 { "ofdel", OFDEL, M_OUTPUT },
177 { "nldly", NLDLY, M_OUTPUT },
180 { "crdly", CRDLY, M_OUTPUT },
183 { "tabdly", TABDLY, M_OUTPUT },
186 { "xtabs", XTABS, M_OUTPUT },
189 { "bsdly", BSDLY, M_OUTPUT },
192 { "vtdly", VTDLY, M_OUTPUT },
195 { "ffdly", FFDLY, M_OUTPUT },
198 { "pageout",PAGEOUT,M_OUTPUT },
199 # endif /* PAGEOUT */
201 { "wrap", WRAP, M_OUTPUT },
205 { "cignore",CIGNORE,M_CONTROL },
208 { "cbaud", CBAUD, M_CONTROL },
211 { "cstopb", CSTOPB, M_CONTROL },
214 { "cread", CREAD, M_CONTROL },
217 { "parenb", PARENB, M_CONTROL },
220 { "parodd", PARODD, M_CONTROL },
223 { "hupcl", HUPCL, M_CONTROL },
226 { "clocal", CLOCAL, M_CONTROL },
229 { "loblk", LOBLK, M_CONTROL },
232 { "cibaud", CIBAUD, M_CONTROL },
236 { "ccts_oflow",CCTS_OFLOW,M_CONTROL },
238 { "crtscts",CRTSCTS,M_CONTROL },
239 # endif /* CCTS_OFLOW */
240 # endif /* CRTSCTS */
242 { "crts_iflow",CRTS_IFLOW,M_CONTROL },
243 # endif /* CRTS_IFLOW */
245 { "mdmbuf", MDMBUF, M_CONTROL },
248 { "rcv1en", RCV1EN, M_CONTROL },
251 { "xmt1en", XMT1EN, M_CONTROL },
255 { "isig", ISIG, M_LINED },
258 { "icanon", ICANON, M_LINED },
261 { "xcase", XCASE, M_LINED },
264 { "echo", ECHO, M_LINED },
267 { "echoe", ECHOE, M_LINED },
270 { "echok", ECHOK, M_LINED },
273 { "echonl", ECHONL, M_LINED },
276 { "noflsh", NOFLSH, M_LINED },
279 { "tostop", TOSTOP, M_LINED },
282 { "echoctl",ECHOCTL,M_LINED },
283 # endif /* ECHOCTL */
285 { "echoprt",ECHOPRT,M_LINED },
286 # endif /* ECHOPRT */
288 { "echoke", ECHOKE, M_LINED },
291 { "defecho",DEFECHO,M_LINED },
292 # endif /* DEFECHO */
294 { "flusho", FLUSHO, M_LINED },
297 { "pendin", PENDIN, M_LINED },
300 { "iexten", IEXTEN, M_LINED },
303 { "nokerninfo",NOKERNINFO,M_LINED },
304 # endif /* NOKERNINFO */
306 { "altwerase",ALTWERASE,M_LINED },
307 # endif /* ALTWERASE */
309 { "extproc",EXTPROC,M_LINED },
310 # endif /* EXTPROC */
312 { "idefault",IDEFAULT,M_LINED },
313 # endif /* IDEFAULT */
318 { "tandem", TANDEM, M_CONTROL },
321 { "cbreak", CBREAK, M_CONTROL },
324 { "lcase", LCASE, M_CONTROL },
327 { "echo", ECHO, M_CONTROL },
330 { "crmod", CRMOD, M_CONTROL },
333 { "raw", RAW, M_CONTROL },
336 { "oddp", ODDP, M_CONTROL },
339 { "evenp", EVENP, M_CONTROL },
342 { "anyp", ANYP, M_CONTROL },
345 { "nldelay",NLDELAY,M_CONTROL },
346 # endif /* NLDELAY */
348 { "tbdelay",TBDELAY,M_CONTROL },
349 # endif /* TBDELAY */
351 { "xtabs", XTABS, M_CONTROL },
354 { "crdelay",CRDELAY,M_CONTROL },
355 # endif /* CRDELAY */
357 { "vtdelay",VTDELAY,M_CONTROL },
358 # endif /* VTDELAY */
360 { "bsdelay",BSDELAY,M_CONTROL },
361 # endif /* BSDELAY */
363 { "crtbs", CRTBS, M_CONTROL },
366 { "prtera", PRTERA, M_CONTROL },
369 { "crtera", CRTERA, M_CONTROL },
372 { "tilde", TILDE, M_CONTROL },
375 { "mdmbuf", MDMBUF, M_CONTROL },
378 { "litout", LITOUT, M_CONTROL },
381 { "tostop", TOSTOP, M_CONTROL },
384 { "flusho", FLUSHO, M_CONTROL },
387 { "nohang", NOHANG, M_CONTROL },
390 { "l001000",L001000,M_CONTROL },
391 # endif /* L001000 */
393 { "crtkil", CRTKIL, M_CONTROL },
396 { "pass8", PASS8, M_CONTROL },
399 { "ctlech", CTLECH, M_CONTROL },
402 { "pendin", PENDIN, M_CONTROL },
405 { "decctq", DECCTQ, M_CONTROL },
408 { "noflsh", NOFLSH, M_CONTROL },
412 { "lcrtbs", LCRTBS, M_LOCAL },
415 { "lprtera",LPRTERA,M_LOCAL },
416 # endif /* LPRTERA */
418 { "lcrtera",LCRTERA,M_LOCAL },
419 # endif /* LCRTERA */
421 { "ltilde", LTILDE, M_LOCAL },
424 { "lmdmbuf",LMDMBUF,M_LOCAL },
425 # endif /* LMDMBUF */
427 { "llitout",LLITOUT,M_LOCAL },
428 # endif /* LLITOUT */
430 { "ltostop",LTOSTOP,M_LOCAL },
431 # endif /* LTOSTOP */
433 { "lflusho",LFLUSHO,M_LOCAL },
434 # endif /* LFLUSHO */
436 { "lnohang",LNOHANG,M_LOCAL },
437 # endif /* LNOHANG */
439 { "lcrtkil",LCRTKIL,M_LOCAL },
440 # endif /* LCRTKIL */
442 { "lpass8", LPASS8, M_LOCAL },
445 { "lctlech",LCTLECH,M_LOCAL },
446 # endif /* LCTLECH */
448 { "lpendin",LPENDIN,M_LOCAL },
449 # endif /* LPENDIN */
451 { "ldecctq",LDECCTQ,M_LOCAL },
452 # endif /* LDECCTQ */
454 { "lnoflsh",LNOFLSH,M_LOCAL },
455 # endif /* LNOFLSH */
457 #endif /* POSIX || TERMIO */
458 # if defined(VINTR) || defined(TIOCGETC)
459 { "intr", C_SH(C_INTR), M_CHAR },
461 # if defined(VQUIT) || defined(TIOCGETC)
462 { "quit", C_SH(C_QUIT), M_CHAR },
464 # if defined(VERASE) || defined(TIOCGETP)
465 { "erase", C_SH(C_ERASE), M_CHAR },
467 # if defined(VKILL) || defined(TIOCGETP)
468 { "kill", C_SH(C_KILL), M_CHAR },
470 # if defined(VEOF) || defined(TIOCGETC)
471 { "eof", C_SH(C_EOF), M_CHAR },
474 { "eol", C_SH(C_EOL), M_CHAR },
477 { "eol2", C_SH(C_EOL2), M_CHAR },
480 { "swtch", C_SH(C_SWTCH), M_CHAR },
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 },
491 # if defined(VSTOP) || defined(TIOCGETC)
492 { "stop", C_SH(C_STOP), M_CHAR },
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 },
500 # if defined(VDSUSP) || defined(TIOCGLTC)
501 { "dsusp", C_SH(C_DSUSP), M_CHAR },
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 },
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 },
518 # if defined(VPGOFF) || defined(TIOCGPAGE)
519 { "pgoff", C_SH(C_PGOFF), M_CHAR },
522 { "kill2", C_SH(C_KILL2), M_CHAR },
524 # if defined(VBRK) || defined(TIOCGETC)
525 { "brk", C_SH(C_BRK), M_CHAR },
528 { "min", C_SH(C_MIN), M_CHAR },
531 { "time", C_SH(C_TIME), M_CHAR },
537 * If EAGAIN and/or EWOULDBLOCK are defined, we can't just return -1 in all
538 * situations where ioctl() does.
540 * On AIX 4.1.5 (and presumably some other versions and OSes), as you
541 * perform the manual test suite in the README, if you 'bg' vi immediately
542 * after suspending it, all is well, but if you wait a few seconds,
543 * usually ioctl() will return -1, which previously caused tty_setty() to
544 * return -1, causing Rawmode() to return -1, causing Inputl() to return
545 * 0, causing bgetc() to return -1, causing readc() to set doneinp to 1,
546 * causing process() to break out of the main loop, causing tcsh to exit
549 * If ioctl()'s errno is EAGAIN/EWOULDBLOCK ("Resource temporarily
550 * unavailable"), apparently the tty is being messed with by the OS and we
551 * need to try again. In my testing, ioctl() was never called more than
554 * -- Dan Harkless <dan@wave.eng.uci.edu>
556 * So, I retry all ioctl's in case others happen to fail too (christos)
559 #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
560 # define OKERROR(e) (((e) == EAGAIN) || ((e) == EWOULDBLOCK) || ((e) == EINTR))
562 # define OKERROR(e) (((e) == EAGAIN) || ((e) == EINTR))
563 #elif defined(EWOULDBLOCK)
564 # define OKERROR(e) (((e) == EWOULDBLOCK) || ((e) == EINTR))
566 # define OKERROR(e) ((e) == EINTR)
569 /* Retry a system call */
573 if (OKERROR(errno)) \
592 char cmdname[BUFSIZE];
595 setname(strcpy(cmdname, short2str(*v++)));
597 while (v && *v && v[0][0] == '-' && v[0][2] == '\0')
616 stderror(ERR_NAME | ERR_SYSTEM, short2str(v[0]),
617 CGETS(8, 1, "Unknown switch"));
624 int len = 0, st = 0, cu;
625 for (m = modelist; m->m_name; m++) {
626 if (m->m_type != i) {
627 xprintf("%s%s", i != -1 ? "\n" : "",
628 ttylist[z][m->m_type].t_name);
630 st = len = strlen(ttylist[z][m->m_type].t_name);
633 x = (ttylist[z][i].t_setmask & m->m_value) ? '+' : '\0';
634 x = (ttylist[z][i].t_clrmask & m->m_value) ? '-' : x;
636 if (x != '\0' || aflag) {
637 cu = strlen(m->m_name) + (x != '\0') + 1;
638 if (len + cu >= T_Cols) {
639 xprintf("\n%*s", st, "");
645 xprintf("%c%s ", x, m->m_name);
647 xprintf("%s ", m->m_name);
653 while (v && (s = *v++)) {
664 for (m = modelist; m->m_name; m++)
665 if (strcmp(m->m_name, d) == 0)
668 stderror(ERR_NAME | ERR_SYSTEM, d, CGETS(8, 2, "Invalid argument"));
672 ttylist[z][m->m_type].t_setmask |= m->m_value;
673 ttylist[z][m->m_type].t_clrmask &= ~m->m_value;
676 ttylist[z][m->m_type].t_setmask &= ~m->m_value;
677 ttylist[z][m->m_type].t_clrmask |= m->m_value;
680 ttylist[z][m->m_type].t_setmask &= ~m->m_value;
681 ttylist[z][m->m_type].t_clrmask &= ~m->m_value;
693 RETRY(tcgetattr(fd, &td->d_t));
694 #else /* TERMIO || GSTTY */
696 RETRY(ioctl(fd, TCGETA, (ioctl_t) &td->d_t));
699 RETRY(ioctl(fd, TIOCGETP, (ioctl_t) &td->d_t));
700 # endif /* TIOCGETP */
702 RETRY(ioctl(fd, TIOCGETC, (ioctl_t) &td->d_tc));
703 # endif /* TIOCGETC */
705 RETRY(ioctl(fd, TIOCGPAGE, (ioctl_t) &td->d_pc));
706 # endif /* TIOCGPAGE */
708 RETRY(ioctl(fd, TIOCLGET, (ioctl_t) &td->d_lb));
709 # endif /* TIOCLGET */
714 RETRY(ioctl(fd, TIOCGLTC, (ioctl_t) &td->d_ltc));
715 #endif /* TIOCGLTC */
726 RETRY(tcsetattr(fd, TCSADRAIN, &td->d_t));
729 RETRY(ioctl(fd, TCSETAW, (ioctl_t) &td->d_t));
732 RETRY(ioctl(fd, TIOCSETN, (ioctl_t) &td->d_t));
733 # endif /* TIOCSETN */
735 RETRY(ioctl(fd, TIOCSETC, (ioctl_t) &td->d_tc));
736 # endif /* TIOCGETC */
738 RETRY(ioctl(fd, TIOCSPAGE, (ioctl_t) &td->d_pc));
739 # endif /* TIOCGPAGE */
741 RETRY(ioctl(fd, TIOCLSET, (ioctl_t) &td->d_lb));
742 # endif /* TIOCLGET */
747 RETRY(ioctl(fd, TIOCSLTC, (ioctl_t) &td->d_ltc));
748 #endif /* TIOCGLTC */
760 struct ltchars *n = &td->d_ltc;
762 s[C_SUSP] = n->t_suspc;
763 s[C_DSUSP] = n->t_dsuspc;
764 s[C_REPRINT] = n->t_rprntc;
765 s[C_DISCARD] = n->t_flushc;
766 s[C_WERASE] = n->t_werasc;
767 s[C_LNEXT] = n->t_lnextc;
769 #endif /* TIOCGLTC */
771 #if defined(POSIX) || defined(TERMIO)
774 struct termios *n = &td->d_t;
776 struct termio *n = &td->d_t;
780 s[C_INTR] = n->c_cc[VINTR];
783 s[C_QUIT] = n->c_cc[VQUIT];
786 s[C_ERASE] = n->c_cc[VERASE];
789 s[C_KILL] = n->c_cc[VKILL];
792 s[C_EOF] = n->c_cc[VEOF];
795 s[C_EOL] = n->c_cc[VEOL];
798 s[C_EOL2] = n->c_cc[VEOL2];
801 s[C_SWTCH] = n->c_cc[VSWTCH];
804 s[C_DSWTCH] = n->c_cc[VDSWTCH];
805 # endif /* VDSWTCH */
807 s[C_ERASE2] = n->c_cc[VERASE2];
808 # endif /* VERASE2 */
810 s[C_START] = n->c_cc[VSTART];
813 s[C_STOP] = n->c_cc[VSTOP];
816 s[C_WERASE] = n->c_cc[VWERASE];
817 # endif /* VWERASE */
819 s[C_SUSP] = n->c_cc[VSUSP];
822 s[C_DSUSP] = n->c_cc[VDSUSP];
825 s[C_REPRINT] = n->c_cc[VREPRINT];
826 # endif /* WREPRINT */
828 s[C_DISCARD] = n->c_cc[VDISCARD];
829 # endif /* VDISCARD */
831 s[C_LNEXT] = n->c_cc[VLNEXT];
834 s[C_STATUS] = n->c_cc[VSTATUS];
835 # endif /* VSTATUS */
837 s[C_PAGE] = n->c_cc[VPAGE];
840 s[C_PGOFF] = n->c_cc[VPGOFF];
843 s[C_KILL2] = n->c_cc[VKILL2];
846 s[C_MIN] = n->c_cc[VMIN];
849 s[C_TIME] = n->c_cc[VTIME];
857 struct ttypagestat *n = &td->d_pc;
859 s[C_STATUS] = n->tps_statc;
860 s[C_PAGE] = n->tps_pagec;
861 s[C_PGOFF] = n->tps_pgoffc;
863 # endif /* TIOCGPAGE */
867 struct tchars *n = &td->d_tc;
869 s[C_INTR] = n->t_intrc;
870 s[C_QUIT] = n->t_quitc;
871 s[C_START] = n->t_startc;
872 s[C_STOP] = n->t_stopc;
873 s[C_EOF] = n->t_eofc;
874 s[C_BRK] = n->t_brkc;
876 # endif /* TIOCGETC */
880 struct sgttyb *n = &td->d_t;
882 s[C_ERASE] = n->sg_erase;
883 s[C_KILL] = n->sg_kill;
885 # endif /* TIOCGETP */
886 #endif /* !POSIX || TERMIO */
898 struct ltchars *n = &td->d_ltc;
900 n->t_suspc = s[C_SUSP];
901 n->t_dsuspc = s[C_DSUSP];
902 n->t_rprntc = s[C_REPRINT];
903 n->t_flushc = s[C_DISCARD];
904 n->t_werasc = s[C_WERASE];
905 n->t_lnextc = s[C_LNEXT];
907 #endif /* TIOCGLTC */
909 #if defined(POSIX) || defined(TERMIO)
912 struct termios *n = &td->d_t;
914 struct termio *n = &td->d_t;
918 n->c_cc[VINTR] = s[C_INTR];
921 n->c_cc[VQUIT] = s[C_QUIT];
924 n->c_cc[VERASE] = s[C_ERASE];
927 n->c_cc[VKILL] = s[C_KILL];
930 n->c_cc[VEOF] = s[C_EOF];
933 n->c_cc[VEOL] = s[C_EOL];
936 n->c_cc[VEOL2] = s[C_EOL2];
939 n->c_cc[VSWTCH] = s[C_SWTCH];
942 n->c_cc[VDSWTCH] = s[C_DSWTCH];
943 # endif /* VDSWTCH */
945 n->c_cc[VERASE2] = s[C_ERASE2];
946 # endif /* VERASE2 */
948 n->c_cc[VSTART] = s[C_START];
951 n->c_cc[VSTOP] = s[C_STOP];
954 n->c_cc[VWERASE] = s[C_WERASE];
955 # endif /* VWERASE */
957 n->c_cc[VSUSP] = s[C_SUSP];
960 n->c_cc[VDSUSP] = s[C_DSUSP];
963 n->c_cc[VREPRINT] = s[C_REPRINT];
964 # endif /* WREPRINT */
966 n->c_cc[VDISCARD] = s[C_DISCARD];
967 # endif /* VDISCARD */
969 n->c_cc[VLNEXT] = s[C_LNEXT];
972 n->c_cc[VSTATUS] = s[C_STATUS];
973 # endif /* VSTATUS */
975 n->c_cc[VPAGE] = s[C_PAGE];
978 n->c_cc[VPGOFF] = s[C_PGOFF];
981 n->c_cc[VKILL2] = s[C_KILL2];
984 n->c_cc[VMIN] = s[C_MIN];
987 n->c_cc[VTIME] = s[C_TIME];
995 struct ttypagestat *n = &td->d_pc;
999 n->tps_statc = s[C_STATUS];
1000 n->tps_pagec = s[C_PAGE];
1001 n->tps_pgoffc = s[C_PGOFF];
1004 # endif /* TIOCGPAGE */
1008 struct tchars *n = &td->d_tc;
1009 n->t_intrc = s[C_INTR];
1010 n->t_quitc = s[C_QUIT];
1011 n->t_startc = s[C_START];
1012 n->t_stopc = s[C_STOP];
1013 n->t_eofc = s[C_EOF];
1014 n->t_brkc = s[C_BRK];
1016 # endif /* TIOCGETC */
1020 struct sgttyb *n = &td->d_t;
1022 n->sg_erase = s[C_ERASE];
1023 n->sg_kill = s[C_KILL];
1025 # endif /* TIOCGETP */
1026 #endif /* !POSIX || TERMIO */
1037 if ((spd = cfgetispeed(&td->d_t)) == 0)
1038 spd = cfgetospeed(&td->d_t);
1042 spd = td->d_t.c_cflag & CBAUD;
1047 spd = td->d_t.sg_ispeed;
1048 # endif /* TERMIO */
1052 } /* end tty_getspeed */
1058 #if defined(POSIX) || defined(TERMIO)
1059 return ((td->d_t.c_oflag & TAB3) == TAB3) ? 0 : 1;
1061 return (td->d_t.sg_flags & XTABS) == XTABS ? 0 : 1;
1062 #endif /* POSIX || TERMIO */
1063 } /* end tty_gettabs */
1069 #if defined(POSIX) || defined(TERMIO)
1070 return (td->d_t.c_cflag & CSIZE) == CS8;
1072 return td->d_lb & (LPASS8 | LLITOUT);
1073 #endif /* POSIX || TERMIO */
1074 } /* end tty_geteightbit */
1080 #if defined(POSIX) || defined(TERMIO)
1081 return (td->d_t.c_lflag & ICANON);
1083 return !(td->d_t.sg_flags & (RAW | CBREAK));
1084 #endif /* POSIX || TERMIO */
1085 } /* end tty_cooked_mode */
1089 tty_setdisc(fd, dis)
1093 static bool edit_discipline = 0;
1094 static union txname tx_disc;
1095 extern char strPOSIX[];
1099 if (edit_discipline) {
1100 if (ioctl(fd, TXSETLD, (ioctl_t) & tx_disc) == -1)
1102 edit_discipline = 0;
1107 tx_disc.tx_which = 0;
1108 if (ioctl(fd, TXGETLD, (ioctl_t) & tx_disc) == -1)
1110 if (strcmp(tx_disc.tx_name, strPOSIX) != 0) {
1111 edit_discipline = 1;
1112 if (ioctl(fd, TXSETLD, (ioctl_t) strPOSIX) == -1)
1120 } /* end tty_setdisc */
1128 struct tcshmodes *m;
1131 for (i = 0; i < C_NCC; i++) {
1132 for (m = modelist; m->m_name; m++)
1133 if (m->m_type == M_CHAR && C_SH(i) == m->m_value)
1136 xprintf("%s ^%c ", m->m_name, s[i] + 'A' - 1);
1142 #endif /* DEBUG_TTY */
1143 #else /* WINNT_NATIVE */
1148 return do_nt_check_cooked_mode();
1150 #endif /* !WINNT_NATIVE */