[alt.sources] finger for aliases

tchrist@convex.com (Tom Christiansen) (02/02/90)

Once upon a time, I lived on a machine where finger would automatically
resolve aliases from /usr/lib/aliases for any of its arguments, which was
useful both for mailing lists and for fingering people at their home
machines.  Alas, those days are no more, so I've written this front end
that does the dirty work for me and then calls the real finger.  It's
brief and actually quite fast, and is also a good example of using
associative arrays bound to dbm files and recursive subroutines in perl.

#!/usr/bin/perl
#
# nfinger -- finger people at their home machines
#	     as defined in the /usr/lib/aliases 
#	     dbm file.  recursively resolve all
#	     aliases first, so works on lists

dbmopen(alias,'/usr/lib/aliases',0444) || die "can't dbmopen aliases";

@finger = ('/usr/ucb/finger');

while ($ARGV[0] =~ /^-/) { 
    push(@finger, shift); 
} 

while ($user = shift) { 
    push(@finger, &resolve($user)); 
}

exec @finger;

##############################################################
sub resolve {
    local($addr,$alias,@list);

    while ($addr = shift) {
	unless (defined $alias{$addr."\000"}) {
	    push(@list, $addr);
	    next;
	} 
	chop($alias = $alias{$addr."\000"});
	$alias =~ s/^\s*(.*)\s*$/$1/;
	$alias =~ s/([^!]*)!(.*)/$2@$1/;
	push(@list,&resolve(split(/[\s,]+/,$alias)));
    } 
    return @list;
} 
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"