git: 04f6b9cb1822 - main - w: cosmetic fixes.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Fri, 21 Oct 2022 16:39:27 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=04f6b9cb1822fdd6ab1cbeeafb38a6b354b61ca7

commit 04f6b9cb1822fdd6ab1cbeeafb38a6b354b61ca7
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2022-10-21 16:37:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2022-10-21 16:37:44 +0000

    w: cosmetic fixes.
    
    Sponsored by:   Klara, Inc.
---
 usr.bin/w/pr_time.c |  2 +-
 usr.bin/w/w.c       | 51 +++++++++++++++++++++++++--------------------------
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c
index 13f3180d511b..20b75704c309 100644
--- a/usr.bin/w/pr_time.c
+++ b/usr.bin/w/pr_time.c
@@ -90,7 +90,7 @@ pr_attime(time_t *started, time_t *now)
 	if (len == width)
 		xo_emit("{:login-time/%-7.7ls/%ls}", buf);
 	else if (width < 7)
-	        xo_emit("{:login-time/%ls}%.*s", buf, 7 - width, "      ");
+		xo_emit("{:login-time/%ls}%.*s", buf, 7 - width, "      ");
 	else {
 		xo_emit("{:login-time/%ls}", buf);
 		offset = width - 7;
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 42874242c5ba..4199e64e90f6 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -95,9 +95,9 @@ static struct utmpx *utmp;
 static struct winsize ws;
 static kvm_t   *kd;
 static time_t	now;		/* the current time of day */
-static int	ttywidth;	/* width of tty */
-static int	fromwidth = 0;	/* max width of "from" field */
-static int	argwidth;	/* width of arguments */
+static size_t	ttywidth;	/* width of tty */
+static size_t	fromwidth = 0;	/* max width of "from" field */
+static size_t	argwidth;	/* width of arguments */
 static int	header = 1;	/* true if -h flag: don't print heading */
 static int	nflag;		/* true if -n flag: don't convert addrs */
 static int	dflag;		/* true if -d flag: output debug info */
@@ -140,11 +140,12 @@ main(int argc, char *argv[])
 	struct kinfo_proc *dkp;
 	struct stat *stp;
 	time_t touched;
+	size_t width;
 	int ch, i, nentries, nusers, wcmd, longidle, longattime;
 	const char *memf, *nlistf, *p, *save_p;
 	char *x_suffix;
-	char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX];
-	char fn[MAXHOSTNAMELEN];
+	char errbuf[_POSIX2_LINE_MAX];
+	char buf[MAXHOSTNAMELEN], fn[MAXHOSTNAMELEN];
 	char *dot;
 
 	(void)setlocale(LC_ALL, "");
@@ -188,7 +189,7 @@ main(int argc, char *argv[])
 			nflag += 1;
 			break;
 		case 'f': case 'l': case 's': case 'u': case 'w':
-			warnx("[-flsuw] no longer supported");
+			warnx("-%c no longer supported", ch);
 			/* FALLTHROUGH */
 		case '?':
 		default:
@@ -310,8 +311,8 @@ main(int argc, char *argv[])
 			p = buf;
 		}
 		ep->from = strdup(p);
-		if ((i = strlen(p)) > fromwidth)
-			fromwidth = i;
+		if ((width = strlen(p)) > fromwidth)
+			fromwidth = width;
 		if (save_p != p)
 			ep->save_from = strdup(save_p);
 	}
@@ -323,10 +324,9 @@ main(int argc, char *argv[])
 #define HEADER_LOGIN_IDLE	"LOGIN@  IDLE "
 #define HEADER_WHAT		"WHAT\n"
 #define WUSED  (W_DISPUSERSIZE + W_DISPLINESIZE + fromwidth + \
-		sizeof(HEADER_LOGIN_IDLE) + 3)	/* header width incl. spaces */ 
+		sizeof(HEADER_LOGIN_IDLE) + 3)	/* header width incl. spaces */
 
-
-	if ((int) sizeof(HEADER_FROM) > fromwidth)
+	if (sizeof(HEADER_FROM) > fromwidth)
 		fromwidth = sizeof(HEADER_FROM);
 	fromwidth++;
 	if (fromwidth > W_MAXHOSTSIZE)
@@ -339,12 +339,11 @@ main(int argc, char *argv[])
 		if (wcmd == 0) {
 			xo_close_container("uptime-information");
 			xo_finish();
-
 			(void)kvm_close(kd);
 			exit(0);
 		}
 
-		xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s}  {T:/%s}", 
+		xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s}  {T:/%s}",
 				W_DISPUSERSIZE, W_DISPUSERSIZE, HEADER_USER,
 				W_DISPLINESIZE, W_DISPLINESIZE, HEADER_TTY,
 				fromwidth, fromwidth, HEADER_FROM,
@@ -430,8 +429,8 @@ main(int argc, char *argv[])
 		xo_open_instance("user-entry");
 
 		if (dflag) {
-		        xo_open_container("process-table");
-		        xo_open_list("process-entry");
+			xo_open_container("process-table");
+			xo_open_list("process-entry");
 
 			for (dkp = ep->dkp; dkp != NULL; dkp = debugproc(dkp)) {
 				const char *ptr;
@@ -445,8 +444,8 @@ main(int argc, char *argv[])
 				    "{:command/%hs}\n", dkp->ki_pid, ptr);
 				xo_close_instance("process-entry");
 			}
-		        xo_close_list("process-entry");
-		        xo_close_container("process-table");
+			xo_close_list("process-entry");
+			xo_close_container("process-table");
 		}
 		xo_emit("{:user/%-*.*s/%@**@s} {:tty/%-*.*s/%@**@s} ",
 			W_DISPUSERSIZE, W_DISPUSERSIZE, ep->utmp.ut_user,
@@ -459,12 +458,12 @@ main(int argc, char *argv[])
 		if (ep->save_from)
 		    xo_attr("address", "%s", ep->save_from);
 		xo_emit("{:from/%-*.*s/%@**@s} ",
-		    fromwidth, fromwidth, ep->from);
+		    (int)fromwidth, (int)fromwidth, ep->from);
 		t = ep->utmp.ut_tv.tv_sec;
 		longattime = pr_attime(&t, &now);
 		longidle = pr_idle(ep->idle);
 		xo_emit("{:command/%.*hs/%@*@hs}\n",
-		    argwidth - longidle - longattime,
+		    (int)argwidth - longidle - longattime,
 		    ep->args);
 
 		xo_close_instance("user-entry");
@@ -510,8 +509,9 @@ pr_header(time_t *nowp, int nusers)
 		mins = uptime / 60;
 		secs = uptime % 60;
 		xo_emit(" up");
-		xo_emit("{e:uptime/%lu}", (unsigned long) tp.tv_sec);
-		xo_emit("{e:days/%d}{e:hours/%d}{e:minutes/%d}{e:seconds/%d}", days, hrs, mins, secs);
+		xo_emit("{e:uptime/%lu}", (unsigned long)tp.tv_sec);
+		xo_emit("{e:days/%d}{e:hours/%d}{e:minutes/%d}{e:seconds/%d}",
+		    days, hrs, mins, secs);
 
 		if (days > 0)
 			sbuf_printf(upbuf, " %d day%s,",
@@ -524,7 +524,7 @@ pr_header(time_t *nowp, int nusers)
 		else if (mins > 0)
 			sbuf_printf(upbuf, " %d min%s,",
 				mins, mins > 1 ? "s" : "");
-		else 
+		else
 			sbuf_printf(upbuf, " %d sec%s,",
 				secs, secs > 1 ? "s" : "");
 		if (sbuf_finish(upbuf) != 0)
@@ -542,7 +542,7 @@ pr_header(time_t *nowp, int nusers)
 	if (getloadavg(avenrun, nitems(avenrun)) == -1)
 		xo_emit(", no load average information available\n");
 	else {
-	        static const char *format[] = {
+		static const char *format[] = {
 		    " {:load-average-1/%.2f}",
 		    " {:load-average-5/%.2f}",
 		    " {:load-average-15/%.2f}",
@@ -564,10 +564,9 @@ ttystat(char *line)
 	char ttybuf[MAXPATHLEN];
 
 	(void)snprintf(ttybuf, sizeof(ttybuf), "%s%s", _PATH_DEV, line);
-	if (stat(ttybuf, &sb) == 0 && S_ISCHR(sb.st_mode)) {
+	if (stat(ttybuf, &sb) == 0 && S_ISCHR(sb.st_mode))
 		return (&sb);
-	} else
-		return (NULL);
+	return (NULL);
 }
 
 static void