Orlando Llanes wrote:
On Thu, 26 Nov 1998, Frank Heckenbach wrote:
Yes, use `Reset' and then `Seek' to the `FileSize' (BP compatible) or use `SeekWrite' or `SeekUpdate' (Extended Pascal standard) instead. (I hope this all works correctly now -- there were some problems with these things earlier. If there still are problems, send me a test program.)
I tried with both BP and GPC, I don't think using Reset is supposed to
work since it's read only (I don't think it should either, it'll make Reset -a read only statement- into an ambiguos statement).
Well, that's what BP does. It's funny -- when GPC behaves differently as BP does, we get requests to make GPC "compatible"; and when we do, people start to realize BP's strangenesses. ;-) In BP, Reset is read-only only for text files, and for typed and untyped files when the global variable FileMode is set to 0 (default 2). In GPC, it's the same now...
I even tried with SeekWrite, didn't bother to write SeekUpdate since 2 out of 3 are not good odds :P The program I wrote to test it is at the end of this e-mail.
Well, I tried it with BP 7.0 and the current GPC, and it does work with both. Of course, foo.txt has to exist before starting the program, just like it has to with Append in BP. If this is the problem, you can check FileExists before opening or use I/O checking like in the following code fragment (again, works well with BP and GPC for me). If there are other problems, tell me which ones.
Assign( f, 'foo.txt' ); {$I-} Reset( F, 1 ); {$I+} if IOResult = 0 then Seek( F, FileSize(F) ) else Rewrite (F, 1); BlockWrite( F, V, sizeof(V) ); Close( F );
Rename the file Create a new file with the old name Copy the contents of the renamed file into the new one Delete the renamed file
This is prolly also the only way to do it.
I hope not. Besides the fact that it's very inefficient as you pointed out, it also loses information about file ownership, permissions etc. (maybe not applicable under Dos).
Kevin A. Foss wrote:
If you want (non-extended) standard Pascal, you'll have to do this on any type of file -- because there is no choice other than to rewrite() when doing file output. The file handling that is there is as simple as possible, probably so it would be portable, but it has always been a pain with Pascal.
True, but I think we should really allow ourselves at least the luxury of Extended Pascal... ;-)
Anyways, here's a use of extend (based on Orlando's code) on an untyped file:
This code doesn't work with the current GPC any more because of too strict type checking, but I fixed it so it should work again with the next GPC version, except that you have to replace
rewrite(out); [...] extend(out);
by
rewrite(out,1); [...] extend(out,1);
(Another stupid BP legacy for untyped files...)-:
So, this will be the best solution after the next release. Until then, Reset and Seek should work fine.
-- Frank Heckenbach, frank@fjf.gnu.de http://fjf.gnu.de/ PGP and GPG keys: http://fjf.gnu.de/plan
On Sun, 29 Nov 1998, Frank Heckenbach wrote:
Well, that's what BP does. It's funny -- when GPC behaves ... 2). In GPC, it's the same now...
I think it's for not wanting to change existing code <grin>
Well, I tried it with BP 7.0 and the current GPC, and it does work ... GPC for me). If there are other problems, tell me which ones.
Doh! NOW I see what I did wrong :}
pointed out, it also loses information about file ownership, permissions etc. (maybe not applicable under Dos).
You do have a point there. Under DOS tho, there's no attributes that can be lost or gained (except for MAYBE Windows NT, I doubt OS/2's DOS would cause any loss of information either).
Kevin A. Foss wrote:
If you want (non-extended) standard Pascal, you'll have to do this on ... it would be portable, but it has always been a pain with Pascal.
Thanks for the tip Kevin! I think I'd rather stick with the FileExist method tho :} Thanks Frank!
See ya! Orlando Llanes
"Meine Damen und Herren, Elvis hat soeben das Gebaeude verlassen!"
"Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org /|____. O <__. /> / \ ____________|_________ http://ourworld.compuserve.com/homepages/Monkey414