Change to includes. no more ../h
[unix-history] / usr / src / sys / kern / tty.c
index 65ea644..2b1e6fe 100644 (file)
@@ -1,21 +1,21 @@
-/*     tty.c   4.46    83/07/06        */
+/*     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
@@ -158,7 +158,6 @@ ttyflush(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;
@@ -179,9 +178,16 @@ ttyblock(tp)
                ttyflush(tp, FREAD|FWRITE);
                tp->t_state &= ~TS_TBLOCK;
        }
                ttyflush(tp, FREAD|FWRITE);
                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);
+               }
        }
 }
 
        }
 }
 
@@ -250,16 +256,18 @@ ttioctl(tp, com, data, flag)
        case TIOCLBIC:
        case TIOCLSET:
        case TIOCSTI:
        case TIOCLBIC:
        case TIOCLSET:
        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.
@@ -276,7 +284,7 @@ ttioctl(tp, com, data, flag)
                register int t = *(int *)data;
                int error = 0;
 
                register int t = *(int *)data;
                int error = 0;
 
-               if (t >= nldisp)
+               if ((unsigned) t >= nldisp)
                        return (ENXIO);
                s = spl5();
                if (tp->t_line)
                        return (ENXIO);
                s = spl5();
                if (tp->t_line)
@@ -453,7 +461,7 @@ ttioctl(tp, com, data, flag)
                break;
 
        case TIOCLGET:
                break;
 
        case TIOCLGET:
-               *(int *)data = tp->t_flags >> 16;
+               *(int *)data = ((unsigned) tp->t_flags) >> 16;
                break;
 
        /* should allow SPGRP and GPGRP only if tty open for reading */
                break;
 
        /* should allow SPGRP and GPGRP only if tty open for reading */
@@ -949,7 +957,8 @@ ttyoutput(c, tp)
                ctype = (tp->t_flags >> 8) & 03;
                if (ctype == 1) { /* tty 37 */
                        if (*colp > 0)
                ctype = (tp->t_flags >> 8) & 03;
                if (ctype == 1) { /* tty 37 */
                        if (*colp > 0)
-                               c = max(((unsigned)*colp>>4) + 3, (unsigned)6);
+                               c = max((((unsigned)*colp) >> 4) + 3,
+                                   (unsigned)6);
                } else if (ctype == 2) /* vt05 */
                        c = mstohz(100);
                *colp = 0;
                } else if (ctype == 2) /* vt05 */
                        c = mstohz(100);
                *colp = 0;
@@ -1018,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) ||
 */
@@ -1030,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
@@ -1042,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;
        }
 
@@ -1119,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"
@@ -1169,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) {
@@ -1181,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
@@ -1527,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