comp.lang.ada
 help / color / mirror / Atom feed
* Streams - copying stdin to stdout
@ 1999-02-07  0:00 Chris Miller
  1999-02-09  0:00 ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Miller @ 1999-02-07  0:00 UTC (permalink / raw)


To test the operation of Streams I wrote the following sample
program that copies standard input to standard output :


with Text_IO;
with Ada.Text_IO.Text_Streams;
with Interfaces;

procedure params is

    Stdin  : Ada.Text_IO.Text_Streams.Stream_Access;
    Stdout : Ada.Text_IO.Text_Streams.Stream_Access;
    C : Interfaces.Unsigned_8;

begin
    Stdin := Ada.Text_IO.Text_Streams.Stream (
      File => Text_IO.Standard_Input);
    Stdout := Ada.Text_IO.Text_Streams.Stream (
      File => Text_IO.Standard_Output);

    while not Text_IO.End_Of_File loop

      Interfaces.Unsigned_8'Read(Stdin,C);
      Interfaces.Unsigned_8'Write(Stdout,C);

--      Text_io.Put_Line("Value of Char read is " &
Integer'Image(Integer(C)));

    end loop;

end params;

The compiler was the recently released Gnat 3.11p on Debian 2.0 Linux.

Using vi I created a file called "input" containing the single line "test".

The program was compiled with gnatmake and then run as

  ./params < input > output


The output from ls -l was

-rw-rw-r--   1 chrismil chrismil        5 Feb  7 16:54 input
-rw-rw-r--   1 chrismil chrismil        4 Feb  7 18:09 output

The problem is that the input file has 5 bytes, which are the characters
"test" plus the line feed added by vi, however the output file is only
4 bytes.

Printing out the characters with the Text_IO statement confirms that
only 4 bytes were processed.

Is this a bug or am I missing something ?.

How does one copy a file, viewed as an unstructered block of bytes, from
standard input to standard output.

Chris Miller
chrismil@ozemail.com.au
7-Feb-1999









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

* Re: Streams - copying stdin to stdout
  1999-02-07  0:00 Streams - copying stdin to stdout Chris Miller
@ 1999-02-09  0:00 ` Stephen Leake
  1999-02-10  0:00   ` David Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Leake @ 1999-02-09  0:00 UTC (permalink / raw)


"Chris Miller" <chrismil@ozemail.com.au> writes:

> To test the operation of Streams I wrote the following sample
> program that copies standard input to standard output :
>
<snip code>
>     while not Text_IO.End_Of_File loop
<snip more code>

> The problem is that the input file has 5 bytes, which are the characters
> "test" plus the line feed added by vi, however the output file is only
> 4 bytes.

I suspect you want Streams_IO.End_Of_File. Text_IO adds semantics
about line and page endings, which will get in your way.

-- Stephe




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

* Re: Streams - copying stdin to stdout
  1999-02-09  0:00 ` Stephen Leake
@ 1999-02-10  0:00   ` David Brown
  1999-02-10  0:00     ` rdt
  0 siblings, 1 reply; 4+ messages in thread
From: David Brown @ 1999-02-10  0:00 UTC (permalink / raw)


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> "Chris Miller" <chrismil@ozemail.com.au> writes:
> 
> > To test the operation of Streams I wrote the following sample
> > program that copies standard input to standard output :
> >
> <snip code>
> >     while not Text_IO.End_Of_File loop
> <snip more code>
> 
> > The problem is that the input file has 5 bytes, which are the characters
> > "test" plus the line feed added by vi, however the output file is only
> > 4 bytes.
> 
> I suspect you want Streams_IO.End_Of_File. Text_IO adds semantics
> about line and page endings, which will get in your way.

Streams_IO.End_Of_File wants a Ada.Stremas.Stream_IO.File_Type
whereas we have either a Ada.Text_IO.Text_Streams.Stream_Access
or Ada.Text_IO.File_Type (or File_Access).

The RM doesn't say much about this.  It looks to me like Text_IO's
End_Of_File would be the one to use, but it doesn't work.

David Brown
dlbrown@acm.org




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

* Re: Streams - copying stdin to stdout
  1999-02-10  0:00   ` David Brown
@ 1999-02-10  0:00     ` rdt
  0 siblings, 0 replies; 4+ messages in thread
From: rdt @ 1999-02-10  0:00 UTC (permalink / raw)


In article <osk8xqoek7.fsf@dt022n82.san.rr.com>,
  David Brown <dlbrown@acm.org> wrote:
> Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:
>
> > "Chris Miller" <chrismil@ozemail.com.au> writes:
> >
> > > To test the operation of Streams I wrote the following sample
> > > program that copies standard input to standard output :
> > >
> > <snip code>
> > >     while not Text_IO.End_Of_File loop
> > <snip more code>
> >
> > > The problem is that the input file has 5 bytes, which are the characters
> > > "test" plus the line feed added by vi, however the output file is only
> > > 4 bytes.
> >
> > I suspect you want Streams_IO.End_Of_File. Text_IO adds semantics
> > about line and page endings, which will get in your way.
>
> Streams_IO.End_Of_File wants a Ada.Stremas.Stream_IO.File_Type
> whereas we have either a Ada.Text_IO.Text_Streams.Stream_Access
> or Ada.Text_IO.File_Type (or File_Access).
>
> The RM doesn't say much about this.  It looks to me like Text_IO's
> End_Of_File would be the one to use, but it doesn't work.

The problem seems to stem from the fact that you are not calling
Text_Io.Close. Sect A10.2(3) of the RM suggests that this is when page/file
terminators are written to text files.

This would be done after the end of the loop before the program terminates.

However, this is not possible with Standard output as you do not have a
variable File_Type.

Regards
Richard Toy

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

end of thread, other threads:[~1999-02-10  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-07  0:00 Streams - copying stdin to stdout Chris Miller
1999-02-09  0:00 ` Stephen Leake
1999-02-10  0:00   ` David Brown
1999-02-10  0:00     ` rdt

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