Author: pjd
Date: Wed Jul  3 20:28:33 2013
New Revision: 252596
URL: http://svnweb.freebsd.org/changeset/base/252596

Log:
  Style cleanups.
  
  Submitted by: Mariusz Zaborski <osho...@freebsd.org>
  Sponsored by: Google Summer of Code 2013
  Reviewed by:  pjd
  MFC after:    1 month

Modified:
  head/usr.bin/rwho/rwho.c

Modified: head/usr.bin/rwho/rwho.c
==============================================================================
--- head/usr.bin/rwho/rwho.c    Wed Jul  3 20:24:37 2013        (r252595)
+++ head/usr.bin/rwho/rwho.c    Wed Jul  3 20:28:33 2013        (r252596)
@@ -1,6 +1,6 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
+/*-
+ * Copyright (c) 1983, 1993 The Regents of the University of California.
+ * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -58,22 +58,21 @@ __FBSDID("$FreeBSD$");
 #include <timeconv.h>
 #include <unistd.h>
 
-static DIR     *dirp;
+#define        NUSERS          1000
+#define        WHDRSIZE        (ssize_t)(sizeof (wd) - sizeof (wd.wd_we))
+/*
+ * this macro should be shared with ruptime.
+ */
+#define        down(w,now)     ((now) - (w)->wd_recvtime > 11 * 60)
 
+static DIR     *dirp;
 static struct  whod wd;
-#define        NUSERS  1000
+static int     nusers;
 static struct  myutmp {
        char    myhost[sizeof(wd.wd_hostname)];
        int     myidle;
        struct  outmp myutmp;
 } myutmp[NUSERS];
-static int     nusers;
-
-#define        WHDRSIZE        (ssize_t)(sizeof (wd) - sizeof (wd.wd_we))
-/*
- * this macro should be shared with ruptime.
- */
-#define        down(w,now)     ((now) - (w)->wd_recvtime > 11 * 60)
 
 static time_t  now;
 static int     aflg;
@@ -88,17 +87,18 @@ main(int argc, char *argv[])
        struct dirent *dp;
        int width;
        ssize_t cc;
-       register struct whod *w = &wd;
-       register struct whoent *we;
-       register struct myutmp *mp;
+       struct whod *w;
+       struct whoent *we;
+       struct myutmp *mp;
        int f, n, i;
        int d_first;
 
+       w = &wd;
        (void) setlocale(LC_TIME, "");
        d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
 
-       while ((ch = getopt(argc, argv, "a")) != -1)
-               switch((char)ch) {
+       while ((ch = getopt(argc, argv, "a")) != -1) {
+               switch ((char)ch) {
                case 'a':
                        aflg = 1;
                        break;
@@ -106,6 +106,7 @@ main(int argc, char *argv[])
                default:
                        usage();
                }
+       }
        argc -= optind;
        argv += optind;
 
@@ -115,9 +116,9 @@ main(int argc, char *argv[])
        if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
                err(1, "%s", _PATH_RWHODIR);
        mp = myutmp;
-       (void)time(&now);
-       while ((dp = readdir(dirp))) {
-               if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
+       (void) time(&now);
+       while ((dp = readdir(dirp)) != NULL) {
+               if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5) != 0)
                        continue;
                f = open(dp->d_name, O_RDONLY);
                if (f < 0)
@@ -127,22 +128,25 @@ main(int argc, char *argv[])
                        (void) close(f);
                        continue;
                }
-               if (down(w,now)) {
+               if (down(w,now) != 0) {
                        (void) close(f);
                        continue;
                }
                cc -= WHDRSIZE;
                we = w->wd_we;
                for (n = cc / sizeof (struct whoent); n > 0; n--) {
-                       if (aflg == 0 && we->we_idle >= 60*60) {
+                       if (aflg == 0 && we->we_idle >= 60 * 60) {
                                we++;
                                continue;
                        }
                        if (nusers >= NUSERS)
                                errx(1, "too many users");
-                       mp->myutmp = we->we_utmp; mp->myidle = we->we_idle;
+                       mp->myutmp = we->we_utmp;
+                       mp->myidle = we->we_idle;
                        (void) strcpy(mp->myhost, w->wd_hostname);
-                       nusers++; we++; mp++;
+                       nusers++;
+                       we++;
+                       mp++;
                }
                (void) close(f);
        }
@@ -151,7 +155,9 @@ main(int argc, char *argv[])
        width = 0;
        for (i = 0; i < nusers; i++) {
                /* append one for the blank and use 8 for the out_line */
-               int j = strlen(mp->myhost) + 1 + sizeof(mp->myutmp.out_line);
+               int j;
+
+               j = strlen(mp->myhost) + 1 + sizeof(mp->myutmp.out_line);
                if (j > width)
                        width = j;
                mp++;
@@ -159,31 +165,33 @@ main(int argc, char *argv[])
        mp = myutmp;
        for (i = 0; i < nusers; i++) {
                char buf[BUFSIZ], cbuf[80];
-               time_t t = _int_to_time(mp->myutmp.out_time);
+               time_t t;
 
+               t = _int_to_time(mp->myutmp.out_time);
                strftime(cbuf, sizeof(cbuf),
-                        d_first ? "%e %b %R" : "%b %e %R",
-                        localtime(&t));
-               (void)sprintf(buf, "%s:%-.*s", mp->myhost,
-                  (int)sizeof(mp->myutmp.out_line), mp->myutmp.out_line);
+                   d_first ? "%e %b %R" : "%b %e %R",
+                   localtime(&t));
+               (void) sprintf(buf, "%s:%-.*s", mp->myhost,
+                   (int)sizeof(mp->myutmp.out_line), mp->myutmp.out_line);
                printf("%-*.*s %-*s %s",
-                  (int)sizeof(mp->myutmp.out_name),
-                  (int)sizeof(mp->myutmp.out_name),
-                  mp->myutmp.out_name,
-                  width,
-                  buf,
-                  cbuf);
+                   (int)sizeof(mp->myutmp.out_name),
+                   (int)sizeof(mp->myutmp.out_name),
+                   mp->myutmp.out_name,
+                   width,
+                   buf,
+                   cbuf);
                mp->myidle /= 60;
-               if (mp->myidle) {
-                       if (aflg) {
-                               if (mp->myidle >= 100*60)
-                                       mp->myidle = 100*60 - 1;
+               if (mp->myidle != 0) {
+                       if (aflg != 0) {
+                               if (mp->myidle >= 100 * 60)
+                                       mp->myidle = 100 * 60 - 1;
                                if (mp->myidle >= 60)
                                        printf(" %2d", mp->myidle / 60);
                                else
                                        printf("   ");
-                       } else
+                       } else {
                                printf(" ");
+                       }
                        printf(":%02d", mp->myidle % 60);
                }
                printf("\n");
@@ -208,12 +216,12 @@ utmpcmp(const void *u1, const void *u2)
        int rc;
 
        rc = strncmp(MYUTMP(u1)->myutmp.out_name, MYUTMP(u2)->myutmp.out_name,
-               sizeof(MYUTMP(u2)->myutmp.out_name));
-       if (rc)
+           sizeof(MYUTMP(u2)->myutmp.out_name));
+       if (rc != 0)
                return (rc);
        rc = strcmp(MYUTMP(u1)->myhost, MYUTMP(u2)->myhost);
-       if (rc)
+       if (rc != 0)
                return (rc);
        return (strncmp(MYUTMP(u1)->myutmp.out_line, 
MYUTMP(u2)->myutmp.out_line,
-               sizeof(MYUTMP(u2)->myutmp.out_line)));
+           sizeof(MYUTMP(u2)->myutmp.out_line)));
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to