Pure Pascal EOF

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Pure Pascal EOF

Post by PeterS »

I am just playing with an old Pure Pascal app I wrote years ago to do some processing of MyMail files.

It needs strings longer than the Pascal 255 ones so I implemented a 1024 char string.

It is read char by char but I have hit problems with testing EOF(file), it is causing a runtime 100 error. I tried changing it from a file of char to a file of byte without success.

Why would EOF cause an error ?

Code: Select all

TYPE
  TTextFile = object(TObject)
    filename : string;
    textfile : file of byte;

...
VAR
    rch        : byte;

...
    READ (textfile, rch);
    if (EOF (textfile) )
    then
      writeln('EOF');
ThorstenOtto
Atari God
Atari God
Posts: 1268
Joined: Sun Aug 03, 2014 5:54 pm

Re: Pure Pascal EOF

Post by ThorstenOtto »

I'm not a pascal expert, but i think you have to check for EOF before trying to read from the file.
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Pure Pascal EOF

Post by PeterS »

That doesn't work.

Once in the read loop it wouldn't make sense either.

Example:
https://www.freepascal.org/docs-html/rt ... m/eof.html


It seems to be any attempt to check EOF causes the error.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2726
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pure Pascal EOF

Post by charles »

need to make the editor reserve more space with memory directive?
increasing heap size?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Pure Pascal EOF

Post by PeterS »

I've never managed to run apps inside the pp editor it just crashes.

I am running my app from bash.
czietz
Hardware Guru
Hardware Guru
Posts: 1347
Joined: Tue May 24, 2016 6:47 pm

Re: Pure Pascal EOF

Post by czietz »

I've refreshed my rusty Pascal knowledge. Thorsten is right! Runtime error 100 means that you tried to read past EOF. I.e., if you're already at the end of the file, try to read from it and have IO exceptions enabled ({$I+} directive), you get runtime error 100. You have to check for EOF before trying to read.

EDIT: From the PurePascal help file (I only have it in German):
Runtime error 100: disk read error
------------------------------------------------------------------

Der Laufzeitfehler 'disk read error' wird erzeugt, wenn versucht
wird, mittels Read über das Ende einer typisierten Datei hinaus-
zulesen.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2726
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pure Pascal EOF

Post by charles »

what size is your file?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Pure Pascal EOF

Post by PeterS »

I had to handle the end of the file by testing for zero in the value returned. Luckily this is ascii so that works.

Does anyone have a list of the Pure Pascal runtime error codes ?
ThorstenOtto
Atari God
Atari God
Posts: 1268
Joined: Sun Aug 03, 2014 5:54 pm

Re: Pure Pascal EOF

Post by ThorstenOtto »

The example you linked above does the same as already mentioned: checking for eof *before* trying to read.

I don't know if there is a list, but if you invoke Help/Help and search for "RUNTIME ERROR 207", you get an explanation.

Edit: i suppose there is a list somewhere in the help file, but i could not find the link to it.
Last edited by ThorstenOtto on Fri May 08, 2020 1:38 pm, edited 1 time in total.
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Pure Pascal EOF

Post by PeterS »

EOF didn't work so I had to test for a 0 in the returned content. It looks like PP eof only works in text files.
czietz
Hardware Guru
Hardware Guru
Posts: 1347
Joined: Tue May 24, 2016 6:47 pm

Re: Pure Pascal EOF

Post by czietz »

PeterS wrote:EOF didn't work so I had to test for a 0 in the returned content. It looks like PP eof only works in text files.
It works just fine with a "File of Byte", too! You just have to test for EOF before reading the next byte -- as mentioned multiple times in this thread.

This will read the entire PP.CFG, byte by byte, without triggering a Runtime Error 100.

Code: Select all

{$I+} 
var
    f : File of Byte;
    w : Byte;
begin
    Assign( f, 'PP.CFG' );
    Reset( f );
    while not Eof( f ) do begin
        Read( f, w );
    end;
    Close( f );
end.
PeterS
Captain Atari
Captain Atari
Posts: 353
Joined: Fri Nov 09, 2007 1:53 pm
Location: England, GB

Re: Pure Pascal EOF

Post by PeterS »

In my tests the eof flag is Never being set no matter where it is tested this results in reading beyond the end of the file.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2726
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pure Pascal EOF

Post by charles »

have you tried Recsize yet ?
command reset(f) or reset(f,1)?
without recsize it assumes and returns undesired filesize

but u may need to use this command too

SetTextBuf
-------------------------------------------------- ----------------

Declaration procedure SetTextBuf (var t: Text; var buf
[; size: LongInt])

Description The SetTextBuf procedure assigns a text file
variable a new size I / O buffer
size too. The specification of size is optional.
Text file variables have one by default
I / O buffer with 128 bytes size. Intervenes
Program frequently towards a text file, so
this the program speed clearly
decrease because many (relatively slow)
accesses to the data carrier are necessary.
Therefore, a larger block is always in
read a buffer or from a buffer
written, so a speed
increase can be achieved. SetTextBuf can
install a larger I / O buffer.

Warning: SetTextBuf must never be on one
open file will be applied!

Cross references

Read Write text

Example var
t: text;
c: Char;
buf: Array [1..8192] of Char;
begin
Assign (t, 'TEST.TXT');
SetTextBuf (t, buf);
Reset (t);
while not Eof (t) do begin
Read (t, c);
Write (c);
end;
Close (t);
end.
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Post Reply

Return to “C / PASCAL etc.”