use the cchars1 array instead of listing the options
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 28 Mar 1994 23:20:17 +0000 (15:20 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 28 Mar 1994 23:20:17 +0000 (15:20 -0800)
From: Charles Hannum <mycroft@sun-lamp.cs.berkeley.edu>

SCCS-vsn: bin/stty/gfmt.c 8.4

usr/src/bin/stty/gfmt.c

index 665afba..339240c 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.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -41,12 +41,12 @@ gread(tp, s)
        char *s;
 {
        register char *ep, *p;
        char *s;
 {
        register char *ep, *p;
+       register struct cchar *cp;
        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 +54,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,40 +82,15 @@ 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);
        }
 }
 
        }
 }