Subject: typo fixes & improvement to finger
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Luke Mewburn <lm@rmit.edu.au>
List: current-users
Date: 06/06/1994 15:15:01
A long time ago I ported net/2 (actually netbsd 0.8) finger to Solaris 2.
In the process I added mail status reporting & hostname display so the
output would be similar to solaris'. At the time, I posted the diffs
for the former (mail status reporting.) for net/2 which has been
integrated into netbsd's finger.  A few months ago I kludged in the
hostname reporting. It was a cruddy way of doing it, and cgd didn't `buy
them back' when I submitted them.

So, I've cleaned up my patch. What it does is changes the default
short display from displaying office information to displaying remote
host info (which is much more useful; because that way you know if the
person is least idle from home or work, etc.)  Another change is that
if the login time is less than a week ago, it prints the name of the
day instead of it's date (e.g, `Fri' instead of `Jun 4'.) which,
again, I feel is better since I know what day it is but the date often
eludes me :)

Both of these ideas were from SunOS/Solaris. I know, NetBSD Is Not
SunOS but I feel that these cosmetic changes make finger more
presentable. You can get the old output back with -o (-h & -o toggle
host & office info.)

Here's a sample output:

---
lm@karybdis 60 ...local/src/finger> finger
Login    Name                 Tty  Idle   Login Time   Where
lm       Luke Mewburn          p0     -    Sun  23:13  goanna.cs.rmit.O
lm       Luke Mewburn          p2     -    Mon  14:33
simonb   Simon Burge           p1  1:05    Mon  13:38  149.135.252.11
lm@karybdis 61 ...local/src/finger> finger @karybdis
[karybdis.cs.rmit.OZ.AU]
Login    Name                 Tty  Idle   Login Time   Where
lm       Luke Mewburn          p0     -    Sun  23:13  goanna.cs.rmit.O
lm       Luke Mewburn          p2     -    Mon  14:33
simonb   Simon Burge           p1  1:05    Mon  13:38  149.135.252.11
lm@karybdis 62 ...local/src/finger> finger -o
Login    Name                 Tty  Idle   Login Time  Office     Office Phone
lm       Luke Mewburn          p0     -    Sun  23:13 10.10.16   x3210
lm       Luke Mewburn          p2     -    Mon  14:33 10.10.16   x3210
simonb   Simon Burge           p1  1:05    Mon  13:38 Telecom    634-3974
---
(Notice remote fingers have changed because finger has. Also, the
login time for myself was `Sun' (yesterday) which I can relate to
much easier than `Jun 5'.)


Patches follow:
--- cut here --- file: fingerdiff
diff -c -b /usr/src/usr.bin/finger/finger.1 finger/finger.1
*** /usr/src/usr.bin/finger/finger.1	Tue Feb 15 21:19:28 1994
--- finger/finger.1	Mon Jun  6 14:59:53 1994
***************
*** 32,38 ****
  .\"	from: @(#)finger.1	6.14 (Berkeley) 7/27/91
  .\"	$Id: finger.1,v 1.4 1994/02/14 19:07:33 cgd Exp $
  .\"
! .Dd July 27, 1991
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
--- 32,38 ----
  .\"	from: @(#)finger.1	6.14 (Berkeley) 7/27/91
  .\"	$Id: finger.1,v 1.4 1994/02/14 19:07:33 cgd Exp $
  .\"
! .Dd June 6, 1994
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
***************
*** 40,46 ****
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmsp
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
--- 40,46 ----
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmpsho
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
***************
*** 54,67 ****
  .Nm Finger
  displays the user's login name, real name, terminal name and write
  status (as a ``*'' before the terminal name if write permission is
! denied), idle time, login time, office location and office phone
! number.
  .Pp
  Idle time is in minutes if it is a single integer, hours and minutes
  if a ``:'' is present, or days if a ``d'' is present.
! Login time is displayed as month, day, hours and minutes, unless
! more than six months ago, in which case the year is displayed rather
! than the hours and minutes.
  .Pp
  Unknown devices as well as nonexistent idle and login times are
  displayed as single asterisks.
--- 54,72 ----
  .Nm Finger
  displays the user's login name, real name, terminal name and write
  status (as a ``*'' before the terminal name if write permission is
! denied), idle time, login time, and either office location and office
! phone number, or the remote host. If
! .Fl h
! is given, the remote host is printed (the default.) If
! .Fl o
! is given, the office location and office phone number is printed
! instead.
  .Pp
  Idle time is in minutes if it is a single integer, hours and minutes
  if a ``:'' is present, or days if a ``d'' is present.
! Login time is displayed as dayname if less than 6 days, else month,
! day; hours and minutes, unless more than six months ago, in which
! case the year is displayed rather than the hours and minutes.
  .Pp
  Unknown devices as well as nonexistent idle and login times are
  displayed as single asterisks.
***************
*** 99,104 ****
--- 104,119 ----
  at their mailbox since new mail arriving, or ``New mail received ...'',
  ``  Unread since ...'' if they have new mail.
  .Pp
+ .It Fl h
+ When used in conjunction with the
+ .Fl s 
+ option, the name of the remote host is displayed instead of the office
+ location and office phone.
+ .It Fl o
+ When used in conjunction with the
+ .Fl s 
+ option, the office location and office phone information is displayed
+ instead of the name of the remote host.
  .It Fl p
  Prevents
  the
diff -c -b /usr/src/usr.bin/finger/finger.c finger/finger.c
*** /usr/src/usr.bin/finger/finger.c	Fri Dec 17 18:11:10 1993
--- finger/finger.c	Mon Jun  6 15:02:32 1994
***************
*** 35,41 ****
   */
  
  /*
!  * Mail status reporting added 931007 by Luke Mewburn, <zak@rmit.edu.au>.
   */
  
  #ifndef lint
--- 35,42 ----
   */
  
  /*
!  * Mail status reporting added 931007 by Luke Mewburn, <lm@rmit.edu.au>.
!  * Host/office toggling added 940606 by Luke Mewburn, <lm@rmit.edu.au>.
   */
  
  #ifndef lint
***************
*** 57,65 ****
   *
   * There are currently two output formats; the short format is one line
   * per user and displays login name, tty, login time, real name, idle time,
!  * and office location/phone number.  The long format gives the same
!  * information (in a more legible format) as well as home directory, shell,
!  * mail info, and .plan/.project files.
   */
  
  #include <sys/param.h>
--- 58,67 ----
   *
   * There are currently two output formats; the short format is one line
   * per user and displays login name, tty, login time, real name, idle time,
!  * and either office location/phone number or remote host info, depending
!  * upon if -o, or -h (the default) is used respectively.
!  * The long format gives the same information (in a more legible format) as
!  * well as home directory, shell, mail info, and .plan/.project files.
   */
  
  #include <sys/param.h>
***************
*** 69,74 ****
--- 71,77 ----
  
  time_t now;
  int lflag, sflag, mflag, pplan;
+ int hflag;
  char tbuf[1024];
  
  main(argc, argv)
***************
*** 79,85 ****
  	int ch;
  	time_t time();
  
! 	while ((ch = getopt(argc, argv, "lmps")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
--- 82,89 ----
  	int ch;
  	time_t time();
  
! 	hflag = 1;		/* print remote host by default */
! 	while ((ch = getopt(argc, argv, "lmpsho")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
***************
*** 93,102 ****
  		case 's':
  			sflag = 1;		/* short format */
  			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmps] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
--- 97,112 ----
  		case 's':
  			sflag = 1;		/* short format */
  			break;
+ 		case 'h':
+ 			hflag = 1;		/* print host, not office */
+ 			break;
+ 		case 'o':
+ 			hflag = 0;		/* print office, not host */
+ 			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmpsho] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
Common subdirectories: /usr/src/usr.bin/finger/obj and finger/obj
diff -c -b /usr/src/usr.bin/finger/sprint.c finger/sprint.c
*** /usr/src/usr.bin/finger/sprint.c	Fri Dec 17 18:11:12 1993
--- finger/sprint.c	Mon Jun  6 14:47:36 1994
***************
*** 50,55 ****
--- 50,56 ----
  sflag_print()
  {
  	extern time_t now;
+ 	extern int    hflag;
  	register PERSON *pn;
  	register WHERE *w;
  	register int cnt;
***************
*** 67,80 ****
  	 *	if terminal writeable (add an '*' to the terminal name
  	 *		if not)
  	 *	if logged in show idle time and day logged in, else
! 	 *		show last login date and time.  If > 6 moths,
! 	 *		show year instead of time.
  	 *	office location
  	 *	office phone
  	 */
  #define	MAXREALNAME	20
! 	(void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle  Login Time   Office     Office Phone");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
  		for (w = pn->whead; w != NULL; w = w->next) {
--- 68,88 ----
  	 *	if terminal writeable (add an '*' to the terminal name
  	 *		if not)
  	 *	if logged in show idle time and day logged in, else
! 	 *		show last login date and time.  If > 6 months,
! 	 *		show year instead of time. If < 6 days,
! 	 *		show day name instead of month & day.
! 	 *	if (-h) given (default):
! 	 *		remote host
! 	 *	else if (-o) given	(mutually exclusive to -h)
  	 *		office location
  	 *		office phone
  	 */
  #define	MAXREALNAME	20
! #define MAXHOSTNAME	20
! 	    /* "Name", "Tty  Idle  Login Time   Office     Office Phone"); */
! 	(void)printf("%-*s %-*s %s  %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle   Login Time", (hflag) ? " Where"
! 						     : "Office     Office Phone");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
  		for (w = pn->whead; w != NULL; w = w->next) {
***************
*** 99,116 ****
  			} else
  				(void)printf("    *  ");
  			p = ctime(&w->loginat);
  			(void)printf("%.6s", p + 4);
  			if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
  				(void)printf("  %.4s", p + 20);
  			else
  				(void)printf(" %.5s", p + 11);
! office:			if (pn->office)
  				(void)printf(" %-10.10s", pn->office);
  			else if (pn->officephone)
  				(void)printf(" %-10.10s", " ");
  			if (pn->officephone)
  				(void)printf(" %-.15s",
  				    prphone(pn->officephone));
  			putchar('\n');
  		}
  	}
--- 107,132 ----
  			} else
  				(void)printf("    *  ");
  			p = ctime(&w->loginat);
+ 			if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1))
+ 				(void)printf("  %.3s ", p);
+ 			else
  				(void)printf("%.6s", p + 4);
  			if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
  				(void)printf("  %.4s", p + 20);
  			else
  				(void)printf(" %.5s", p + 11);
! office:			
! 			if (hflag)
! 				(void)printf("  %.*s", MAXHOSTNAME, w->host);
! 			else {
! 				if (pn->office)
  					(void)printf(" %-10.10s", pn->office);
  				else if (pn->officephone)
  					(void)printf(" %-10.10s", " ");
  				if (pn->officephone)
  					(void)printf(" %-.15s",
  					    prphone(pn->officephone));
+ 			}
  			putchar('\n');
  		}
  	}
--- cut here ---

-- 
``Concealment is never as hard as people think, you          Luke Mewburn
  must understand that. It's action while hiding that's    <lm@rmit.edu.au>
  the hard part''
        -- Coyote, in Kim Stanley Robinson's `Green Mars'

------------------------------------------------------------------------------