vactest.c 2.7 KB

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