diff options
author | rsc <devnull@localhost> | 2005-07-12 15:23:36 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-07-12 15:23:36 +0000 |
commit | a0d146edd7a7de6236a0d60baafeeb59f8452aae (patch) | |
tree | b55baa526d9f5adfc73246e6ee2fadf455e0b7a2 /src/cmd/venti/readlist.c | |
parent | 88bb285e3d87ec2508840af33f7e0af53ec3c13c (diff) | |
download | plan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.tar.gz plan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.tar.bz2 plan9port-a0d146edd7a7de6236a0d60baafeeb59f8452aae.zip |
return of venti
Diffstat (limited to 'src/cmd/venti/readlist.c')
-rw-r--r-- | src/cmd/venti/readlist.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/cmd/venti/readlist.c b/src/cmd/venti/readlist.c new file mode 100644 index 00000000..bb1d9b6b --- /dev/null +++ b/src/cmd/venti/readlist.c @@ -0,0 +1,112 @@ +#include <u.h> +#include <libc.h> +#include <thread.h> +#include <venti.h> +#include <bio.h> + +char *host; +Biobuf b; +VtConn *z; +uchar *buf; +void run(Biobuf*); +int nn; + +void +usage(void) +{ + fprint(2, "usage: readlist [-h host] list\n"); + threadexitsall("usage"); +} + +int +parsescore(uchar *score, char *buf, int n) +{ + int i, c; + + memset(score, 0, VtScoreSize); + + if(n != VtScoreSize*2){ + werrstr("score wrong length %d", n); + return -1; + } + for(i=0; i<VtScoreSize*2; i++) { + if(buf[i] >= '0' && buf[i] <= '9') + c = buf[i] - '0'; + else if(buf[i] >= 'a' && buf[i] <= 'f') + c = buf[i] - 'a' + 10; + else if(buf[i] >= 'A' && buf[i] <= 'F') + c = buf[i] - 'A' + 10; + else { + c = buf[i]; + werrstr("bad score char %d '%c'", c, c); + return -1; + } + + if((i & 1) == 0) + c <<= 4; + + score[i>>1] |= c; + } + return 0; +} + +void +threadmain(int argc, char *argv[]) +{ + int fd, i; + + ARGBEGIN{ + case 'h': + host = EARGF(usage()); + break; + default: + usage(); + break; + }ARGEND + + fmtinstall('V', vtscorefmt); + buf = vtmallocz(VtMaxLumpSize); + z = vtdial(host); + if(z == nil) + sysfatal("could not connect to server: %r"); + if(vtconnect(z) < 0) + sysfatal("vtconnect: %r"); + + if(argc == 0){ + Binit(&b, 0, OREAD); + run(&b); + }else{ + for(i=0; i<argc; i++){ + if((fd = open(argv[i], OREAD)) < 0) + sysfatal("open %s: %r", argv[i]); + Binit(&b, fd, OREAD); + run(&b); + } + } + threadexitsall(nil); +} + +void +run(Biobuf *b) +{ + char *p, *f[10]; + int nf; + uchar score[20]; + int type, n; + + while((p = Brdline(b, '\n')) != nil){ + p[Blinelen(b)-1] = 0; + nf = tokenize(p, f, nelem(f)); + if(nf != 2) + sysfatal("syntax error in work list"); + if(parsescore(score, f[0], strlen(f[0])) < 0) + sysfatal("bad score %s in work list", f[0]); + type = atoi(f[1]); + n = vtread(z, score, type, buf, VtMaxLumpSize); + if(n < 0) + sysfatal("could not read %s %s: %r", f[0], f[1]); + // write(1, buf, n); + if(++nn%1000 == 0) + print("%d...", nn); + } +} |