comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@aries.mitre.org (Robert I. Eachus)
Subject: Re: Text_Io Questions
Date: 30 Jan 91 00:04:02 GMT	[thread overview]
Message-ID: <EACHUS.91Jan29180402@aries.mitre.org> (raw)
In-Reply-To: tmcclory@valhalla.cs.wright.edu's message of 26 Jan 91 18:53:19 GMT

In article <1991Jan26.185319.15676@cs.wright.edu> tmcclory@valhalla.cs.wright.edu (Tom McClory) writes:

   A few novice questions on using Text_Io ...
-- Actually one easy, one not....

   1) How to open a text file to append to an existing text file?
-- Check the Appendix F supplied with your compiler.  If it supports
-- opening files in append mode, it should tell you what entry to put
-- in the FORM string to do it.  Unfortunately, this string is
-- implementation specific, so I usually use a literal to make the
-- code more portable: 

   APPEND := constant String := "<whatever>";
   ...
   Text_Io.Open(Foo, Text_IO.Out_File, Name => "Bar", Form => Append);

   2) Is there some way to write to either Standard_Output or to a file?

-- You can't OPEN, CLOSE, DELETE, or RESET, the standard input and
-- output files because these procedures take in out parameters.
-- However, the other I/O functions are quite happy to take the value
-- returned by Standard_Output as a parameter.  But you want to write
-- a section of code which writes something either to a named file or
-- to the standard output file?  Sound like a procedure with a
-- parameter of Text_IO.File_Type.  You should probably have an
-- exception handler or code to deal with cases where the file passed
-- is not open:

   procedure Write_Message (To: in Text_IO.File_Type, Message: in String) is
     Was_Closed: Boolean := not IS_OPEN(To)
   begin
     if Was_Closed
     then
       begin
          OPEN(To, TEXT_IO.Out_File, "Junk");
       exception
          -- what goes here depends on how careful you need to be.
       end;
    end if;
    Text_IO.Put_Line(" Junk_Message: " & Message);
  end Write_Message;
--

					Robert I. Eachus

     Our troops will have the best possible support in the entire
world.  And they will not be asked to fight with one hand tied behind
their back.  President George Bush, January 16, 1991

  parent reply	other threads:[~1991-01-30  0:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
1991-01-30  0:05 ` Robert I. Eachus
     [not found] <185319@<1991Jan26>
1991-01-29 17:58 ` stt
replies disabled

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