rminnichmerge57758a716 years agoHistory
66 lines · 839 B · C
RawDownload
#include <u.h>#include <libc.h>#include <mpipe.h> int nhash; intmain(int argc, char **argv){	int i;	int *fds;		ARGBEGIN{		}ARGEND;		fds = malloc(argc*sizeof(char*));	for(i = 0; i < argc; i++)		fds[i] = atoi(argv[i]);	nfds = argc;	nl(fds, argc);	// gompipe(p)} /* modified djb2 */ulonghash(char *s, int n; int *len){	ulong hash = 5381;	int c;	*len = 0; 	for(;(c = *s++) != '\n'; n--, *len++){		if(n == 0){			*len = -1;			return 0;		}		h = ((h << 5) + h) + c;	} 	return h % nfds;} voidnl(int *fds, int n){	int n, h, len;	char *buf, *b;	buf = emalloc(8192);	n = 0;start:	while((n = read(0, buf+n, 8192)) > 0){		b = buf;		while(n){			h = hash(buf, n, &len);			if(len == -1){				memmove(buf, b, n);				goto start;			}			write(fds[h], buf, len);			n -= len;			buf+=len;		}	}	free(buf);}

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