NULL-terminate cchar arrays for Chris; better information hiding
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 10 Jun 1991 22:39:47 +0000 (14:39 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 10 Jun 1991 22:39:47 +0000 (14:39 -0800)
SCCS-vsn: bin/stty/cchar.c 5.4
SCCS-vsn: bin/stty/extern.h 5.4
SCCS-vsn: bin/stty/gfmt.c 5.4
SCCS-vsn: bin/stty/key.c 5.3
SCCS-vsn: bin/stty/modes.c 5.4
SCCS-vsn: bin/stty/print.c 5.4
SCCS-vsn: bin/stty/stty.h 5.3

usr/src/bin/stty/cchar.c
usr/src/bin/stty/extern.h
usr/src/bin/stty/gfmt.c
usr/src/bin/stty/key.c
usr/src/bin/stty/modes.c
usr/src/bin/stty/print.c
usr/src/bin/stty/stty.h

index 212144b..bface5b 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cchar.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)cchar.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -40,7 +40,7 @@ struct cchar cchars1[] = {
        "stop",         VSTOP,          CSTOP,
        "susp",         VSUSP,          CSUSP,
        "werase",       VWERASE,        CWERASE,
        "stop",         VSTOP,          CSTOP,
        "susp",         VSUSP,          CSUSP,
        "werase",       VWERASE,        CWERASE,
-       "",                                             /* not NULL */
+       NULL,
 };
 
 struct cchar cchars2[] = {
 };
 
 struct cchar cchars2[] = {
@@ -49,7 +49,7 @@ struct cchar cchars2[] = {
        "rprnt",        VREPRINT,       CREPRINT,
        "xoff",         VSTOP,          CSTOP,
        "xon",          VSTART,         CSTART,
        "rprnt",        VREPRINT,       CREPRINT,
        "xoff",         VSTOP,          CSTOP,
        "xon",          VSTART,         CSTART,
-       "",                                             /* not NULL */
+       NULL,
 };
 
 csearch(argvp, ip)
 };
 
 csearch(argvp, ip)
@@ -66,9 +66,9 @@ csearch(argvp, ip)
 
        tmp.name = name;
        if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
 
        tmp.name = name;
        if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
-           sizeof(cchars1)/sizeof(struct cchar), sizeof(struct cchar),
+           sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
            c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
            c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
-           sizeof(cchars1)/sizeof(struct cchar), sizeof(struct cchar),
+           sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
            c_cchar)))
                return(0);
 
            c_cchar)))
                return(0);
 
index 8322c74..f745250 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)extern.h    5.3 (Berkeley) %G%
+ *     @(#)extern.h    5.4 (Berkeley) %G%
  */
 
 __BEGIN_DECLS
  */
 
 __BEGIN_DECLS
@@ -23,5 +23,4 @@ void  warn __P((const char *, ...));
 __END_DECLS
 
 extern struct cchar cchars1[], cchars2[];
 __END_DECLS
 
 extern struct cchar cchars1[], cchars2[];
-extern struct modes cmodes[], imodes[], lmodes[], omodes[];
 extern char *usage;
 extern char *usage;
index 8feb20d..438ab35 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)gfmt.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)gfmt.c     5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -27,7 +27,7 @@ gprint(tp, wp, ldisc)
 
        (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);
-       for (cp = cchars1; *cp->name; ++cp)
+       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)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
        (void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
 }
index 08edc5c..787eed3 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)key.c      5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)key.c      5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -35,7 +35,13 @@ void f_speed __P((struct info *));
 void   f_tty __P((struct info *));
 __END_DECLS
 
 void   f_tty __P((struct info *));
 __END_DECLS
 
-static struct key keys[] = {
+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,
        "all",          f_all,          0,
        "cbreak",       f_cbreak,       F_OFFOK,
        "cols",         f_columns,      F_NEEDARG,
index 4feb6f9..b26e946 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)modes.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)modes.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -14,6 +14,12 @@ static char sccsid[] = "@(#)modes.c  5.3 (Berkeley) %G%";
 #include <string.h>
 #include "stty.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".
 /*
  * The code in optlist() depends on minus options following regular
  * options, i.e. "foo" must immediately precede "-foo".
index 8690eff..cb159cc 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -144,7 +144,7 @@ print(tp, wp, ldisc, fmt)
        cc = tp->c_cc;
        if (fmt == POSIX) {
                binit("cchars");
        cc = tp->c_cc;
        if (fmt == POSIX) {
                binit("cchars");
-               for (p = cchars1; *p->name; ++p) {
+               for (p = cchars1; p->name; ++p) {
                        (void)snprintf(buf1, sizeof(buf1), "%s = %s;",
                            p->name, ccval(cc[p->sub]));
                        bput(buf1);
                        (void)snprintf(buf1, sizeof(buf1), "%s = %s;",
                            p->name, ccval(cc[p->sub]));
                        bput(buf1);
@@ -152,7 +152,7 @@ print(tp, wp, ldisc, fmt)
                binit(NULL);
        } else {
                binit(NULL);
                binit(NULL);
        } else {
                binit(NULL);
-               for (p = cchars1, cnt = 0; *p->name; ++p) {
+               for (p = cchars1, cnt = 0; p->name; ++p) {
                        if (fmt != BSD && cc[p->sub] == p->def)
                                continue;
 #define        WD      "%-8s"
                        if (fmt != BSD && cc[p->sub] == p->def)
                                continue;
 #define        WD      "%-8s"
index 47df4ed..f388d58 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)stty.h      5.2 (Berkeley) %G%
+ *     @(#)stty.h      5.3 (Berkeley) %G%
  */
 
 #include <sys/ioctl.h>
  */
 
 #include <sys/ioctl.h>
@@ -21,20 +21,6 @@ struct info {
        struct winsize win;                     /* window info */
 };
 
        struct winsize win;                     /* window info */
 };
 
-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;
-};
-
-struct modes {
-       char *name;
-       long set;
-       long unset;
-};
-
 struct cchar {
        char *name;
        int sub;
 struct cchar {
        char *name;
        int sub;