Blob
1 #include "stdinc.h"2 #include "vac.h"3 #include "dat.h"4 #include "fns.h"6 void usage(void);7 int unvac(VacFS *fs);8 int readScore(int fd, uchar score[VtScoreSize]);9 static void warn(char *fmt, ...);10 void dirlist(VacFS *fs, char *path);12 static int nwant;13 static char **want;14 static int dflag = 1;15 static int cflag;16 static int lower;17 static int verbose;18 static int settimes;20 void21 main(int argc, char *argv[])22 {23 char *zfile;24 int ok, table;25 VtSession *z;26 char *vsrv = nil;27 char *host = nil;28 char *p;29 int ncache = 1000;30 VacFS *fs;32 table = 0;33 zfile = nil;34 ARGBEGIN{35 case 'D':36 dflag++;37 break;38 case 'c':39 cflag++;40 break;41 case 'C':42 p = ARGF();43 if(p == nil)44 usage();45 ncache = atoi(p);46 if(ncache < 10)47 ncache = 10;48 if(ncache > 1000000)49 ncache = 1000000;50 break;51 case 'i':52 lower++;53 break;54 case 'f':55 zfile = ARGF();56 if(zfile == nil)57 usage();58 break;59 case 'h':60 host = ARGF();61 break;62 case 't':63 table++;64 break;65 case 'T':66 settimes++;67 break;68 case 's':69 vsrv = ARGF();70 break;71 case 'v':72 verbose++;73 break;74 default:75 usage();76 break;77 }ARGEND79 nwant = argc;80 want = argv;82 vtAttach();84 if(zfile == nil)85 usage();87 if(vsrv != nil)88 z = vtStdioServer(vsrv);89 else90 z = vtDial(host);91 if(z == nil)92 vtFatal("could not connect to server: %s", vtGetError());93 vtSetDebug(z, 0);94 if(!vtConnect(z, 0))95 vtFatal("vtConnect: %s", vtGetError());96 fs = vfsOpen(z, zfile, 1, ncache);97 if(fs == nil)98 vtFatal("vfsOpen: %s", vtGetError());99 ok = unvac(fs);100 vtClose(z);101 vtDetach();103 exits(ok? 0 : "error");104 }106 void107 usage(void)108 {109 fprint(2, "usage: %s [-tTcDv] -f zipfile [-s ventid] [-h host] [file ...]\n", argv0);110 exits("usage");111 }113 void114 suck(VacFile *f)115 {116 USED(f);117 }120 void121 vacfile(VacFS *fs, char *path, VacDir *vd)122 {123 char *path2;125 path2 = vtMemAlloc(strlen(path) + 1 + strlen(vd->elem) + 1);126 if(path[1] == 0)127 sprintf(path2, "/%s", vd->elem);128 else129 sprintf(path2, "%s/%s", path, vd->elem);130 fprint(2, "vac file: %s\n", path2);131 if(vd->mode & ModeDir)132 dirlist(fs, path2);133 vtMemFree(path2);134 }136 void137 dirlist(VacFS *fs, char *path)138 {139 VacDir vd[50];140 VacDirEnum *ds;141 int i, n;143 ds = vdeOpen(fs, path);144 if(ds == nil) {145 fprint(2, "could not open: %s: %s\n", path, vtGetError());146 return;147 }148 for(;;) {149 n = vdeRead(ds, vd, sizeof(vd)/sizeof(VacDir));150 if(n < 0) {151 warn("vdRead failed: %s: %s", path, vtGetError());152 return;153 }154 if(n == 0)155 break;156 for(i=0; i<n; i++) {157 vacfile(fs, path, &vd[i]);158 vdCleanup(&vd[i]);159 }160 }161 vdeFree(ds);162 }164 int165 unvac(VacFS *fs)166 {167 dirlist(fs, "/");169 return 1;170 }172 static void173 warn(char *fmt, ...)174 {175 va_list arg;177 va_start(arg, fmt);178 fprint(2, "%s: ", argv0);179 vfprint(2, fmt, arg);180 fprint(2, "\n");181 va_end(arg);182 }