1 /* $Header: /p/tcsh/cvsroot/tcsh/ed.term.c,v 1.36 2006/03/02 18:46:44 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. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 RCSID("$tcsh: ed.term.c,v 1.36 2006/03/02 18:46:44 christos Exp $")
43 #if defined(POSIX) || defined(TERMIO)
44 { "iflag:", ICRNL
, (INLCR
|IGNCR
) },
45 { "oflag:", (OPOST
|ONLCR
), ONLRET
},
47 { "lflag:", (ISIG
|ICANON
|ECHO
|ECHOE
|ECHOCTL
|IEXTEN
),
48 (NOFLSH
|ECHONL
|EXTPROC
|FLUSHO
|IDEFAULT
) },
50 { "nrmal:", (ECHO
|CRMOD
|ANYP
), (CBREAK
|RAW
|LCASE
|VTDELAY
|ALLDELAY
) },
51 { "local:", (LCRTBS
|LCRTERA
|LCRTKIL
), (LPRTERA
|LFLUSHO
) },
52 #endif /* POSIX || TERMIO */
56 #if defined(POSIX) || defined(TERMIO)
57 { "iflag:", (INLCR
|ICRNL
), IGNCR
},
58 { "oflag:", (OPOST
|ONLCR
), ONLRET
},
61 (NOFLSH
|ICANON
|ECHO
|ECHOK
|ECHONL
|EXTPROC
|IEXTEN
|FLUSHO
|
64 { "nrmal:", (CBREAK
|CRMOD
|ANYP
), (RAW
|ECHO
|LCASE
|VTDELAY
|ALLDELAY
) },
65 { "local:", (LCRTBS
|LCRTERA
|LCRTKIL
), (LPRTERA
|LFLUSHO
) },
66 #endif /* POSIX || TERMIO */
67 { "chars:", (C_SH(C_MIN
)|C_SH(C_TIME
)|C_SH(C_SWTCH
)|C_SH(C_DSWTCH
)|
68 C_SH(C_WERASE
)|C_SH(C_REPRINT
)|C_SH(C_SUSP
)|C_SH(C_DSUSP
)|
69 C_SH(C_EOF
)|C_SH(C_EOL
)|C_SH(C_DISCARD
)|C_SH(C_PGOFF
)|
70 C_SH(C_KILL2
)|C_SH(C_PAGE
)|C_SH(C_STATUS
)|C_SH(C_CHECKPT
)|
75 #if defined(POSIX) || defined(TERMIO)
76 { "iflag:", 0, IXON
| IXOFF
},
79 { "lflag:", 0, ISIG
| IEXTEN
},
81 { "nrmal:", RAW
, CBREAK
},
83 #endif /* POSIX || TERMIO */
88 static const struct tcshmodes
{
91 unsigned long m_value
;
97 #if defined(POSIX) || defined(TERMIO)
100 { "ignbrk", IGNBRK
, M_INPUT
},
103 { "brkint", BRKINT
, M_INPUT
},
106 { "ignpar", IGNPAR
, M_INPUT
},
109 { "parmrk", PARMRK
, M_INPUT
},
112 { "inpck", INPCK
, M_INPUT
},
115 { "istrip", ISTRIP
, M_INPUT
},
118 { "inlcr", INLCR
, M_INPUT
},
121 { "igncr", IGNCR
, M_INPUT
},
124 { "icrnl", ICRNL
, M_INPUT
},
127 { "iuclc", IUCLC
, M_INPUT
},
130 { "ixon", IXON
, M_INPUT
},
133 { "ixany", IXANY
, M_INPUT
},
136 { "ixoff", IXOFF
, M_INPUT
},
139 { "imaxbel",IMAXBEL
,M_INPUT
},
140 # endif /* IMAXBEL */
142 { "idelete",IDELETE
,M_INPUT
},
143 # endif /* IDELETE */
146 { "opost", OPOST
, M_OUTPUT
},
149 { "olcuc", OLCUC
, M_OUTPUT
},
152 { "onlcr", ONLCR
, M_OUTPUT
},
155 { "ocrnl", OCRNL
, M_OUTPUT
},
158 { "onocr", ONOCR
, M_OUTPUT
},
161 { "onoeot", ONOEOT
, M_OUTPUT
},
164 { "onlret", ONLRET
, M_OUTPUT
},
167 { "ofill", OFILL
, M_OUTPUT
},
170 { "ofdel", OFDEL
, M_OUTPUT
},
173 { "nldly", NLDLY
, M_OUTPUT
},
176 { "crdly", CRDLY
, M_OUTPUT
},
179 { "tabdly", TABDLY
, M_OUTPUT
},
182 { "xtabs", XTABS
, M_OUTPUT
},
185 { "bsdly", BSDLY
, M_OUTPUT
},
188 { "vtdly", VTDLY
, M_OUTPUT
},
191 { "ffdly", FFDLY
, M_OUTPUT
},
194 { "pageout",PAGEOUT
,M_OUTPUT
},
195 # endif /* PAGEOUT */
197 { "wrap", WRAP
, M_OUTPUT
},
201 { "cignore",CIGNORE
,M_CONTROL
},
204 { "cbaud", CBAUD
, M_CONTROL
},
207 { "cstopb", CSTOPB
, M_CONTROL
},
210 { "cread", CREAD
, M_CONTROL
},
213 { "parenb", PARENB
, M_CONTROL
},
216 { "parodd", PARODD
, M_CONTROL
},
219 { "hupcl", HUPCL
, M_CONTROL
},
222 { "clocal", CLOCAL
, M_CONTROL
},
225 { "loblk", LOBLK
, M_CONTROL
},
228 { "cibaud", CIBAUD
, M_CONTROL
},
232 { "ccts_oflow",CCTS_OFLOW
,M_CONTROL
},
234 { "crtscts",CRTSCTS
,M_CONTROL
},
235 # endif /* CCTS_OFLOW */
236 # endif /* CRTSCTS */
238 { "crts_iflow",CRTS_IFLOW
,M_CONTROL
},
239 # endif /* CRTS_IFLOW */
241 { "mdmbuf", MDMBUF
, M_CONTROL
},
244 { "rcv1en", RCV1EN
, M_CONTROL
},
247 { "xmt1en", XMT1EN
, M_CONTROL
},
251 { "isig", ISIG
, M_LINED
},
254 { "icanon", ICANON
, M_LINED
},
257 { "xcase", XCASE
, M_LINED
},
260 { "echo", ECHO
, M_LINED
},
263 { "echoe", ECHOE
, M_LINED
},
266 { "echok", ECHOK
, M_LINED
},
269 { "echonl", ECHONL
, M_LINED
},
272 { "noflsh", NOFLSH
, M_LINED
},
275 { "tostop", TOSTOP
, M_LINED
},
278 { "echoctl",ECHOCTL
,M_LINED
},
279 # endif /* ECHOCTL */
281 { "echoprt",ECHOPRT
,M_LINED
},
282 # endif /* ECHOPRT */
284 { "echoke", ECHOKE
, M_LINED
},
287 { "defecho",DEFECHO
,M_LINED
},
288 # endif /* DEFECHO */
290 { "flusho", FLUSHO
, M_LINED
},
293 { "pendin", PENDIN
, M_LINED
},
296 { "iexten", IEXTEN
, M_LINED
},
299 { "nokerninfo",NOKERNINFO
,M_LINED
},
300 # endif /* NOKERNINFO */
302 { "altwerase",ALTWERASE
,M_LINED
},
303 # endif /* ALTWERASE */
305 { "extproc",EXTPROC
,M_LINED
},
306 # endif /* EXTPROC */
308 { "idefault",IDEFAULT
,M_LINED
},
309 # endif /* IDEFAULT */
314 { "tandem", TANDEM
, M_CONTROL
},
317 { "cbreak", CBREAK
, M_CONTROL
},
320 { "lcase", LCASE
, M_CONTROL
},
323 { "echo", ECHO
, M_CONTROL
},
326 { "crmod", CRMOD
, M_CONTROL
},
329 { "raw", RAW
, M_CONTROL
},
332 { "oddp", ODDP
, M_CONTROL
},
335 { "evenp", EVENP
, M_CONTROL
},
338 { "anyp", ANYP
, M_CONTROL
},
341 { "nldelay",NLDELAY
,M_CONTROL
},
342 # endif /* NLDELAY */
344 { "tbdelay",TBDELAY
,M_CONTROL
},
345 # endif /* TBDELAY */
347 { "xtabs", XTABS
, M_CONTROL
},
350 { "crdelay",CRDELAY
,M_CONTROL
},
351 # endif /* CRDELAY */
353 { "vtdelay",VTDELAY
,M_CONTROL
},
354 # endif /* VTDELAY */
356 { "bsdelay",BSDELAY
,M_CONTROL
},
357 # endif /* BSDELAY */
359 { "crtbs", CRTBS
, M_CONTROL
},
362 { "prtera", PRTERA
, M_CONTROL
},
365 { "crtera", CRTERA
, M_CONTROL
},
368 { "tilde", TILDE
, M_CONTROL
},
371 { "mdmbuf", MDMBUF
, M_CONTROL
},
374 { "litout", LITOUT
, M_CONTROL
},
377 { "tostop", TOSTOP
, M_CONTROL
},
380 { "flusho", FLUSHO
, M_CONTROL
},
383 { "nohang", NOHANG
, M_CONTROL
},
386 { "l001000",L001000
,M_CONTROL
},
387 # endif /* L001000 */
389 { "crtkil", CRTKIL
, M_CONTROL
},
392 { "pass8", PASS8
, M_CONTROL
},
395 { "ctlech", CTLECH
, M_CONTROL
},
398 { "pendin", PENDIN
, M_CONTROL
},
401 { "decctq", DECCTQ
, M_CONTROL
},
404 { "noflsh", NOFLSH
, M_CONTROL
},
408 { "lcrtbs", LCRTBS
, M_LOCAL
},
411 { "lprtera",LPRTERA
,M_LOCAL
},
412 # endif /* LPRTERA */
414 { "lcrtera",LCRTERA
,M_LOCAL
},
415 # endif /* LCRTERA */
417 { "ltilde", LTILDE
, M_LOCAL
},
420 { "lmdmbuf",LMDMBUF
,M_LOCAL
},
421 # endif /* LMDMBUF */
423 { "llitout",LLITOUT
,M_LOCAL
},
424 # endif /* LLITOUT */
426 { "ltostop",LTOSTOP
,M_LOCAL
},
427 # endif /* LTOSTOP */
429 { "lflusho",LFLUSHO
,M_LOCAL
},
430 # endif /* LFLUSHO */
432 { "lnohang",LNOHANG
,M_LOCAL
},
433 # endif /* LNOHANG */
435 { "lcrtkil",LCRTKIL
,M_LOCAL
},
436 # endif /* LCRTKIL */
438 { "lpass8", LPASS8
, M_LOCAL
},
441 { "lctlech",LCTLECH
,M_LOCAL
},
442 # endif /* LCTLECH */
444 { "lpendin",LPENDIN
,M_LOCAL
},
445 # endif /* LPENDIN */
447 { "ldecctq",LDECCTQ
,M_LOCAL
},
448 # endif /* LDECCTQ */
450 { "lnoflsh",LNOFLSH
,M_LOCAL
},
451 # endif /* LNOFLSH */
453 #endif /* POSIX || TERMIO */
454 # if defined(VINTR) || defined(TIOCGETC)
455 { "intr", C_SH(C_INTR
), M_CHAR
},
457 # if defined(VQUIT) || defined(TIOCGETC)
458 { "quit", C_SH(C_QUIT
), M_CHAR
},
460 # if defined(VERASE) || defined(TIOCGETP)
461 { "erase", C_SH(C_ERASE
), M_CHAR
},
463 # if defined(VKILL) || defined(TIOCGETP)
464 { "kill", C_SH(C_KILL
), M_CHAR
},
466 # if defined(VEOF) || defined(TIOCGETC)
467 { "eof", C_SH(C_EOF
), M_CHAR
},
470 { "eol", C_SH(C_EOL
), M_CHAR
},
473 { "eol2", C_SH(C_EOL2
), M_CHAR
},
476 { "swtch", C_SH(C_SWTCH
), M_CHAR
},
478 # if defined(VDSWTCH)
479 { "dswtch", C_SH(C_DSWTCH
), M_CHAR
},
480 # endif /* VDSWTCH */
481 # if defined(VERASE2)
482 { "erase2", C_SH(C_ERASE2
), M_CHAR
},
483 # endif /* VERASE2 */
484 # if defined(VSTART) || defined(TIOCGETC)
485 { "start", C_SH(C_START
), M_CHAR
},
487 # if defined(VSTOP) || defined(TIOCGETC)
488 { "stop", C_SH(C_STOP
), M_CHAR
},
490 # if defined(VWERASE) || defined(TIOCGLTC)
491 { "werase", C_SH(C_WERASE
), M_CHAR
},
492 # endif /* VWERASE */
493 # if defined(VSUSP) || defined(TIOCGLTC)
494 { "susp", C_SH(C_SUSP
), M_CHAR
},
496 # if defined(VDSUSP) || defined(TIOCGLTC)
497 { "dsusp", C_SH(C_DSUSP
), M_CHAR
},
499 # if defined(VREPRINT) || defined(TIOCGLTC)
500 { "reprint", C_SH(C_REPRINT
),M_CHAR
},
501 # endif /* WREPRINT */
502 # if defined(VDISCARD) || defined(TIOCGLTC)
503 { "discard", C_SH(C_DISCARD
),M_CHAR
},
504 # endif /* VDISCARD */
505 # if defined(VLNEXT) || defined(TIOCGLTC)
506 { "lnext", C_SH(C_LNEXT
), M_CHAR
},
508 # if defined(VSTATUS) || defined(TIOCGPAGE)
509 { "status", C_SH(C_STATUS
), M_CHAR
},
510 # endif /* VSTATUS */
511 # if defined(VCHECKPT) || defined(TIOCGPAGE)
512 { "ckpt", C_SH(C_CHECKPT
),M_CHAR
},
513 # endif /* VCHECKPT */
514 # if defined(VPAGE) || defined(TIOCGPAGE)
515 { "page", C_SH(C_PAGE
), M_CHAR
},
517 # if defined(VPGOFF) || defined(TIOCGPAGE)
518 { "pgoff", C_SH(C_PGOFF
), M_CHAR
},
521 { "kill2", C_SH(C_KILL2
), M_CHAR
},
523 # if defined(VBRK) || defined(TIOCGETC)
524 { "brk", C_SH(C_BRK
), M_CHAR
},
527 { "min", C_SH(C_MIN
), M_CHAR
},
530 { "time", C_SH(C_TIME
), M_CHAR
},
536 * If EAGAIN and/or EWOULDBLOCK are defined, we can't just return -1 in all
537 * situations where ioctl() does.
539 * On AIX 4.1.5 (and presumably some other versions and OSes), as you
540 * perform the manual test suite in the README, if you 'bg' vi immediately
541 * after suspending it, all is well, but if you wait a few seconds,
542 * usually ioctl() will return -1, which previously caused tty_setty() to
543 * return -1, causing Rawmode() to return -1, causing Inputl() to return
544 * 0, causing bgetc() to return -1, causing readc() to set doneinp to 1,
545 * causing process() to break out of the main loop, causing tcsh to exit
548 * If ioctl()'s errno is EAGAIN/EWOULDBLOCK ("Resource temporarily
549 * unavailable"), apparently the tty is being messed with by the OS and we
550 * need to try again. In my testing, ioctl() was never called more than
553 * -- Dan Harkless <dan@wave.eng.uci.edu>
555 * So, I retry all ioctl's in case others happen to fail too (christos)
558 #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
559 # define OKERROR(e) (((e) == EAGAIN) || ((e) == EWOULDBLOCK) || ((e) == EINTR))
560 #elif defined(EAGAIN)
561 # define OKERROR(e) (((e) == EAGAIN) || ((e) == EINTR))
562 #elif defined(EWOULDBLOCK)
563 # define OKERROR(e) (((e) == EWOULDBLOCK) || ((e) == EINTR))
565 # define OKERROR(e) ((e) == EINTR)
569 #define KLUDGE (errno == ENOTTY && count < 10)
574 /* Retry a system call */
579 for (count = 0;; count++) \
581 if (OKERROR(errno) || KLUDGE) \
592 dosetty(Char
**v
, struct command
*t
)
594 const struct tcshmodes
*m
;
595 char x
, *d
, *cmdname
;
601 cmdname
= strsave(short2str(*v
++));
602 cleanup_push(cmdname
, xfree
);
605 while (v
&& *v
&& v
[0][0] == '-' && v
[0][2] == '\0')
624 stderror(ERR_NAME
| ERR_SYSTEM
, short2str(v
[0]),
625 CGETS(8, 1, "Unknown switch"));
632 int len
= 0, st
= 0, cu
;
633 for (m
= modelist
; m
->m_name
; m
++) {
634 if (m
->m_type
!= i
) {
635 xprintf("%s%s", i
!= -1 ? "\n" : "",
636 ttylist
[z
][m
->m_type
].t_name
);
638 st
= len
= strlen(ttylist
[z
][m
->m_type
].t_name
);
641 x
= (ttylist
[z
][i
].t_setmask
& m
->m_value
) ? '+' : '\0';
642 x
= (ttylist
[z
][i
].t_clrmask
& m
->m_value
) ? '-' : x
;
644 if (x
!= '\0' || aflag
) {
645 cu
= strlen(m
->m_name
) + (x
!= '\0') + 1;
646 if (len
+ cu
>= TermH
) {
647 xprintf("\n%*s", st
, "");
653 xprintf("%c%s ", x
, m
->m_name
);
655 xprintf("%s ", m
->m_name
);
659 cleanup_until(cmdname
);
662 while (v
&& (s
= *v
++)) {
673 for (m
= modelist
; m
->m_name
; m
++)
674 if (strcmp(m
->m_name
, d
) == 0)
677 stderror(ERR_NAME
| ERR_SYSTEM
, d
, CGETS(8, 2, "Invalid argument"));
681 ttylist
[z
][m
->m_type
].t_setmask
|= m
->m_value
;
682 ttylist
[z
][m
->m_type
].t_clrmask
&= ~m
->m_value
;
685 ttylist
[z
][m
->m_type
].t_setmask
&= ~m
->m_value
;
686 ttylist
[z
][m
->m_type
].t_clrmask
|= m
->m_value
;
689 ttylist
[z
][m
->m_type
].t_setmask
&= ~m
->m_value
;
690 ttylist
[z
][m
->m_type
].t_clrmask
&= ~m
->m_value
;
694 cleanup_until(cmdname
);
698 tty_getty(int fd
, ttydata_t
*td
)
701 RETRY(tcgetattr(fd
, &td
->d_t
));
702 #else /* TERMIO || GSTTY */
704 RETRY(ioctl(fd
, TCGETA
, (ioctl_t
) &td
->d_t
));
707 RETRY(ioctl(fd
, TIOCGETP
, (ioctl_t
) &td
->d_t
));
708 # endif /* TIOCGETP */
710 RETRY(ioctl(fd
, TIOCGETC
, (ioctl_t
) &td
->d_tc
));
711 # endif /* TIOCGETC */
713 RETRY(ioctl(fd
, TIOCGPAGE
, (ioctl_t
) &td
->d_pc
));
714 # endif /* TIOCGPAGE */
716 RETRY(ioctl(fd
, TIOCLGET
, (ioctl_t
) &td
->d_lb
));
717 # endif /* TIOCLGET */
722 RETRY(ioctl(fd
, TIOCGLTC
, (ioctl_t
) &td
->d_ltc
));
723 #endif /* TIOCGLTC */
729 tty_setty(int fd
, ttydata_t
*td
)
732 RETRY(xtcsetattr(fd
, TCSADRAIN
, &td
->d_t
));
735 RETRY(ioctl(fd
, TCSETAW
, (ioctl_t
) &td
->d_t
));
738 RETRY(ioctl(fd
, TIOCSETN
, (ioctl_t
) &td
->d_t
));
739 # endif /* TIOCSETN */
741 RETRY(ioctl(fd
, TIOCSETC
, (ioctl_t
) &td
->d_tc
));
742 # endif /* TIOCGETC */
744 RETRY(ioctl(fd
, TIOCSPAGE
, (ioctl_t
) &td
->d_pc
));
745 # endif /* TIOCGPAGE */
747 RETRY(ioctl(fd
, TIOCLSET
, (ioctl_t
) &td
->d_lb
));
748 # endif /* TIOCLGET */
753 RETRY(ioctl(fd
, TIOCSLTC
, (ioctl_t
) &td
->d_ltc
));
754 #endif /* TIOCGLTC */
760 tty_getchar(ttydata_t
*td
, unsigned char *s
)
764 struct ltchars
*n
= &td
->d_ltc
;
766 s
[C_SUSP
] = n
->t_suspc
;
767 s
[C_DSUSP
] = n
->t_dsuspc
;
768 s
[C_REPRINT
] = n
->t_rprntc
;
769 s
[C_DISCARD
] = n
->t_flushc
;
770 s
[C_WERASE
] = n
->t_werasc
;
771 s
[C_LNEXT
] = n
->t_lnextc
;
773 #endif /* TIOCGLTC */
775 #if defined(POSIX) || defined(TERMIO)
778 struct termios
*n
= &td
->d_t
;
780 struct termio
*n
= &td
->d_t
;
784 s
[C_INTR
] = n
->c_cc
[VINTR
];
787 s
[C_QUIT
] = n
->c_cc
[VQUIT
];
790 s
[C_ERASE
] = n
->c_cc
[VERASE
];
793 s
[C_KILL
] = n
->c_cc
[VKILL
];
796 s
[C_EOF
] = n
->c_cc
[VEOF
];
799 s
[C_EOL
] = n
->c_cc
[VEOL
];
802 s
[C_EOL2
] = n
->c_cc
[VEOL2
];
805 s
[C_SWTCH
] = n
->c_cc
[VSWTCH
];
808 s
[C_DSWTCH
] = n
->c_cc
[VDSWTCH
];
809 # endif /* VDSWTCH */
811 s
[C_ERASE2
] = n
->c_cc
[VERASE2
];
812 # endif /* VERASE2 */
814 s
[C_START
] = n
->c_cc
[VSTART
];
817 s
[C_STOP
] = n
->c_cc
[VSTOP
];
820 s
[C_WERASE
] = n
->c_cc
[VWERASE
];
821 # endif /* VWERASE */
823 s
[C_SUSP
] = n
->c_cc
[VSUSP
];
826 s
[C_DSUSP
] = n
->c_cc
[VDSUSP
];
829 s
[C_REPRINT
] = n
->c_cc
[VREPRINT
];
830 # endif /* WREPRINT */
832 s
[C_DISCARD
] = n
->c_cc
[VDISCARD
];
833 # endif /* VDISCARD */
835 s
[C_LNEXT
] = n
->c_cc
[VLNEXT
];
838 s
[C_STATUS
] = n
->c_cc
[VSTATUS
];
839 # endif /* VSTATUS */
841 s
[C_CHECKPT
] = n
->c_cc
[VCHECKPT
];
842 # endif /* VCHECKPT */
844 s
[C_PAGE
] = n
->c_cc
[VPAGE
];
847 s
[C_PGOFF
] = n
->c_cc
[VPGOFF
];
850 s
[C_KILL2
] = n
->c_cc
[VKILL2
];
853 s
[C_MIN
] = n
->c_cc
[VMIN
];
856 s
[C_TIME
] = n
->c_cc
[VTIME
];
864 struct ttypagestat
*n
= &td
->d_pc
;
866 s
[C_STATUS
] = n
->tps_statc
;
867 s
[C_CHECKPT
] = n
->tps_checkp
;
868 s
[C_PAGE
] = n
->tps_pagec
;
869 s
[C_PGOFF
] = n
->tps_pgoffc
;
871 # endif /* TIOCGPAGE */
875 struct tchars
*n
= &td
->d_tc
;
877 s
[C_INTR
] = n
->t_intrc
;
878 s
[C_QUIT
] = n
->t_quitc
;
879 s
[C_START
] = n
->t_startc
;
880 s
[C_STOP
] = n
->t_stopc
;
881 s
[C_EOF
] = n
->t_eofc
;
882 s
[C_BRK
] = n
->t_brkc
;
884 # endif /* TIOCGETC */
888 struct sgttyb
*n
= &td
->d_t
;
890 s
[C_ERASE
] = n
->sg_erase
;
891 s
[C_KILL
] = n
->sg_kill
;
893 # endif /* TIOCGETP */
894 #endif /* !POSIX || TERMIO */
900 tty_setchar(ttydata_t
*td
, unsigned char *s
)
904 struct ltchars
*n
= &td
->d_ltc
;
906 n
->t_suspc
= s
[C_SUSP
];
907 n
->t_dsuspc
= s
[C_DSUSP
];
908 n
->t_rprntc
= s
[C_REPRINT
];
909 n
->t_flushc
= s
[C_DISCARD
];
910 n
->t_werasc
= s
[C_WERASE
];
911 n
->t_lnextc
= s
[C_LNEXT
];
913 #endif /* TIOCGLTC */
915 #if defined(POSIX) || defined(TERMIO)
918 struct termios
*n
= &td
->d_t
;
920 struct termio
*n
= &td
->d_t
;
924 n
->c_cc
[VINTR
] = s
[C_INTR
];
927 n
->c_cc
[VQUIT
] = s
[C_QUIT
];
930 n
->c_cc
[VERASE
] = s
[C_ERASE
];
933 n
->c_cc
[VKILL
] = s
[C_KILL
];
936 n
->c_cc
[VEOF
] = s
[C_EOF
];
939 n
->c_cc
[VEOL
] = s
[C_EOL
];
942 n
->c_cc
[VEOL2
] = s
[C_EOL2
];
945 n
->c_cc
[VSWTCH
] = s
[C_SWTCH
];
948 n
->c_cc
[VDSWTCH
] = s
[C_DSWTCH
];
949 # endif /* VDSWTCH */
951 n
->c_cc
[VERASE2
] = s
[C_ERASE2
];
952 # endif /* VERASE2 */
954 n
->c_cc
[VSTART
] = s
[C_START
];
957 n
->c_cc
[VSTOP
] = s
[C_STOP
];
960 n
->c_cc
[VWERASE
] = s
[C_WERASE
];
961 # endif /* VWERASE */
963 n
->c_cc
[VSUSP
] = s
[C_SUSP
];
966 n
->c_cc
[VDSUSP
] = s
[C_DSUSP
];
969 n
->c_cc
[VREPRINT
] = s
[C_REPRINT
];
970 # endif /* WREPRINT */
972 n
->c_cc
[VDISCARD
] = s
[C_DISCARD
];
973 # endif /* VDISCARD */
975 n
->c_cc
[VLNEXT
] = s
[C_LNEXT
];
978 n
->c_cc
[VSTATUS
] = s
[C_STATUS
];
979 # endif /* VSTATUS */
981 n
->c_cc
[VCHECKPT
] = s
[C_CHECKPT
];
982 # endif /* VCHECKPT */
984 n
->c_cc
[VPAGE
] = s
[C_PAGE
];
987 n
->c_cc
[VPGOFF
] = s
[C_PGOFF
];
990 n
->c_cc
[VKILL2
] = s
[C_KILL2
];
993 n
->c_cc
[VMIN
] = s
[C_MIN
];
996 n
->c_cc
[VTIME
] = s
[C_TIME
];
1004 struct ttypagestat
*n
= &td
->d_pc
;
1008 n
->tps_statc
= s
[C_STATUS
];
1009 n
->tps_pagec
= s
[C_PAGE
];
1010 n
->tps_pgoffc
= s
[C_PGOFF
];
1013 # endif /* TIOCGPAGE */
1017 struct tchars
*n
= &td
->d_tc
;
1018 n
->t_intrc
= s
[C_INTR
];
1019 n
->t_quitc
= s
[C_QUIT
];
1020 n
->t_startc
= s
[C_START
];
1021 n
->t_stopc
= s
[C_STOP
];
1022 n
->t_eofc
= s
[C_EOF
];
1023 n
->t_brkc
= s
[C_BRK
];
1025 # endif /* TIOCGETC */
1029 struct sgttyb
*n
= &td
->d_t
;
1031 n
->sg_erase
= s
[C_ERASE
];
1032 n
->sg_kill
= s
[C_KILL
];
1034 # endif /* TIOCGETP */
1035 #endif /* !POSIX || TERMIO */
1040 tty_getspeed(ttydata_t
*td
)
1045 if ((spd
= cfgetispeed(&td
->d_t
)) == 0)
1046 spd
= cfgetospeed(&td
->d_t
);
1050 spd
= td
->d_t
.c_cflag
& CBAUD
;
1055 spd
= td
->d_t
.sg_ispeed
;
1056 # endif /* TERMIO */
1060 } /* end tty_getspeed */
1063 tty_gettabs(ttydata_t
*td
)
1065 #if defined(POSIX) || defined(TERMIO)
1066 return ((td
->d_t
.c_oflag
& TAB3
) == TAB3
) ? 0 : 1;
1068 return (td
->d_t
.sg_flags
& XTABS
) == XTABS
? 0 : 1;
1069 #endif /* POSIX || TERMIO */
1070 } /* end tty_gettabs */
1073 tty_geteightbit(ttydata_t
*td
)
1075 #if defined(POSIX) || defined(TERMIO)
1076 return (td
->d_t
.c_cflag
& CSIZE
) == CS8
;
1078 return td
->d_lb
& (LPASS8
| LLITOUT
);
1079 #endif /* POSIX || TERMIO */
1080 } /* end tty_geteightbit */
1083 tty_cooked_mode(ttydata_t
*td
)
1085 #if defined(POSIX) || defined(TERMIO)
1086 return (td
->d_t
.c_lflag
& ICANON
);
1088 return !(td
->d_t
.sg_flags
& (RAW
| CBREAK
));
1089 #endif /* POSIX || TERMIO */
1090 } /* end tty_cooked_mode */
1094 tty_setdisc(int fd
, int dis
)
1096 static int edit_discipline
= 0;
1097 static union txname tx_disc
;
1098 extern char strPOSIX
[];
1102 if (edit_discipline
) {
1103 if (ioctl(fd
, TXSETLD
, (ioctl_t
) & tx_disc
) == -1)
1105 edit_discipline
= 0;
1110 tx_disc
.tx_which
= 0;
1111 if (ioctl(fd
, TXGETLD
, (ioctl_t
) & tx_disc
) == -1)
1113 if (strcmp(tx_disc
.tx_name
, strPOSIX
) != 0) {
1114 edit_discipline
= 1;
1115 if (ioctl(fd
, TXSETLD
, (ioctl_t
) strPOSIX
) == -1)
1123 } /* end tty_setdisc */
1128 tty_printchar(unsigned char *s
)
1130 struct tcshmodes
*m
;
1133 for (i
= 0; i
< C_NCC
; i
++) {
1134 for (m
= modelist
; m
->m_name
; m
++)
1135 if (m
->m_type
== M_CHAR
&& C_SH(i
) == m
->m_value
)
1138 xprintf("%s ^%c ", m
->m_name
, s
[i
] + 'A' - 1);
1144 #endif /* DEBUG_TTY */
1145 #else /* WINNT_NATIVE */
1147 tty_cooked_mode(void *td
)
1149 return do_nt_check_cooked_mode();
1151 #endif /* !WINNT_NATIVE */