typo
[unix-history] / usr / src / usr.bin / ruptime / ruptime.c
index 11d9345..1c2e737 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)ruptime.c  4.14 (Berkeley) 83/07/01";
+static char sccsid[] = "@(#)ruptime.c  4.16 (Berkeley) 83/11/17";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -7,7 +7,7 @@ static char sccsid[] = "@(#)ruptime.c   4.14 (Berkeley) 83/07/01";
 #include <sys/dir.h>
 #include "../etc/rwhod/rwhod.h"
 
 #include <sys/dir.h>
 #include "../etc/rwhod/rwhod.h"
 
-DIR    *etc;
+DIR    *dirp;
 
 #define        NHOSTS  100
 int    nhosts;
 
 #define        NHOSTS  100
 int    nhosts;
@@ -25,8 +25,9 @@ char  *interval();
 int    now;
 char   *malloc(), *sprintf();
 int    aflg;
 int    now;
 char   *malloc(), *sprintf();
 int    aflg;
+int    rflg = 1;
 
 
-#define down(h)                (now - (h)->hs_wd->wd_recvtime > 5 * 60)
+#define down(h)                (now - (h)->hs_wd->wd_recvtime > 11 * 60)
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -35,45 +36,50 @@ main(argc, argv)
        struct direct *dp;
        int f, i, t;
        char buf[BUFSIZ]; int cc;
        struct direct *dp;
        int f, i, t;
        char buf[BUFSIZ]; int cc;
+       char *name;
        register struct hs *hsp = hs;
        register struct whod *wd;
        register struct whoent *we;
        int maxloadav = 0;
        int (*cmp)() = hscmp;
 
        register struct hs *hsp = hs;
        register struct whod *wd;
        register struct whoent *we;
        int maxloadav = 0;
        int (*cmp)() = hscmp;
 
+       name = *argv;
+       while (*++argv) 
+               while (**argv)
+                       switch (*(*argv)++) {
+                       case 'a':
+                               aflg++;
+                               break;
+                       case 'l':
+                               cmp = lcmp;
+                               break;
+                       case 'u':
+                               cmp = ucmp;
+                               break;
+                       case 't':
+                               cmp = tcmp;
+                               break;
+                       case 'r':
+                               rflg = -rflg;
+                               break;
+                       case '-':
+                               break;
+                       default: 
+                               fprintf(stderr, "Usage: %s [ -ar [ lut ] ]\n",
+                                       name);
+                               exit (1);
+                       }
        time(&t);
        time(&t);
-       argc--, argv++;
-again:
-       if (argc && !strcmp(*argv, "-a")) {
-               aflg++;
-               argc--, argv++;
-               goto again;
-       }
-       if (argc && !strcmp(*argv, "-l")) {
-               cmp = lcmp;
-               argc--, argv++;
-               goto again;
-       }
-       if (argc && !strcmp(*argv, "-u")) {
-               cmp = ucmp;
-               argc--, argv++;
-               goto again;
-       }
-       if (argc && !strcmp(*argv, "-t")) {
-               cmp = tcmp;
-               argc--, argv++;
-               goto again;
-       }
        if (chdir(RWHODIR) < 0) {
                perror(RWHODIR);
                exit(1);
        }
        if (chdir(RWHODIR) < 0) {
                perror(RWHODIR);
                exit(1);
        }
-       etc = opendir(".");
-       if (etc == NULL) {
-               perror("/etc");
+       dirp = opendir(".");
+       if (dirp == NULL) {
+               perror(RWHODIR);
                exit(1);
        }
                exit(1);
        }
-       while (dp = readdir(etc)) {
+       while (dp = readdir(dirp)) {
                if (dp->d_ino == 0)
                        continue;
                if (strncmp(dp->d_name, "whod.", 5))
                if (dp->d_ino == 0)
                        continue;
                if (strncmp(dp->d_name, "whod.", 5))
@@ -160,7 +166,7 @@ hscmp(h1, h2)
        struct hs *h1, *h2;
 {
 
        struct hs *h1, *h2;
 {
 
-       return (strcmp(h1->hs_wd->wd_hostname, h2->hs_wd->wd_hostname));
+       return (rflg * strcmp(h1->hs_wd->wd_hostname, h2->hs_wd->wd_hostname));
 }
 
 /*
 }
 
 /*
@@ -174,11 +180,12 @@ lcmp(h1, h2)
                if (down(h2))
                        return (tcmp(h1, h2));
                else
                if (down(h2))
                        return (tcmp(h1, h2));
                else
-                       return (1);
+                       return (rflg);
        else if (down(h2))
        else if (down(h2))
-               return (-1);
+               return (-rflg);
        else
        else
-               return (h2->hs_wd->wd_loadav[0] - h1->hs_wd->wd_loadav[0]);
+               return (rflg * 
+                       (h2->hs_wd->wd_loadav[0] - h1->hs_wd->wd_loadav[0]));
 }
 
 /*
 }
 
 /*
@@ -192,11 +199,11 @@ ucmp(h1, h2)
                if (down(h2))
                        return (tcmp(h1, h2));
                else
                if (down(h2))
                        return (tcmp(h1, h2));
                else
-                       return (1);
+                       return (rflg);
        else if (down(h2))
        else if (down(h2))
-               return (-1);
+               return (-rflg);
        else
        else
-               return (h2->hs_nusers - h1->hs_nusers);
+               return (rflg * (h2->hs_nusers - h1->hs_nusers));
 }
 
 /*
 }
 
 /*
@@ -207,11 +214,11 @@ tcmp(h1, h2)
 {
        long t1, t2;
 
 {
        long t1, t2;
 
-       return (
+       return (rflg * (
                (down(h2) ? h2->hs_wd->wd_recvtime - now
                          : h2->hs_wd->wd_sendtime - h2->hs_wd->wd_boottime)
                -
                (down(h1) ? h1->hs_wd->wd_recvtime - now
                          : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_boottime)
                (down(h2) ? h2->hs_wd->wd_recvtime - now
                          : h2->hs_wd->wd_sendtime - h2->hs_wd->wd_boottime)
                -
                (down(h1) ? h1->hs_wd->wd_recvtime - now
                          : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_boottime)
-       );
+       ));
 }
 }