Subject: 4.4-lite finger patch...
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Luke Mewburn <lm@rmit.edu.au>
List: current-users
Date: 06/30/1994 12:29:53
The finger in netbsd 0.9c is net/2's with some hacks by yours truly.
Heres a patch with puts those hacks into the 4.4 finger.

Note that 4.4-lite finger also shows .forward info (check out
some people @vangogh.cs.berkeley.edu, or even root@karybdis.cs.rmit.oz.au)
I think it has some other changes over the stock Net/2 finger too.


My patch does:
    - mail status ("No Mail", "Mail read:...", or "New Mail ...,
      Unread since ...".)
    - 4 digit phone extensions (3210 is printed as x3210.)
    - short day names (`Tue' printed instead of `Jun 21' if the login
      time is < 6 days.
    - host/office toggling in short format with -h & -o.


The first two are already in 0.9c's finger. The third and fourth are
more recent hacks.

Personally I find that the remote host info in the short listing 
as more useful. E.g,
    % finger @karybdis
[karybdis]
Login    Name                 Tty  Idle   Login Time   Where
lm       Luke Mewburn g        p0  1:07    Thu  11:11  goanna.cs.rmit.O
root     Ueberhacker           vg     3    Thu  10:51  

Instead of the office info. That way people can easily work out where
you are least idle, instead of getting x copies of your office & phone
info printed when they probably already know that...


And the printing of the day name instead of the date for days close to
today (within the last week) is useful for us who can't remember the
date but know that it's friday today :)


---
diff -cb finger-4.4-lite/finger.1 finger/finger.1
*** finger-4.4-lite/finger.1	Thu Feb 17 06:21:20 1994
--- finger/finger.1	Wed Jun 22 14:20:26 1994
***************
*** 31,37 ****
  .\"
  .\"	@(#)finger.1	8.2 (Berkeley) 2/16/94
  .\"
! .Dd February 16, 1994
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
--- 31,37 ----
  .\"
  .\"	@(#)finger.1	8.2 (Berkeley) 2/16/94
  .\"
! .Dd June 22, 1994
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
***************
*** 39,45 ****
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmsp
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
--- 39,45 ----
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmpsho
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
***************
*** 53,76 ****
  .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.
  .Pp
  .It Fl l
  Produces a multi-line format displaying all of the information
  described for the
  .Fl s
  option as well as the user's home directory, home phone number, login
! shell, and the contents of the files
  .Dq Pa .forward ,
  .Dq Pa .plan
  and
--- 53,93 ----
  .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 the 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.
  .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.
+ .Pp
+ .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.
+ .Pp
  .It Fl l
  Produces a multi-line format displaying all of the information
  described for the
  .Fl s
  option as well as the user's home directory, home phone number, login
! shell, mail status, and the contents of the files
  .Dq Pa .forward ,
  .Dq Pa .plan
  and
***************
*** 85,90 ****
--- 102,108 ----
  Numbers specified as ten or seven digits are printed as the appropriate
  subset of that string.
  Numbers specified as five digits are printed as ``xN-NNNN''.
+ Numbers specified as four digits are printed as ``xNNNN''.
  .Pp
  If write permission is denied to the device, the phrase ``(messages off)''
  is appended to the line containing the device name.
***************
*** 92,97 ****
--- 110,120 ----
  .Fl l
  option; if a user is logged on multiple times, terminal information
  is repeated once per login.
+ .Pp
+ Mail status is shown as ``No Mail.'' if there is no mail at all, ``Mail
+ last read DDD MMM ## HH:MM YYYY (TZ)'' if the person has looked at their
+ mailbox since new mail arriving, or ``New mail received ...'', ``Unread
+ since ...'' if they have new mail.
  .Pp
  .It Fl p
  Prevents
diff -cb finger-4.4-lite/finger.c finger/finger.c
*** finger-4.4-lite/finger.c	Wed Nov 17 06:55:35 1993
--- finger/finger.c	Wed Jun 22 13:11:11 1994
***************
*** 34,39 ****
--- 34,49 ----
   * SUCH DAMAGE.
   */
  
+ /*
+  * Luke Mewburn <lm@rmit.edu.au> added the following on 940622:
+  *    - mail status ("No Mail", "Mail read:...", or "New Mail ...,
+  *	Unread since ...".)
+  *    - 4 digit phone extensions (3210 is printed as x3210.)
+  *    - host/office toggling in short format with -h & -o.
+  *    - short day names (`Tue' printed instead of `Jun 21' if the
+  *	login time is < 6 days.
+  */
+ 
  #ifndef lint
  static char copyright[] =
  "@(#) Copyright (c) 1989, 1993\n\
***************
*** 52,60 ****
   *
   * 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>
--- 62,71 ----
   *
   * 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 remote host information (default) or office location/phone
!  * number, depending on if -h or -o 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>
***************
*** 71,77 ****
  
  DB *db;
  time_t now;
! int entries, lflag, mflag, pplan, sflag;
  char tbuf[1024];
  
  static void loginlist __P((void));
--- 82,88 ----
  
  DB *db;
  time_t now;
! int entries, lflag, mflag, oflag, pplan, sflag;
  char tbuf[1024];
  
  static void loginlist __P((void));
***************
*** 83,89 ****
  {
  	int ch;
  
! 	while ((ch = getopt(argc, argv, "lmps")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
--- 94,100 ----
  {
  	int ch;
  
! 	while ((ch = getopt(argc, argv, "lmpsho")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
***************
*** 97,106 ****
  		case 's':
  			sflag = 1;		/* short format */
  			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmps] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
--- 108,123 ----
  		case 's':
  			sflag = 1;		/* short format */
  			break;
+ 		case 'h':
+ 			oflag = 0;		/* remote host info */
+ 			break;
+ 		case 'o':
+ 			oflag = 1;		/* office info */
+ 			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmpsho] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
diff -cb finger-4.4-lite/finger.h finger/finger.h
*** finger-4.4-lite/finger.h	Mon Jun  7 07:39:26 1993
--- finger/finger.h	Wed Jun 22 12:42:18 1994
***************
*** 45,50 ****
--- 45,52 ----
  	char   *officephone;		/* pointer to office phone no. */
  	char   *realname;		/* pointer to full name */
  	char   *shell;			/* user's shell */
+ 	time_t	mailread;		/* last time mail was read */
+ 	time_t	mailrecv;		/* last time mail was received */
  	struct where *whead, *wtail;	/* list of where user is or has been */
  } PERSON;
  
diff -cb finger-4.4-lite/lprint.c finger/lprint.c
*** finger-4.4-lite/lprint.c	Mon Jun  7 07:39:31 1993
--- finger/lprint.c	Wed Jun 22 12:45:38 1994
***************
*** 113,118 ****
--- 113,119 ----
  	 *	home directory
  	 *	shell
  	 *	office, office phone, home phone if available
+ 	 *	mail status
  	 */
  	(void)printf("Login: %-15s\t\t\tName: %s\nDirectory: %-25s",
  	    pn->name, pn->realname, pn->dir);
***************
*** 152,158 ****
  		putchar('\n');
  
  	/*
! 	 * long format con't: * if logged in
  	 *	terminal
  	 *	idle time
  	 *	if messages allowed
--- 153,160 ----
  		putchar('\n');
  
  	/*
! 	 * long format con't:
! 	 * if logged in
  	 *	terminal
  	 *	idle time
  	 *	if messages allowed
***************
*** 220,225 ****
--- 222,244 ----
  			(void)printf(" from %s", w->host);
  		}
  		putchar('\n');
+ 	}
+ 	if (pn->mailrecv == -1)
+ 		printf("No Mail.\n");
+ 	else if (pn->mailrecv > pn->mailread) {
+ 		tp = localtime(&pn->mailrecv);
+ 		t = asctime(tp);
+ 		tzn = tp->tm_zone;
+ 		printf("New mail received %.16s %.4s (%s)\n", t, t + 20, tzn);
+ 		tp = localtime(&pn->mailread);
+ 		t = asctime(tp);
+ 		tzn = tp->tm_zone;
+ 		printf("     Unread since %.16s %.4s (%s)\n", t, t + 20, tzn);
+ 	} else {
+ 		tp = localtime(&pn->mailread);
+ 		t = asctime(tp);
+ 		tzn = tp->tm_zone;
+ 		printf("Mail last read %.16s %.4s (%s)\n", t, t + 20, tzn);
  	}
  }
  
diff -cb finger-4.4-lite/sprint.c finger/sprint.c
*** finger-4.4-lite/sprint.c	Mon Jun  7 07:39:43 1993
--- finger/sprint.c	Wed Jun 22 13:10:54 1994
***************
*** 57,62 ****
--- 57,63 ----
  sflag_print()
  {
  	extern time_t now;
+ 	extern int    oflag;
  	register PERSON *pn;
  	register WHERE *w;
  	register int sflag, r;
***************
*** 71,84 ****
  	 *	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 (sflag = R_FIRST;; sflag = R_NEXT) {
  		r = (*db->seq)(db, &key, &data, sflag);
--- 72,92 ----
  	 *	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 (-o given, overriding -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", (oflag)
! 		    ? "Office     Office Phone" : " Where");
  
  	for (sflag = R_FIRST;; sflag = R_NEXT) {
  		r = (*db->seq)(db, &key, &data, sflag);
***************
*** 110,127 ****
  			} 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');
  		}
  	}
--- 118,141 ----
  			} 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 (oflag) {
! 				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));
+ 			} else
+ 				(void)printf("  %.*s", MAXHOSTNAME, w->host);
  			putchar('\n');
  		}
  	}
diff -cb finger-4.4-lite/util.c finger/util.c
*** finger-4.4-lite/util.c	Mon Jun  7 07:39:49 1993
--- finger/util.c	Wed Jun 22 13:02:28 1994
***************
*** 276,289 ****
--- 276,292 ----
  		*p++ = *num++;
  		break;
  	case 5:				/* x0-1234 */
+ 	case 4:				/* x1234 */
  		*p++ = 'x';
  		*p++ = *num++;
  		break;
  	default:
  		return(num);
  	}
+ 	if (len != 4) {
  		*p++ = '-';
  		*p++ = *num++;
+ 	}
  	*p++ = *num++;
  	*p++ = *num++;
  	*p++ = *num++;
***************
*** 317,322 ****
--- 320,326 ----
  {
  	register char *p, *t;
  	char *bp, name[1024];
+ 	struct stat sb;
  
  	pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
  
***************
*** 349,354 ****
--- 353,370 ----
  	    strdup(p) : NULL;
  	pn->homephone = ((p = strsep(&bp, ",")) && *p) ?
  	    strdup(p) : NULL;
+ 	(void)sprintf(tbuf,"%s/%s", _PATH_MAILDIR, pw->pw_name);
+ 	pn->mailrecv = -1;		/* -1 == not_valid */
+ 	if (stat(tbuf, &sb) < 0) {
+ 		if (errno != ENOENT) {
+ 			(void)fprintf(stderr,
+ 			    "finger: %s: %s\n", tbuf, strerror(errno));
+ 			return;
+ 		}
+ 	} else if (sb.st_size != 0) {
+ 		pn->mailrecv = sb.st_mtime;
+ 		pn->mailread = sb.st_atime;
+ 	}
  }
  
  #if __STDC__

-- 
``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'

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