%%s 0/0/0 %%d D 1.1 25-Mar-82 12:15:17 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- split.r 1792 asc 25-mar-82 08:54:39 v1.1 (sw-tools v1.1) #-h- main 832 asc 25-mar-82 08:54:17 v1.1 (sw-tools v1.1) ## split - split a file into pieces DRIVER(split) integer getarg, create, open, ctoi, nlcopy character buf(MAXLINE), outf(FILENAMESIZE) integer nl, i, j, in, usein, out data outf(1), outf(2) / 'x', EOS/ call query("usage: split [-n] [file [name]].") nl = 1000 usein = NO in = STDIN #pick up file name(s) for (i=1; getarg(i,buf,MAXLINE)!=EOF; i=i+1) { if (buf(1) == '-') { if (buf(2) == EOS) usein = YES else { j = 2 nl = max(ctoi(buf,j), 1) } } else if (usein == NO) { in = open(buf,READ) if (in == ERR) call cant(buf) usein = YES } else call scopy(buf, 1, outf, 1) } #main loop to break up file repeat { call extnam(outf, buf) out = create(buf, WRITE) if (out == ERR) call cant(buf) if (nlcopy(in, out, nl) == EOF) break call close(out) } DRETURN end #-h- extnam 447 asc 25-mar-82 08:54:18 v1.1 (sw-tools v1.1) ## extnam - add unique extension to filename -file- subroutine extnam (file, name) character file(ARB), name(ARB), append(3) integer length data append(1), append(2), append(3) /'a', 'a', EOS/ call scopy(file, 1, name, 1) if (append(2) > 'z') { append(2) = 'a' append(1) = append(1) + 1 if (append(1) > 'z') call error ("out of file names.") } call scopy(append, 1, name, length(name)+1) append(2) = append(2) + 1 return end #-h- nlcopy 294 asc 25-mar-82 08:54:20 v1.1 (sw-tools v1.1) ## nlcopy - copy n lines from file in to file out integer function nlcopy (in, out, n) character buf(MAXLINE) integer getlin integer in, out, n, i for (i=1; i<=n; i=i+1) { if (getlin(buf,in) == EOF) { nlcopy = EOF return } call putlin(buf, out) } nlcopy = OK return end #-h- split.fmt 566 asc 25-mar-82 08:54:41 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Split (1) 11-Jan-79 split a file into pieces .sy split [-n] [file [name] ] .ds Split reads `file' and writes it in n-line pieces (default 1000), as many as necessary, onto a set of output files. The name of the output file is `name' with `aa' appended, and so on lexicographically. If no output name is given, `x' is default. If no input file is given, or if - is given in its stead, then the standard input file is used. .fl .sa The Unix command 'split' .di A message is printed if the input file could not be opened. .au Debbie Scherrer .bu %%E 1