Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat More cleanup -- use strtok() rather than roll...



details:   https://anonhg.NetBSD.org/src/rev/32dba52bb889
branches:  trunk
changeset: 479752:32dba52bb889
user:      jwise <jwise%NetBSD.org@localhost>
date:      Mon Dec 20 21:42:50 1999 +0000

description:
More cleanup -- use strtok() rather than rolling our own not-quite-correct version.

diffstat:

 usr.bin/systat/cmds.c |  37 +++++++++++++++++--------------------
 1 files changed, 17 insertions(+), 20 deletions(-)

diffs (81 lines):

diff -r b700d8b993d9 -r 32dba52bb889 usr.bin/systat/cmds.c
--- a/usr.bin/systat/cmds.c     Mon Dec 20 21:04:41 1999 +0000
+++ b/usr.bin/systat/cmds.c     Mon Dec 20 21:42:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.15 1999/12/20 04:06:25 jwise Exp $  */
+/*     $NetBSD: cmds.c,v 1.16 1999/12/20 21:42:50 jwise Exp $  */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.2 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: cmds.c,v 1.15 1999/12/20 04:06:25 jwise Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.16 1999/12/20 21:42:50 jwise Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -57,25 +57,22 @@
 {
        struct command *c;
        struct mode *p;
-       char *cp;
+       char *args;
        sigset_t set;
 
        sigemptyset(&set);
        sigaddset(&set, SIGALRM);
        sigprocmask(SIG_BLOCK, &set, NULL);
-       for (cp = cmd; *cp && !isspace((unsigned char)*cp); cp++)
-               ;
-       if (*cp)
-               *cp++ = '\0';
-       if (*cmd == '\0')
-               return;
-       for (; *cp && isspace((unsigned char)*cp); cp++)
-               ;
+
+       args = cmd;
+
+       args  = strtok(cmd, " \t");
+       args  = strtok(NULL, " \t");
 
        if (curmode->c_commands) {
                for (c = curmode->c_commands; c->c_name; c++) {
                        if (strcmp(cmd, c->c_name) == 0) {
-                               (c->c_cmd)(cp);
+                               (c->c_cmd)(args);
                                goto done;
                        }
                }
@@ -83,7 +80,14 @@
 
        for (c = global_commands; c->c_name; c++) {
                if (strcmp(cmd, c->c_name) == 0) {
-                       (c->c_cmd)(cp);
+                       (c->c_cmd)(args);
+                       goto done;
+               }
+       }
+
+       for (p = modes; p->c_name; p++) {
+               if (strcmp(cmd, p->c_name) == 0) {
+                       switch_mode(p);
                        goto done;
                }
        }
@@ -93,13 +97,6 @@
                goto done;
        }
 
-       for (p = modes; p->c_name; p++) {
-               if (strcmp(cmd, p->c_name) == 0) {
-                       switch_mode(p);
-                       goto done;
-               }
-       }
-
        error("%s: Unknown command.", cmd);
 done:
        sigprocmask(SIG_UNBLOCK, &set, NULL);



Home | Main Index | Thread Index | Old Index