BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / window / wwinit.c
index c41a2ee..7ed318b 100644 (file)
@@ -5,23 +5,37 @@
  * This code is derived from software contributed to Berkeley by
  * Edward Wang at The University of California, Berkeley.
  *
  * This code is derived from software contributed to Berkeley by
  * Edward Wang at The University of California, Berkeley.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.39 (Berkeley) 6/6/90";
+static char sccsid[] = "@(#)wwinit.c   3.40 (Berkeley) 8/12/90";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -51,7 +65,7 @@ wwinit()
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        wwnewtty.ww_sgttyb.sg_erase = -1;
        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        wwnewtty.ww_sgttyb.sg_erase = -1;
@@ -73,6 +87,12 @@ wwinit()
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
 #else
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
 #else
+#ifndef OXTABS
+#define OXTABS XTABS
+#endif
+#ifndef _POSIX_VDISABLE
+#define _POSIX_VDISABLE -1
+#endif
        wwwintty.ww_termios.c_oflag &= ~OXTABS;
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
        wwwintty.ww_termios.c_oflag &= ~OXTABS;
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
@@ -82,11 +102,11 @@ wwinit()
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
-       for (i = 0; i < NCC; i++)
+       for (i = 0; i < NCCS; i++)
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
-       if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
+       if (wwsettty(0, &wwnewtty) < 0)
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
@@ -97,15 +117,70 @@ wwinit()
                wwerrno = WWE_BADTERM;
                goto bad;
        }
                wwerrno = WWE_BADTERM;
                goto bad;
        }
-#ifndef POSIX_TTY
-       wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
+#ifdef OLD_TTY
+       wwospeed = wwoldtty.ww_sgttyb.sg_ospeed;
 #else
 #else
-#ifdef CBAUD
-       wwbaud = wwbaudmap[wwoldtty.ww_termios.c_cflag & CBAUD];
+       wwospeed = cfgetospeed(&wwoldtty.ww_termios);
+#endif
+       switch (wwospeed) {
+       default:
+       case B0:
+               wwbaud = 0;
+               break;
+       case B50:
+               wwbaud = 50;
+               break;
+       case B75:
+               wwbaud = 75;
+               break;
+       case B110:
+               wwbaud = 110;
+               break;
+       case B134:
+               wwbaud = 134;
+               break;
+       case B150:
+               wwbaud = 150;
+               break;
+       case B200:
+               wwbaud = 200;
+               break;
+       case B300:
+               wwbaud = 300;
+               break;
+       case B600:
+               wwbaud = 600;
+               break;
+       case B1200:
+               wwbaud = 1200;
+               break;
+       case B1800:
+               wwbaud = 1800;
+               break;
+       case B2400:
+               wwbaud = 2400;
+               break;
+       case B4800:
+               wwbaud = 4800;
+               break;
+       case B9600:
+               wwbaud = 9600;
+               break;
+#ifdef B19200
+       case B19200:
 #else
 #else
-       wwbaud = wwoldtty.ww_termios.c_ospeed;
+       case EXTA:
 #endif
 #endif
+               wwbaud = 19200;
+               break;
+#ifdef B38400
+       case B38400:
+#else
+       case EXTB:
 #endif
 #endif
+               wwbaud = 38400;
+               break;
+       }
 
        if (xxinit() < 0)
                goto bad;
 
        if (xxinit() < 0)
                goto bad;
@@ -219,7 +294,7 @@ bad:
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
-       (void) wwsettty(0, &wwoldtty, &wwnewtty);
+       (void) wwsettty(0, &wwoldtty);
        (void) signal(SIGIO, SIG_DFL);
        (void) sigsetmask(s);
        return -1;
        (void) signal(SIGIO, SIG_DFL);
        (void) sigsetmask(s);
        return -1;