comp.lang.ada
 help / color / mirror / Atom feed
From: kst@alsys.com (Keith Thompson)
Subject: Re: Opening a File for Appending
Date: Sat, 7 Jan 1995 01:28:44 GMT
Date: 1995-01-07T01:28:44+00:00	[thread overview]
Message-ID: <D20HFw.3I@alsys.com> (raw)
In-Reply-To: 3ejufu$g56@Starbase.NeoSoft.COM

In <3ejufu$g56@Starbase.NeoSoft.COM> dweller@Starbase.NeoSoft.COM (David Weller) writes:
> Um, in Ada95, one of the file modes is Append_File (for any of Text,
> Sequential, Wide, and Stream_IO files).
> 
> Appending a file in Ada83 is OS dependent (unless the POSIX binding
> supports this -- I'm not sure).

Yes it does, via the Form parameter of Text_IO.Open.

Here's a test/demo program; you can compile and execute it to find out
whether your implementation supports POSIX-style appending to a text file.

Note that it isn't necessary to explicitly "with" any POSIX packages;
POSIX specifies this behavior for the LRM-defined Text_IO package.

with Text_IO;
procedure Append_Test is
   File: Text_IO.File_Type;
   File_Name: constant String := "append.txt";
   Line1: constant String := "First line";
   Line2: constant String := "Second line";
   Ok: Boolean := True;
begin
   Text_IO.Create( File => File,
                   Mode => Text_IO.Out_File,
                   Name => File_Name );
   Text_IO.Put_Line(File, Line1);
   Text_IO.Close(File);

   Text_IO.Open( File => File,
                 Mode => Text_IO.Out_File,
                 Name => File_Name,
                 Form => "Append => True" );
   Text_IO.Put_Line(File, Line2);
   Text_IO.Close(File);

   declare
      S: String(1 .. 100);
      Last: Natural;
   begin
      Text_IO.Open( File => File,
                    Mode => Text_IO.In_File,
                    Name => File_Name );
      Text_IO.Get_Line(File, S, Last);
      if S(S'First .. Last) /= Line1 or Text_IO.End_Of_File(File) then
         Ok := False;
      else
         Text_IO.Get_Line(File, S, Last);
         if S(S'First .. Last) /= Line2 then
            Ok := False;
         end if;
      end if;
   exception
      when others =>
         Ok := False;
   end;

   begin
      Text_IO.Delete( File );
   exception
      when others => 
         Ok := False;
   end;

   if Ok then
      Text_IO.Put_Line("This implementation supports POSIX-style");
      Text_IO.Put_Line("appending to a text file via the Form parameter.");
   else
      Text_IO.Put_Line("This implementation does not support POSIX-style");
      Text_IO.Put_Line("appending to a text file via the Form parameter,");
      Text_IO.Put_Line("or some other problem occurred.");
   end if;

end Append_Test;

-- 
Keith Thompson (The_Other_Keith)  kst@thomsoft.com (kst@alsys.com still works)
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
When you're a nail, every problem looks like a hammer.



  parent reply	other threads:[~1995-01-07  1:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-01-05 15:44 Opening a File for Appending Thomas Albrecht
1995-01-06 17:26 ` David Weller
1995-01-06 23:14   ` Steven B. Opdahl
1995-01-07  1:28   ` Keith Thompson [this message]
1995-01-07 22:23   ` Richard Riehle
replies disabled

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