mkroot.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. char *host;
  5. void
  6. usage(void)
  7. {
  8. fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
  9. exits("usage");
  10. }
  11. int
  12. main(int argc, char *argv[])
  13. {
  14. uchar score[VtScoreSize];
  15. uchar buf[VtRootSize];
  16. VtSession *z;
  17. VtRoot root;
  18. ARGBEGIN{
  19. case 'h':
  20. host = EARGF(usage());
  21. break;
  22. default:
  23. usage();
  24. break;
  25. }ARGEND
  26. if(argc != 5)
  27. usage();
  28. vtAttach();
  29. fmtinstall('V', vtScoreFmt);
  30. fmtinstall('R', vtErrFmt);
  31. root.version = VtRootVersion;
  32. strecpy(root.name, root.name+sizeof root.name, argv[0]);
  33. strecpy(root.type, root.type+sizeof root.type, argv[1]);
  34. if(!vtParseScore(argv[2], strlen(argv[2]), root.score))
  35. vtFatal("bad score '%s'", argv[2]);
  36. root.blockSize = atoi(argv[3]);
  37. if(!vtParseScore(argv[4], strlen(argv[4]), root.prev))
  38. vtFatal("bad score '%s'", argv[4]);
  39. vtRootPack(&root, buf);
  40. z = vtDial(host, 0);
  41. if(z == nil)
  42. vtFatal("could not connect to server: %R");
  43. if(!vtConnect(z, 0))
  44. sysfatal("vtConnect: %r");
  45. if(!vtWrite(z, score, VtRootType, buf, VtRootSize))
  46. vtFatal("vtWrite: %R");
  47. vtClose(z);
  48. print("%V\n", score);
  49. vtDetach();
  50. exits(0);
  51. return 0;
  52. }