From owner-svn-src-head@FreeBSD.ORG Wed Jul 3 20:28:34 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 788087F9; Wed, 3 Jul 2013 20:28:34 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 5A8A61624; Wed, 3 Jul 2013 20:28:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r63KSYNW004380; Wed, 3 Jul 2013 20:28:34 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r63KSYqA004379; Wed, 3 Jul 2013 20:28:34 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201307032028.r63KSYqA004379@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Wed, 3 Jul 2013 20:28:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252596 - head/usr.bin/rwho X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jul 2013 20:28:34 -0000 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 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 #include -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))); }