aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vac/vactest.c
blob: c456604f854b14b6e115a3712af29ff6d45da428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "stdinc.h"
#include "vac.h"
#include "dat.h"
#include "fns.h"

void usage(void);
int unvac(VacFS *fs);
int readScore(int fd, uchar score[VtScoreSize]);
static void warn(char *fmt, ...);
void dirlist(VacFS *fs, char *path);

static	int	nwant;
static	char	**want;
static	int	dflag = 1;
static	int	cflag;
static	int	lower;
static	int	verbose;
static	int	settimes;

void
main(int argc, char *argv[])
{
	char *zfile;
	int ok, table;
	VtSession *z;
	char *vsrv = nil;
	char *host = nil;
	char *p;
	int ncache = 1000;
	VacFS *fs;

	table = 0;
	zfile = nil;
	ARGBEGIN{
	case 'D':
		dflag++;
		break;
	case 'c':
		cflag++;
		break;
	case 'C':
		p = ARGF();
		if(p == nil)
			usage();
		ncache = atoi(p);
		if(ncache < 10)
			ncache = 10;
		if(ncache > 1000000)
			ncache = 1000000;
		break;
	case 'i':
		lower++;
		break;
	case 'f':
		zfile = ARGF();
		if(zfile == nil)
			usage();
		break;
	case 'h':
		host = ARGF();
		break;
	case 't':
		table++;
		break;
	case 'T':
		settimes++;
		break;
	case 's':
		vsrv = ARGF();
		break;
	case 'v':
		verbose++;
		break;
	default:
		usage();
		break;
	}ARGEND

	nwant = argc;
	want = argv;

	vtAttach();

	if(zfile == nil)
		usage();

	if(vsrv != nil)
		z = vtStdioServer(vsrv);
	else
		z = vtDial(host);
	if(z == nil)
		vtFatal("could not connect to server: %s", vtGetError());
	vtSetDebug(z, 0);
	if(!vtConnect(z, 0))
		vtFatal("vtConnect: %s", vtGetError());
	fs = vfsOpen(z, zfile, 1, ncache);
	if(fs == nil)
		vtFatal("vfsOpen: %s", vtGetError());
	ok = unvac(fs);
	vtClose(z);
	vtDetach();
	
	exits(ok? 0 : "error");
}

void
usage(void)
{
	fprint(2, "usage: %s [-tTcDv] -f zipfile [-s ventid] [-h host] [file ...]\n", argv0);
	exits("usage");
}

void
suck(VacFile *f)
{
	USED(f);
}


void
vacfile(VacFS *fs, char *path, VacDir *vd)
{
	char *path2;

	path2 = vtMemAlloc(strlen(path) + 1 + strlen(vd->elem) + 1);
	if(path[1] == 0)
		sprintf(path2, "/%s", vd->elem);
	else
		sprintf(path2, "%s/%s", path, vd->elem);
fprint(2, "vac file: %s\n", path2);
	if(vd->mode & ModeDir)
		dirlist(fs, path2);
	vtMemFree(path2);
}

void
dirlist(VacFS *fs, char *path)
{
	VacDir vd[50];
	VacDirEnum *ds;
	int i, n;

	ds = vdeOpen(fs, path);
	if(ds == nil) {
		fprint(2, "could not open: %s: %s\n", path, vtGetError());
		return;
	}
	for(;;) {
		n = vdeRead(ds, vd, sizeof(vd)/sizeof(VacDir));
		if(n < 0) {
			warn("vdRead failed: %s: %s", path, vtGetError());
			return;
		}
		if(n == 0)
			break;
		for(i=0; i<n; i++) {
			vacfile(fs, path, &vd[i]);
			vdCleanup(&vd[i]);
		}
	}
	vdeFree(ds);
}

int
unvac(VacFS *fs)
{
	dirlist(fs, "/");

	return 1;
}

static void
warn(char *fmt, ...)
{
	va_list arg;

	va_start(arg, fmt);
	fprint(2, "%s: ", argv0);
	vfprint(2, fmt, arg);
	fprint(2, "\n");
	va_end(arg);
}