comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
Date: Sat, 1 Aug 2020 10:23:53 -0700 (PDT)	[thread overview]
Message-ID: <87b699c8-171d-444f-8b7d-0332cb19a75fo@googlegroups.com> (raw)
In-Reply-To: <rg36ke$1gtg$1@gioia.aioe.org>

On Saturday, August 1, 2020 at 1:46:24 AM UTC-6, Blady wrote:
> Le 31/07/2020 à 20:19, Shark8 a écrit :
> > On Thursday, July 30, 2020 at 2:21:10 PM UTC-6, Blady wrote:
> >> Hello,
> >>
> >> Given a legacy code calling many Put_Line from Ada.Text_IO which works
> >> nice in a Terminal, I want to add a mode which sends these outputs to
> >> another process without changing the legacy code too much.
> >> And I want to keep the Terminal mode.
> >>
> >> Is there a way to create a File_Type object (from Ada.Text_IO) which
> >> would have user defined Get and Put subprograms instead of the
> >> predefined ones of the file system?
> > 
> > Kind of; I have a generic interface-package that I use for dealing with text-io and its permutations.
> > 
> > I just published it on github: https://github.com/OneWingedShark/EVIL/tree/master/src
> > It's part of what's intended to be a verified, general purpose library -- though I'm still teaching myself SPARK -- and so I've only published the file-interfacing utility portion.
> 
> Have you an example of how to use it?

with
--Ada.Wide_Wide_Text_IO.Text_Streams;
Ada.Text_IO.Text_Streams;

use
--Ada.Wide_Wide_Text_IO;
Ada.Text_IO;

Package Example is
   -- Bring in the Text-stream namespace.
   Use Ada.Text_IO.Text_Streams;
   
   -- Instantiate EVIL.Util.Files.
   Package Uniform_IO is New EVIL.Util.Files
      (
        Character	=> Character,
        String		=> String,
	File_Type	=> Ada.Text_IO.File_Type,
	File_Mode	=> Ada.Text_IO.File_Mode,
	Stream_Access	=> Ada.Text_IO.Text_Streams.Stream_Access
      );
  File : Uniform_IO.File:= Uniform_IO.Create( "Test.tmp", Ada.Text_IO.Out_File );
Begin

   Declare
      Test_String : Constant String := "-TESTING!!-";
   Begin
      String'Write( Test_File.Stream, Test_String );
   End;

End Example;

I don't have it implemented yet, but I plan on doing a "stream splitter" so you could say, use one stream to write to both the file and Standard_IO.

> >> Thus in my case, I will create a custom File_Type object My_Output with
> >> the user define Put which will send the lines to the other process and
> >> then I will call "Set_Output (My_Ouput);" before the legacy code.
> > 
> > It might be a better idea to have them as TASKs and in a single program, selecting and/or creating/executing the proper task ass needed. (If you have access to the legacy-program sources, you could wrap them or their interfaces in the TASK.)
> 
> Yes, I'll try in that way.

It'll probably save you some headache; I've found tasks really good at timed/cyclic events.

  reply	other threads:[~2020-08-01 17:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30 20:21 Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
2020-07-30 21:51 ` J-P. Rosen
2020-07-31 17:06   ` Blady
2020-08-01  5:35     ` J-P. Rosen
2020-08-01  7:42       ` Blady
2020-08-01 13:45         ` J-P. Rosen
2020-07-31 18:19 ` Shark8
2020-08-01  7:46   ` Blady
2020-08-01 17:23     ` Shark8 [this message]
2020-09-04 10:14 ` liyan white
2020-09-24  4:10 ` nimaopatel121
replies disabled

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