Saturday April 18 1998 19:22, Rickey Parrish wrote to All:
RP> I just installed Turbo Pascal 7.0 about 2 hours ago, and am now
RP> trying to write a file viewing program for my BBS. What I want to do,
RP> is open a file and create an array with all the stuff in the file. Hard
RP> to put it into words,so heres the code (its crappy, so it'll probably be
RP> just as hard to understand )
I'll do my best! :>
program FileView;
uses
Crt;
const
Max_Lines = 16000;
type
String80 = String[80]; { That's just good habit }
LineAry = array[1..Max_Lines] of ^String80; { Since we're using a LARGE
array,
we'll have to use pointers }
var
Lines: LineAry; { Reference to LineAry }
f: Text; { File we're dealing with }
i,j: Word; { We're not going to use any negatuve values, so we'll
use a Word instead. }
procedure Cleanup;
(*
Frees memory allocated for strings.
*)
var
Tempi: Word;
begin
for Tempi := 1 to j do
if Lines[j] nil then Freemem(Lines[j], SizeOf(String80));
{ You should look up both Getmem and Freemem for more information.
You should also look up pointers. They're easier to use than you
think - really :> }
end;
begin
i := 0;
j := 0;
{ I had to change the filename for testing purposes }
Assign(f, 'C:\BWAVE\DEFAULT.TAG'); { Just to be safe, always use drive
letters }
{$I-} { Turn IO Checking off. Just in case there is a file error.
Look up "$I: Input/Output-Checking Switch" in the online
help for more information. }
Reset(f);
{$I+}
if IOResult 0 then { If there was an error opening file... }
begin
Write('Error opening file! Aborting!');
Halt(1);
end;
while not Eof(f) do
begin
Inc(i); { Instead of i:=i+1; Does the same thing, but looks nicer :> }
Inc(j); { Ditto }
if i >= Max_Lines then Break; { That makes sure you have room in
the array }
if Memavail < SizeOf(String80) * 2 then Break;
Getmem(Lines[i], SizeOf(String80)); { Allocate memory for pointer }
ReadLn(f, lines[i]^);
end;
Close(f);
i := 0;
while i < j do
begin
Inc(i);
Writeln(lines[i]^);
Delay(300); { So I can read the lines }
if Keypressed then { For testing purposes }
begin
ReadKey;
Break;
end;
end;
CleanUp; { *VERY* inportant that we clean up after ourselves! }
end.
In protected mode, that succeeded in reading in 16000 lines of my tagline
file, and under real mode, you'll likely have to reduce Max_Lines to about
5000 or so, which should allow you to read approximately that many lines
in. But you have to remember, under real mode, you're limited to 655320(?)
bytes on the heap, and each line takes up 81 bytes. But the heap is reduced
by any TSR's etc. that you have loaded, IOW - it's just better to compile
for protected mode :>
RP> Anyway, because its the largest text file I got, Im opening the
RP> help file for the shotgun BBS. Its just shy of 10,000 lines. Just to
RP> see how much of that I could read, I set the array line to
RP> "lines[1..10000]" but it said "Error 22: Structure too large.". It
That's because that array would be 810000 bytes, and you're limited to 64k
of variables under DOS. It sucks, but it's the way it works :/
RP> (BTW - I know that this will not work for a remote user on my
RP> BBS. Once I get the array and other crap worked out I will find a door
RP> kit and use that)
I reccommend EDoor. It can be found at Tiny's BBS 905-723-1575, or FREQ'ed
at 1:229/452 up to 28800 BPS, or in the file section on the web at
http://tinys.oix.com/bbs/ in the programming section. It's about the
easiest door library to use. It requires a 4 line config file (sysop name,
BBS name, BPS rate, drop file type), to start the door library takes two
lines (CfgFn := 'CONFIG_FILE.NAME'; and LoadCfg; ) then to use it, you just
use DWrite() instead of Write(), and DWriteLn() instead of WriteLn, etc..
Stewart Honsberger (AKA Blackdeath)
WWW - http://tinys.oix.com/blackdeath
E-Mail - blackdeath@tinys.oix.com
... Become a programmer - Make a living crashing your computer.
-!- GOPGP v1.11
--- Squish/386 v1.11
---------------
* Origin: Blackdeath BBS - Private (1:229/604)
|