| ---
treadlist.c (1993B)
---
1 #include
2 #include
3 #include
4 #include
5 #include
6
7 enum
8 {
9 // XXX What to do here?
10 VtMaxLumpSize = 65535,
11 };
12
13 char *host;
14 Biobuf b;
15 VtConn *z;
16 uchar *buf;
17 void run(Biobuf*);
18 int nn;
19
20 void
21 usage(void)
22 {
23 fprint(2, "usage: readlist [-h host] list\n");
24 threadexitsall("usage");
25 }
26
27 int
28 parsescore(uchar *score, char *buf, int n)
29 {
30 int i, c;
31
32 memset(score, 0, VtScoreSize);
33
34 if(n != VtScoreSize*2){
35 werrstr("score wrong length %d", n);
36 return -1;
37 }
38 for(i=0; i= '0' && buf[i] <= '9')
40 c = buf[i] - '0';
41 else if(buf[i] >= 'a' && buf[i] <= 'f')
42 c = buf[i] - 'a' + 10;
43 else if(buf[i] >= 'A' && buf[i] <= 'F')
44 c = buf[i] - 'A' + 10;
45 else {
46 c = buf[i];
47 werrstr("bad score char %d '%c'", c, c);
48 return -1;
49 }
50
51 if((i & 1) == 0)
52 c <<= 4;
53
54 score[i>>1] |= c;
55 }
56 return 0;
57 }
58
59 void
60 threadmain(int argc, char *argv[])
61 {
62 int fd, i;
63
64 ARGBEGIN{
65 case 'h':
66 host = EARGF(usage());
67 break;
68 default:
69 usage();
70 break;
71 }ARGEND
72
73 fmtinstall('V', vtscorefmt);
74 buf = vtmallocz(VtMaxLumpSize);
75 z = vtdial(host);
76 if(z == nil)
77 sysfatal("could not connect to server: %r");
78 if(vtconnect(z) < 0)
79 sysfatal("vtconnect: %r");
80
81 if(argc == 0){
82 Binit(&b, 0, OREAD);
83 run(&b);
84 }else{
85 for(i=0; i |