comp.lang.ada
 help / color / mirror / Atom feed
From: stt@inmet.inmet.com
Subject: Re: Text_Io Questions
Date: 29 Jan 91 17:58:00 GMT	[thread overview]
Message-ID: <20600077@inmet> (raw)
In-Reply-To: 185319@<1991Jan26


Re: Text-IO questions.

1) Open with append

There is a semi-standard Form string of "APPEND=>YES" which
several compilers recognize to get open with append.
I think is what the Posix/Ada binding proposed.

To be completely portable, you generally have to create
a temp file, copy the contents of the old file into the new file,
and then write your new data onto the end of the temp file.  When all done
you copy the temp file back on top of the old file.

One final mechanism is to write just your new data to a temp file,
and then call a Unix.System("cat temp_file >> old_file") subprogram
that some vendors provide.

2) Standard Output or other file

As far as having a file which is either Standard_Output
or some other file, you can use the function Current_Output instead,
which is initially Standard_Output, but may be changed
by a Set_Output call.  

If this is not flexible enough,
you can write your own function Switchable_Output, which takes
a File_Type and returns it if Is_Open returns True, and returns
Standard_Output otherwise.

For example:

function Switchable_Output(File : File_Type) return File_Type is
begin
    if Is_Open(File) then
        return File;
    else
        return Standard_Output;
    end if;
end Switchable_Output;

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

P.S. Text-IO has been identified in the Ada 9X requirements
document as requiring additional functionality, in particular
the open-with-append capability.

       reply	other threads:[~1991-01-29 17:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <185319@<1991Jan26>
1991-01-29 17:58 ` stt [this message]
1991-01-26 18:53 Text_Io Questions Tom McClory
1991-01-29  4:02 ` Michael Feldman
1991-01-30  0:04 ` Robert I. Eachus
1991-01-30  0:05 ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox