-/*
- * Send stop character on input overflow.
- */
-ttyblock(tp)
-register struct tty *tp;
-{
- register x;
- x = q1.c_cc + q2.c_cc;
- if (q1.c_cc > TTYHOG) {
- flushtty(tp, FREAD|FWRITE);
- tp->t_state &= ~TBLOCK;
- }
- if (x >= TTYHOG/2) {
- if (putc(tun.t_stopc, &tp->t_outq)==0) {
- tp->t_state |= TBLOCK;
- tp->t_char++;
- ttstart(tp);
- }
- }
-}
-
-/*
- * put character on TTY output queue, adding delays,
- * expanding tabs, and handling the CR/NL bit.
- * It is called both from the top half for output, and from
- * interrupt level for echoing.
- * The arguments are the character and the tty structure.
- */
-ttyoutput(c, tp)
-register c;
-register struct tty *tp;
-{
- register char *colp;
- register ctype;
-
- /*
- * Ignore EOT in normal mode to avoid hanging up
- * certain terminals.
- * In raw mode dump the char unchanged.
- */
- if ((tp->t_flags&RAW)==0) {
- c &= 0177;
- if ((tp->t_flags&CBREAK)==0 && c==CEOT)
- return;
- } else {
- tk_nout++;
- (void) putc(c, &tp->t_outq);
- return;
- }
-
- /*
- * Turn tabs to spaces as required
- */
- if (c=='\t' && (tp->t_flags&TBDELAY)==XTABS) {
- c = 8 - (tp->t_col & 7);
- (void) b_to_q(" ", c, &tp->t_outq);
- tp->t_col += c;
- tk_nout += c;
- return;
- }
- tk_nout++;
- /*
- * for upper-case-only terminals,
- * generate escapes.
- */
- if (tp->t_flags&LCASE) {
- colp = "({)}!|^~'`";
- while(*colp++)
- if(c == *colp++) {
- ttyoutput('\\', tp);
- c = colp[-2];
- break;
- }
- if ('a'<=c && c<='z')
- c += 'A' - 'a';
- }
- /*
- * turn <nl> to <cr><lf> if desired.
- */
- if (c=='\n' && tp->t_flags&CRMOD)
- ttyoutput('\r', tp);
- (void) putc(c, &tp->t_outq);
- /*
- * Calculate delays.
- * The numbers here represent clock ticks
- * and are not necessarily optimal for all terminals.
- * The delays are indicated by characters above 0200.
- * In raw mode there are no delays and the
- * transmission path is 8 bits wide.
- */
- colp = &tp->t_col;
- ctype = partab[c];
- c = 0;
- switch (ctype&077) {
-
- /* ordinary */
- case 0:
- (*colp)++;
-
- /* non-printing */
- case 1:
- break;
-
- /* backspace */
- case 2:
- if (*colp)
- (*colp)--;
- break;
-
- /* newline */
- case 3:
- ctype = (tp->t_flags >> 8) & 03;
- if(ctype == 1) { /* tty 37 */
- if (*colp)
- c = max(((unsigned)*colp>>4) + 3, (unsigned)6);
- } else
- if(ctype == 2) { /* vt05 */
- c = 6;
- }
- *colp = 0;
- break;
-
- /* tab */
- case 4:
- ctype = (tp->t_flags >> 10) & 03;
- if(ctype == 1) { /* tty 37 */
- c = 1 - (*colp | ~07);
- if(c < 5)
- c = 0;
- }
- *colp |= 07;
- (*colp)++;
- break;
-
- /* vertical motion */
- case 5:
- if(tp->t_flags & VTDELAY) /* tty 37 */
- c = 0177;
- break;
-
- /* carriage return */
- case 6:
- ctype = (tp->t_flags >> 12) & 03;
- if(ctype == 1) { /* tn 300 */
- c = 5;
- } else if(ctype == 2) { /* ti 700 */
- c = 10;
- } else if(ctype == 3) { /* concept 100 */
- int i;
- if ((i = *colp) >= 0)
- for (; i<9; i++)
- (void) putc(0177, &tp->t_outq);
- }
- *colp = 0;
- }
- if(c)
- (void) putc(c|0200, &tp->t_outq);
-}
-
-/*
- * Restart typewriter output following a delay
- * timeout.
- * The name of the routine is passed to the timeout
- * subroutine and it is called during a clock interrupt.
- */
-ttrstrt(tp)
-register struct tty *tp;
-{
-
- tp->t_state &= ~TIMEOUT;
- ttstart(tp);
-}
-
-/*
- * Start output on the typewriter. It is used from the top half
- * after some characters have been put on the output queue,
- * from the interrupt routine to transmit the next
- * character, and after a timeout has finished.
- */
-ttstart(tp)
-register struct tty *tp;
-{
- register s;
-
- s = spl5();
- if((tp->t_state&(TIMEOUT|TTSTOP|BUSY)) == 0)
- (*tp->t_oproc)(tp);
- splx(s);
-}
-
-/*
- * Called from device's read routine after it has
- * calculated the tty-structure given as argument.
- */
-ttread(tp)
-register struct tty *tp;
-{
-register s;
-
- if ((tp->t_state&CARR_ON)==0)
- return(-1);
- s = spl5();
- if (tp->t_canq.c_cc==0)
- while (canon(tp)<0)
- if (tp->t_chan==NULL) {
- sleep((caddr_t)&tp->t_rawq, TTIPRI);
- } else {
- splx(s);
- return(0);
- }
- splx(s);
- while (tp->t_canq.c_cc && passc(getc(&tp->t_canq))>=0)
- ;
- return(tp->t_rawq.c_cc+tp->t_canq.c_cc);
-}