comp.lang.ada
 help / color / Atom feed
* Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
@ 2020-07-30 20:21 Blady
  2020-07-30 21:51 ` J-P. Rosen
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Blady @ 2020-07-30 20:21 UTC (permalink / raw)


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?

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.

Thanks Pascal.

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  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-07-31 18:19 ` Shark8
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: J-P. Rosen @ 2020-07-30 21:51 UTC (permalink / raw)


Le 30/07/2020 à 22:21, Blady a écrit :

> 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?
> 
> 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.
> 
Why don't you simply pipe the first process to the second one?


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 21:51 ` J-P. Rosen
@ 2020-07-31 17:06   ` Blady
  2020-08-01  5:35     ` J-P. Rosen
  0 siblings, 1 reply; 11+ messages in thread
From: Blady @ 2020-07-31 17:06 UTC (permalink / raw)


Le 30/07/2020 à 23:51, J-P. Rosen a écrit :
> Le 30/07/2020 à 22:21, Blady a écrit :
> 
>> 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?
>>
>> 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.
>>
> Why don't you simply pipe the first process to the second one?

Yes, it was an option.
But I have to catch the outputs during some specific execution phases 
and on some particular output values.
Both processes should then have an extra synchronization path which is 
too far for the considered changes.

The simplest solution (I found) is to add a virtual dummy Text_IO 
package (name My_TIO) with Put_Line defined inside processing the values 
and sending the lines to the other process if needed.
And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
But Text_IO is also used for file management inside the legacy code 
which made me going to wrap all the Text_IO stuff :-(

Then I went to think of the possibility of user defined Put and Get 
subprograms for a Text_IO File_Type object.
However, I even don't know if it is feasible on an Unix-Like OS but I 
would be pleased to having this possibility in an Ada way.

Pascal.


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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  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 18:19 ` Shark8
  2020-08-01  7:46   ` Blady
  2020-09-04 10:14 ` liyan white
  2020-09-24  4:10 ` nimaopatel121
  3 siblings, 1 reply; 11+ messages in thread
From: Shark8 @ 2020-07-31 18:19 UTC (permalink / raw)


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.

> 
> 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.)

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-31 17:06   ` Blady
@ 2020-08-01  5:35     ` J-P. Rosen
  2020-08-01  7:42       ` Blady
  0 siblings, 1 reply; 11+ messages in thread
From: J-P. Rosen @ 2020-08-01  5:35 UTC (permalink / raw)


Le 31/07/2020 à 19:06, Blady a écrit :
> The simplest solution (I found) is to add a virtual dummy Text_IO
> package (name My_TIO) with Put_Line defined inside processing the values
> and sending the lines to the other process if needed.
Looks reasonable

> And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
> But Text_IO is also used for file management inside the legacy code
> which made me going to wrap all the Text_IO stuff :-(
Did you think that you can simply use "renames" to reexport the
operations of Text_IO from My_TIO ?

You could also leave Text_IO and My_TIO. Use Adasubst to automatically
change all the special operations from Text_IO to My_TIO.
https://www.adalog.fr/en/components.html#adasubst

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  5:35     ` J-P. Rosen
@ 2020-08-01  7:42       ` Blady
  2020-08-01 13:45         ` J-P. Rosen
  0 siblings, 1 reply; 11+ messages in thread
From: Blady @ 2020-08-01  7:42 UTC (permalink / raw)


Le 01/08/2020 à 07:35, J-P. Rosen a écrit :
> Le 31/07/2020 à 19:06, Blady a écrit :
>> The simplest solution (I found) is to add a virtual dummy Text_IO
>> package (name My_TIO) with Put_Line defined inside processing the values
>> and sending the lines to the other process if needed.
> Looks reasonable
> 
>> And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
>> But Text_IO is also used for file management inside the legacy code
>> which made me going to wrap all the Text_IO stuff :-(
> Did you think that you can simply use "renames" to reexport the
> operations of Text_IO from My_TIO ?

Yes I'll try in that way.

> You could also leave Text_IO and My_TIO. Use Adasubst to automatically
> change all the special operations from Text_IO to My_TIO.
> https://www.adalog.fr/en/components.html#adasubst

There is always use clause for Text_IO in the code, the point is to 
catch those Put_Line calls with no file parameter.

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-31 18:19 ` Shark8
@ 2020-08-01  7:46   ` Blady
  2020-08-01 17:23     ` Shark8
  0 siblings, 1 reply; 11+ messages in thread
From: Blady @ 2020-08-01  7:46 UTC (permalink / raw)


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?

>> 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.

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  7:42       ` Blady
@ 2020-08-01 13:45         ` J-P. Rosen
  0 siblings, 0 replies; 11+ messages in thread
From: J-P. Rosen @ 2020-08-01 13:45 UTC (permalink / raw)


Le 01/08/2020 à 09:42, Blady a écrit :
> There is always use clause for Text_IO in the code, the point is to
> catch those Put_Line calls with no file parameter.
That's exactly where Adasubst comes handy:
Just use a dictionary with:
   ada.text_io.put_line{standard.string} => My_TIO.Put_Line


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  7:46   ` Blady
@ 2020-08-01 17:23     ` Shark8
  0 siblings, 0 replies; 11+ messages in thread
From: Shark8 @ 2020-08-01 17:23 UTC (permalink / raw)


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.

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  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 18:19 ` Shark8
@ 2020-09-04 10:14 ` liyan white
  2020-09-24  4:10 ` nimaopatel121
  3 siblings, 0 replies; 11+ messages in thread
From: liyan white @ 2020-09-04 10:14 UTC (permalink / raw)


On Friday, July 31, 2020 at 1:51:10 AM UTC+5:30, 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?
> 
> 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.
> 
> Thanks Pascal.

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

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 20:21 Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
                   ` (2 preceding siblings ...)
  2020-09-04 10:14 ` liyan white
@ 2020-09-24  4:10 ` nimaopatel121
  3 siblings, 0 replies; 11+ messages in thread
From: nimaopatel121 @ 2020-09-24  4:10 UTC (permalink / raw)


On Friday, 31 July 2020 01:51:10 UTC+5:30, 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?
> 
> 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.
> 
> Thanks Pascal.

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

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-09-04 10:14 ` liyan white
2020-09-24  4:10 ` nimaopatel121

comp.lang.ada

Archives are clonable: git clone --mirror https://archive.legitdata.co/comp.lang.ada

Example config snippet for mirrors


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git