copy -> bcopy (more than vax and tahoe now)
[unix-history] / usr / src / bin / stty / stty.c
index bde04e3..046efe3 100644 (file)
@@ -1,17 +1,17 @@
 /*
 /*
- * Copyright (c) 1980, 1989 Regents of the University of California.
+ * Copyright (c) 1980, 1989, 1991 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
 
 #ifndef lint
 char copyright[] =
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1980, 1989 Regents of the University of California.\n\
+"@(#) Copyright (c) 1980, 1989, 1991 Regents of the University of California.\n\
  All rights reserved.\n";
 #endif not lint
 
 #ifndef lint
  All rights reserved.\n";
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)stty.c     5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)stty.c     5.19 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -170,6 +170,10 @@ struct modes lmodes[] = {
        "-crt",         ECHOK, ECHOE|ECHOKE|ECHOCTL,
        "newcrt",       ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
        "-newcrt",      ECHOK, ECHOE|ECHOKE|ECHOCTL, 
        "-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,
        0
 };
 
        0
 };
 
@@ -203,17 +207,17 @@ struct {
        {{ "stop", "stop", "xoff" },    VSTOP,  CSTOP, },
        {{ "start", "star", "xon" },    VSTART, CSTART, },
        {{ "lnext", "lnxt" },           VLNEXT, CLNEXT, },
        {{ "stop", "stop", "xoff" },    VSTOP,  CSTOP, },
        {{ "start", "star", "xon" },    VSTART, CSTART, },
        {{ "lnext", "lnxt" },           VLNEXT, CLNEXT, },
-       {{ "flusho", "fls", "flush" },  VFLUSHO, CFLUSHO, },
+       {{ "discard", "disc", "flush" },        VDISCARD, CDISCARD, },
        {{ "reprint", "rpnt", "rprnt" },        VREPRINT, CREPRINT, },
        {{ "reprint", "rpnt", "rprnt" },        VREPRINT, CREPRINT, },
-       {{ "info", "info" },            VINFO, CINFO, },
+       {{ "status", "stat" },          VSTATUS, CSTATUS, },
        0
 };
 
 struct winsize win;
 int ldisc;
        0
 };
 
 struct winsize win;
 int ldisc;
-int dodisc;
 int debug = 0;
 int trace, dotrace;
 int debug = 0;
 int trace, dotrace;
+int extproc;
 
 #define OUT    stdout          /* informational output stream */
 #define ERR    stderr          /* error message stream */
 
 #define OUT    stdout          /* informational output stream */
 #define ERR    stderr          /* error message stream */
@@ -225,8 +229,7 @@ extern errno;
 #define NORMAL 0       /* only print modes differing from defaults */
 #define ALL    1       /* print all modes - POSIX standard format */
 #define ALL_BSD        2       /* print all modes - using BSD shorthand for cc's */
 #define NORMAL 0       /* only print modes differing from defaults */
 #define ALL    1       /* print all modes - POSIX standard format */
 #define ALL_BSD        2       /* print all modes - using BSD shorthand for cc's */
-#define GFMT   3       /* print modes in a form that can be re-input to stty */
-
+#define        GFMT    3       /* print modes in form suitable to be re-input */
 
 main(argc, argv) 
        char *argv[];
 
 main(argc, argv) 
        char *argv[];
@@ -242,6 +245,10 @@ main(argc, argv)
                fmt = ALL;
                argc--, argv++;
        }
                fmt = ALL;
                argc--, argv++;
        }
+       if (argc > 0 && eq(argv[0], "-g")) {
+               fmt = GFMT;
+               argc--, argv++;
+       }
        if (argc > 0 && eq(argv[0], "-f")) {
                argc--, argv++;
                if ((ctl = open(argv[0], O_RDONLY | O_NONBLOCK)) < 0)
        if (argc > 0 && eq(argv[0], "-f")) {
                argc--, argv++;
                if ((ctl = open(argv[0], O_RDONLY | O_NONBLOCK)) < 0)
@@ -259,9 +266,6 @@ main(argc, argv)
        if (argc == 0 || fmt) {
                prmode(&t, ldisc, fmt);
                exit(0);
        if (argc == 0 || fmt) {
                prmode(&t, ldisc, fmt);
                exit(0);
-       } else if (argc == 1 && strlen(argv[0]) > 2 && *(argv[0]+2) == ':') {
-               gfmtset(argv[0]);
-               goto setit;
        }
        
        while (*argv) {
        }
        
        while (*argv) {
@@ -273,10 +277,11 @@ main(argc, argv)
                        prmode(&t, ldisc, ALL);
                        exit(0);
                }
                        prmode(&t, ldisc, ALL);
                        exit(0);
                }
-               if (eq("old", *argv)) {
-                       goto next;
-               }
-               if (eq("new", *argv)) {
+               if (eq("tty", *argv) || eq("old", *argv) || eq("new", *argv)) {
+                       int nldisc = TTYDISC;
+
+                       if (ioctl(0, TIOCSETD, &nldisc) < 0)
+                               syserrexit("TIOCSETD");
                        goto next;
                }
                if (eq("nl", *argv)) {
                        goto next;
                }
                if (eq("nl", *argv)) {
@@ -304,8 +309,14 @@ main(argc, argv)
                        t.c_cflag |= CS8;
                        goto next;
                }
                        t.c_cflag |= CS8;
                        goto next;
                }
+               if (eq("cbreak", *argv)) {
+                       t.c_iflag |  BRKINT|IXON|IMAXBEL;
+                       t.c_oflag |= OPOST;
+                       t.c_lflag |= ISIG|IEXTEN;
+                       t.c_lflag &= ~ICANON;
+               }
                if (eq("cooked", *argv) || eq("-raw", *argv) ||
                if (eq("cooked", *argv) || eq("-raw", *argv) ||
-                   eq("sane", *argv)) {
+                   eq("sane", *argv) || eq("-cbreak", *argv)) {
                        t.c_cflag = TTYDEF_CFLAG | (t.c_cflag & CLOCAL);
                        t.c_iflag = TTYDEF_IFLAG;
                        t.c_iflag |= ICRNL;
                        t.c_cflag = TTYDEF_CFLAG | (t.c_cflag & CLOCAL);
                        t.c_iflag = TTYDEF_IFLAG;
                        t.c_iflag |= ICRNL;
@@ -344,6 +355,13 @@ main(argc, argv)
                        put("%d %d\n", win.ws_row, win.ws_col);
                        exit(0);
                }
                        put("%d %d\n", win.ws_row, win.ws_col);
                        exit(0);
                }
+               if (eq("extrpc", *argv) || eq("-extproc", *argv)) {
+                       if (**argv == '-')
+                               extproc = 0;
+                       else
+                               extproc = 1;
+                       ioctl(ctl, TIOCEXT, &extproc);
+               }
                if (eq("speed", *argv)) {
                        put("%d\n", cfgetospeed(&t));
                        exit(0);
                if (eq("speed", *argv)) {
                        put("%d\n", cfgetospeed(&t));
                        exit(0);
@@ -400,6 +418,10 @@ main(argc, argv)
                        cfsetispeed(&t, atoi(*argv));
                        goto next;
                }
                        cfsetispeed(&t, atoi(*argv));
                        goto next;
                }
+               if (strncmp(*argv, "-gfmt", sizeof ("-gfmt") - 1) == 0) {
+                       gfmtset(&t, *argv);
+                       goto next;
+               }
                /* didn't match anything */
                errexit("unknown option: %s", *argv);
                exit(1);
                /* didn't match anything */
                errexit("unknown option: %s", *argv);
                exit(1);
@@ -415,7 +437,60 @@ setit:
        exit(0);
 }
 
        exit(0);
 }
 
-gfmtset() {
+gfmtset(tp, s) 
+       register struct termios *tp;
+       char *s;
+{
+       register int cnt;
+       char sep;
+       char *saves = s;
+       int cval;
+#define advance(c)     while (*(s) && *(s) != (c)) (s)++; if (*s) (s)++ ; \
+                               else \
+                                       errexit("bad gfmt operand: %s", saves)
+#define chkeq(string)  if (strncmp(s, (string), strlen(string))) \
+                               errexit("bad gfmt operand: %s", saves)
+
+       if (s == NULL)
+               errexit("missing gfmt string");
+       advance(':');
+       chkeq("iflag=");
+       advance('=');
+       sscanf(s, "%x", &tp->c_iflag);
+
+       advance(':');
+       chkeq("oflag");
+       advance('=');
+       sscanf(s, "%x", &tp->c_oflag);
+
+       advance(':');
+       chkeq("cflag");
+       advance('=');
+       sscanf(s, "%x", &tp->c_cflag);
+
+       advance(':');
+       chkeq("lflag");
+       advance('=');
+       sscanf(s, "%x", &tp->c_lflag);
+
+       advance(':');
+       chkeq("cc=");
+
+       for (cnt = 0, sep = '='; cnt < NCCS; cnt++, sep = ',') {
+               advance(sep);
+               sscanf(s, "%o", &cval);
+               tp->c_cc[cnt] = cval;
+       }
+
+       advance(':');
+       chkeq("ispeed=");
+       advance('=');
+       sscanf(s, "%d", &tp->c_ispeed);
+
+       advance(':');
+       chkeq("ospeed=");
+       advance('=');
+       sscanf(s, "%d", &tp->c_ospeed);
 }
 
 prmode(tp, ldisc, fmt)
 }
 
 prmode(tp, ldisc, fmt)
@@ -431,8 +506,19 @@ prmode(tp, ldisc, fmt)
        char    unknown[32],
                *ld;
        char *ccval();
        char    unknown[32],
                *ld;
        char *ccval();
-       
 
 
+       if (fmt == GFMT) {
+               int     cnt;
+               char    sep;
+
+               printf("-gfmt:iflag=%x:oflag=%x:cflag=%x:lflag=%x:cc",
+                       i, o, c, l);
+               for (cnt = 0, sep = '='; cnt < NCCS; cnt++, sep = ',')
+                       printf("%c%o", sep, cc[cnt]);
+               printf(":ispeed=%d:ospeed=%d:\n", ispeed, ospeed);
+               return;
+       }
+       
        /*
         * line discipline
         */
        /*
         * line discipline
         */
@@ -447,6 +533,7 @@ prmode(tp, ldisc, fmt)
                default:        
                        sprintf(unknown, "#%d", ldisc);
                        ld = unknown;
                default:        
                        sprintf(unknown, "#%d", ldisc);
                        ld = unknown;
+                       break;
                }
                put("%s disc; ", ld);
        }
                }
                put("%s disc; ", ld);
        }
@@ -484,6 +571,8 @@ prmode(tp, ldisc, fmt)
        lput("-mdmbuf ",MDMBUF, 0);
        lput("-flusho ",FLUSHO, 0);
        lput("-pendin ",PENDIN, 0);
        lput("-mdmbuf ",MDMBUF, 0);
        lput("-flusho ",FLUSHO, 0);
        lput("-pendin ",PENDIN, 0);
+       lput("-nokerninfo ",NOKERNINFO, 0);
+       lput("-extproc ",EXTPROC, 0);
        /*
         * input flags
         */
        /*
         * input flags
         */