Orlando Llanes wrote:
Is it possible to open a file for writing without truncating it?
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.)
BTW, should we make `Append'/`Extend' work on typed and untyped files? Neither BP or the standard do it/allow it, but I don't see any reason why not, and it doesn't *seem* too hard to implement...
-- Frank Heckenbach, frank@fjf.gnu.de http://fjf.gnu.de/ PGP and GPG keys: http://fjf.gnu.de/plan
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). 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.
BTW, should we make `Append'/`Extend' work on typed and untyped files? Neither BP or the standard do it/allow it, but I don't see any reason why not, and it doesn't *seem* too hard to implement...
So far, the easiest way I've seen is to..
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'm going to write an asm test program that uses straight OS calls to do the same stuff. I'll post an e-mail with the results once I code it and run it. If (at least for DOS) append is supported by the OS level to do no more than open a file for reading/writing and seek to the end of the file I think it would be worth the effort, otherwise it might not be (imagine appending to a 100MB file by copying its contents!).
{-------} program Tmp;
var F : File; V : array[ 1..4 ] of Char;
begin V := 'Foo,'; Assign( F, 'foo.txt' ); Reset( F, 1 ); Seek( F, FileSize(F) ); BlockWrite( F, V, sizeof(V) ); Close( F );
V := ' Bar'; Assign( F, 'foo.txt' ); Reset( F, 1 ); Seek( F, FileSize(F) ); BlockWrite( F, V, sizeof(V) ); Close( F ); end. {-------}
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