Lines Matching refs:tp

59 #define	CMP_CC(v,c) (tp->t_termios.c_cc[v] != _POSIX_VDISABLE && \
60 tp->t_termios.c_cc[v] == (c))
61 #define CMP_FLAG(field,opt) (tp->t_termios.c_ ## field ## flag & (opt))
85 ttydisc_open(struct tty *tp)
87 ttydisc_optimize(tp);
91 ttydisc_close(struct tty *tp)
95 tp->t_flags &= ~(TF_STOPPED|TF_HIWAT|TF_ZOMBIE);
98 ttyinq_flush(&tp->t_inq);
99 ttyoutq_flush(&tp->t_outq);
101 if (!tty_gone(tp)) {
102 ttydevsw_inwakeup(tp);
103 ttydevsw_outwakeup(tp);
106 if (ttyhook_hashook(tp, close))
107 ttyhook_close(tp);
111 ttydisc_read_canonical(struct tty *tp, struct uio *uio, int ioflag)
119 if (tp->t_termios.c_cc[c] != _POSIX_VDISABLE) \
120 breakc[n++] = tp->t_termios.c_cc[c]; \
129 error = tty_wait_background(tp, curthread, SIGTTIN);
151 clen = ttyinq_findchar(&tp->t_inq, breakc, uio->uio_resid,
156 if (tp->t_flags & TF_ZOMBIE)
161 error = tty_wait(tp, &tp->t_inwait);
174 error = ttyinq_read_uio(&tp->t_inq, tp, uio, clen, flen);
184 ttydisc_read_raw_no_timer(struct tty *tp, struct uio *uio, int ioflag)
186 size_t vmin = tp->t_termios.c_cc[VMIN];
190 MPASS(tp->t_termios.c_cc[VTIME] == 0);
199 error = tty_wait_background(tp, curthread, SIGTTIN);
203 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
211 if (tp->t_flags & TF_ZOMBIE)
216 error = tty_wait(tp, &tp->t_inwait);
223 ttydisc_read_raw_read_timer(struct tty *tp, struct uio *uio, int ioflag,
226 size_t vmin = MAX(tp->t_termios.c_cc[VMIN], 1);
227 unsigned int vtime = tp->t_termios.c_cc[VTIME];
231 MPASS(tp->t_termios.c_cc[VTIME] != 0);
240 error = tty_wait_background(tp, curthread, SIGTTIN);
244 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
263 if (tp->t_flags & TF_ZOMBIE)
268 error = tty_timedwait(tp, &tp->t_inwait, hz);
277 ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
279 size_t vmin = tp->t_termios.c_cc[VMIN];
283 MPASS(tp->t_termios.c_cc[VMIN] != 0);
284 MPASS(tp->t_termios.c_cc[VTIME] != 0);
293 error = tty_wait_background(tp, curthread, SIGTTIN);
297 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
312 if (tp->t_flags & TF_ZOMBIE)
317 error = tty_wait(tp, &tp->t_inwait);
322 return ttydisc_read_raw_read_timer(tp, uio, ioflag, oresid);
326 ttydisc_read(struct tty *tp, struct uio *uio, int ioflag)
330 tty_lock_assert(tp, MA_OWNED);
336 error = ttydisc_read_canonical(tp, uio, ioflag);
337 else if (tp->t_termios.c_cc[VTIME] == 0)
338 error = ttydisc_read_raw_no_timer(tp, uio, ioflag);
339 else if (tp->t_termios.c_cc[VMIN] == 0)
340 error = ttydisc_read_raw_read_timer(tp, uio, ioflag,
343 error = ttydisc_read_raw_interbyte_timer(tp, uio, ioflag);
345 if (ttyinq_bytesleft(&tp->t_inq) >= tp->t_inlow ||
346 ttyinq_bytescanonicalized(&tp->t_inq) == 0) {
348 tty_hiwat_in_unblock(tp);
369 ttydisc_write_oproc(struct tty *tp, char c)
376 #define PRINT_NORMAL() ttyoutq_write_nofrag(&tp->t_outq, &c, 1)
388 if (tp->t_column > 0)
389 tp->t_column--;
394 scnt = 8 - (tp->t_column & 7);
396 error = ttyoutq_write_nofrag(&tp->t_outq,
404 tp->t_column += scnt;
405 MPASS((tp->t_column % 8) == 0);
412 error = ttyoutq_write_nofrag(&tp->t_outq, "\r\n", 2);
420 tp->t_column = tp->t_writepos = 0;
421 ttyinq_reprintpos_set(&tp->t_inq);
430 if (CMP_FLAG(o, ONOCR) && tp->t_column == 0)
435 tp->t_column = tp->t_writepos = 0;
436 ttyinq_reprintpos_set(&tp->t_inq);
455 ttydisc_write(struct tty *tp, struct uio *uio, int ioflag)
462 tty_lock_assert(tp, MA_OWNED);
464 if (tp->t_flags & TF_ZOMBIE)
481 tty_unlock(tp);
483 tty_lock(tp);
488 if (tty_gone(tp)) {
511 if (ttydisc_write_oproc(tp, *obstart) == 0) {
515 tp->t_writepos = tp->t_column;
516 ttyinq_reprintpos_set(&tp->t_inq);
521 wlen = ttyoutq_write(&tp->t_outq, obstart, plen);
524 tp->t_column += wlen;
526 tp->t_writepos = tp->t_column;
527 ttyinq_reprintpos_set(&tp->t_inq);
534 tp->t_flags |= TF_HIWAT_OUT;
546 ttydevsw_outwakeup(tp);
547 if ((tp->t_flags & TF_HIWAT_OUT) == 0)
550 error = tty_wait(tp, &tp->t_outwait);
554 if (tp->t_flags & TF_ZOMBIE) {
562 if (!tty_gone(tp))
563 ttydevsw_outwakeup(tp);
575 ttydisc_optimize(struct tty *tp)
577 tty_lock_assert(tp, MA_OWNED);
579 if (ttyhook_hashook(tp, rint_bypass)) {
580 tp->t_flags |= TF_BYPASS;
581 } else if (ttyhook_hashook(tp, rint)) {
582 tp->t_flags &= ~TF_BYPASS;
588 tp->t_flags |= TF_BYPASS;
590 tp->t_flags &= ~TF_BYPASS;
595 ttydisc_modem(struct tty *tp, int open)
598 tty_lock_assert(tp, MA_OWNED);
601 cv_broadcast(&tp->t_dcdwait);
609 if (!tty_opened(tp) || CMP_FLAG(c, CLOCAL))
616 tp->t_flags |= TF_ZOMBIE;
618 tty_signal_sessleader(tp, SIGHUP);
619 tty_flush(tp, FREAD|FWRITE);
630 ttydisc_echo_force(struct tty *tp, char c, int quote)
638 return ttydisc_write_oproc(tp, c);
653 return ttyoutq_write_nofrag(&tp->t_outq, ob, 4);
655 tp->t_column += 2;
656 return ttyoutq_write_nofrag(&tp->t_outq, ob, 2);
660 tp->t_column++;
661 return ttyoutq_write_nofrag(&tp->t_outq, &c, 1);
666 ttydisc_echo(struct tty *tp, char c, int quote)
677 return ttydisc_echo_force(tp, c, quote);
683 struct tty *tp = d;
685 ttydisc_echo(tp, c, quote);
689 ttydisc_reprint(struct tty *tp)
694 c = tp->t_termios.c_cc[VREPRINT];
696 ttydisc_echo(tp, c, 0);
697 ttydisc_echo(tp, CNL, 0);
698 ttyinq_reprintpos_reset(&tp->t_inq);
700 ttyinq_line_iterate_from_linestart(&tp->t_inq, ttydisc_reprint_char, tp);
704 struct tty *tp;
712 struct tty *tp = data->tp;
725 ttydisc_recalc_linelength(struct tty *tp)
727 struct ttydisc_recalc_length data = { tp, tp->t_writepos };
729 ttyinq_line_iterate_from_reprintpos(&tp->t_inq,
735 ttydisc_rubchar(struct tty *tp)
741 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
743 ttyinq_unputchar(&tp->t_inq);
751 if (tp->t_writepos >= tp->t_column) {
753 ttydisc_reprint(tp);
758 tp->t_column -= 2;
759 ttyoutq_write_nofrag(&tp->t_outq,
764 tp->t_column -= 1;
765 ttyoutq_write_nofrag(&tp->t_outq, "\b", 1);
778 prevpos = ttydisc_recalc_linelength(tp);
779 if (prevpos >= tp->t_column)
782 tablen = tp->t_column - prevpos;
786 tp->t_column = prevpos;
787 ttyoutq_write_nofrag(&tp->t_outq,
795 tp->t_column -= 1;
796 ttyoutq_write_nofrag(&tp->t_outq, "\b \b", 3);
800 ttydisc_echo(tp, tp->t_termios.c_cc[VERASE], 0);
808 ttydisc_rubword(struct tty *tp)
815 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
819 ttydisc_rubchar(tp);
828 ttydisc_rubchar(tp);
830 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
840 ttydisc_rint(struct tty *tp, char c, int flags)
846 tty_lock_assert(tp, MA_OWNED);
850 if (ttyhook_hashook(tp, rint))
851 return ttyhook_rint(tp, c, flags);
853 if (tp->t_flags & TF_BYPASS)
863 tty_flush(tp, FREAD|FWRITE);
864 tty_signal_pgrp(tp, SIGINT);
884 tp->t_flags &= ~TF_STOPPED;
891 if (tp->t_flags & TF_LITERAL) {
892 tp->t_flags &= ~TF_LITERAL;
903 ttyoutq_write_nofrag(&tp->t_outq, "^\b", 2);
905 ttydisc_echo(tp, c, 0);
907 tp->t_flags |= TF_LITERAL;
918 tty_signal_pgrp(tp, SIGINFO);
944 tty_flush(tp, FREAD|FWRITE);
945 ttydisc_echo(tp, c, 0);
946 tty_signal_pgrp(tp, signal);
957 if ((tp->t_flags & TF_STOPPED) == 0) {
958 tp->t_flags |= TF_STOPPED;
970 tp->t_flags &= ~TF_STOPPED;
992 ttydisc_rubchar(tp);
995 while (ttydisc_rubchar(tp) == 0);
999 ttydisc_rubword(tp);
1002 ttydisc_reprint(tp);
1034 if (ttyinq_write_nofrag(&tp->t_inq, ob, ol, quote) != 0) {
1036 ttyoutq_write_nofrag(&tp->t_outq, "\a", 1);
1046 if (ttyinq_bytescanonicalized(&tp->t_inq) == 0)
1049 tty_hiwat_in_block(tp);
1060 ttyinq_canonicalize(&tp->t_inq);
1063 ttydisc_echo(tp, c, quote);
1069 ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len)
1073 if (ttydisc_can_bypass(tp))
1074 return (ttydisc_rint_bypass(tp, buf, len));
1077 if (ttydisc_rint(tp, *cbuf, 0) != 0)
1085 ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len)
1089 tty_lock_assert(tp, MA_OWNED);
1091 MPASS(tp->t_flags & TF_BYPASS);
1095 if (ttyhook_hashook(tp, rint_bypass))
1096 return ttyhook_rint_bypass(tp, buf, len);
1098 ret = ttyinq_write(&tp->t_inq, buf, len, 0);
1099 ttyinq_canonicalize(&tp->t_inq);
1101 tty_hiwat_in_block(tp);
1107 ttydisc_rint_done(struct tty *tp)
1110 tty_lock_assert(tp, MA_OWNED);
1112 if (ttyhook_hashook(tp, rint_done))
1113 ttyhook_rint_done(tp);
1116 tty_wakeup(tp, FREAD);
1118 ttydevsw_outwakeup(tp);
1122 ttydisc_rint_poll(struct tty *tp)
1126 tty_lock_assert(tp, MA_OWNED);
1128 if (ttyhook_hashook(tp, rint_poll))
1129 return ttyhook_rint_poll(tp);
1137 l = ttyinq_bytesleft(&tp->t_inq);
1138 if (l == 0 && (tp->t_flags & TF_HIWAT_IN) == 0)
1145 ttydisc_wakeup_watermark(struct tty *tp)
1149 c = ttyoutq_bytesleft(&tp->t_outq);
1150 if (tp->t_flags & TF_HIWAT_OUT) {
1152 if (c < tp->t_outlow)
1156 tp->t_flags &= ~TF_HIWAT_OUT;
1162 tty_wakeup(tp, FWRITE);
1166 ttydisc_getc(struct tty *tp, void *buf, size_t len)
1169 tty_lock_assert(tp, MA_OWNED);
1171 if (tp->t_flags & TF_STOPPED)
1174 if (ttyhook_hashook(tp, getc_inject))
1175 return ttyhook_getc_inject(tp, buf, len);
1177 len = ttyoutq_read(&tp->t_outq, buf, len);
1179 if (ttyhook_hashook(tp, getc_capture))
1180 ttyhook_getc_capture(tp, buf, len);
1182 ttydisc_wakeup_watermark(tp);
1189 ttydisc_getc_uio(struct tty *tp, struct uio *uio)
1196 tty_lock_assert(tp, MA_OWNED);
1198 if (tp->t_flags & TF_STOPPED)
1206 if (ttyhook_hashook(tp, getc_capture) ||
1207 ttyhook_hashook(tp, getc_inject)) {
1210 len = ttydisc_getc(tp, buf,
1216 tty_unlock(tp);
1218 tty_lock(tp);
1224 error = ttyoutq_read_uio(&tp->t_outq, tp, uio);
1226 ttydisc_wakeup_watermark(tp);
1234 ttydisc_getc_poll(struct tty *tp)
1237 tty_lock_assert(tp, MA_OWNED);
1239 if (tp->t_flags & TF_STOPPED)
1242 if (ttyhook_hashook(tp, getc_poll))
1243 return ttyhook_getc_poll(tp);
1245 return ttyoutq_bytesused(&tp->t_outq);
1255 tty_putchar(struct tty *tp, char c)
1257 tty_lock_assert(tp, MA_OWNED);
1259 if (tty_gone(tp))
1262 ttydisc_echo_force(tp, c, 0);
1263 tp->t_writepos = tp->t_column;
1264 ttyinq_reprintpos_set(&tp->t_inq);
1266 ttydevsw_outwakeup(tp);