here is a small text reader i made recently. i have finally (sort of)
gotten the hang of pointers :)
note: it only reads txt's up to 16000 lines long, i beleive..
program txtread2;
uses crt, dos;
const
escape = #27;
up = #72; { directional keys courtesy of Kim Forwood! :) }
down = #80;
pageup = #73;
pagedown = #81;
home = #71;
endkey = #79;
enter = #13;
type
line = string[80];
pline = ^line;
var
doc : pline;
index : array[1..16000] of pline;
open, i, j, lines, top, bottom, num, counter : integer;
blank80 : string;
check : SearchRec;
f : text;
c : char;
procedure init;
begin
TextColor(0);
TextBackGround(7);
GotoXY(1, 1);
Write('reading file...');
top := 1;
bottom := 24;
end;
procedure ReadFile(filename : string);
begin
assign(f, filename);
reset(f);
ClrScr;
num := 0;
while not eof(f) do begin
inc(num);
new(doc);
ReadLn(f, doc^);
index[num] := doc;
end;
lines := num;
end;
procedure PrintScreen(top, bottom : integer);
var i : integer;
begin
GotoXY(1, 1);
TextColor(7);
TextBackGround(0);
for i := top to bottom do begin
Write(index[i]^);
ClrEol;
GotoXY(1, (WhereY + 1));
end;
GotoXY(1, 25);
TextColor(0);
TextBackGround(7);
write(' text reader v.01 by chainsaw - 4/26/96 - filename: ');
GotoXY(53, 25);
write(ParamStr(open));
end;
procedure TrapKeys;
begin
c := ReadKey;
if c = escape then exit;
if c = up then begin
dec(top);
dec(bottom);
end;
if c = down then begin
inc(top);
inc(bottom);
end;
if c = PageUp then begin
top := top - 23;
bottom := bottom - 23;
end;
if c = PageDown then begin
top := top + 23;
bottom := bottom + 23;
end;
end;
procedure CheckVal;
begin
if top < 1 then begin
top := 1;
bottom := 24;
end;
if bottom > lines then begin
bottom := lines;
top := lines - 23;
end;
end;
procedure DisplayParameters;
begin
WriteLn(' ');
WriteLn(' text reader v.01 by chainsaw - 4/26/96 ');
WriteLn(' parameters: tr filename.ext [filename.ext] [filename.ext] [etc..]');
WriteLn(' specifying more than one file will display each file in the order listed ');
WriteLn(' note: displaying binary files with this reader could be ');
WriteLn(' hazardous to your health (it beeps a LOT)');
WriteLn(' ');
halt(0);
end;
procedure Error;
begin
WriteLn(' ');
WriteLn(' text reader v.01 by chainsaw - 4/26/96 ');
WriteLn(' invalid filename "', ParamStr(i), '"');
WriteLn(' ');
halt(0);
end;
begin
if ParamCount = 0 then DisplayParameters;
for i := 1 to ParamCount do begin
FindFirst(ParamStr(i), AnyFile, check);
if DosError <> 0 then Error;
end;
for i := 1 to ParamCount do begin
init;
ReadFile(ParamStr(i));
repeat
open := i;
PrintScreen(top, bottom);
TrapKeys;
CheckVal;
until c = escape;
end;
end.
ok, well i hope this was inspiring.. use it as you like, and if you have
you can modify the source freely, just be sure to send me a copy! :)
victor dods