Re: How do I point a file to stdin or stdout ?



Aaron Gray <ang.usenet@xxxxxxxxx> wrote:
> > This is gcc ?
>
> Yes GFC.
>

I guess you mean GPC

> > Why can't you use the standard "input" and "output" files ?
>
> I cannot seem to assign a Text file variable used to indirect file IO to a
> file or standard io.
>
> e.g.
>
> var InFile : Text;
>
> assign( InFile, 'test.txt');
>
> // use InFile
>
> InFile := Input; // This does not work
>
> // use InFile
>
> If there is no way to get round this then I will have to use an if statement
> and duplicate the code.
>

Assignment to file variables is illegal in Pascal. But you can use pointers
to files:

program inp(input, output);
var ifp : ^text;
s : string(2000);
begin
new(ifp);
{$I-} reset(ifp^, 'foo.txt'); {$I+}
if not (IOResult = 0) then begin
writeln('Can not open foo.txt');
halt;
end;
readln(ifp^, s);
writeln(s);
dispose(ifp);
ifp := @input;
readln(ifp^, s);
writeln(s);
end
..

The above is non-standard. Unfortunatly, it seems that EP way of
doing this does not work with GPC.

--
Waldek Hebisch
hebisch@xxxxxxxxxxxxxxxx
.