Blob


1 #include "stdinc.h"
2 #include <bio.h>
4 typedef struct Source Source;
6 struct Source
7 {
8 ulong gen;
9 int psize;
10 int dsize;
11 int dir;
12 int active;
13 int depth;
14 uvlong size;
15 uchar score[VtScoreSize];
16 int reserved;
17 };
19 int bsize;
20 Biobuf *bout;
21 VtRootLump root;
22 int ver;
23 int cmp;
24 int all;
25 int find;
26 uchar fscore[VtScoreSize];
27 int dirSize;
28 void (*parse)(Source*, uchar*);
29 VtSession *z;
31 int vtGetUint16(uchar *p);
32 ulong vtGetUint32(uchar *p);
33 uvlong vtGetUint48(uchar *p);
34 void usage(void);
35 int parseScore(uchar *score, char *buf, int n);
36 void readRoot(VtRootLump*, uchar *score, char *file);
37 void parse1(Source*, uchar*);
38 void parse2(Source*, uchar*);
39 int dumpDir(Source*, int indent);
41 void
42 main(int argc, char *argv[])
43 {
44 char *host = nil;
45 uchar score[VtScoreSize];
46 uchar buf[VtMaxLumpSize];
47 int type;
48 int n;
50 type = VtDataType;
52 ARGBEGIN{
53 case 't':
54 type = atoi(ARGF());
55 break;
56 }ARGEND
58 vtAttach();
60 bout = vtMemAllocZ(sizeof(Biobuf));
61 Binit(bout, 1, OWRITE);
63 if(argc != 1)
64 usage();
66 vtAttach();
68 fmtinstall('V', vtScoreFmt);
69 fmtinstall('R', vtErrFmt);
71 z = vtDial(host);
72 if(z == nil)
73 vtFatal("could not connect to server: %s", vtGetError());
75 if(!vtConnect(z, 0))
76 sysfatal("vtConnect: %r");
78 if(!parseScore(score, argv[0], strlen(argv[0])))
79 vtFatal("could not parse score: %s", vtGetError());
81 n = vtRead(z, score, type, buf, VtMaxLumpSize);
82 if(n < 0)
83 vtFatal("could not read block: %s", vtGetError());
84 Bwrite(bout, buf, n);
86 Bterm(bout);
88 vtClose(z);
89 vtDetach();
90 exits(0);
91 }
93 void
94 usage(void)
95 {
96 fprint(2, "%s: -t type score\n", argv0);
97 exits("usage");
98 }
100 int
101 parseScore(uchar *score, char *buf, int n)
103 int i, c;
105 memset(score, 0, VtScoreSize);
107 if(n < VtScoreSize*2)
108 return 0;
109 for(i=0; i<VtScoreSize*2; i++) {
110 if(buf[i] >= '0' && buf[i] <= '9')
111 c = buf[i] - '0';
112 else if(buf[i] >= 'a' && buf[i] <= 'f')
113 c = buf[i] - 'a' + 10;
114 else if(buf[i] >= 'A' && buf[i] <= 'F')
115 c = buf[i] - 'A' + 10;
116 else {
117 return 0;
120 if((i & 1) == 0)
121 c <<= 4;
123 score[i>>1] |= c;
125 return 1;