1 /* $Header: /p/tcsh/cvsroot/tcsh/ed.term.c,v 1.38 2011/02/25 23:58: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. 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.38 2011/02/25 23:58:34 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
);
642 x
= (ttylist
[z
][i
].t_setmask
& m
->m_value
) ? '+' : '\0';
643 x
= (ttylist
[z
][i
].t_clrmask
& m
->m_value
) ? '-' : x
;
645 if (x
!= '\0' || aflag
) {
646 cu
= strlen(m
->m_name
) + (x
!= '\0') + 1;
647 if (len
+ cu
>= TermH
) {
648 xprintf("\n%*s", st
, "");
654 xprintf("%c%s ", x
, m
->m_name
);
656 xprintf("%s ", m
->m_name
);
660 cleanup_until(cmdname
);
663 while (v
&& (s
= *v
++)) {
674 for (m
= modelist
; m
->m_name
; m
++)
675 if (strcmp(m
->m_name
, d
) == 0)
678 stderror(ERR_NAME
| ERR_SYSTEM
, d
, CGETS(8, 2, "Invalid argument"));
682 ttylist
[z
][m
->m_type
].t_setmask
|= m
->m_value
;
683 ttylist
[z
][m
->m_type
].t_clrmask
&= ~m
->m_value
;
686 ttylist
[z
][m
->m_type
].t_setmask
&= ~m
->m_value
;
687 ttylist
[z
][m
->m_type
].t_clrmask
|= m
->m_value
;
690 ttylist
[z
][m
->m_type
].t_setmask
&= ~m
->m_value
;
691 ttylist
[z
][m
->m_type
].t_clrmask
&= ~m
->m_value
;
695 cleanup_until(cmdname
);
699 tty_getty(int fd
, ttydata_t
*td
)
702 RETRY(tcgetattr(fd
, &td
->d_t
));
703 #else /* TERMIO || GSTTY */
705 RETRY(ioctl(fd
, TCGETA
, (ioctl_t
) &td
->d_t
));
708 RETRY(ioctl(fd
, TIOCGETP
, (ioctl_t
) &td
->d_t
));
709 # endif /* TIOCGETP */
711 RETRY(ioctl(fd
, TIOCGETC
, (ioctl_t
) &td
->d_tc
));
712 # endif /* TIOCGETC */
714 RETRY(ioctl(fd
, TIOCGPAGE
, (ioctl_t
) &td
->d_pc
));
715 # endif /* TIOCGPAGE */
717 RETRY(ioctl(fd
, TIOCLGET
, (ioctl_t
) &td
->d_lb
));
718 # endif /* TIOCLGET */
723 RETRY(ioctl(fd
, TIOCGLTC
, (ioctl_t
) &td
->d_ltc
));
724 #endif /* TIOCGLTC */
730 tty_setty(int fd
, ttydata_t
*td
)
733 RETRY(xtcsetattr(fd
, TCSADRAIN
, &td
->d_t
));
736 RETRY(ioctl(fd
, TCSETAW
, (ioctl_t
) &td
->d_t
));
739 RETRY(ioctl(fd
, TIOCSETN
, (ioctl_t
) &td
->d_t
));
740 # endif /* TIOCSETN */
742 RETRY(ioctl(fd
, TIOCSETC
, (ioctl_t
) &td
->d_tc
));
743 # endif /* TIOCGETC */
745 RETRY(ioctl(fd
, TIOCSPAGE
, (ioctl_t
) &td
->d_pc
));
746 # endif /* TIOCGPAGE */
748 RETRY(ioctl(fd
, TIOCLSET
, (ioctl_t
) &td
->d_lb
));
749 # endif /* TIOCLGET */
754 RETRY(ioctl(fd
, TIOCSLTC
, (ioctl_t
) &td
->d_ltc
));
755 #endif /* TIOCGLTC */
761 tty_getchar(ttydata_t
*td
, unsigned char *s
)
765 struct ltchars
*n
= &td
->d_ltc
;
767 s
[C_SUSP
] = n
->t_suspc
;
768 s
[C_DSUSP
] = n
->t_dsuspc
;
769 s
[C_REPRINT
] = n
->t_rprntc
;
770 s
[C_DISCARD
] = n
->t_flushc
;
771 s
[C_WERASE
] = n
->t_werasc
;
772 s
[C_LNEXT
] = n
->t_lnextc
;
774 #endif /* TIOCGLTC */
776 #if defined(POSIX) || defined(TERMIO)
779 struct termios
*n
= &td
->d_t
;
781 struct termio
*n
= &td
->d_t
;
785 s
[C_INTR
] = n
->c_cc
[VINTR
];
788 s
[C_QUIT
] = n
->c_cc
[VQUIT
];
791 s
[C_ERASE
] = n
->c_cc
[VERASE
];
794 s
[C_KILL
] = n
->c_cc
[VKILL
];
797 s
[C_EOF
] = n
->c_cc
[VEOF
];
800 s
[C_EOL
] = n
->c_cc
[VEOL
];
803 s
[C_EOL2
] = n
->c_cc
[VEOL2
];
806 s
[C_SWTCH
] = n
->c_cc
[VSWTCH
];
809 s
[C_DSWTCH
] = n
->c_cc
[VDSWTCH
];
810 # endif /* VDSWTCH */
812 s
[C_ERASE2
] = n
->c_cc
[VERASE2
];
813 # endif /* VERASE2 */
815 s
[C_START
] = n
->c_cc
[VSTART
];
818 s
[C_STOP
] = n
->c_cc
[VSTOP
];
821 s
[C_WERASE
] = n
->c_cc
[VWERASE
];
822 # endif /* VWERASE */
824 s
[C_SUSP
] = n
->c_cc
[VSUSP
];
827 s
[C_DSUSP
] = n
->c_cc
[VDSUSP
];
830 s
[C_REPRINT
] = n
->c_cc
[VREPRINT
];
831 # endif /* WREPRINT */
833 s
[C_DISCARD
] = n
->c_cc
[VDISCARD
];
834 # endif /* VDISCARD */
836 s
[C_LNEXT
] = n
->c_cc
[VLNEXT
];
839 s
[C_STATUS
] = n
->c_cc
[VSTATUS
];
840 # endif /* VSTATUS */
842 s
[C_CHECKPT
] = n
->c_cc
[VCHECKPT
];
843 # endif /* VCHECKPT */
845 s
[C_PAGE
] = n
->c_cc
[VPAGE
];
848 s
[C_PGOFF
] = n
->c_cc
[VPGOFF
];
851 s
[C_KILL2
] = n
->c_cc
[VKILL2
];
854 s
[C_MIN
] = n
->c_cc
[VMIN
];
857 s
[C_TIME
] = n
->c_cc
[VTIME
];
865 struct ttypagestat
*n
= &td
->d_pc
;
867 s
[C_STATUS
] = n
->tps_statc
;
868 s
[C_CHECKPT
] = n
->tps_checkp
;
869 s
[C_PAGE
] = n
->tps_pagec
;
870 s
[C_PGOFF
] = n
->tps_pgoffc
;
872 # endif /* TIOCGPAGE */
876 struct tchars
*n
= &td
->d_tc
;
878 s
[C_INTR
] = n
->t_intrc
;
879 s
[C_QUIT
] = n
->t_quitc
;
880 s
[C_START
] = n
->t_startc
;
881 s
[C_STOP
] = n
->t_stopc
;
882 s
[C_EOF
] = n
->t_eofc
;
883 s
[C_BRK
] = n
->t_brkc
;
885 # endif /* TIOCGETC */
889 struct sgttyb
*n
= &td
->d_t
;
891 s
[C_ERASE
] = n
->sg_erase
;
892 s
[C_KILL
] = n
->sg_kill
;
894 # endif /* TIOCGETP */
895 #endif /* !POSIX || TERMIO */
901 tty_setchar(ttydata_t
*td
, unsigned char *s
)
905 struct ltchars
*n
= &td
->d_ltc
;
907 n
->t_suspc
= s
[C_SUSP
];
908 n
->t_dsuspc
= s
[C_DSUSP
];
909 n
->t_rprntc
= s
[C_REPRINT
];
910 n
->t_flushc
= s
[C_DISCARD
];
911 n
->t_werasc
= s
[C_WERASE
];
912 n
->t_lnextc
= s
[C_LNEXT
];
914 #endif /* TIOCGLTC */
916 #if defined(POSIX) || defined(TERMIO)
919 struct termios
*n
= &td
->d_t
;
921 struct termio
*n
= &td
->d_t
;
925 n
->c_cc
[VINTR
] = s
[C_INTR
];
928 n
->c_cc
[VQUIT
] = s
[C_QUIT
];
931 n
->c_cc
[VERASE
] = s
[C_ERASE
];
934 n
->c_cc
[VKILL
] = s
[C_KILL
];
937 n
->c_cc
[VEOF
] = s
[C_EOF
];
940 n
->c_cc
[VEOL
] = s
[C_EOL
];
943 n
->c_cc
[VEOL2
] = s
[C_EOL2
];
946 n
->c_cc
[VSWTCH
] = s
[C_SWTCH
];
949 n
->c_cc
[VDSWTCH
] = s
[C_DSWTCH
];
950 # endif /* VDSWTCH */
952 n
->c_cc
[VERASE2
] = s
[C_ERASE2
];
953 # endif /* VERASE2 */
955 n
->c_cc
[VSTART
] = s
[C_START
];
958 n
->c_cc
[VSTOP
] = s
[C_STOP
];
961 n
->c_cc
[VWERASE
] = s
[C_WERASE
];
962 # endif /* VWERASE */
964 n
->c_cc
[VSUSP
] = s
[C_SUSP
];
967 n
->c_cc
[VDSUSP
] = s
[C_DSUSP
];
970 n
->c_cc
[VREPRINT
] = s
[C_REPRINT
];
971 # endif /* WREPRINT */
973 n
->c_cc
[VDISCARD
] = s
[C_DISCARD
];
974 # endif /* VDISCARD */
976 n
->c_cc
[VLNEXT
] = s
[C_LNEXT
];
979 n
->c_cc
[VSTATUS
] = s
[C_STATUS
];
980 # endif /* VSTATUS */
982 n
->c_cc
[VCHECKPT
] = s
[C_CHECKPT
];
983 # endif /* VCHECKPT */
985 n
->c_cc
[VPAGE
] = s
[C_PAGE
];
988 n
->c_cc
[VPGOFF
] = s
[C_PGOFF
];
991 n
->c_cc
[VKILL2
] = s
[C_KILL2
];
994 n
->c_cc
[VMIN
] = s
[C_MIN
];
997 n
->c_cc
[VTIME
] = s
[C_TIME
];
1005 struct ttypagestat
*n
= &td
->d_pc
;
1009 n
->tps_statc
= s
[C_STATUS
];
1010 n
->tps_pagec
= s
[C_PAGE
];
1011 n
->tps_pgoffc
= s
[C_PGOFF
];
1014 # endif /* TIOCGPAGE */
1018 struct tchars
*n
= &td
->d_tc
;
1019 n
->t_intrc
= s
[C_INTR
];
1020 n
->t_quitc
= s
[C_QUIT
];
1021 n
->t_startc
= s
[C_START
];
1022 n
->t_stopc
= s
[C_STOP
];
1023 n
->t_eofc
= s
[C_EOF
];
1024 n
->t_brkc
= s
[C_BRK
];
1026 # endif /* TIOCGETC */
1030 struct sgttyb
*n
= &td
->d_t
;
1032 n
->sg_erase
= s
[C_ERASE
];
1033 n
->sg_kill
= s
[C_KILL
];
1035 # endif /* TIOCGETP */
1036 #endif /* !POSIX || TERMIO */
1041 tty_getspeed(ttydata_t
*td
)
1046 if ((spd
= cfgetispeed(&td
->d_t
)) == 0)
1047 spd
= cfgetospeed(&td
->d_t
);
1051 spd
= td
->d_t
.c_cflag
& CBAUD
;
1056 spd
= td
->d_t
.sg_ispeed
;
1057 # endif /* TERMIO */
1061 } /* end tty_getspeed */
1064 tty_gettabs(ttydata_t
*td
)
1066 #if defined(POSIX) || defined(TERMIO)
1067 return ((td
->d_t
.c_oflag
& TAB3
) == TAB3
) ? 0 : 1;
1069 return (td
->d_t
.sg_flags
& XTABS
) == XTABS
? 0 : 1;
1070 #endif /* POSIX || TERMIO */
1071 } /* end tty_gettabs */
1074 tty_geteightbit(ttydata_t
*td
)
1076 #if defined(POSIX) || defined(TERMIO)
1077 return (td
->d_t
.c_cflag
& CSIZE
) == CS8
;
1079 return td
->d_lb
& (LPASS8
| LLITOUT
);
1080 #endif /* POSIX || TERMIO */
1081 } /* end tty_geteightbit */
1084 tty_cooked_mode(ttydata_t
*td
)
1086 #if defined(POSIX) || defined(TERMIO)
1087 return (td
->d_t
.c_lflag
& ICANON
);
1089 return !(td
->d_t
.sg_flags
& (RAW
| CBREAK
));
1090 #endif /* POSIX || TERMIO */
1091 } /* end tty_cooked_mode */
1095 tty_setdisc(int fd
, int dis
)
1097 static int edit_discipline
= 0;
1098 static union txname tx_disc
;
1099 extern char strPOSIX
[];
1103 if (edit_discipline
) {
1104 if (ioctl(fd
, TXSETLD
, (ioctl_t
) & tx_disc
) == -1)
1106 edit_discipline
= 0;
1111 tx_disc
.tx_which
= 0;
1112 if (ioctl(fd
, TXGETLD
, (ioctl_t
) & tx_disc
) == -1)
1114 if (strcmp(tx_disc
.tx_name
, strPOSIX
) != 0) {
1115 edit_discipline
= 1;
1116 if (ioctl(fd
, TXSETLD
, (ioctl_t
) strPOSIX
) == -1)
1124 } /* end tty_setdisc */
1129 tty_printchar(unsigned char *s
)
1131 struct tcshmodes
*m
;
1134 for (i
= 0; i
< C_NCC
; i
++) {
1135 for (m
= modelist
; m
->m_name
; m
++)
1136 if (m
->m_type
== M_CHAR
&& C_SH(i
) == m
->m_value
)
1139 xprintf("%s ^%c ", m
->m_name
, s
[i
] + 'A' - 1);
1145 #endif /* DEBUG_TTY */
1146 #else /* WINNT_NATIVE */
1148 tty_cooked_mode(void *td
)
1150 return do_nt_check_cooked_mode();
1152 #endif /* !WINNT_NATIVE */