On Sat, 28 Nov 1998 19:50:35 -0500 (EST), Orlando Llanes wrote:
>On Thu, 26 Nov 1998, Frank Heckenbach wrote:
>> 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...
As far as I know, Extend already does. I tried the code that follows
with GPC 980420 (the last version that worked with gcc 2.7.x) and it
worked fine for me.
>
> 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
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.
Anyways, here's a use of extend (based on Orlando's code) on an untyped
file:
program Tmp(output);
var
out : bindable file;
b : BindingType;
V : array[ 1..4 ] of char;
begin
b := binding(out);
b.name := 'foo.txt';
bind(out,b);
b := binding(out);
rewrite(out);
V := 'Foo,';
BlockWrite(out, V, sizeof(V));
unbind(out);
b := binding(out);
b.name := 'foo.txt';
bind(out, b);
b := binding(out);
extend(out);
V := 'Bar';
BlockWrite(out, V, sizeof(V));
unbind(out);
end.
--
Kevin A. Foss --- kfoss(a)mint.net