Program Look; { S. Schwartz 22-Feb-79 (link with svrs.mac } { prints 23 lines from an input file on the monitor and then waits for a command to proceed or end the program. The program in proceed will look for a command to look at the next 23 lines or backup and look at the previous 23 lines. The command 'E' will end the program. There are no side effects to the files . } Type filepos = array[1..3] of integer; Const maxsize = 300; Var infile :text; rnum :array[1..3] of integer; cmd :char; linept :array[1..maxsize] of filepos; j,k :integer; Procedure savep(var f: text;var n:filepos);extern; Procedure restp(var f: text;var n:filepos);extern; Procedure xfer(var f:text); Var num :integer; Procedure transfer; Var i :integer; ch :char; begin i:=1; while (not eoln(infile)) and (i<=78) do begin read(infile,ch); if (ch=chr(12)) then begin write(''); i:=i+4 end else if (ch=chr(09)) then begin write(ch); i:=i+8-i mod 8 end else begin write(ch); i:=i+1 end end{ of while loop }; writeln end{ of transfer a line of the file }; begin{ *xfer* } num:=1; while not eof(infile) and (num<=23) do begin transfer; num:=num+1; if num<24 then readln(infile) end {while}; end;{ of xfer } begin { *main* } reset(infile,argv[1]^); cmd:='+'; rnum[1]:=0; rnum[2]:=1; rnum[3]:=0; For k:= 1 to 3 do linept[1,k]:=rnum[k]; j:=1; while cmd<>'E' do begin xfer(infile); readln; read(cmd); if (cmd='+') and (not eof(infile)) then begin savep(infile,rnum); j:=j+1; if (j<=maxsize) then For k:= 1 to 3 do linept[j,k]:=rnum[k] else begin j:=1; For k:= 1 to 3 do linept[j,k]:=rnum[k]; writeln('ERROR OF TYPE 2: EXCEEDED SIZE ') end end else if (cmd='-') and (j>=2) then begin j:=j-1; For k:= 1 to 3 do rnum[k]:=linept[j,k]; restp(infile,rnum); end; if not eof(infile) then readln(infile) end{of while not 'E'} end { of *main* }.