Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/misc/finger.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * finger [-v] person ...
 */

#include <u.h>
#include <libc.h>
#include <bio.h>

static	void	lookup(char*, int);

void
main(int argc, char **argv)
{
	int verbose = 0;

	ARGBEGIN{
	case 'v':
		verbose = 1;
		break;
	}
	ARGEND

	for(; *argv; argv++)
		lookup(*argv, verbose);
	exits(0);
}

static void
lookup(char *name, int verbose)
{
	int fd, l;
	Biobuf ib;
	char dest[100], *cp, *lp;

	if((cp = strrchr(name, '@')) != 0) {
		*cp++ = 0;
		strcpy(dest, cp);
	} 
	else if((cp = strrchr(name, '!')) != 0) {
		*cp++ = 0;
		strcpy(dest, name);
		name = cp;
	} 
	else {
		fprint(2, "finger: local info not available for %s\n", name);
		return;
	}
	fd = dial(netmkaddr(dest, "net", "finger"), 0, 0, 0);
	if(fd < 0) {
		fprint(2, "finger: error dialing %s: %r\n", dest);
		return;
	}
	fprint(fd, "%s%s\r\n", verbose?"/w ": "", name);
	Binit(&ib, fd, OREAD);
	while((lp = Brdline(&ib, '\n')) != 0) {
		l = Blinelen(&ib);
		if(l > 1 && lp[l-2] == '\r') {
			l--;
			lp[l-1] = '\n';
		}
		write(1, lp, l);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.