comp.lang.ada
 help / color / mirror / Atom feed
* Random Access in Ada.Text_IO files
@ 2003-02-11 18:34 Micha� Morawski
  2003-02-11 18:58 ` Stephen Leake
  2003-02-11 21:03 ` Jeffrey Carter
  0 siblings, 2 replies; 5+ messages in thread
From: Micha� Morawski @ 2003-02-11 18:34 UTC (permalink / raw)


Hi,

I have encountered the following problem

My program (one task) constantly writes some information to the file (log).
This is simple text line produced every 2 seconds.

Sometimes, other task try to analyze the log and the task need to read the
same file.

This works if files are opened in the "shared=" form. But of course both
tasks use different file position pointers. I wrote the simple test program
presented below. If shared is in "no" mode - I receive use_errer, If "yes"
mode, the file "aaaaaaa" is destroyed by Get (Ascii.null is inserted). After
I wrote the simple monitor to separate the operarions I must write either
extension of Ada.Text_IO or own module. In the first case I cannot compile
the module (I receive the message - it is the system module and cannot be
compiled), and my own module have no acces to stream field of File_Type.

Can anyone give me some advice?

procedure TF is

   NAZWA_PLIKU : constant String := "aaaaaaa";

   task Wr is
   end Wr;

   task body Wr is
      F : File_Type;
      ch : Character := 'a';
   begin
      Create (F, Out_File, NAZWA_PLIKU, "shared=no");
      loop
         Put (F, ch);
         ch := Character'Succ (ch);
         if ch > 'z' then
            ch := 'a';
         end if;
         delay 0.01;
      end loop;
   exception
      when others =>
         Put_Line ("Blad w zadaniu");
   end Wr;

   P : File_Type;
   ch : Character;
begin
   delay 3.0;
   Open (P, In_File, NAZWA_PLIKU, "shared=no");
   Reset (P);
   loop
      Get (P, ch);
      Put (ch);
      delay 0.1;
   end loop;
exception
   when E : others =>
      Put (Ada.Exceptions.Exception_Information (E) &
           GNAT.Traceback.Symbolic.Symbolic_Traceback (E));
end TF;


--

Michal Morawski





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-02-12  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-11 18:34 Random Access in Ada.Text_IO files Micha� Morawski
2003-02-11 18:58 ` Stephen Leake
2003-02-11 21:03 ` Jeffrey Carter
2003-02-12  9:11   ` Egil Harald H�vik
2003-02-12  9:42     ` Egil Harald H�vik

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