1 #include "stdinc.h" 2 #include "dat.h" 3 #include "fns.h" 4 5 char *host; 6 7 void 8 usage(void) 9 { 10 fprint(2, "usage: write [-z] [-h host] [-t type] <datablock\n"); 11 exits("usage"); 12 } 13 14 int 15 main(int argc, char *argv[]) 16 { 17 uchar *p, score[VtScoreSize]; 18 int type, n, dotrunc; 19 VtSession *z; 20 21 dotrunc = 0; 22 type = VtDataType; 23 ARGBEGIN{ 24 case 'z': 25 dotrunc = 1; 26 break; 27 case 'h': 28 host = EARGF(usage()); 29 break; 30 case 't': 31 type = atoi(EARGF(usage())); 32 break; 33 default: 34 usage(); 35 break; 36 }ARGEND 37 38 if(argc != 0) 39 usage(); 40 41 vtAttach(); 42 43 fmtinstall('V', vtScoreFmt); 44 fmtinstall('R', vtErrFmt); 45 46 p = vtMemAllocZ(VtMaxLumpSize+1); 47 n = readn(0, p, VtMaxLumpSize+1); 48 if(n > VtMaxLumpSize) 49 vtFatal("data too big"); 50 z = vtDial(host, 0); 51 if(z == nil) 52 vtFatal("could not connect to server: %R"); 53 if(!vtConnect(z, 0)) 54 vtFatal("vtConnect: %r"); 55 if(dotrunc) 56 n = vtZeroTruncate(type, p, n); 57 if(!vtWrite(z, score, type, p, n)) 58 vtFatal("vtWrite: %R"); 59 vtClose(z); 60 print("%V\n", score); 61 vtDetach(); 62 exits(0); 63 return 0; /* shut up compiler */ 64 } 65