87 lines · 1.5 KB · C
RawDownload
/*  * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include <u.h>#include <libc.h>#include <bio.h> char *server;char *status;int statusonly; voidusage(void){	fprint(2, "usage: ndb/csquery [/net/cs [addr...]]\n");	exits("usage");} voidquery(char *addr){	char buf[128];	int fd, n; 	fd = open(server, ORDWR);	if(fd < 0)		sysfatal("cannot open %s: %r", server);	if(write(fd, addr, strlen(addr)) != strlen(addr)){		if(!statusonly)			fprint(2, "translating %s: %r\n", addr);		status = "errors";		close(fd);		return;	}	if(!statusonly){		seek(fd, 0, 0);		while((n = read(fd, buf, sizeof(buf)-1)) > 0){			buf[n] = 0;			print("%s\n", buf);		}	}	close(fd);} voidmain(int argc, char **argv){	char *p;	int i;	Biobuf in; 	ARGBEGIN{	case 's':		statusonly = 1;		break;	default:		usage();	}ARGEND 	if(argc > 0)		server = argv[0];	else		server = "/net/cs"; 	if(argc > 1){		for(i=1; i<argc; i++)			query(argv[i]);		exits(status);	} 	Binit(&in, 0, OREAD);	for(;;){		print("> ");		p = Brdline(&in, '\n');		if(p == 0)			break;		p[Blinelen(&in)-1] = 0;		query(p);	}	exits(nil);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t