prettyness police
[unix-history] / usr / src / bin / stty / gfmt.c
index 665afba..c29a96c 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)gfmt.c     8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)gfmt.c     8.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -18,7 +18,15 @@ static char sccsid[] = "@(#)gfmt.c   8.3 (Berkeley) %G%";
 #include "stty.h"
 #include "extern.h"
 
 #include "stty.h"
 #include "extern.h"
 
-static void gerr __P((char *));
+static void
+gerr(s)
+       char *s;
+{
+       if (s)
+               errx(1, "illegal gfmt1 option -- %s", s);
+       else
+               errx(1, "illegal gfmt1 option");
+}
 
 void
 gprint(tp, wp, ldisc)
 
 void
 gprint(tp, wp, ldisc)
@@ -26,7 +34,7 @@ gprint(tp, wp, ldisc)
        struct winsize *wp;
        int ldisc;
 {
        struct winsize *wp;
        int ldisc;
 {
-       register struct cchar *cp;
+       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);
 
        (void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
            tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
@@ -37,16 +45,16 @@ gprint(tp, wp, ldisc)
 
 void
 gread(tp, s) 
 
 void
 gread(tp, s) 
-       register struct termios *tp;
+       struct termios *tp;
        char *s;
 {
        char *s;
 {
-       register char *ep, *p;
+       struct cchar *cp;
+       char *ep, *p;
        long tmp;
 
        long tmp;
 
-#define        CHK(s)  (*p == s[0] && !strcmp(p, s))
-       if (!(s = strchr(s, ':')))
+       if ((s = strchr(s, ':')) == NULL)
                gerr(NULL);
                gerr(NULL);
-       for (++s; s;) {
+       for (++s; s != NULL;) {
                p = strsep(&s, ":\0");
                if (!p || !*p)
                        break;
                p = strsep(&s, ":\0");
                if (!p || !*p)
                        break;
@@ -54,64 +62,25 @@ gread(tp, s)
                        gerr(p);
                *ep++ = '\0';
                (void)sscanf(ep, "%lx", &tmp);
                        gerr(p);
                *ep++ = '\0';
                (void)sscanf(ep, "%lx", &tmp);
+
+#define        CHK(s)  (*p == s[0] && !strcmp(p, s))
                if (CHK("cflag")) {
                        tp->c_cflag = tmp;
                        continue;
                }
                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("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("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("lflag")) {
                        tp->c_lflag = tmp;
                        continue;
                }
-               if (CHK("lnext")) {
-                       tp->c_cc[VLNEXT] = tmp;
-                       continue;
-               }
-               if (CHK("min")) {
-                       (void)sscanf(ep, "%ld", &tmp);
-                       tp->c_cc[VMIN] = tmp;
-                       continue;
-               }
                if (CHK("oflag")) {
                        tp->c_oflag = tmp;
                        continue;
                if (CHK("oflag")) {
                        tp->c_oflag = tmp;
                        continue;
@@ -121,49 +90,14 @@ gread(tp, s)
                        tp->c_ospeed = tmp;
                        continue;
                }
                        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("time")) {
-                       (void)sscanf(ep, "%ld", &tmp);
-                       tp->c_cc[VTIME] = tmp;
-                       continue;
-               }
-               if (CHK("werase")) {
-                       tp->c_cc[VWERASE] = tmp;
-                       continue;
-               }
-               gerr(p);
+               for (cp = cchars1; cp->name != NULL; ++cp)
+                       if (CHK(cp->name)) {
+                               if (cp->sub == VMIN || cp->sub == VTIME)
+                                       (void)sscanf(ep, "%ld", &tmp);
+                               tp->c_cc[cp->sub] = tmp;
+                               break;
+                       }
+               if (cp->name == NULL)
+                       gerr(p);
        }
 }
        }
 }
-
-static void
-gerr(s)
-       char *s;
-{
-       if (s)
-               errx(1, "illegal gfmt1 option -- %s", s);
-       else
-               errx(1, "illegal gfmt1 option");
-}