comp.lang.ada
 help / color / mirror / Atom feed
* how to designate standard input from another file
@ 2000-06-05  0:00 Terry Westley
  2000-06-05  0:00 ` Jean-Pierre Rosen
  0 siblings, 1 reply; 3+ messages in thread
From: Terry Westley @ 2000-06-05  0:00 UTC (permalink / raw)


A certain program reads two files designated by their names on
the command line.  I would like to be able to use the string "-"
to designate standard input in place of a either file name, as is
often done in Unix utilities.

Its pretty obvious how to open a file and designate it as the
default input (Ada.Text_IO.Set_Input), but I don't know how to
read standard input designated by a Text_IO File_Type.

Something like this would be nice except that File_Type is
limited private:

declare
   File : Ada.Text_IO.File_Type;
begin
   if File_Name = "-" then
      File := Ada.Text_IO.Standard_Input;
   else
      Ada.Text_IO.Open (File, In_File, File_Name);
   end if;
end;

Then, I can just read from File rather than testing
on every read whether I'm reading from File or Standard_Input.

This has got to be easy; what am I missing?

--
Terry J. Westley, Software Systems Engineering Supervisor
Veridian Engineering, Calspan Operations
twestley@buffalo.veridian.com   http://www.veridian.com/
-------------------------------------------------------
Author of TASH, an Ada binding to Tcl/Tk.
Visit the TASH web site at http://www.adatcl.com.
-------------------------------------------------------







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

* Re: how to designate standard input from another file
  2000-06-05  0:00 ` Jean-Pierre Rosen
@ 2000-06-05  0:00   ` Terry Westley
  0 siblings, 0 replies; 3+ messages in thread
From: Terry Westley @ 2000-06-05  0:00 UTC (permalink / raw)


Jean-Pierre Rosen writes:
> Do it the other way round, i.e. read from Standard_Input, and redirect it if necessary:
>  declare
>     File : Ada.Text_IO.File_Type;
>  begin
>     if File_Name /= "-" then
>        Ada.Text_IO.Open (File, In_File, File_Name);
>        Ada.Text_IO.Set_Input (File);
>     end if;
>  end;

Yes, I know this will work; I've done it.

But, what if there are two files for which you want to
allow the user to specify standard input for either file?
The code above won't work unless you require that only
one file be standard input.  And, if the files have some
sort of precedence (as in diff, compare, or merge),
you've lost that unless you keep flags indicating which
one is default input and which is an opened file.

--
Terry J. Westley, Software Systems Engineering Supervisor
Veridian Engineering, Calspan Operations
twestley@buffalo.veridian.com   http://www.veridian.com/
-------------------------------------------------------
Author of TASH, an Ada binding to Tcl/Tk.
Visit the TASH web site at http://www.adatcl.com.
-------------------------------------------------------







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

* Re: how to designate standard input from another file
  2000-06-05  0:00 how to designate standard input from another file Terry Westley
@ 2000-06-05  0:00 ` Jean-Pierre Rosen
  2000-06-05  0:00   ` Terry Westley
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Pierre Rosen @ 2000-06-05  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 690 bytes --]


Terry Westley <twestley@buffalo.veridian.com> a �crit dans le message : amQ_4.2$m22.237@wdc-read-01.qwest.net...
> Something like this would be nice except that File_Type is
> limited private:
>
> declare
>    File : Ada.Text_IO.File_Type;
> begin
>    if File_Name = "-" then
>       File := Ada.Text_IO.Standard_Input;
>    else
>       Ada.Text_IO.Open (File, In_File, File_Name);
>    end if;
> end;
>
Do it the other way round, i.e. read from Standard_Input, and redirect it if necessary:
 declare
    File : Ada.Text_IO.File_Type;
 begin
    if File_Name /= "-" then
       Ada.Text_IO.Open (File, In_File, File_Name);
       Ada.Text_IO.Set_Input (File);
    end if;
 end;








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

end of thread, other threads:[~2000-06-05  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-05  0:00 how to designate standard input from another file Terry Westley
2000-06-05  0:00 ` Jean-Pierre Rosen
2000-06-05  0:00   ` Terry Westley

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