program copy(fin, fout, output); (* file copying program thomas schneider copyright 1982 module libraries: delman, delmods *) label 1; (* end of program *) const (* begin module version *) version = 1.07; (* of copy.p 1994 sep 5 *) (* end module version *) (* begin module describe.copy *) (* name copy: copy one file to another file synopsis copy(fin: in, fout: out, output: out) files fin: the file to be copied fout: the copy of fin output: messages to the user description copy makes one copy of the file fin on the file fout. you may discover that this is a simple task that you often want to do, but that your system does not provide an easy way. see also shift.p author thomas d. schneider bugs none known *) (* end module describe.copy *) var fin, fout: text; (* copy from fin to fout *) linescopied: integer; (* the number of lines copied *) (* begin module package.primitive *) (* ************************************************************************ *) (* begin module halt *) procedure halt; (* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. *) begin writeln(output,' program halt.'); goto 1 end; (* end module halt version = 'delmod 6.51 85 apr 17 tds/gds' *) (* begin module unlimitln *) procedure unlimitln(var afile: text); (* this procedure removes a stupid system dependent limit on the number of lines that one can write to a file. you may remove it from the code if your system does not want or need this. suggested method: place comments around the contents of the procedure. *) begin (* linelimit(afile, maxint); (* set 'infinite' lines allowed for afile *) end; (* end module unlimitln version = 'delmod 6.51 85 apr 17 tds/gds' *) (* begin module copyaline *) procedure copyaline(var fin, fout: text); (* copy a line from file fin to file fout *) begin (* copyaline *) while not eoln(fin) do begin fout^ := fin^; put(fout); get(fin) end; readln(fin); writeln(fout); end; (* copyaline *) (* end module copyaline version = 'delmod 6.51 85 apr 17 tds/gds' *) (* begin module copylines *) function copylines(var fin, fout: text; n: integer): integer; (* copy n lines of file fin to file fout. the actual number of lines copied is returned. *) var index: integer; (* the current line number *) begin (* copylines *) index := 0; while (not eof(fin)) and (index < n) do begin copyaline(fin, fout); index := succ(index) end; copylines := index end; (* copylines *) (* end module copylines version = 'delmod 6.51 85 apr 17 tds/gds' *) (* ************************************************************************ *) (* end module package.primitive version = 'delmod 6.51 85 apr 17 tds/gds' *) begin (* copy *) (* begin module copy.main *) writeln(output,' copy ',version:4:2); reset(fin); rewrite(fout); unlimitln(fout); linescopied := 0; while not eof(fin) do linescopied := linescopied + copylines(fin, fout, maxint); writeln(output,' ',linescopied:1,' lines copied'); (* end module copy.main *) 1: end. (* copy *)