! COPY with automatic filestore switching ! RWT January 1991 %option "-low-nodiag-nocheck" %include "inc:fs.imp" %include "inc:util.imp" %begin %string(255)ins,in,out %predicate done remotely ! Attempt to get the filestore to perform the copying. ! If the input contains a comma (indicating more than one file), or ! if either of the file names begin with ':' (indicating a device name), ! this will fail (result FALSE). Otherwise (result TRUE) the filestore ! will (start to) do the copying (completing it asynchronously). %integer i %on 3 %start; %false; %finish copy(ins,out); %true %end ! Parse the parameter, which consists of one or more comma-separated ! input file names, plus an output file name, separated from the input(s) ! by '/' or space. ins = cliparam %cycle %stopif ins="" %if charno(ins,1)=' ' %start ins = substring(ins,2,length(ins)) %elseif charno(ins,length(ins))=' ' ins = substring(ins,1,length(ins)-1) %elseif ins -> in.(", ").ins %or ins -> in.(" ,").ins ins = in.",".ins %elseif ins -> in.(" ").ins ins = in." ".in %finishelseexit %repeat ins = in."/".ins %if ins -> in.(" ").ins out = "" %unless ins -> ins.("/").out ! Default input(s) or output is the terminal (":"). out = ":" %if out="" ins = ":" %if ins="" %stopif done remotely ! End of easy bit. ! If we get here, it's because either there's a problem with the files, ! or device names or concatenation are involved, or explicit or implicit ! inter-filestore transfer is required. ! Ether comms %routine ackwait(%integer port) %integer bit=1<marktime %repeatuntil cputime>deadline printline("No ACK/NAK"); %signal 9 %end %routine dtxwait(%integer port) %integer bit=1<marktime %repeatuntil cputime>deadline printline("No response"); %signal 9 %end %predicate nacked(%integer port) %integer bit=1< server.("::").rawfilename %start retried = 1 {no retrying if server specified explicitly} k = charno(server,1)&95 %unless server="" %if length(server)=1 %and 'A'<=k<='Z' %start dte = dtetable(k) %else dte = 0 %while server#"" %cycle k = charno(server,1); server = substring(server,2,length(server)) %if '0'<=k<='9' %start dte = dte<<4-'0'+k %else k = k&95; %exitunless 'A'<=k<='F' dte = dte<<4-'A'+k+10 %finish %repeat %finish %if dte=0 %start no: select(1); printstring("Unknown server ") printline(filename); %result = 0 %finish %finish %finish rdte = dte; port = allocate port; ->no %if port=0 select(port); open(1,rawfilename); selectoutput(0) %result = port %end %routine transfer %bytearray buf(0:4095) %integer n=0,i %on 9 %start closeinput select(outport); selectoutput(1) printsymbol(buf(i)) %for i = 0,1,n-1 selectoutput(0) %return %finish %cycle select(inport); selectinput(1) n = 0 %cycle readsymbol(buf(n)); n = n+1 %repeatuntil n=4096 select(outport); selectoutput(1) printsymbol(buf(i)) %for i = 0,1,n-1 %repeat %end ! Main program for local copying begins here portinfo(1) = cur portinfo(i) = 0 %for i = 2,1,31 outport = access(openoutput,out); %stopif outport=0 ins = ins."," %while ins -> in.(",").ins %cycle inport = access(openinput,in); %continueif inport=0 transfer %repeat selectoutput(1); closeoutput; selectoutput(0) %for i = 2,1,31 %cycle select(i); disconnect %repeat select(1) space{?just to see if it got here ok?} %end %end