Change to includes. no more ../h
[unix-history] / usr / src / sys / kern / tty.c
index 4e41d2f..2b1e6fe 100644 (file)
@@ -1,21 +1,21 @@
-/*     tty.c   4.39    83/01/17        */
+/*     tty.c   6.10    84/08/29        */
 
 #include "../machine/reg.h"
 
 
 #include "../machine/reg.h"
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/ioctl.h"
-#include "../h/tty.h"
-#include "../h/proc.h"
-#include "../h/inode.h"
-#include "../h/file.h"
-#include "../h/conf.h"
-#include "../h/buf.h"
-#include "../h/dk.h"
-#include "../h/uio.h"
-#include "../h/kernel.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "proc.h"
+#include "inode.h"
+#include "file.h"
+#include "conf.h"
+#include "buf.h"
+#include "dk.h"
+#include "uio.h"
+#include "kernel.h"
 
 /*
  * Table giving parity for characters and indicating
 
 /*
  * Table giving parity for characters and indicating
@@ -112,26 +112,32 @@ ttychars(tp)
 /*
  * Wait for output to drain, then flush input waiting.
  */
 /*
  * Wait for output to drain, then flush input waiting.
  */
-wflushtty(tp)
+ttywflush(tp)
        register struct tty *tp;
 {
        register struct tty *tp;
 {
-       int s;
 
 
-       s = spl5();
-       while (tp->t_outq.c_cc && tp->t_state&TS_CARR_ON
-           && tp->t_oproc) {           /* kludge for pty */
+       ttywait(tp);
+       ttyflush(tp, FREAD);
+}
+
+ttywait(tp)
+       register struct tty *tp;
+{
+       register int s = spl5();
+
+       while ((tp->t_outq.c_cc || tp->t_state&TS_BUSY) &&
+           tp->t_state&TS_CARR_ON && tp->t_oproc) {    /* kludge for pty */
                (*tp->t_oproc)(tp);
                tp->t_state |= TS_ASLEEP;
                sleep((caddr_t)&tp->t_outq, TTOPRI);
        }
                (*tp->t_oproc)(tp);
                tp->t_state |= TS_ASLEEP;
                sleep((caddr_t)&tp->t_outq, TTOPRI);
        }
-       flushtty(tp, FREAD);
        splx(s);
 }
 
 /*
  * Flush all TTY queues
  */
        splx(s);
 }
 
 /*
  * Flush all TTY queues
  */
-flushtty(tp, rw)
+ttyflush(tp, rw)
        register struct tty *tp;
 {
        register s;
        register struct tty *tp;
 {
        register s;
@@ -152,7 +158,6 @@ flushtty(tp, rw)
        if (rw & FREAD) {
                while (getc(&tp->t_rawq) >= 0)
                        ;
        if (rw & FREAD) {
                while (getc(&tp->t_rawq) >= 0)
                        ;
-               tp->t_delct = 0;
                tp->t_rocount = 0;
                tp->t_rocol = 0;
                tp->t_state &= ~TS_LOCAL;
                tp->t_rocount = 0;
                tp->t_rocol = 0;
                tp->t_state &= ~TS_LOCAL;
@@ -170,12 +175,19 @@ ttyblock(tp)
 
        x = tp->t_rawq.c_cc + tp->t_canq.c_cc;
        if (tp->t_rawq.c_cc > TTYHOG) {
 
        x = tp->t_rawq.c_cc + tp->t_canq.c_cc;
        if (tp->t_rawq.c_cc > TTYHOG) {
-               flushtty(tp, FREAD|FWRITE);
+               ttyflush(tp, FREAD|FWRITE);
                tp->t_state &= ~TS_TBLOCK;
        }
                tp->t_state &= ~TS_TBLOCK;
        }
-       if (x >= TTYHOG/2 && putc(tp->t_stopc, &tp->t_outq) == 0) {
-               tp->t_state |= TS_TBLOCK;
-               ttstart(tp);
+       /*
+        * Block further input iff:
+        * Current input > threshold AND input is available to user program
+        */
+       if (x >= TTYHOG/2 && 
+           ((tp->t_flags & (RAW|CBREAK)) || (tp->t_canq.c_cc > 0))) {
+               if (putc(tp->t_stopc, &tp->t_outq)==0) {
+                       tp->t_state |= TS_TBLOCK;
+                       ttstart(tp);
+               }
        }
 }
 
        }
 }
 
@@ -224,6 +236,7 @@ ttioctl(tp, com, data, flag)
        int dev = tp->t_dev;
        extern int nldisp;
        int s;
        int dev = tp->t_dev;
        extern int nldisp;
        int s;
+       register int newflags;
 
        /*
         * If the ioctl involves modification,
 
        /*
         * If the ioctl involves modification,
@@ -242,20 +255,19 @@ ttioctl(tp, com, data, flag)
        case TIOCLBIS:
        case TIOCLBIC:
        case TIOCLSET:
        case TIOCLBIS:
        case TIOCLBIC:
        case TIOCLSET:
-       case TIOCBIS:
-       case TIOCBIC:
-       case TIOCSET:
        case TIOCSTI:
        case TIOCSTI:
+#define bit(a) (1<<(a-1))
                while (tp->t_line == NTTYDISC &&
                   u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp &&
                   (u.u_procp->p_flag&SVFORK) == 0 &&
                while (tp->t_line == NTTYDISC &&
                   u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp &&
                   (u.u_procp->p_flag&SVFORK) == 0 &&
-                  u.u_signal[SIGTTOU] != SIG_IGN &&
-                  u.u_signal[SIGTTOU] != SIG_HOLD) {
+                  !(u.u_procp->p_sigignore & bit(SIGTTOU)) &&
+                  !(u.u_procp->p_sigmask & bit(SIGTTOU))) {
                        gsignal(u.u_procp->p_pgrp, SIGTTOU);
                        sleep((caddr_t)&lbolt, TTOPRI);
                }
                break;
        }
                        gsignal(u.u_procp->p_pgrp, SIGTTOU);
                        sleep((caddr_t)&lbolt, TTOPRI);
                }
                break;
        }
+#undef bit
 
        /*
         * Process the ioctl.
 
        /*
         * Process the ioctl.
@@ -272,18 +284,21 @@ ttioctl(tp, com, data, flag)
                register int t = *(int *)data;
                int error = 0;
 
                register int t = *(int *)data;
                int error = 0;
 
-               if (t >= nldisp) {
-                       u.u_error = ENXIO;
-                       break;
-               }
+               if ((unsigned) t >= nldisp)
+                       return (ENXIO);
                s = spl5();
                if (tp->t_line)
                        (*linesw[tp->t_line].l_close)(tp);
                if (t)
                        error = (*linesw[t].l_open)(dev, tp);
                splx(s);
                s = spl5();
                if (tp->t_line)
                        (*linesw[tp->t_line].l_close)(tp);
                if (t)
                        error = (*linesw[t].l_open)(dev, tp);
                splx(s);
-               if (error)
+               if (error) {
+                       s = spl5();
+                       if (tp->t_line)
+                               (void) (*linesw[tp->t_line].l_open)(dev, tp);
+                       splx(s);
                        return (error);
                        return (error);
+               }
                tp->t_line = t;
                break;
        }
                tp->t_line = t;
                break;
        }
@@ -297,74 +312,6 @@ ttioctl(tp, com, data, flag)
                tp->t_state &= ~TS_XCLUDE;
                break;
 
                tp->t_state &= ~TS_XCLUDE;
                break;
 
-       case TIOCSET:
-       case TIOCBIS: {
-               u_long newflags = *(u_long *)data;
-
-               s = spl5();
-               if (tp->t_flags&RAW || newflags&RAW)
-                       wflushtty(tp);
-               else if ((tp->t_flags&CBREAK) != (newflags&CBREAK))
-                       if (newflags&CBREAK) {
-                               struct clist tq;
-
-                               catq(&tp->t_rawq, &tp->t_canq);
-                               tq = tp->t_rawq;
-                               tp->t_rawq = tp->t_canq;
-                               tp->t_canq = tq;
-                       } else {
-                               tp->t_flags |= PENDIN;
-                               ttwakeup(tp);
-                       }
-               if (com == TIOCSET)
-                       tp->t_flags = newflags;
-               else
-                       tp->t_flags |= newflags;
-               if (tp->t_flags&RAW) {
-                       tp->t_state &= ~TS_TTSTOP;
-                       ttstart(tp);
-               }
-               splx(s);
-               break;
-       }
-
-       case TIOCBIC: {
-               u_long newflags = *(long *)data;
-
-               if (tp->t_flags&RAW)
-                       wflushtty(tp);
-               else if ((tp->t_flags&CBREAK) != (CBREAK&~newflags))
-                       if (newflags&CBREAK) {
-                               tp->t_flags |= PENDIN;
-                               ttwakeup(tp);
-                       } else {
-                               struct clist tq;
-
-                               catq(&tp->t_rawq, &tp->t_canq);
-                               tq = tp->t_rawq;
-                               tp->t_rawq = tp->t_canq;
-                               tp->t_canq = tq;
-                       }
-               if (tp->t_flags&RAW) {
-                       tp->t_state &= ~TS_TTSTOP;
-                       ttstart(tp);
-               }
-               splx(s);
-               break;
-       }
-
-       case TIOCGET:
-               *(long *)data = tp->t_flags;
-               break;
-
-       case TIOCCGET:
-               bcopy((caddr_t)&tp->t_chars, data, sizeof (struct ttychars));
-               break;
-
-       case TIOCCSET:
-               bcopy(data, (caddr_t)&tp->t_chars, sizeof (struct ttychars));
-               break;
-
        /* hang up line on last close */
        case TIOCHPCL:
                tp->t_state |= TS_HUPCLS;
        /* hang up line on last close */
        case TIOCHPCL:
                tp->t_state |= TS_HUPCLS;
@@ -377,7 +324,7 @@ ttioctl(tp, com, data, flag)
                        flags = FREAD|FWRITE;
                else
                        flags &= FREAD|FWRITE;
                        flags = FREAD|FWRITE;
                else
                        flags &= FREAD|FWRITE;
-               flushtty(tp, flags);
+               ttyflush(tp, flags);
                break;
        }
 
                break;
        }
 
@@ -386,6 +333,10 @@ ttioctl(tp, com, data, flag)
                *(off_t *)data = ttnread(tp);
                break;
 
                *(off_t *)data = ttnread(tp);
                break;
 
+       case TIOCOUTQ:
+               *(int *)data = tp->t_outq.c_cc;
+               break;
+
        case TIOCSTOP:
                s = spl5();
                if ((tp->t_state&TS_TTSTOP) == 0) {
        case TIOCSTOP:
                s = spl5();
                if ((tp->t_state&TS_TTSTOP) == 0) {
@@ -414,12 +365,116 @@ ttioctl(tp, com, data, flag)
                (*linesw[tp->t_line].l_rint)(*(char *)data, tp);
                break;
 
                (*linesw[tp->t_line].l_rint)(*(char *)data, tp);
                break;
 
+       case TIOCSETP:
+       case TIOCSETN: {
+               register struct sgttyb *sg = (struct sgttyb *)data;
+
+               tp->t_erase = sg->sg_erase;
+               tp->t_kill = sg->sg_kill;
+               tp->t_ispeed = sg->sg_ispeed;
+               tp->t_ospeed = sg->sg_ospeed;
+               newflags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffff);
+               s = spl5();
+               if (tp->t_flags&RAW || newflags&RAW || com == TIOCSETP) {
+                       ttywait(tp);
+                       ttyflush(tp, FREAD);
+               } else if ((tp->t_flags&CBREAK) != (newflags&CBREAK)) {
+                       if (newflags&CBREAK) {
+                               struct clist tq;
+
+                               catq(&tp->t_rawq, &tp->t_canq);
+                               tq = tp->t_rawq;
+                               tp->t_rawq = tp->t_canq;
+                               tp->t_canq = tq;
+                       } else {
+                               tp->t_flags |= PENDIN;
+                               newflags |= PENDIN;
+                               ttwakeup(tp);
+                       }
+               }
+               tp->t_flags = newflags;
+               if (tp->t_flags&RAW) {
+                       tp->t_state &= ~TS_TTSTOP;
+                       ttstart(tp);
+               }
+               splx(s);
+               break;
+       }
+
+       /* send current parameters to user */
+       case TIOCGETP: {
+               register struct sgttyb *sg = (struct sgttyb *)data;
+
+               sg->sg_ispeed = tp->t_ispeed;
+               sg->sg_ospeed = tp->t_ospeed;
+               sg->sg_erase = tp->t_erase;
+               sg->sg_kill = tp->t_kill;
+               sg->sg_flags = tp->t_flags;
+               break;
+       }
+
+       case FIONBIO:
+               if (*(int *)data)
+                       tp->t_state |= TS_NBIO;
+               else
+                       tp->t_state &= ~TS_NBIO;
+               break;
+
+       case FIOASYNC:
+               if (*(int *)data)
+                       tp->t_state |= TS_ASYNC;
+               else
+                       tp->t_state &= ~TS_ASYNC;
+               break;
+
+       case TIOCGETC:
+               bcopy((caddr_t)&tp->t_intrc, data, sizeof (struct tchars));
+               break;
+
+       case TIOCSETC:
+               bcopy(data, (caddr_t)&tp->t_intrc, sizeof (struct tchars));
+               break;
+
+       /* set/get local special characters */
+       case TIOCSLTC:
+               bcopy(data, (caddr_t)&tp->t_suspc, sizeof (struct ltchars));
+               break;
+
+       case TIOCGLTC:
+               bcopy((caddr_t)&tp->t_suspc, data, sizeof (struct ltchars));
+               break;
+
+       /*
+        * Modify local mode word.
+        */
+       case TIOCLBIS:
+               tp->t_flags |= *(int *)data << 16;
+               break;
+
+       case TIOCLBIC:
+               tp->t_flags &= ~(*(int *)data << 16);
+               break;
+
+       case TIOCLSET:
+               tp->t_flags &= 0xffff;
+               tp->t_flags |= *(int *)data << 16;
+               break;
+
+       case TIOCLGET:
+               *(int *)data = ((unsigned) tp->t_flags) >> 16;
+               break;
+
+       /* should allow SPGRP and GPGRP only if tty open for reading */
+       case TIOCSPGRP:
+               tp->t_pgrp = *(int *)data;
+               break;
+
+       case TIOCGPGRP:
+               *(int *)data = tp->t_pgrp;
+               break;
+
        default:
        default:
-#ifndef NOCOMPAT
-               return (ottioctl(tp, com, data, flag));
-#else
                return (-1);
                return (-1);
-#endif
        }
        return (0);
 }
        }
        return (0);
 }
@@ -495,7 +550,7 @@ ttyopen(dev, tp)
        tp->t_state &= ~TS_WOPEN;
        tp->t_state |= TS_ISOPEN;
        if (tp->t_line != NTTYDISC)
        tp->t_state &= ~TS_WOPEN;
        tp->t_state |= TS_ISOPEN;
        if (tp->t_line != NTTYDISC)
-               wflushtty(tp);
+               ttywflush(tp);
        return (0);
 }
 
        return (0);
 }
 
@@ -507,12 +562,12 @@ ttyclose(tp)
 {
 
        if (tp->t_line) {
 {
 
        if (tp->t_line) {
-               wflushtty(tp);
+               ttywflush(tp);
                tp->t_line = 0;
                return;
        }
        tp->t_pgrp = 0;
                tp->t_line = 0;
                return;
        }
        tp->t_pgrp = 0;
-       wflushtty(tp);
+       ttywflush(tp);
        tp->t_state = 0;
 }
 
        tp->t_state = 0;
 }
 
@@ -570,7 +625,7 @@ ttyinput(c, tp)
                 * in input q w/o interpretation.
                 */
                if (tp->t_rawq.c_cc > TTYHOG) 
                 * in input q w/o interpretation.
                 */
                if (tp->t_rawq.c_cc > TTYHOG) 
-                       flushtty(tp, FREAD|FWRITE);
+                       ttyflush(tp, FREAD|FWRITE);
                else {
                        if (putc(c, &tp->t_rawq) >= 0)
                                ttwakeup(tp);
                else {
                        if (putc(c, &tp->t_rawq) >= 0)
                                ttwakeup(tp);
@@ -611,7 +666,7 @@ ttyinput(c, tp)
                        if (tp->t_flags&FLUSHO)
                                tp->t_flags &= ~FLUSHO;
                        else {
                        if (tp->t_flags&FLUSHO)
                                tp->t_flags &= ~FLUSHO;
                        else {
-                               flushtty(tp, FWRITE);
+                               ttyflush(tp, FWRITE);
                                ttyecho(c, tp);
                                if (tp->t_rawq.c_cc + tp->t_canq.c_cc)
                                        ttyretype(tp);
                                ttyecho(c, tp);
                                if (tp->t_rawq.c_cc + tp->t_canq.c_cc)
                                        ttyretype(tp);
@@ -621,7 +676,7 @@ ttyinput(c, tp)
                }
                if (c == tp->t_suspc) {
                        if ((tp->t_flags&NOFLSH) == 0)
                }
                if (c == tp->t_suspc) {
                        if ((tp->t_flags&NOFLSH) == 0)
-                               flushtty(tp, FREAD);
+                               ttyflush(tp, FREAD);
                        ttyecho(c, tp);
                        gsignal(tp->t_pgrp, SIGTSTP);
                        goto endcase;
                        ttyecho(c, tp);
                        gsignal(tp->t_pgrp, SIGTSTP);
                        goto endcase;
@@ -649,7 +704,7 @@ ttyinput(c, tp)
         */
        if (c == tp->t_intrc || c == tp->t_quitc) {
                if ((tp->t_flags&NOFLSH) == 0)
         */
        if (c == tp->t_intrc || c == tp->t_quitc) {
                if ((tp->t_flags&NOFLSH) == 0)
-                       flushtty(tp, FREAD|FWRITE);
+                       ttyflush(tp, FREAD|FWRITE);
                ttyecho(c, tp);
                gsignal(tp->t_pgrp, c == tp->t_intrc ? SIGINT : SIGQUIT);
                goto endcase;
                ttyecho(c, tp);
                gsignal(tp->t_pgrp, c == tp->t_intrc ? SIGINT : SIGQUIT);
                goto endcase;
@@ -892,13 +947,20 @@ ttyoutput(c, tp)
                        (*colp)--;
                break;
 
                        (*colp)--;
                break;
 
+       /*
+        * This macro is close enough to the correct thing;
+        * it should be replaced by real user settable delays
+        * in any event...
+        */
+#define        mstohz(ms)      (((ms) * hz) >> 10)
        case NEWLINE:
                ctype = (tp->t_flags >> 8) & 03;
                if (ctype == 1) { /* tty 37 */
        case NEWLINE:
                ctype = (tp->t_flags >> 8) & 03;
                if (ctype == 1) { /* tty 37 */
-                       if (*colp)
-                               c = max(((unsigned)*colp>>4) + 3, (unsigned)6);
+                       if (*colp > 0)
+                               c = max((((unsigned)*colp) >> 4) + 3,
+                                   (unsigned)6);
                } else if (ctype == 2) /* vt05 */
                } else if (ctype == 2) /* vt05 */
-                       c = 6;
+                       c = mstohz(100);
                *colp = 0;
                break;
 
                *colp = 0;
                break;
 
@@ -921,9 +983,9 @@ ttyoutput(c, tp)
        case RETURN:
                ctype = (tp->t_flags >> 12) & 03;
                if (ctype == 1) /* tn 300 */
        case RETURN:
                ctype = (tp->t_flags >> 12) & 03;
                if (ctype == 1) /* tn 300 */
-                       c = 5;
+                       c = mstohz(83);
                else if (ctype == 2) /* ti 700 */
                else if (ctype == 2) /* ti 700 */
-                       c = 10;
+                       c = mstohz(166);
                else if (ctype == 3) { /* concept 100 */
                        int i;
 
                else if (ctype == 3) { /* concept 100 */
                        int i;
 
@@ -937,6 +999,7 @@ ttyoutput(c, tp)
                (void) putc(c|0200, &tp->t_outq);
        return (-1);
 }
                (void) putc(c|0200, &tp->t_outq);
        return (-1);
 }
+#undef mstohz
 
 /*
  * Called from device's read routine after it has
 
 /*
  * Called from device's read routine after it has
@@ -964,9 +1027,10 @@ loop:
        /*
         * Hang process if it's in the background.
         */
        /*
         * Hang process if it's in the background.
         */
+#define bit(a) (1<<(a-1))
        while (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) {
        while (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) {
-               if (u.u_signal[SIGTTIN] == SIG_IGN ||
-                   u.u_signal[SIGTTIN] == SIG_HOLD ||
+               if ((u.u_procp->p_sigignore & bit(SIGTTIN)) ||
+                  (u.u_procp->p_sigmask & bit(SIGTTIN)) ||
 /*
                    (u.u_procp->p_flag&SDETACH) ||
 */
 /*
                    (u.u_procp->p_flag&SDETACH) ||
 */
@@ -976,6 +1040,7 @@ loop:
                sleep((caddr_t)&lbolt, TTIPRI);
        }
        t_flags = tp->t_flags;
                sleep((caddr_t)&lbolt, TTIPRI);
        }
        t_flags = tp->t_flags;
+#undef bit
 
        /*
         * In raw mode take characters directly from the
 
        /*
         * In raw mode take characters directly from the
@@ -988,15 +1053,15 @@ loop:
                        if ((tp->t_state&TS_CARR_ON) == 0 ||
                            (tp->t_state&TS_NBIO)) {
                                splx(s);
                        if ((tp->t_state&TS_CARR_ON) == 0 ||
                            (tp->t_state&TS_NBIO)) {
                                splx(s);
-                               return (0);
+                               return (EWOULDBLOCK);
                        }
                        sleep((caddr_t)&tp->t_rawq, TTIPRI);
                        splx(s);
                        goto loop;
                }
                splx(s);
                        }
                        sleep((caddr_t)&tp->t_rawq, TTIPRI);
                        splx(s);
                        goto loop;
                }
                splx(s);
-               while (!error && tp->t_rawq.c_cc && uio->uio_iovcnt)
-                       error = passuc(getc(&tp->t_rawq), uio);
+               while (!error && tp->t_rawq.c_cc && uio->uio_resid)
+                       error = ureadc(getc(&tp->t_rawq), uio);
                goto checktandem;
        }
 
                goto checktandem;
        }
 
@@ -1065,10 +1130,10 @@ loop:
                /*
                 * Give user character.
                 */
                /*
                 * Give user character.
                 */
-               error = passuc(c & 0177, uio);
+               error = ureadc(c & 0177, uio);
                if (error)
                        break;
                if (error)
                        break;
-               if (uio->uio_iovcnt == 0)
+               if (uio->uio_resid == 0)
                        break;
                /*
                 * In cooked mode check for a "break character"
                        break;
                /*
                 * In cooked mode check for a "break character"
@@ -1115,10 +1180,11 @@ loop:
        /*
         * Hang the process if it's in the background.
         */
        /*
         * Hang the process if it's in the background.
         */
+#define bit(a) (1<<(a-1))
        while (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp &&
            (tp->t_flags&TOSTOP) && (u.u_procp->p_flag&SVFORK)==0 &&
        while (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp &&
            (tp->t_flags&TOSTOP) && (u.u_procp->p_flag&SVFORK)==0 &&
-           u.u_signal[SIGTTOU] != SIG_IGN &&
-           u.u_signal[SIGTTOU] != SIG_HOLD
+           !(u.u_procp->p_sigignore & bit(SIGTTOU)) &&
+           !(u.u_procp->p_sigmask & bit(SIGTTOU))
 /*
                                             &&
            (u.u_procp->p_flag&SDETACH)==0) {
 /*
                                             &&
            (u.u_procp->p_flag&SDETACH)==0) {
@@ -1127,6 +1193,7 @@ loop:
                gsignal(u.u_procp->p_pgrp, SIGTTOU);
                sleep((caddr_t)&lbolt, TTIPRI);
        }
                gsignal(u.u_procp->p_pgrp, SIGTTOU);
                sleep((caddr_t)&lbolt, TTIPRI);
        }
+#undef bit
 
        /*
         * Process the user's data in at most OBUFSIZ
 
        /*
         * Process the user's data in at most OBUFSIZ
@@ -1150,7 +1217,7 @@ loop:
                if (cc > OBUFSIZ)
                        cc = OBUFSIZ;
                cp = obuf;
                if (cc > OBUFSIZ)
                        cc = OBUFSIZ;
                cp = obuf;
-               error = uiomove(cp, (unsigned)cc, UIO_WRITE, uio);
+               error = uiomove(cp, cc, UIO_WRITE, uio);
                if (error)
                        break;
                if (tp->t_outq.c_cc > hiwat)
                if (error)
                        break;
                if (tp->t_outq.c_cc > hiwat)
@@ -1191,7 +1258,8 @@ loop:
                        if (tp->t_flags & (RAW|LITOUT))
                                ce = cc;
                        else {
                        if (tp->t_flags & (RAW|LITOUT))
                                ce = cc;
                        else {
-                               ce = cc - scanc(cc, cp, partab, 077);
+                               ce = cc - scanc((unsigned)cc, (caddr_t)cp,
+                                  (caddr_t)partab, 077);
                                /*
                                 * If ce is zero, then we're processing
                                 * a special character through ttyoutput.
                                /*
                                 * If ce is zero, then we're processing
                                 * a special character through ttyoutput.
@@ -1457,10 +1525,12 @@ ttwakeup(tp)
                tp->t_state &= ~TS_RCOLL;
                tp->t_rsel = 0;
        }
                tp->t_state &= ~TS_RCOLL;
                tp->t_rsel = 0;
        }
+       if (tp->t_state & TS_ASYNC)
+               gsignal(tp->t_pgrp, SIGIO); 
        wakeup((caddr_t)&tp->t_rawq);
 }
 
        wakeup((caddr_t)&tp->t_rawq);
 }
 
-#if !defined(vax) && !defined(sun)
+#if !defined(vax)
 scanc(size, cp, table, mask)
        register int size;
        register char *cp, table[];
 scanc(size, cp, table, mask)
        register int size;
        register char *cp, table[];
@@ -1470,6 +1540,6 @@ scanc(size, cp, table, mask)
 
        while ((table[*(u_char *)(cp + i)]&mask) == 0 && i < size)
                i++;
 
        while ((table[*(u_char *)(cp + i)]&mask) == 0 && i < size)
                i++;
-       return (i);
+       return (size - i);
 }
 #endif
 }
 #endif