Module Name:    src
Committed By:   mrg
Date:           Thu May 26 02:24:00 UTC 2022

Modified Files:
        src/usr.bin/w: w.1 w.c

Log Message:
default to not sorting tty names with alphabetical sort and add
a new -A switch to sort them again.

enable the sorting code if either utmp or utmpx are enabled,
not just both.  shouldn't matter as we enable both.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/w/w.1
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/w/w.c

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

Modified files:

Index: src/usr.bin/w/w.1
diff -u src/usr.bin/w/w.1:1.19 src/usr.bin/w/w.1:1.20
--- src/usr.bin/w/w.1:1.19	Thu Dec  6 19:15:35 2018
+++ src/usr.bin/w/w.1	Thu May 26 02:24:00 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: w.1,v 1.19 2018/12/06 19:15:35 sevan Exp $
+.\"	$NetBSD: w.1,v 1.20 2022/05/26 02:24:00 mrg Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)w.1	8.1 (Berkeley) 6/6/93
 .\"
-.Dd December 6, 2018
+.Dd May 25, 2022
 .Dt W 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd who present users are and what they are doing
 .Sh SYNOPSIS
 .Nm
-.Op Fl hinw
+.Op Fl Ahinw
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Op Ar user
@@ -61,6 +61,8 @@ and the name and arguments of the curren
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl A
+Sort tty names alphabetically, instead of utmp or utmpx order.
 .It Fl h
 Suppress the heading.
 .It Fl i
@@ -94,7 +96,9 @@ list of users on the system
 .Xr ps 1 ,
 .Xr uptime 1 ,
 .Xr who 1 ,
-.Xr getloadavg 3
+.Xr getloadavg 3 ,
+.Xr utmp 5 ,
+.Xr utmpx 5
 .Sh HISTORY
 The
 .Nm

Index: src/usr.bin/w/w.c
diff -u src/usr.bin/w/w.c:1.91 src/usr.bin/w/w.c:1.92
--- src/usr.bin/w/w.c:1.91	Sat Apr 17 06:14:15 2021
+++ src/usr.bin/w/w.c	Thu May 26 02:24:00 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: w.c,v 1.91 2021/04/17 06:14:15 maya Exp $	*/
+/*	$NetBSD: w.c,v 1.92 2022/05/26 02:24:00 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)w.c	8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.91 2021/04/17 06:14:15 maya Exp $");
+__RCSID("$NetBSD: w.c,v 1.92 2022/05/26 02:24:00 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -95,7 +95,8 @@ int		argwidth;	/* width of tty left to p
 int		header = 1;	/* true if -h flag: don't print heading */
 int		nflag;		/* true if -n flag: don't convert addrs */
 int		wflag;		/* true if -w flag: wide printout */
-int		sortidle;	/* sort bu idle time */
+int		sortidle;	/* sort by idle time */
+int		alphasort;	/* sort by tty alphabeta, not numeric */
 char	       *sel_user;	/* login of particular user selected */
 char		domain[MAXHOSTNAMELEN + 1];
 int maxname = 8, maxline = 3, maxhost = 16;
@@ -158,12 +159,15 @@ main(int argc, char **argv)
 		options = "";
 	} else {
 		wcmd = 1;
-		options = "hiM:N:nw";
+		options = "AhiM:N:nw";
 	}
 
 	memf = nlistf = NULL;
 	while ((ch = getopt(argc, argv, options)) != -1)
 		switch (ch) {
+		case 'A':
+			alphasort = 1;
+			break;
 		case 'h':
 			header = 0;
 			break;
@@ -382,8 +386,8 @@ main(int argc, char **argv)
 			*nextp = save;
 		}
 	}
-#if defined(SUPPORT_UTMP) && defined(SUPPORT_UTMPX)
-	else if (ehead != NULL) {
+#if defined(SUPPORT_UTMP) || defined(SUPPORT_UTMPX)
+	else if (ehead != NULL && alphasort) {
 		struct entry *from = ehead, *save;
 
 		ehead = NULL;

Reply via email to