386BSD 0.1 development
authorWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Mon, 10 Jun 1991 14:40:04 +0000 (06:40 -0800)
committerWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Mon, 10 Jun 1991 14:40:04 +0000 (06:40 -0800)
Work on file usr/src/bin/stty/cchar.c
Work on file usr/src/bin/stty/extern.h
Work on file usr/src/bin/stty/key.c
Work on file usr/src/bin/stty/gfmt.c
Work on file usr/src/bin/stty/modes.c
Work on file usr/src/bin/stty/print.c
Work on file usr/src/bin/stty/stty.h

Co-Authored-By: Lynne Greer Jolitz <ljolitz@cardio.ucsf.edu>
Synthesized-from: 386BSD-0.1

usr/src/bin/stty/cchar.c [new file with mode: 0644]
usr/src/bin/stty/extern.h [new file with mode: 0644]
usr/src/bin/stty/gfmt.c [new file with mode: 0644]
usr/src/bin/stty/key.c [new file with mode: 0644]
usr/src/bin/stty/modes.c [new file with mode: 0644]
usr/src/bin/stty/print.c [new file with mode: 0644]
usr/src/bin/stty/stty.h [new file with mode: 0644]

diff --git a/usr/src/bin/stty/cchar.c b/usr/src/bin/stty/cchar.c
new file mode 100644 (file)
index 0000000..458867c
--- /dev/null
@@ -0,0 +1,122 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)cchar.c    5.4 (Berkeley) 6/10/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include "stty.h"
+#include "extern.h"
+
+/*
+ * Special control characters.
+ *
+ * Cchars1 are the standard names, cchars2 are the old aliases.
+ * The first are displayed, but both are recognized on the
+ * command line.
+ */
+struct cchar cchars1[] = {
+       "discard",      VDISCARD,       CDISCARD,
+       "dsusp",        VDSUSP,         CDSUSP,
+       "eof",          VEOF,           CEOF,
+       "eol",          VEOL,           CEOL,
+       "eol2",         VEOL2,          CEOL,
+       "erase",        VERASE,         CERASE,
+       "intr",         VINTR,          CINTR,
+       "kill",         VKILL,          CKILL,
+       "lnext",        VLNEXT,         CLNEXT,
+       "quit",         VQUIT,          CQUIT,
+       "reprint",      VREPRINT,       CREPRINT,
+       "start",        VSTART,         CSTART,
+       "status",       VSTATUS,        CSTATUS,
+       "stop",         VSTOP,          CSTOP,
+       "susp",         VSUSP,          CSUSP,
+       "werase",       VWERASE,        CWERASE,
+       NULL,
+};
+
+struct cchar cchars2[] = {
+       "brk",          VEOL,           CEOL,
+       "flush",        VDISCARD,       CDISCARD,
+       "rprnt",        VREPRINT,       CREPRINT,
+       "xoff",         VSTOP,          CSTOP,
+       "xon",          VSTART,         CSTART,
+       NULL,
+};
+
+csearch(argvp, ip)
+       char ***argvp;
+       struct info *ip;
+{
+       extern char *usage;
+       register struct cchar *cp;
+       struct cchar tmp;
+       char *arg, *name;
+       static int c_cchar __P((const void *, const void *));
+               
+       name = **argvp;
+
+       tmp.name = name;
+       if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
+           sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
+           c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
+           sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
+           c_cchar)))
+               return(0);
+
+       arg = *++*argvp;
+       if (!arg)
+               err("option requires an argument -- %s\n%s", name, usage);
+
+#define CHK(s)  (*name == s[0] && !strcmp(name, s))
+       if (CHK("undef") || CHK("<undef>"))
+               ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
+       else if (arg[0] == '^')
+               ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
+                   (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
+       else
+               ip->t.c_cc[cp->sub] = arg[0];
+       ip->set = 1;
+       return(1);
+}
+
+static
+c_cchar(a, b)
+        const void *a, *b;
+{
+        return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
+}
diff --git a/usr/src/bin/stty/extern.h b/usr/src/bin/stty/extern.h
new file mode 100644 (file)
index 0000000..e1cbcb0
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ *     @(#)extern.h    5.4 (Berkeley) 6/10/91
+ */
+
+__BEGIN_DECLS
+int    c_cchars __P((const void *, const void *));
+int    c_modes __P((const void *, const void *));
+int    csearch __P((char ***, struct info *));
+void   checkredirect __P((void));
+void   err __P((const char *, ...));
+void   gprint __P((struct termios *, struct winsize *, int));
+void   gread __P((struct termios *, char *));
+int    ksearch __P((char ***, struct info *));
+int    msearch __P((char ***, struct info *));
+void   optlist __P((void));
+void   print __P((struct termios *, struct winsize *, int, enum FMT));
+void   warn __P((const char *, ...));
+__END_DECLS
+
+extern struct cchar cchars1[], cchars2[];
+extern char *usage;
diff --git a/usr/src/bin/stty/gfmt.c b/usr/src/bin/stty/gfmt.c
new file mode 100644 (file)
index 0000000..3953e64
--- /dev/null
@@ -0,0 +1,182 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)gfmt.c     5.4 (Berkeley) 6/10/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include "stty.h"
+#include "extern.h"
+
+static void gerr __P((char *));
+
+void
+gprint(tp, wp, ldisc)
+       struct termios *tp;
+       struct winsize *wp;
+       int ldisc;
+{
+       register struct cchar *cp;
+
+       (void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
+           tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
+       for (cp = cchars1; cp->name; ++cp)
+               (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
+       (void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
+}
+
+void
+gread(tp, s) 
+       register struct termios *tp;
+       char *s;
+{
+       register char *ep, *p;
+       long tmp;
+
+#define        CHK(s)  (*p == s[0] && !strcmp(p, s))
+       if (!(s = index(s, ':')))
+               gerr(NULL);
+       for (++s; s;) {
+               p = strsep(&s, ":\0");
+               if (!p || !*p)
+                       break;
+               if (!(ep = index(p, '=')))
+                       gerr(p);
+               *ep++ = '\0';
+               (void)sscanf(ep, "%lx", &tmp);
+               if (CHK("cflag")) {
+                       tp->c_cflag = tmp;
+                       continue;
+               }
+               if (CHK("discard")) {
+                       tp->c_cc[VDISCARD] = tmp;
+                       continue;
+               }
+               if (CHK("dsusp")) {
+                       tp->c_cc[VDSUSP] = tmp;
+                       continue;
+               }
+               if (CHK("eof")) {
+                       tp->c_cc[VEOF] = tmp;
+                       continue;
+               }
+               if (CHK("eol")) {
+                       tp->c_cc[VEOL] = tmp;
+                       continue;
+               }
+               if (CHK("eol2")) {
+                       tp->c_cc[VEOL2] = tmp;
+                       continue;
+               }
+               if (CHK("erase")) {
+                       tp->c_cc[VERASE] = tmp;
+                       continue;
+               }
+               if (CHK("iflag")) {
+                       tp->c_iflag = tmp;
+                       continue;
+               }
+               if (CHK("intr")) {
+                       tp->c_cc[VINTR] = tmp;
+                       continue;
+               }
+               if (CHK("ispeed")) {
+                       (void)sscanf(ep, "%ld", &tmp);
+                       tp->c_ispeed = tmp;
+                       continue;
+               }
+               if (CHK("kill")) {
+                       tp->c_cc[VKILL] = tmp;
+                       continue;
+               }
+               if (CHK("lflag")) {
+                       tp->c_lflag = tmp;
+                       continue;
+               }
+               if (CHK("lnext")) {
+                       tp->c_cc[VLNEXT] = tmp;
+                       continue;
+               }
+               if (CHK("oflag")) {
+                       tp->c_oflag = tmp;
+                       continue;
+               }
+               if (CHK("ospeed")) {
+                       (void)sscanf(ep, "%ld", &tmp);
+                       tp->c_ospeed = tmp;
+                       continue;
+               }
+               if (CHK("quit")) {
+                       tp->c_cc[VQUIT] = tmp;
+                       continue;
+               }
+               if (CHK("reprint")) {
+                       tp->c_cc[VREPRINT] = tmp;
+                       continue;
+               }
+               if (CHK("start")) {
+                       tp->c_cc[VSTART] = tmp;
+                       continue;
+               }
+               if (CHK("status")) {
+                       tp->c_cc[VSTATUS] = tmp;
+                       continue;
+               }
+               if (CHK("stop")) {
+                       tp->c_cc[VSTOP] = tmp;
+                       continue;
+               }
+               if (CHK("susp")) {
+                       tp->c_cc[VSUSP] = tmp;
+                       continue;
+               }
+               if (CHK("werase")) {
+                       tp->c_cc[VWERASE] = tmp;
+                       continue;
+               }
+               gerr(p);
+       }
+}
+
+static void
+gerr(s)
+       char *s;
+{
+       if (s)
+               err("illegal gfmt1 option -- %s", s);
+       else
+               err("illegal gfmt1 option");
+}
diff --git a/usr/src/bin/stty/key.c b/usr/src/bin/stty/key.c
new file mode 100644 (file)
index 0000000..8ec7f96
--- /dev/null
@@ -0,0 +1,281 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)key.c      5.3 (Berkeley) 6/10/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "stty.h"
+#include "extern.h"
+
+__BEGIN_DECLS
+void   f_all __P((struct info *));
+void   f_cbreak __P((struct info *));
+void   f_columns __P((struct info *));
+void   f_dec __P((struct info *));
+void   f_everything __P((struct info *));
+void   f_extproc __P((struct info *));
+void   f_ispeed __P((struct info *));
+void   f_nl __P((struct info *));
+void   f_ospeed __P((struct info *));
+void   f_raw __P((struct info *));
+void   f_rows __P((struct info *));
+void   f_sane __P((struct info *));
+void   f_size __P((struct info *));
+void   f_speed __P((struct info *));
+void   f_tty __P((struct info *));
+__END_DECLS
+
+static struct key {
+       char *name;                             /* name */
+       void (*f) __P((struct info *));         /* function */
+#define        F_NEEDARG       0x01                    /* needs an argument */
+#define        F_OFFOK         0x02                    /* can turn off */
+       int flags;
+} keys[] = {
+       "all",          f_all,          0,
+       "cbreak",       f_cbreak,       F_OFFOK,
+       "cols",         f_columns,      F_NEEDARG,
+       "columns",      f_columns,      F_NEEDARG,
+       "cooked",       f_sane,         0,
+       "dec",          f_dec,          0,
+       "everything",   f_everything,   0,
+       "extproc",      f_extproc,      F_OFFOK,
+       "ispeed",       f_ispeed,       0,
+       "new",          f_tty,          0,
+       "nl",           f_nl,           F_OFFOK,
+       "old",          f_tty,          0,
+       "ospeed",       f_ospeed,       F_NEEDARG,
+       "raw",          f_raw,          F_OFFOK,
+       "rows",         f_rows,         F_NEEDARG,
+       "sane",         f_sane,         0,
+       "size",         f_size,         0,
+       "speed",        f_speed,        0,
+       "tty",          f_tty,          0,
+};
+
+ksearch(argvp, ip)
+       char ***argvp;
+       struct info *ip;
+{
+       register struct key *kp;
+       register char *name;
+       struct key tmp;
+       static int c_key __P((const void *, const void *));
+
+       name = **argvp;
+       if (*name == '-') {
+               ip->off = 1;
+               ++name;
+       } else
+               ip->off = 0;
+
+       tmp.name = name;
+       if (!(kp = (struct key *)bsearch(&tmp, keys,
+           sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key)))
+               return(0);
+       if (!(kp->flags & F_OFFOK) && ip->off)
+               err("illegal option -- %s\n%s", name, usage);
+       if (kp->flags & F_NEEDARG && !(ip->arg = *++*argvp))
+               err("option requires an argument -- %s\n%s", name, usage);
+       kp->f(ip);
+       return(1);
+}
+
+static
+c_key(a, b)
+        const void *a, *b;
+{
+        return(strcmp(((struct key *)a)->name, ((struct key *)b)->name));
+}
+
+void
+f_all(ip)
+       struct info *ip;
+{
+       print(&ip->t, &ip->win, ip->ldisc, BSD);
+}
+
+void
+f_cbreak(ip)
+       struct info *ip;
+{
+       if (ip->off)
+               f_sane(ip);
+       else {
+               ip->t.c_iflag |= BRKINT|IXON|IMAXBEL;
+               ip->t.c_oflag |= OPOST;
+               ip->t.c_lflag |= ISIG|IEXTEN;
+               ip->t.c_lflag &= ~ICANON;
+               ip->set = 1;
+       }
+}
+
+void
+f_columns(ip)
+       struct info *ip;
+{
+       ip->win.ws_col = atoi(ip->arg);
+       ip->wset = 1;
+}
+
+void
+f_dec(ip)
+       struct info *ip;
+{
+       ip->t.c_cc[VERASE] = (u_char)0177;
+       ip->t.c_cc[VKILL] = CTRL('u');
+       ip->t.c_cc[VINTR] = CTRL('c');
+       ip->t.c_lflag &= ~ECHOPRT;
+       ip->t.c_lflag |= ECHOE|ECHOKE|ECHOCTL;
+       ip->t.c_iflag &= ~IXANY;
+       ip->set = 1;
+}
+
+void
+f_everything(ip)
+       struct info *ip;
+{
+       print(&ip->t, &ip->win, ip->ldisc, BSD);
+}
+
+void
+f_extproc(ip)
+       struct info *ip;
+{
+       int tmp;
+
+       if (ip->set) {
+               tmp = 1;
+               (void)ioctl(ip->fd, TIOCEXT, &tmp);
+       } else {
+               tmp = 0;
+               (void)ioctl(ip->fd, TIOCEXT, &tmp);
+       }
+}
+
+void
+f_ispeed(ip)
+       struct info *ip;
+{
+       cfsetispeed(&ip->t, atoi(ip->arg));
+       ip->set = 1;
+}
+
+void
+f_nl(ip)
+       struct info *ip;
+{
+       if (ip->off) {
+               ip->t.c_iflag |= ICRNL;
+               ip->t.c_oflag |= ONLCR;
+       } else {
+               ip->t.c_iflag &= ~ICRNL;
+               ip->t.c_oflag &= ~ONLCR;
+       }
+       ip->set = 1;
+}
+
+void
+f_ospeed(ip)
+       struct info *ip;
+{
+       cfsetospeed(&ip->t, atoi(ip->arg));
+       ip->set = 1;
+}
+
+void
+f_raw(ip)
+       struct info *ip;
+{
+       if (ip->off)
+               f_sane(ip);
+       else {
+               cfmakeraw(&ip->t);
+               ip->t.c_cflag &= ~(CSIZE|PARENB);
+               ip->t.c_cflag |= CS8;
+               ip->set = 1;
+       }
+}
+
+void
+f_rows(ip)
+       struct info *ip;
+{
+       ip->win.ws_row = atoi(ip->arg);
+       ip->wset = 1;
+}
+
+void
+f_sane(ip)
+       struct info *ip;
+{
+       ip->t.c_cflag = TTYDEF_CFLAG | (ip->t.c_cflag & CLOCAL);
+       ip->t.c_iflag = TTYDEF_IFLAG;
+       ip->t.c_iflag |= ICRNL;
+       /* preserve user-preference flags in lflag */
+#define        LKEEP   (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
+       ip->t.c_lflag = TTYDEF_LFLAG | (ip->t.c_lflag & LKEEP);
+       ip->t.c_oflag = TTYDEF_OFLAG;
+       ip->set = 1;
+}
+
+void
+f_size(ip)
+       struct info *ip;
+{
+       (void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col);
+}
+
+void
+f_speed(ip)
+       struct info *ip;
+{
+       (void)printf("%d\n", cfgetospeed(&ip->t));
+}
+
+void
+f_tty(ip)
+       struct info *ip;
+{
+       int tmp;
+
+       tmp = TTYDISC;
+       if (ioctl(0, TIOCSETD, &tmp) < 0)
+               err("TIOCSETD: %s", strerror(errno));
+}
diff --git a/usr/src/bin/stty/modes.c b/usr/src/bin/stty/modes.c
new file mode 100644 (file)
index 0000000..4b5f854
--- /dev/null
@@ -0,0 +1,230 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)modes.c    5.4 (Berkeley) 6/10/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <string.h>
+#include "stty.h"
+
+struct modes {
+       char *name;
+       long set;
+       long unset;
+};
+
+/*
+ * The code in optlist() depends on minus options following regular
+ * options, i.e. "foo" must immediately precede "-foo".
+ */
+struct modes cmodes[] = {
+       "cs5",          CS5, CSIZE,
+       "cs6",          CS6, CSIZE,
+       "cs7",          CS7, CSIZE,
+       "cs8",          CS8, CSIZE,
+       "cstopb",       CSTOPB, 0,
+       "-cstopb",      0, CSTOPB,
+       "cread",        CREAD, 0,
+       "-cread",       0, CREAD,
+       "parenb",       PARENB, 0,
+       "-parenb",      0, PARENB,
+       "parodd",       PARODD, 0,
+       "-parodd",      0, PARODD,
+       "parity",       PARENB | CS7, PARODD | CSIZE,
+       "-parity",      CS8, PARODD | PARENB | CSIZE,
+       "evenp",        PARENB | CS7, PARODD | CSIZE,
+       "-evenp",       CS8, PARODD | PARENB | CSIZE,
+       "oddp",         PARENB | CS7 | PARODD, CSIZE,
+       "-oddp",        CS8, PARODD | PARENB | CSIZE,
+       "pass8",        CS8, PARODD | PARENB | CSIZE,
+       "hupcl",        HUPCL, 0,
+       "-hupcl",       0, HUPCL,
+       "hup",          HUPCL, 0,
+       "-hup",         0, HUPCL,
+       "clocal",       CLOCAL, 0,
+       "-clocal",      0, CLOCAL,
+       "crtscts",      CRTSCTS, 0,
+       "-crtscts",     0, CRTSCTS,
+       NULL
+};
+
+struct modes imodes[] = {
+       "ignbrk",       IGNBRK, 0,
+       "-ignbrk",      0, IGNBRK,
+       "brkint",       BRKINT, 0,
+       "-brkint",      0, BRKINT,
+       "ignpar",       IGNPAR, 0,
+       "-ignpar",      0, IGNPAR,
+       "parmrk",       PARMRK, 0,
+       "-parmrk",      0, PARMRK,
+       "inpck",        INPCK, 0,
+       "-inpck",       0, INPCK,
+       "istrip",       ISTRIP, 0,
+       "-istrip",      0, ISTRIP,
+       "inlcr",        INLCR, 0,
+       "-inlcr",       0, INLCR,
+       "igncr",        IGNCR, 0,
+       "-igncr",       0, IGNCR,
+       "icrnl",        ICRNL, 0,
+       "-icrnl",       0, ICRNL,
+       "ixon",         IXON, 0,
+       "-ixon",        0, IXON,
+       "flow",         IXON, 0,
+       "-flow",        0, IXON,
+       "ixoff",        IXOFF, 0,
+       "-ixoff",       0, IXOFF,
+       "tandem",       IXOFF, 0,
+       "-tandem",      0, IXOFF,
+       "ixany",        IXANY, 0,
+       "-ixany",       0, IXANY,
+       "decctlq",      0, IXANY,
+       "-decctlq",     IXANY, 0,
+       "imaxbel",      IMAXBEL, 0,
+       "-imaxbel",     0, IMAXBEL,
+       NULL
+};
+
+struct modes lmodes[] = {
+       "echo",         ECHO, 0,
+       "-echo",        0, ECHO,
+       "echoe",        ECHOE, 0,
+       "-echoe",       0, ECHOE,
+       "crterase",     ECHOE, 0,
+       "-crterase",    0, ECHOE,
+       "crtbs",        ECHOE, 0,   /* crtbs not supported, close enough */
+       "-crtbs",       0, ECHOE,
+       "echok",        ECHOK, 0,
+       "-echok",       0, ECHOK,
+       "echoke",       ECHOKE, 0,
+       "-echoke",      0, ECHOKE,
+       "crtkill",      ECHOKE, 0,
+       "-crtkill",     0, ECHOKE,
+       "altwerase",    ALTWERASE, 0,
+       "-altwerase",   0, ALTWERASE,
+       "iexten",       IEXTEN, 0,
+       "-iexten",      0, IEXTEN,
+       "echonl",       ECHONL, 0,
+       "-echonl",      0, ECHONL,
+       "echoctl",      ECHOCTL, 0,
+       "-echoctl",     0, ECHOCTL,
+       "ctlecho",      ECHOCTL, 0,
+       "-ctlecho",     0, ECHOCTL,
+       "echoprt",      ECHOPRT, 0,
+       "-echoprt",     0, ECHOPRT,
+       "prterase",     ECHOPRT, 0,
+       "-prterase",    0, ECHOPRT,
+       "isig",         ISIG, 0,
+       "-isig",        0, ISIG,
+       "icanon",       ICANON, 0,
+       "-icanon",      0, ICANON,
+       "noflsh",       NOFLSH, 0,
+       "-noflsh",      0, NOFLSH,
+       "tostop",       TOSTOP, 0,
+       "-tostop",      0, TOSTOP,
+       "mdmbuf",       MDMBUF, 0,
+       "-mdmbuf",      0, MDMBUF,
+       "flusho",       FLUSHO, 0,
+       "-flusho",      0, FLUSHO,
+       "pendin",       PENDIN, 0,
+       "-pendin",      0, PENDIN,
+       "crt",          ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
+       "-crt",         ECHOK, ECHOE|ECHOKE|ECHOCTL,
+       "newcrt",       ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
+       "-newcrt",      ECHOK, ECHOE|ECHOKE|ECHOCTL, 
+       "nokerninfo",   NOKERNINFO, 0,
+       "-nokerninfo",  0, NOKERNINFO,
+       "kerninfo",     0, NOKERNINFO,
+       "-kerninfo",    NOKERNINFO, 0,
+       NULL
+};
+
+struct modes omodes[] = {
+       "opost",        OPOST, 0,
+       "-opost",       0, OPOST,
+       "litout",       0, OPOST,
+       "-litout",      OPOST, 0,
+       "onlcr",        ONLCR, 0,
+       "-onlcr",       0, ONLCR,
+       "tabs",         0, OXTABS,      /* "preserve" tabs */
+       "-tabs",        OXTABS, 0,
+       "xtabs",        OXTABS, 0,
+       "-xtabs",       0, OXTABS,
+       "oxtabs",       OXTABS, 0,
+       "-oxtabs",      0, OXTABS,
+       NULL
+};
+
+#define        CHK(s)  (*name == s[0] && !strcmp(name, s))
+
+msearch(argvp, ip)
+       char ***argvp;
+       struct info *ip;
+{
+       register struct modes *mp;
+       register char *name;
+
+       name = **argvp;
+
+       for (mp = cmodes; mp->name; ++mp)
+               if (CHK(mp->name)) {
+                       ip->t.c_cflag &= ~mp->unset;
+                       ip->t.c_cflag |= mp->set;
+                       ip->set = 1;
+                       return(1);
+               }
+       for (mp = imodes; mp->name; ++mp)
+               if (CHK(mp->name)) {
+                       ip->t.c_iflag &= ~mp->unset;
+                       ip->t.c_iflag |= mp->set;
+                       ip->set = 1;
+                       return(1);
+               }
+       for (mp = lmodes; mp->name; ++mp)
+               if (CHK(mp->name)) {
+                       ip->t.c_lflag &= ~mp->unset;
+                       ip->t.c_lflag |= mp->set;
+                       ip->set = 1;
+                       return(1);
+               }
+       for (mp = omodes; mp->name; ++mp)
+               if (CHK(mp->name)) {
+                       ip->t.c_oflag &= ~mp->unset;
+                       ip->t.c_oflag |= mp->set;
+                       ip->set = 1;
+                       return(1);
+               }
+       return(0);
+}
diff --git a/usr/src/bin/stty/print.c b/usr/src/bin/stty/print.c
new file mode 100644 (file)
index 0000000..c2f7a8e
--- /dev/null
@@ -0,0 +1,258 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)print.c    5.4 (Berkeley) 6/10/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include "stty.h"
+#include "extern.h"
+
+static void  binit __P((char *));
+static void  bput __P((char *));
+static char *ccval __P((int));
+
+void
+print(tp, wp, ldisc, fmt)
+       struct termios *tp;
+       struct winsize *wp;
+       int ldisc;
+       enum FMT fmt;
+{
+       register struct cchar *p;
+       register long tmp;
+       register int cnt;
+       register u_char *cc;
+       int ispeed, ospeed;
+       char buf1[100], buf2[100];
+
+       cnt = 0;
+
+       /* Line discipline. */
+       if (ldisc != TTYDISC) {
+               switch(ldisc) {
+               case TABLDISC:  
+                       cnt += printf("tablet disc; ");
+                       break;
+               case SLIPDISC:  
+                       cnt += printf("slip disc; ");
+                       break;
+               default:        
+                       cnt += printf("#%d disc; ", ldisc);
+                       break;
+               }
+       }
+
+       /* Line speed. */
+       ispeed = cfgetispeed(tp);
+       ospeed = cfgetospeed(tp);
+       if (ispeed != ospeed)
+               cnt +=
+                   printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
+       else
+               cnt += printf("speed %d baud;", ispeed);
+       if (fmt >= BSD)
+               cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
+       if (cnt)
+               (void)printf("\n");
+
+#define        on(f)   ((tmp&f) != 0)
+#define put(n, f, d) \
+       if (fmt >= BSD || on(f) != d) \
+               bput(n + on(f));
+
+       /* "local" flags */
+       tmp = tp->c_lflag;
+       binit("lflags");
+       put("-icanon", ICANON, 1);
+       put("-isig", ISIG, 1);
+       put("-iexten", IEXTEN, 1);
+       put("-echo", ECHO, 1);
+       put("-echoe", ECHOE, 0);
+       put("-echok", ECHOK, 0);
+       put("-echoke", ECHOKE, 0);
+       put("-echonl", ECHONL, 0);
+       put("-echoctl", ECHOCTL, 0);
+       put("-echoprt", ECHOPRT, 0);
+       put("-altwerase", ALTWERASE, 0);
+       put("-noflsh", NOFLSH, 0);
+       put("-tostop", TOSTOP, 0);
+       put("-mdmbuf", MDMBUF, 0);
+       put("-flusho", FLUSHO, 0);
+       put("-pendin", PENDIN, 0);
+       put("-nokerninfo", NOKERNINFO, 0);
+       put("-extproc", EXTPROC, 0);
+
+       /* input flags */
+       tmp = tp->c_iflag;
+       binit("iflags");
+       put("-istrip", ISTRIP, 0);
+       put("-icrnl", ICRNL, 1);
+       put("-inlcr", INLCR, 0);
+       put("-igncr", IGNCR, 0);
+       put("-ixon", IXON, 1);
+       put("-ixoff", IXOFF, 0);
+       put("-ixany", IXANY, 1);
+       put("-imaxbel", IMAXBEL, 1);
+       put("-ignbrk", IGNBRK, 0);
+       put("-brkint", BRKINT, 1);
+       put("-inpck", INPCK, 0);
+       put("-ignpar", IGNPAR, 0);
+       put("-parmrk", PARMRK, 0);
+
+       /* output flags */
+       tmp = tp->c_oflag;
+       binit("oflags");
+       put("-opost", OPOST, 1);
+       put("-onlcr", ONLCR, 1);
+       put("-oxtabs", OXTABS, 1);
+
+       /* control flags (hardware state) */
+       tmp = tp->c_cflag;
+       binit("cflags");
+       put("-cread", CREAD, 1);
+       switch(tmp&CSIZE) {
+       case CS5:
+               bput("cs5");
+               break;
+       case CS6:
+               bput("cs6");
+               break;
+       case CS7:
+               bput("cs7");
+               break;
+       case CS8:
+               bput("cs8");
+               break;
+       }
+       bput("-parenb" + on(PARENB));
+       put("-parodd", PARODD, 0);
+       put("-hupcl", HUPCL, 1);
+       put("-clocal", CLOCAL, 0);
+       put("-cstopb", CSTOPB, 0);
+       put("-crtscts", CRTSCTS, 0);
+
+       /* special control characters */
+       cc = tp->c_cc;
+       if (fmt == POSIX) {
+               binit("cchars");
+               for (p = cchars1; p->name; ++p) {
+                       (void)snprintf(buf1, sizeof(buf1), "%s = %s;",
+                           p->name, ccval(cc[p->sub]));
+                       bput(buf1);
+               }
+               binit(NULL);
+       } else {
+               binit(NULL);
+               for (p = cchars1, cnt = 0; p->name; ++p) {
+                       if (fmt != BSD && cc[p->sub] == p->def)
+                               continue;
+#define        WD      "%-8s"
+                       (void)sprintf(buf1 + cnt * 8, WD, p->name);
+                       (void)sprintf(buf2 + cnt * 8, WD, ccval(cc[p->sub]));
+                       if (++cnt == LINELENGTH / 8) {
+                               cnt = 0;
+                               (void)printf("%s\n", buf1);
+                               (void)printf("%s\n", buf2);
+                       }
+               }
+               if (cnt) {
+                       (void)printf("%s\n", buf1);
+                       (void)printf("%s\n", buf2);
+               }
+       }
+}
+
+static int col;
+static char *label;
+
+static void
+binit(lb)
+       char *lb;
+{
+       if (col) {
+               (void)printf("\n");
+               col = 0;
+       }
+       label = lb;
+}
+
+static void
+bput(s)
+       char *s;
+{
+       if (col == 0) {
+               col = printf("%s: %s", label, s);
+               return;
+       }
+       if ((col + strlen(s)) > LINELENGTH) {
+               (void)printf("\n\t");
+               col = printf("%s", s) + 8;
+               return;
+       }
+       col += printf(" %s", s);
+}
+
+static char *
+ccval(c)
+       int c;
+{
+       static char buf[5];
+       char *bp;
+
+       if (c == _POSIX_VDISABLE)
+               return("<undef>");
+
+       bp = buf;
+       if (c & 0200) {
+               *bp++ = 'M';
+               *bp++ = '-';
+               c &= 0177;
+       }
+       if (c == 0177) {
+               *bp++ = '^';
+               *bp++ = '?';
+       }
+       else if (c < 040) {
+               *bp++ = '^';
+               *bp++ = c + '@';
+       }
+       else
+               *bp++ = c;
+       *bp = '\0';
+       return(buf);
+}
diff --git a/usr/src/bin/stty/stty.h b/usr/src/bin/stty/stty.h
new file mode 100644 (file)
index 0000000..5f71c7d
--- /dev/null
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ *     @(#)stty.h      5.3 (Berkeley) 6/10/91
+ */
+
+#include <sys/ioctl.h>
+#include <termios.h>
+
+struct info {
+       int fd;                                 /* file descriptor */
+       int ldisc;                              /* line discipline */
+       int off;                                /* turn off */
+       int set;                                /* need set */
+       int wset;                               /* need window set */
+       char *arg;                              /* argument */
+       struct termios t;                       /* terminal info */
+       struct winsize win;                     /* window info */
+};
+
+struct cchar {
+       char *name;
+       int sub;
+       u_char def;
+};
+
+enum FMT { NOTSET, GFLAG, BSD, POSIX };
+
+#define        LINELENGTH      72