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);
101 tty_flush(tp, FREAD | FWRITE);
103 if (ttyhook_hashook(tp, close))
104 ttyhook_close(tp);
108 ttydisc_read_canonical(struct tty *tp, struct uio *uio, int ioflag)
116 if (tp->t_termios.c_cc[c] != _POSIX_VDISABLE) \
117 breakc[n++] = tp->t_termios.c_cc[c]; \
126 error = tty_wait_background(tp, curthread, SIGTTIN);
148 clen = ttyinq_findchar(&tp->t_inq, breakc, uio->uio_resid,
153 if (tp->t_flags & TF_ZOMBIE)
158 error = tty_wait(tp, &tp->t_inwait);
171 error = ttyinq_read_uio(&tp->t_inq, tp, uio, clen, flen);
181 ttydisc_read_raw_no_timer(struct tty *tp, struct uio *uio, int ioflag)
183 size_t vmin = tp->t_termios.c_cc[VMIN];
187 MPASS(tp->t_termios.c_cc[VTIME] == 0);
196 error = tty_wait_background(tp, curthread, SIGTTIN);
200 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
208 if (tp->t_flags & TF_ZOMBIE)
213 error = tty_wait(tp, &tp->t_inwait);
220 ttydisc_read_raw_read_timer(struct tty *tp, struct uio *uio, int ioflag,
223 size_t vmin = MAX(tp->t_termios.c_cc[VMIN], 1);
224 unsigned int vtime = tp->t_termios.c_cc[VTIME];
228 MPASS(tp->t_termios.c_cc[VTIME] != 0);
237 error = tty_wait_background(tp, curthread, SIGTTIN);
241 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
260 if (tp->t_flags & TF_ZOMBIE)
265 error = tty_timedwait(tp, &tp->t_inwait, hz);
274 ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
276 size_t vmin = tp->t_termios.c_cc[VMIN];
280 MPASS(tp->t_termios.c_cc[VMIN] != 0);
281 MPASS(tp->t_termios.c_cc[VTIME] != 0);
290 error = tty_wait_background(tp, curthread, SIGTTIN);
294 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
309 if (tp->t_flags & TF_ZOMBIE)
314 error = tty_wait(tp, &tp->t_inwait);
319 return ttydisc_read_raw_read_timer(tp, uio, ioflag, oresid);
323 ttydisc_read(struct tty *tp, struct uio *uio, int ioflag)
327 tty_lock_assert(tp, MA_OWNED);
333 error = ttydisc_read_canonical(tp, uio, ioflag);
334 else if (tp->t_termios.c_cc[VTIME] == 0)
335 error = ttydisc_read_raw_no_timer(tp, uio, ioflag);
336 else if (tp->t_termios.c_cc[VMIN] == 0)
337 error = ttydisc_read_raw_read_timer(tp, uio, ioflag,
340 error = ttydisc_read_raw_interbyte_timer(tp, uio, ioflag);
342 if (ttyinq_bytesleft(&tp->t_inq) >= tp->t_inlow ||
343 ttyinq_bytescanonicalized(&tp->t_inq) == 0) {
345 tty_hiwat_in_unblock(tp);
366 ttydisc_write_oproc(struct tty *tp, char c)
373 #define PRINT_NORMAL() ttyoutq_write_nofrag(&tp->t_outq, &c, 1)
385 if (tp->t_column > 0)
386 tp->t_column--;
391 scnt = 8 - (tp->t_column & 7);
393 error = ttyoutq_write_nofrag(&tp->t_outq,
401 tp->t_column += scnt;
402 MPASS((tp->t_column % 8) == 0);
409 error = ttyoutq_write_nofrag(&tp->t_outq, "\r\n", 2);
417 tp->t_column = tp->t_writepos = 0;
418 ttyinq_reprintpos_set(&tp->t_inq);
427 if (CMP_FLAG(o, ONOCR) && tp->t_column == 0)
432 tp->t_column = tp->t_writepos = 0;
433 ttyinq_reprintpos_set(&tp->t_inq);
452 ttydisc_write(struct tty *tp, struct uio *uio, int ioflag)
459 tty_lock_assert(tp, MA_OWNED);
461 if (tp->t_flags & TF_ZOMBIE)
478 tty_unlock(tp);
480 tty_lock(tp);
485 if (tty_gone(tp)) {
508 if (ttydisc_write_oproc(tp, *obstart) == 0) {
512 tp->t_writepos = tp->t_column;
513 ttyinq_reprintpos_set(&tp->t_inq);
518 wlen = ttyoutq_write(&tp->t_outq, obstart, plen);
521 tp->t_column += wlen;
523 tp->t_writepos = tp->t_column;
524 ttyinq_reprintpos_set(&tp->t_inq);
531 tp->t_flags |= TF_HIWAT_OUT;
543 ttydevsw_outwakeup(tp);
544 if ((tp->t_flags & TF_HIWAT_OUT) == 0)
547 error = tty_wait(tp, &tp->t_outwait);
551 if (tp->t_flags & TF_ZOMBIE) {
559 if (!tty_gone(tp))
560 ttydevsw_outwakeup(tp);
572 ttydisc_optimize(struct tty *tp)
574 tty_lock_assert(tp, MA_OWNED);
576 if (ttyhook_hashook(tp, rint_bypass)) {
577 tp->t_flags |= TF_BYPASS;
578 } else if (ttyhook_hashook(tp, rint)) {
579 tp->t_flags &= ~TF_BYPASS;
585 tp->t_flags |= TF_BYPASS;
587 tp->t_flags &= ~TF_BYPASS;
592 ttydisc_modem(struct tty *tp, int open)
595 tty_lock_assert(tp, MA_OWNED);
598 cv_broadcast(&tp->t_dcdwait);
606 if (!tty_opened(tp) || CMP_FLAG(c, CLOCAL))
613 tp->t_flags |= TF_ZOMBIE;
615 tty_signal_sessleader(tp, SIGHUP);
616 tty_flush(tp, FREAD|FWRITE);
627 ttydisc_echo_force(struct tty *tp, char c, int quote)
635 return ttydisc_write_oproc(tp, c);
650 return ttyoutq_write_nofrag(&tp->t_outq, ob, 4);
652 tp->t_column += 2;
653 return ttyoutq_write_nofrag(&tp->t_outq, ob, 2);
657 tp->t_column++;
658 return ttyoutq_write_nofrag(&tp->t_outq, &c, 1);
663 ttydisc_echo(struct tty *tp, char c, int quote)
674 return ttydisc_echo_force(tp, c, quote);
680 struct tty *tp = d;
682 ttydisc_echo(tp, c, quote);
686 ttydisc_reprint(struct tty *tp)
691 c = tp->t_termios.c_cc[VREPRINT];
693 ttydisc_echo(tp, c, 0);
694 ttydisc_echo(tp, CNL, 0);
695 ttyinq_reprintpos_reset(&tp->t_inq);
697 ttyinq_line_iterate_from_linestart(&tp->t_inq, ttydisc_reprint_char, tp);
701 struct tty *tp;
709 struct tty *tp = data->tp;
722 ttydisc_recalc_linelength(struct tty *tp)
724 struct ttydisc_recalc_length data = { tp, tp->t_writepos };
726 ttyinq_line_iterate_from_reprintpos(&tp->t_inq,
732 ttydisc_rubchar(struct tty *tp)
738 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
740 ttyinq_unputchar(&tp->t_inq);
748 if (tp->t_writepos >= tp->t_column) {
750 ttydisc_reprint(tp);
755 tp->t_column -= 2;
756 ttyoutq_write_nofrag(&tp->t_outq,
761 tp->t_column -= 1;
762 ttyoutq_write_nofrag(&tp->t_outq, "\b", 1);
775 prevpos = ttydisc_recalc_linelength(tp);
776 if (prevpos >= tp->t_column)
779 tablen = tp->t_column - prevpos;
783 tp->t_column = prevpos;
784 ttyoutq_write_nofrag(&tp->t_outq,
792 tp->t_column -= 1;
793 ttyoutq_write_nofrag(&tp->t_outq, "\b \b", 3);
797 ttydisc_echo(tp, tp->t_termios.c_cc[VERASE], 0);
805 ttydisc_rubword(struct tty *tp)
812 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
816 ttydisc_rubchar(tp);
825 ttydisc_rubchar(tp);
827 if (ttyinq_peekchar(&tp->t_inq, &c, &quote) != 0)
837 ttydisc_rint(struct tty *tp, char c, int flags)
843 tty_lock_assert(tp, MA_OWNED);
847 if (ttyhook_hashook(tp, rint))
848 return ttyhook_rint(tp, c, flags);
850 if (tp->t_flags & TF_BYPASS)
860 tty_flush(tp, FREAD|FWRITE);
861 tty_signal_pgrp(tp, SIGINT);
881 tp->t_flags &= ~TF_STOPPED;
888 if (tp->t_flags & TF_LITERAL) {
889 tp->t_flags &= ~TF_LITERAL;
900 ttyoutq_write_nofrag(&tp->t_outq, "^\b", 2);
902 ttydisc_echo(tp, c, 0);
904 tp->t_flags |= TF_LITERAL;
915 tty_signal_pgrp(tp, SIGINFO);
941 tty_flush(tp, FREAD|FWRITE);
942 ttydisc_echo(tp, c, 0);
943 tty_signal_pgrp(tp, signal);
954 if ((tp->t_flags & TF_STOPPED) == 0) {
955 tp->t_flags |= TF_STOPPED;
967 tp->t_flags &= ~TF_STOPPED;
989 ttydisc_rubchar(tp);
992 while (ttydisc_rubchar(tp) == 0);
996 ttydisc_rubword(tp);
999 ttydisc_reprint(tp);
1031 if (ttyinq_write_nofrag(&tp->t_inq, ob, ol, quote) != 0) {
1033 ttyoutq_write_nofrag(&tp->t_outq, "\a", 1);
1043 if (ttyinq_bytescanonicalized(&tp->t_inq) == 0)
1046 tty_hiwat_in_block(tp);
1057 ttyinq_canonicalize(&tp->t_inq);
1060 ttydisc_echo(tp, c, quote);
1066 ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len)
1070 if (ttydisc_can_bypass(tp))
1071 return (ttydisc_rint_bypass(tp, buf, len));
1074 if (ttydisc_rint(tp, *cbuf, 0) != 0)
1082 ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len)
1086 tty_lock_assert(tp, MA_OWNED);
1088 MPASS(tp->t_flags & TF_BYPASS);
1092 if (ttyhook_hashook(tp, rint_bypass))
1093 return ttyhook_rint_bypass(tp, buf, len);
1095 ret = ttyinq_write(&tp->t_inq, buf, len, 0);
1096 ttyinq_canonicalize(&tp->t_inq);
1098 tty_hiwat_in_block(tp);
1104 ttydisc_rint_done(struct tty *tp)
1107 tty_lock_assert(tp, MA_OWNED);
1109 if (ttyhook_hashook(tp, rint_done))
1110 ttyhook_rint_done(tp);
1113 tty_wakeup(tp, FREAD);
1115 ttydevsw_outwakeup(tp);
1119 ttydisc_rint_poll(struct tty *tp)
1123 tty_lock_assert(tp, MA_OWNED);
1125 if (ttyhook_hashook(tp, rint_poll))
1126 return ttyhook_rint_poll(tp);
1134 l = ttyinq_bytesleft(&tp->t_inq);
1135 if (l == 0 && (tp->t_flags & TF_HIWAT_IN) == 0)
1142 ttydisc_wakeup_watermark(struct tty *tp)
1146 c = ttyoutq_bytesleft(&tp->t_outq);
1147 if (tp->t_flags & TF_HIWAT_OUT) {
1149 if (c < tp->t_outlow)
1153 tp->t_flags &= ~TF_HIWAT_OUT;
1159 tty_wakeup(tp, FWRITE);
1163 ttydisc_getc(struct tty *tp, void *buf, size_t len)
1166 tty_lock_assert(tp, MA_OWNED);
1168 if (tp->t_flags & TF_STOPPED)
1171 if (ttyhook_hashook(tp, getc_inject))
1172 return ttyhook_getc_inject(tp, buf, len);
1174 len = ttyoutq_read(&tp->t_outq, buf, len);
1176 if (ttyhook_hashook(tp, getc_capture))
1177 ttyhook_getc_capture(tp, buf, len);
1179 ttydisc_wakeup_watermark(tp);
1186 ttydisc_getc_uio(struct tty *tp, struct uio *uio)
1193 tty_lock_assert(tp, MA_OWNED);
1195 if (tp->t_flags & TF_STOPPED)
1203 if (ttyhook_hashook(tp, getc_capture) ||
1204 ttyhook_hashook(tp, getc_inject)) {
1207 len = ttydisc_getc(tp, buf,
1213 tty_unlock(tp);
1215 tty_lock(tp);
1221 error = ttyoutq_read_uio(&tp->t_outq, tp, uio);
1223 ttydisc_wakeup_watermark(tp);
1231 ttydisc_getc_poll(struct tty *tp)
1234 tty_lock_assert(tp, MA_OWNED);
1236 if (tp->t_flags & TF_STOPPED)
1239 if (ttyhook_hashook(tp, getc_poll))
1240 return ttyhook_getc_poll(tp);
1242 return ttyoutq_bytesused(&tp->t_outq);
1252 tty_putchar(struct tty *tp, char c)
1254 tty_lock_assert(tp, MA_OWNED);
1256 if (tty_gone(tp))
1259 ttydisc_echo_force(tp, c, 0);
1260 tp->t_writepos = tp->t_column;
1261 ttyinq_reprintpos_set(&tp->t_inq);
1263 ttydevsw_outwakeup(tp);