/*
* 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);
}
}
|