Module Name:    src
Committed By:   dholland
Date:           Sun Apr 20 23:31:40 UTC 2014

Modified Files:
        src/bin/ps: ps.c

Log Message:
Don't bother using variables whose value is never changed from the
initialization value.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/bin/ps/ps.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/ps/ps.c
diff -u src/bin/ps/ps.c:1.80 src/bin/ps/ps.c:1.81
--- src/bin/ps/ps.c:1.80	Wed Feb 19 20:42:14 2014
+++ src/bin/ps/ps.c	Sun Apr 20 23:31:40 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ps.c,v 1.80 2014/02/19 20:42:14 dsl Exp $	*/
+/*	$NetBSD: ps.c,v 1.81 2014/04/20 23:31:40 dholland Exp $	*/
 
 /*
  * Copyright (c) 2000-2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
 #if 0
 static char sccsid[] = "@(#)ps.c	8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: ps.c,v 1.80 2014/02/19 20:42:14 dsl Exp $");
+__RCSID("$NetBSD: ps.c,v 1.81 2014/04/20 23:31:40 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -199,7 +199,7 @@ main(int argc, char *argv[])
 	struct kinfo_lwp *kl, *l;
 	int ch, i, j, fmt, lineno, nentries, nlwps;
 	long long flag;
-	int prtheader, wflag, what, xflg, mode, showlwps;
+	int prtheader, wflag, what, xflg, showlwps;
 	char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
 	char *ttname;
 
@@ -221,7 +221,7 @@ main(int argc, char *argv[])
 	what = KERN_PROC_UID;
 	flag = myuid = getuid();
 	memf = nlistf = swapf = NULL;
-	mode = PRINTMODE;
+
 	while ((ch = getopt(argc, argv, GETOPTSTR)) != -1)
 		switch((char)ch) {
 		case 'A':
@@ -421,33 +421,32 @@ main(int argc, char *argv[])
 	 * "setwidth" mode to determine the widest element of
 	 * the column.
 	 */
-	if (mode == PRINTMODE)
-		for (i = 0; i < nentries; i++) {
-			struct kinfo_proc2 *ki = &kinfo[i];
-
-			if (xflg == 0 && (ki->p_tdev == (uint32_t)NODEV ||
-			    (ki->p_flag & P_CONTROLT) == 0))
-				continue;
-
-			kl = kvm_getlwps(kd, ki->p_pid, ki->p_paddr,
-			    sizeof(struct kinfo_lwp), &nlwps);
-			if (kl == 0)
-				nlwps = 0;
-			if (showlwps == 0) {
-				l = pick_representative_lwp(ki, kl, nlwps);
-				SIMPLEQ_FOREACH(vent, &displaylist, next)
-					OUTPUT(vent, ki, l, WIDTHMODE);
-			} else {
-				/* The printing is done with the loops
-				 * reversed, but here we don't need that,
-				 * and this improves the code locality a bit.
-				 */
-				SIMPLEQ_FOREACH(vent, &displaylist, next)
-					for (j = 0; j < nlwps; j++)
-						OUTPUT(vent, ki, &kl[j],
-						    WIDTHMODE);
-			}
+
+	for (i = 0; i < nentries; i++) {
+		struct kinfo_proc2 *ki = &kinfo[i];
+
+		if (xflg == 0 && (ki->p_tdev == (uint32_t)NODEV ||
+		    (ki->p_flag & P_CONTROLT) == 0))
+			continue;
+
+		kl = kvm_getlwps(kd, ki->p_pid, ki->p_paddr,
+		    sizeof(struct kinfo_lwp), &nlwps);
+		if (kl == 0)
+			nlwps = 0;
+		if (showlwps == 0) {
+			l = pick_representative_lwp(ki, kl, nlwps);
+			SIMPLEQ_FOREACH(vent, &displaylist, next)
+				OUTPUT(vent, ki, l, WIDTHMODE);
+		} else {
+			/* The printing is done with the loops
+			 * reversed, but here we don't need that,
+			 * and this improves the code locality a bit.
+			 */
+			SIMPLEQ_FOREACH(vent, &displaylist, next)
+				for (j = 0; j < nlwps; j++)
+					OUTPUT(vent, ki, &kl[j], WIDTHMODE);
 		}
+	}
 	/*
 	 * Print header - AFTER determining process field widths.
 	 * printheader() also adds up the total width of all
@@ -471,7 +470,7 @@ main(int argc, char *argv[])
 		if (showlwps == 0) {
 			l = pick_representative_lwp(ki, kl, nlwps);
 			SIMPLEQ_FOREACH(vent, &displaylist, next) {
-				OUTPUT(vent, ki, l, mode);
+				OUTPUT(vent, ki, l, PRINTMODE);
 				if (SIMPLEQ_NEXT(vent, next) != NULL)
 					(void)putchar(' ');
 			}
@@ -484,7 +483,7 @@ main(int argc, char *argv[])
 		} else {
 			for (j = 0; j < nlwps; j++) {
 				SIMPLEQ_FOREACH(vent, &displaylist, next) {
-					OUTPUT(vent, ki, &kl[j], mode);
+					OUTPUT(vent, ki, &kl[j], PRINTMODE);
 					if (SIMPLEQ_NEXT(vent, next) != NULL)
 						(void)putchar(' ');
 				}

Reply via email to