From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ac8:520f:: with SMTP id r15mr9708993qtn.116.1596302633844; Sat, 01 Aug 2020 10:23:53 -0700 (PDT) X-Received: by 2002:ac8:6f51:: with SMTP id n17mr9237525qtv.233.1596302633590; Sat, 01 Aug 2020 10:23:53 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 1 Aug 2020 10:23:53 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.17.79; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.17.79 References: <868e4e17-8624-421d-86bb-64d682a691a9o@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <87b699c8-171d-444f-8b7d-0332cb19a75fo@googlegroups.com> Subject: Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms. From: Shark8 Injection-Date: Sat, 01 Aug 2020 17:23:53 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:59624 List-Id: On Saturday, August 1, 2020 at 1:46:24 AM UTC-6, Blady wrote: > Le 31/07/2020 =C3=A0 20:19, Shark8 a =C3=A9crit=C2=A0: > > 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? > >=20 > > Kind of; I have a generic interface-package that I use for dealing with= text-io and its permutations. > >=20 > > I just published it on github: https://github.com/OneWingedShark/EVIL/t= ree/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. >=20 > 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; =20 -- Instantiate EVIL.Util.Files. Package Uniform_IO is New EVIL.Util.Files ( Character =3D> Character, String =3D> String, File_Type =3D> Ada.Text_IO.File_Type, File_Mode =3D> Ada.Text_IO.File_Mode, Stream_Access =3D> Ada.Text_IO.Text_Streams.Stream_Access ); File : Uniform_IO.File:=3D Uniform_IO.Create( "Test.tmp", Ada.Text_IO.Out= _File ); Begin Declare Test_String : Constant String :=3D "-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 wit= h > >> 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. > >=20 > > 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 h= ave access to the legacy-program sources, you could wrap them or their inte= rfaces in the TASK.) >=20 > Yes, I'll try in that way. It'll probably save you some headache; I've found tasks really good at time= d/cyclic events.