program decat(input, decatp, f0,f1,f2,f3,f4,f5,f6,f7,f8,f9, output); (* decat: break a file into 10 files Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.lecb.ncifcrf.gov/~toms/ *) {label 1; (* end of program *)} const (* begin module version *) version = 1.14; (* of decat.p 2004 Sep 17 2004 Sep 17, 1.14: empty files not written! 1989 Sep 25, 1.13: functional 1988 Sep 22, 1.00: origin *) (* end module version *) (* begin module describe.decat *) (* name decat: break a file into 10 files synopsis decat(input: in, decatp: in, f0,f1,f2,f3,f4,f5,f6,f7,f8,f9: out, output: out) files input: multiple line detailed description of file 1, etc decatp: parameters. one integer, the number of bytes to put into each file. fx: input split into parts f1..fx Empty files are not written! output: messages to the user description Break a file into parts. Any excess goes into the last file. The files are split at the next line after the size given in decatp has been exceeded. This avoids broken lines, but it means that the user must leave a safety. Purpose: to be able to send files larger than 50000 bytes. The mailer at boulder objects to ones larger. Test for correctness: cat f0 ... f9 >x; diff of input and x should be empty. author Thomas Dana Schneider bugs fixed number of files. *) (* end module describe.decat *) var decatp, (* parameters *) f0,f1,f2,f3,f4,f5,f6,f7,f8,f9: text; (* output files *) (* begin module decat.themain *) procedure themain(var afile: text); (* the main procedure of the program *) var c: char; (* a character from afile *) count: integer; (* number of bytes put to the current output file *) size: integer; (* size of output files *) total: integer; (* number of bytes in input (hopefully!) *) overflow: boolean; (* the last file is overflowing the specified size *) which: integer; (* index to which file to put things into *) begin writeln(output,'decat ',version:4:2); reset(decatp); readln(decatp, size); count := 0; total := 0; overflow := false; which := 0; (* reset(afile); note: can't reset standard input in pipes under UNIX. *) { Old code was to rewrite all - don't do that! rewrite(f0); rewrite(f1); rewrite(f2); rewrite(f3); rewrite(f4); rewrite(f5); rewrite(f6); rewrite(f7); rewrite(f8); rewrite(f9); } if not eof(afile) then begin rewrite(f0); end; while not eof(afile) do begin while not eoln(afile) do begin (* put a single line out *) read(afile,c); case which of 0: write(f0,c); 1: write(f1,c); 2: write(f2,c); 3: write(f3,c); 4: write(f4,c); 5: write(f5,c); 6: write(f6,c); 7: write(f7,c); 8: write(f8,c); 9: write(f9,c); end; count := count + 1; end; readln(afile); case which of (* finish the line *) 0: writeln(f0); 1: writeln(f1); 2: writeln(f2); 3: writeln(f3); 4: writeln(f4); 5: writeln(f5); 6: writeln(f6); 7: writeln(f7); 8: writeln(f8); 9: writeln(f9); end; count := count + 1; (* return *) if count >= size then begin if not overflow then writeln(output,' file ',which:1, ': ', count:1, ' bytes'); total := total + count; count := 0; (* ready for next file *) if which < 9 then begin which := which + 1; case which of (* start the new file *) 0: rewrite(f0); (* not used but kept for consistency *) 1: rewrite(f1); 2: rewrite(f2); 3: rewrite(f3); 4: rewrite(f4); 5: rewrite(f5); 6: rewrite(f6); 7: rewrite(f7); 8: rewrite(f8); 9: rewrite(f9); end; end else if not overflow then begin overflow := true; writeln(output,'WARNING:', ' last file will be too big'); end end end; if count > 0 (* tell about the last one *) then begin writeln(output,' file ',which:1, ': ', count:1, ' bytes'); total := total + count; end; writeln(output,'total bytes split out: ',total:1); end; (* end module decat.themain *) begin themain(input); {1:} end.