comp.lang.ada
 help / color / mirror / Atom feed
* How to test if file = Ada.Text_IO.Standard_Input ?
@ 2021-10-23  8:06 reinert
  2021-10-23 10:22 ` Jeffrey R.Carter
  0 siblings, 1 reply; 5+ messages in thread
From: reinert @ 2021-10-23  8:06 UTC (permalink / raw)


Hello,

the following program:

  procedure test1 (file1 : in Ada.Text_IO.File_Type) is
      term1 : constant Boolean := file1 in Ada.Text_IO.Standard_Input;
   begin
      null;
   end test1;

compiles under gnat-10 (debian). The point here is to test if "file1" represents the terminal.

However, when I try to compile using the current GNAT Community Edition from AdaCore, I get the error:

test7.adb:38:41: error: invalid operand types for operator "="
test7.adb:38:41: error: left operand has private type "Ada.Text_Io.File_Type"
test7.adb:38:41: error: right operand has type "Ada.Text_Io.File_Access"
gnatmake: "test7.adb" compilation error

So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?

reinert

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

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23  8:06 How to test if file = Ada.Text_IO.Standard_Input ? reinert
@ 2021-10-23 10:22 ` Jeffrey R.Carter
  2021-10-23 12:28   ` reinert
  2021-10-24 20:51   ` Keith Thompson
  0 siblings, 2 replies; 5+ messages in thread
From: Jeffrey R.Carter @ 2021-10-23 10:22 UTC (permalink / raw)


On 10/23/21 10:06, reinert wrote:
> 
> So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?

Have you tried

Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input)

? (I haven't.)

-- 
Jeff Carter
"C++: The power, elegance and simplicity of a hand grenade."
Ole-Hjalmar Kristensen
90

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

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 10:22 ` Jeffrey R.Carter
@ 2021-10-23 12:28   ` reinert
  2021-10-23 15:40     ` Gautier write-only address
  2021-10-24 20:51   ` Keith Thompson
  1 sibling, 1 reply; 5+ messages in thread
From: reinert @ 2021-10-23 12:28 UTC (permalink / raw)


Yes, now it compiles !

reinert

lørdag 23. oktober 2021 kl. 12:22:40 UTC+2 skrev Jeffrey R.Carter:
> On 10/23/21 10:06, reinert wrote: 
> > 
> > So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?
> Have you tried 
> 
> Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input) 
> 
> ? (I haven't.) 
> 
> -- 
> Jeff Carter 
> "C++: The power, elegance and simplicity of a hand grenade." 
> Ole-Hjalmar Kristensen 
> 90

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

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 12:28   ` reinert
@ 2021-10-23 15:40     ` Gautier write-only address
  0 siblings, 0 replies; 5+ messages in thread
From: Gautier write-only address @ 2021-10-23 15:40 UTC (permalink / raw)


Le samedi 23 octobre 2021 à 14:28:24 UTC+2, reinert a écrit :
> Yes, now it compiles ! 

Interesting to see what name GNAT gives to Standard_Input:

with Ada.Text_IO;

procedure SIO is
begin
  Ada.Text_IO.Put_Line ('[' & Ada.Text_IO.Name (Ada.Text_IO.Standard_Input) & ']');
  Ada.Text_IO.Put_Line ('[' & Ada.Text_IO.Name (Ada.Text_IO.Standard_Error) & ']');
end;

[*stdin]
[*stderr]

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

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 10:22 ` Jeffrey R.Carter
  2021-10-23 12:28   ` reinert
@ 2021-10-24 20:51   ` Keith Thompson
  1 sibling, 0 replies; 5+ messages in thread
From: Keith Thompson @ 2021-10-24 20:51 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
> On 10/23/21 10:06, reinert wrote:
>> So how can I test if "file1" referes to the terminal using the
>> lastest GNAT Community Edition?
>
> Have you tried
>
> Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input)
>
> ? (I haven't.)

That might well serve reinert's needs, but strictly speaking it doesn't
tell you whether File1 refers to the terminal.  At best it might tell
you whether File1 and Standard_Input refer to the same external file --
which may not even be a terminal if standard input was redirected.

GNAT apparently uses "*stdin" as the Name of Standard_Input, regardless
of what actual file it refers to.  There could be an actual file with
that name.  It's not likely, but it means that this method could be
broken maliciously.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

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

end of thread, other threads:[~2021-10-24 20:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-23  8:06 How to test if file = Ada.Text_IO.Standard_Input ? reinert
2021-10-23 10:22 ` Jeffrey R.Carter
2021-10-23 12:28   ` reinert
2021-10-23 15:40     ` Gautier write-only address
2021-10-24 20:51   ` Keith Thompson

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