comp.lang.ada
 help / color / mirror / Atom feed
* Fill string with multiple lines from standard_input
@ 2002-08-14 19:34 Vincent Smeets
  2002-08-14 20:37 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Vincent Smeets @ 2002-08-14 19:34 UTC (permalink / raw)


Hallo,

How can I fill a string with multiple lines from the standard_input? I want
to have all the characters read from the input till a end of file in a
string.

In C I can do it like this:
    char buffer[1024];
    ssize_t length;

    length = read (1, buffer, sizeof (buffer));
    if (length < 0) {
        perror ("read");
        exit (1);
    }

I can do it with Get_Immediate:
    Buffer : String (1 .. 1024);
    Length : Natural;

    Length := 0;
    while not Ent_Of_File and Length < Buffer'Last loop
        Length := Length + 1;
        Get_Immediate (Buffer (Length));
    end loop;
This works but is very slow with GNAT 3.13p on Windows 2000.

I haven't tried sequential IO, but that is also character by character. I
want something to read a buffer at once. I have been thinking about using
streams. Something like:
    Buffer : String (1 .. 1024);

    String'Read (
        Text_IO.Text_Streams.Stream (Text_IO.Standard_Input),
        Buffer);
But here I don't know how much of the Buffer has been filled.

The last non portable design is to use a pragma import for the C "read"
function. It will work but I don't like it because it isn't portable.

Is the a nice Ada95 way to do this?





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

* Re: Fill string with multiple lines from standard_input
  2002-08-14 19:34 Fill string with multiple lines from standard_input Vincent Smeets
@ 2002-08-14 20:37 ` Stephen Leake
  2002-08-15 17:57   ` Vincent Smeets
  2002-08-15  2:30 ` SteveD
  2002-08-16 17:33 ` Alexei Polkhanov
  2 siblings, 1 reply; 29+ messages in thread
From: Stephen Leake @ 2002-08-14 20:37 UTC (permalink / raw)


"Vincent Smeets" <No@Spam.org> writes:

> Hallo,
> 
> How can I fill a string with multiple lines from the standard_input? I want
> to have all the characters read from the input till a end of file in a
> string.

This sounds like a homework assignment. In which case, the best answer
is "go read your textbook".

If this is not a homework assignment, write back saying that, and why
you need to do this. Then we can provide useful advice.

-- 
-- Stephe



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

* Re: Fill string with multiple lines from standard_input
  2002-08-14 19:34 Fill string with multiple lines from standard_input Vincent Smeets
  2002-08-14 20:37 ` Stephen Leake
@ 2002-08-15  2:30 ` SteveD
  2002-08-15 18:02   ` Vincent Smeets
  2002-08-15 19:07   ` Vincent Smeets
  2002-08-16 17:33 ` Alexei Polkhanov
  2 siblings, 2 replies; 29+ messages in thread
From: SteveD @ 2002-08-15  2:30 UTC (permalink / raw)



"Vincent Smeets" <No@Spam.org> wrote in message
news:ajebhb$ndl$01$1@news.t-online.com...
> Is the a nice Ada95 way to do this?
>
Try this:

with Ada.Text_Io.Text_Streams;
with Ada.Streams;
procedure TestRead is

  in_stream   : Ada.Text_Io.Text_Streams.Stream_Access;
  out_stream  : Ada.Text_Io.Text_Streams.Stream_Access;
  input_chars : Ada.Streams.Stream_Element_Array( 1 .. 1024 );
  last        : Ada.Streams.Stream_Element_Offset;
begin
  in_stream := Ada.Text_Io.Text_Streams.Stream( Ada.Text_Io.Current_Input );
  out_stream := Ada.Text_Io.Text_Streams.Stream(
Ada.Text_Io.Current_Output );
  Ada.Streams.Read( in_Stream.ALL, input_chars, last );
  Ada.Streams.Write( out_Stream.ALL, input_chars(1 .. last ) );
end TestRead;

BTW: There is nothing that says a stream element will correspond to a
character, but in practice I think it will be.

SteveD






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

* Re: Fill string with multiple lines from standard_input
  2002-08-14 20:37 ` Stephen Leake
@ 2002-08-15 17:57   ` Vincent Smeets
  2002-08-15 20:47     ` Stephen Leake
  0 siblings, 1 reply; 29+ messages in thread
From: Vincent Smeets @ 2002-08-15 17:57 UTC (permalink / raw)


Hallo,

No. this is not homework!

"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uk7mt18ig.fsf@gsfc.nasa.gov...
> "Vincent Smeets" <No@Spam.org> writes:
>
> > Hallo,
> >
> > How can I fill a string with multiple lines from the standard_input? I
want
> > to have all the characters read from the input till a end of file in a
> > string.
>
> This sounds like a homework assignment. In which case, the best answer
> is "go read your textbook".
>
> If this is not a homework assignment, write back saying that, and why
> you need to do this. Then we can provide useful advice.
>
> --
> -- Stephe




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

* Re: Fill string with multiple lines from standard_input
  2002-08-15  2:30 ` SteveD
@ 2002-08-15 18:02   ` Vincent Smeets
  2002-08-16  0:25     ` Robert Dewar
  2002-08-15 19:07   ` Vincent Smeets
  1 sibling, 1 reply; 29+ messages in thread
From: Vincent Smeets @ 2002-08-15 18:02 UTC (permalink / raw)


Thanks,

This will give me a Stream_Element_Array. Is it possible to read it directly
in a String or do I have to convert every element to a character in a
string?

Vincent

"SteveD" <nospam_steved94@attbi.com> wrote in message
news:bnE69.29717$Zl2.6800@sccrnsc02...
>
> "Vincent Smeets" <No@Spam.org> wrote in message
> news:ajebhb$ndl$01$1@news.t-online.com...
> > Is the a nice Ada95 way to do this?
> >
> Try this:
>
> with Ada.Text_Io.Text_Streams;
> with Ada.Streams;
> procedure TestRead is
>
>   in_stream   : Ada.Text_Io.Text_Streams.Stream_Access;
>   out_stream  : Ada.Text_Io.Text_Streams.Stream_Access;
>   input_chars : Ada.Streams.Stream_Element_Array( 1 .. 1024 );
>   last        : Ada.Streams.Stream_Element_Offset;
> begin
>   in_stream :=
Ada.Text_Io.Text_Streams.Stream( Ada.Text_Io.Current_Input );
>   out_stream := Ada.Text_Io.Text_Streams.Stream(
> Ada.Text_Io.Current_Output );
>   Ada.Streams.Read( in_Stream.ALL, input_chars, last );
>   Ada.Streams.Write( out_Stream.ALL, input_chars(1 .. last ) );
> end TestRead;
>
> BTW: There is nothing that says a stream element will correspond to a
> character, but in practice I think it will be.
>
> SteveD
>
>
>




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

* Re: Fill string with multiple lines from standard_input
  2002-08-15  2:30 ` SteveD
  2002-08-15 18:02   ` Vincent Smeets
@ 2002-08-15 19:07   ` Vincent Smeets
  2002-08-15 21:49     ` chris.danx
  1 sibling, 1 reply; 29+ messages in thread
From: Vincent Smeets @ 2002-08-15 19:07 UTC (permalink / raw)


Hallo,

I have tested your streams and it didn't work! (Win2000 GNAT 3.13p)

I have a file of 253283 bytes (3310 lines with <CR><LF>). I start my program
with:
    prog <file
and I read 249873 bytes in my buffer. That is exactly 3310 bytes less than
the input file. There is probably some input processing that will leave out
the <CR>. How can I also read the <CR>?

I think that Stream_IO won't do any input processing, but with Stream_IO, I
can only read from a file, not from Standard_Input!

Thanks for any help.

"SteveD" <nospam_steved94@attbi.com> wrote in message
news:bnE69.29717$Zl2.6800@sccrnsc02...
>
> "Vincent Smeets" <No@Spam.org> wrote in message
> news:ajebhb$ndl$01$1@news.t-online.com...
> > Is the a nice Ada95 way to do this?
> >
> Try this:
>
> with Ada.Text_Io.Text_Streams;
> with Ada.Streams;
> procedure TestRead is
>
>   in_stream   : Ada.Text_Io.Text_Streams.Stream_Access;
>   out_stream  : Ada.Text_Io.Text_Streams.Stream_Access;
>   input_chars : Ada.Streams.Stream_Element_Array( 1 .. 1024 );
>   last        : Ada.Streams.Stream_Element_Offset;
> begin
>   in_stream :=
Ada.Text_Io.Text_Streams.Stream( Ada.Text_Io.Current_Input );
>   out_stream := Ada.Text_Io.Text_Streams.Stream(
> Ada.Text_Io.Current_Output );
>   Ada.Streams.Read( in_Stream.ALL, input_chars, last );
>   Ada.Streams.Write( out_Stream.ALL, input_chars(1 .. last ) );
> end TestRead;
>
> BTW: There is nothing that says a stream element will correspond to a
> character, but in practice I think it will be.
>
> SteveD
>
>
>




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

* Re: Fill string with multiple lines from standard_input
  2002-08-15 17:57   ` Vincent Smeets
@ 2002-08-15 20:47     ` Stephen Leake
  2002-08-19 19:39       ` Vincent Smeets
  0 siblings, 1 reply; 29+ messages in thread
From: Stephen Leake @ 2002-08-15 20:47 UTC (permalink / raw)


"Vincent Smeets" <No@Spam.org> writes:

> Hallo,
> 
> No. this is not homework!

Ok. But you didn't answer the other part: 

Why do you want to do this?

From your other posts about streams, it seems clear that you have some
larger goal in mind. Perhaps if you told us what that was, we could
help more.

It is very unlikely that building a large string is a reasonable first
step to anything.

-- 
-- Stephe



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

* Re: Fill string with multiple lines from standard_input
  2002-08-15 19:07   ` Vincent Smeets
@ 2002-08-15 21:49     ` chris.danx
  2002-08-16 19:30       ` Ted Dennison
  0 siblings, 1 reply; 29+ messages in thread
From: chris.danx @ 2002-08-15 21:49 UTC (permalink / raw)


Vincent Smeets wrote:

> I think that Stream_IO won't do any input processing, but with Stream_IO, I
> can only read from a file, not from Standard_Input!

Standard_Input is a file of sorts.  Check the RM for more details.

-- 
for personal replies change 'spamoff' to 'chris'




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

* Re: Fill string with multiple lines from standard_input
  2002-08-15 18:02   ` Vincent Smeets
@ 2002-08-16  0:25     ` Robert Dewar
  0 siblings, 0 replies; 29+ messages in thread
From: Robert Dewar @ 2002-08-16  0:25 UTC (permalink / raw)


"Vincent Smeets" <No@Spam.org> wrote in message news:<ajgrfb$uo2$05$2@news.t-online.com>...
> Thanks,
> 
> This will give me a Stream_Element_Array. Is it possible to read it directly
> in a String or do I have to convert every element to a character in a
> string?

Just leave it as a Stream_Element_Array and work with it
in that form, that sounds like the best idea to me. You
still have not given the foggiest idea why you are trying
to do this (which is what has suggested to some that this
is a homework assignment, in which case your assignment is
to figure out the answer :-)

If it is not a homework assignment you will get much more
effective help if you explain your problem, rather than 
asking about specific possibly inappropriate solutions.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-14 19:34 Fill string with multiple lines from standard_input Vincent Smeets
  2002-08-14 20:37 ` Stephen Leake
  2002-08-15  2:30 ` SteveD
@ 2002-08-16 17:33 ` Alexei Polkhanov
  2 siblings, 0 replies; 29+ messages in thread
From: Alexei Polkhanov @ 2002-08-16 17:33 UTC (permalink / raw)


Did you consider using POSIX library like Florist ? Like this code I use in
order to read
configuration parameters:

----------------------------------------------------------------------------
----
    -- Read configuration parameters from file
    ------------------------------------------------------------------------
--------
    procedure Read_Configuration(File : in String; Options : in out
Service_Options)
    is
        ConfigFile         : POSIX.IO.File_Descriptor;
        ConfigPathname     : POSIX.Pathname :=
           POSIX.To_POSIX_String(File & ASCII.NUL);

        LineNum            : Integer := 0;
        Total              : POSIX.IO_Count := 0; -- total characters read
    begin

        declare

            Use  POSIX;

            Buffer          : POSIX.IO.IO_Buffer(1..Read_Block_Size); --
read buffer
            LineBuffer      : POSIX.IO.IO_Buffer(1..256); -- temporary
buffer to skim line
            Last            : POSIX.IO_Count; -- last character in read
buffer

            CopyFromPosition: Integer := 0;
            PasteAtPosition : Integer := 1;
            CharactersToCopy: Integer := 0;

            -- copy characters from read buffer into line buffer
            procedure AddCharactersToLine is
            begin
                LineBuffer(PasteAtPosition..(PasteAtPosition +
CharactersToCopy - 1 )) :=
                    Buffer(CopyFromPosition..(CopyFromPosition +
CharactersToCopy - 1 ));
            end AddCharactersToLine;

            ParamName : Token;
            ParamValue: Token;

        begin
            ConfigFile := POSIX.IO.Open(ConfigPathname, POSIX.IO.Read_Only);

            while true loop

                 POSIX.IO.Read(ConfigFile, Buffer, Last);

                 CopyFromPosition := 0;
                 CharactersToCopy := 0;

                 for BufferPos in 1..Last loop
                     if Buffer(Integer(BufferPos)) = LF then

                         if CharactersToCopy > 0 then
                             AddCharactersToLine;

                             declare
                                Line : String :=
POSIX.To_String(LineBuffer(LineBuffer'First..CharactersToCopy));
                             begin
                                Split(Line, ParamName, ParamValue);
                                UpdateValue(Line, ParamName, ParamValue);

                                -- if ParamName.exists and ParamValue.exists
then
                                --   Put_Line(Integer'Image(LineNum) & ": "
                                --      &
Line(ParamName.first..ParamName.last)
                                --      & " =[" &
Line(ParamValue.first..ParamValue.last) & "]");
                                -- else
                                --   null;
                                -- end if;

                             end;

                             CharactersToCopy := 0;
                             CopyFromPosition := 0;
                             PasteAtPosition := 1;

                         else
                             null;
                         end if;

                         LineNum := LineNum + 1;
                      else
                             if CopyFromPosition = 0 then
                                 CopyFromPosition := Integer(BufferPos);
                             else
                                 null;
                             end if;
                             CharactersToCopy := CharactersToCopy + 1;
                      end if;
                  end loop;

                  if CharactersToCopy > 0 then
                      AddCharactersToLine;
                      PasteAtPosition := CharactersToCopy;
                  else
                      null;
                  end if;

                  Total := Total + Last;

              end loop;

            exception
                -- when Ada.Io_Exceptions.End_Error =>
                --    POSIX.IO.Close(ConfigFile);
                when others =>
                    POSIX.IO.Close(ConfigFile);
        end;

        exception
            when others =>
                Put_Line("Exception rethrown");

    end Read_Configuration;


Cheers,

---
Alexei Polkhanov,
Sr. Software Engineer,
Incognito Software Inc,
Vancouver, Canada

"Vincent Smeets" <No@Spam.org> wrote in message
news:ajebhb$ndl$01$1@news.t-online.com...
> Hallo,
>
> How can I fill a string with multiple lines from the standard_input? I
want
> to have all the characters read from the input till a end of file in a
> string.
>
> In C I can do it like this:
>     char buffer[1024];
>     ssize_t length;
>
>     length = read (1, buffer, sizeof (buffer));
>     if (length < 0) {
>         perror ("read");
>         exit (1);
>     }
>
> I can do it with Get_Immediate:
>     Buffer : String (1 .. 1024);
>     Length : Natural;
>
>     Length := 0;
>     while not Ent_Of_File and Length < Buffer'Last loop
>         Length := Length + 1;
>         Get_Immediate (Buffer (Length));
>     end loop;
> This works but is very slow with GNAT 3.13p on Windows 2000.
>
> I haven't tried sequential IO, but that is also character by character. I
> want something to read a buffer at once. I have been thinking about using
> streams. Something like:
>     Buffer : String (1 .. 1024);
>
>     String'Read (
>         Text_IO.Text_Streams.Stream (Text_IO.Standard_Input),
>         Buffer);
> But here I don't know how much of the Buffer has been filled.
>
> The last non portable design is to use a pragma import for the C "read"
> function. It will work but I don't like it because it isn't portable.
>
> Is the a nice Ada95 way to do this?
>
>





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

* Re: Fill string with multiple lines from standard_input
  2002-08-15 21:49     ` chris.danx
@ 2002-08-16 19:30       ` Ted Dennison
  2002-08-17  2:26         ` Randy Brukardt
  2002-08-17 10:24         ` Robert Dewar
  0 siblings, 2 replies; 29+ messages in thread
From: Ted Dennison @ 2002-08-16 19:30 UTC (permalink / raw)


"chris.danx" <spamoff.danx@ntlworld.com> wrote in message news:<emV69.1927$U06.25552@newsfep3-gui.server.ntli.net>...
> Vincent Smeets wrote:
> 
> > I think that Stream_IO won't do any input processing, but with Stream_IO, I
> > can only read from a file, not from Standard_Input!
> 
> Standard_Input is a file of sorts.  Check the RM for more details.

Yeah, but its an Ada.Text_IO.File_Type. Stream_IO can only deal with
files it can open by name itself.

What we don't have here is a reason why the input processing that
Ada.Text_IO.Text_Streams is doing to him is a problem. The only reason
I could think of is that it actually contains data rather than text.
This may sound a bit cheesy, but its exactly what a lot of Unix
programs like gunzip do. So the person trying to rewrite Linux in Ada
might stumble over this issue. :-)

-- 
T.E.D. 
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/~dennison/Ted/TED.html



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

* Re: Fill string with multiple lines from standard_input
  2002-08-16 19:30       ` Ted Dennison
@ 2002-08-17  2:26         ` Randy Brukardt
  2002-08-17 10:24         ` Robert Dewar
  1 sibling, 0 replies; 29+ messages in thread
From: Randy Brukardt @ 2002-08-17  2:26 UTC (permalink / raw)


Ted Dennison wrote in message
<4519e058.0208161130.6c77138c@posting.google.com>...
>> Standard_Input is a file of sorts.  Check the RM for more details.
>
>Yeah, but its an Ada.Text_IO.File_Type. Stream_IO can only deal with
>files it can open by name itself.


Huh? The point of Ada.Text_IO.Text_Streams is to convert a File_Type
into a Stream.

OIC -- someone is confusing Stream_IO with Streams.

>What we don't have here is a reason why the input processing that
>Ada.Text_IO.Text_Streams is doing to him is a problem. The only reason
>I could think of is that it actually contains data rather than text.
>This may sound a bit cheesy, but its exactly what a lot of Unix
>programs like gunzip do. So the person trying to rewrite Linux in Ada
>might stumble over this issue. :-)


What input processing? I can't quite see why an implementor
(particularly on Unix or Windows) would bother with any special
processing here. The "stream" just does input on the raw handle (taking
into account any buffering that is used) that corresponds to the Text_IO
file. The device itself might be doing some special processing (as in a
terminal or keyboard), but that doesn't extend to a disk file. Doing
something else is more work and much slower -- why would you want to do
that? (Besides the point that it is dubious that it is intended or
allowed.)

Keep in mind that Stream_IO was virtually untested by the ACATS until
recently, and even now the standard has serious problems which can make
the use of Stream_IO non-portable (since compilers pretty much all do
the wrong thing). So even an implementation which passes the ACATS tests
may still have problems in some cases (having to do with writing,
reading is OK).

                    Randy.








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

* Re: Fill string with multiple lines from standard_input
  2002-08-16 19:30       ` Ted Dennison
  2002-08-17  2:26         ` Randy Brukardt
@ 2002-08-17 10:24         ` Robert Dewar
  2002-08-19 13:40           ` Ted Dennison
  1 sibling, 1 reply; 29+ messages in thread
From: Robert Dewar @ 2002-08-17 10:24 UTC (permalink / raw)


dennison@telepath.com (Ted Dennison) wrote in message news:<4519e058.0208161130.6c77138c@posting.google.com>...

> Yeah, but its an Ada.Text_IO.File_Type. Stream_IO can 
> only deal with files it can open by name itself.

You are confusing stream input-output and the package Stream_IO, have
a look at Ada.Text_IO.Text_Streams.
Seems like you have missed a major and important language
feature!



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

* Re: Fill string with multiple lines from standard_input
  2002-08-17 10:24         ` Robert Dewar
@ 2002-08-19 13:40           ` Ted Dennison
  2002-08-20  0:03             ` Robert Dewar
  0 siblings, 1 reply; 29+ messages in thread
From: Ted Dennison @ 2002-08-19 13:40 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) wrote in message news:<5ee5b646.0208170224.19d9d267@posting.google.com>...
> dennison@telepath.com (Ted Dennison) wrote in message news:<4519e058.0208161130.6c77138c@posting.google.com>...
> 
> > Yeah, but its an Ada.Text_IO.File_Type. Stream_IO can 
> > only deal with files it can open by name itself.
> 
> You are confusing stream input-output and the package Stream_IO, have
> a look at Ada.Text_IO.Text_Streams.
> Seems like you have missed a major and important language
> feature!

err...have a look about 3 posts back. He tried that first, but it was
translating line terminators on him (or at least he said it was...).



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

* Re: Fill string with multiple lines from standard_input
  2002-08-15 20:47     ` Stephen Leake
@ 2002-08-19 19:39       ` Vincent Smeets
  2002-08-20 15:01         ` Stephen Leake
  2002-08-21 14:37         ` Kevin Cline
  0 siblings, 2 replies; 29+ messages in thread
From: Vincent Smeets @ 2002-08-19 19:39 UTC (permalink / raw)



"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:ulm77svbe.fsf@gsfc.nasa.gov...
> "Vincent Smeets" <No@Spam.org> writes:
>
> > Hallo,
> >
> > No. this is not homework!
>
> Ok. But you didn't answer the other part:
>
> Why do you want to do this?

I am working on a remote site and I want all my e-mail to be encrypted and
forwarded. I am writing a program that will create a new mail with an
attachment that contains the encrypted mail (with PGP).

Just encrypting the complete mail isn't correct because the RFC822 and MIME
headers should be in clear text (also inside attachments). I read the mail
in one buffer and then scan for every attachment boundary (recursivly). The
headers will be output as they are and every body part will first be decoded
(base64, quoted-printable) and then encrypted with PGP.

I will need the <CR> if they are in the lines because a message part can be
signed by PGP. Removing the <CR>s will break the signature.

I know that using the buffers will cost a lot of memory but that is not the
problem at this moment. My consern is that reading all the bytes from the
input stream will NOT give you the exact image of what the input stream
actualy was!

As a second release, I want to rewrite my program to work line by line. This
way, I will need to preserve more state in between the processing of the
lines, but this will too need the <CR>s as they are in the input stream!

Thanks,
Vincent





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

* Re: Fill string with multiple lines from standard_input
  2002-08-19 13:40           ` Ted Dennison
@ 2002-08-20  0:03             ` Robert Dewar
  0 siblings, 0 replies; 29+ messages in thread
From: Robert Dewar @ 2002-08-20  0:03 UTC (permalink / raw)


dennison@telepath.com (Ted Dennison) wrote in message news:<4519e058.0208190540.3f183c65@posting.google.com>...
> err...have a look about 3 posts back. He tried that first, but it was
> translating line terminators on him (or at least he said it was...).

I saw nothing unexpected happening. Line terminator translation is not
something that happens at the Ada I/O
level!



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

* Re: Fill string with multiple lines from standard_input
  2002-08-19 19:39       ` Vincent Smeets
@ 2002-08-20 15:01         ` Stephen Leake
  2002-08-20 18:26           ` Vincent Smeets
  2002-08-21 14:37         ` Kevin Cline
  1 sibling, 1 reply; 29+ messages in thread
From: Stephen Leake @ 2002-08-20 15:01 UTC (permalink / raw)


"Vincent Smeets" <No@Spam.org> writes:

> I am working on a remote site and I want all my e-mail to be encrypted and
> forwarded. I am writing a program that will create a new mail with an
> attachment that contains the encrypted mail (with PGP).

Ok, that makes sense. Most likely a stream-based approach will be
best; just leave everything in stream buffers.

> <snip description of mail processing system>

> As a second release, I want to rewrite my program to work line by line. This
> way, I will need to preserve more state in between the processing of the
> lines, but this will too need the <CR>s as they are in the input stream!

What is the advantage of working "line by line"? If it is to reduce
the memory usage, then a better approach is to define a stream buffer
size, and handle the end-of-buffer condition appropriately. "lines"
don't mean much in this kind of application; in fact, as you have
seen, using Ada.Text_IO to read lines actually breaks the application.

-- 
-- Stephe



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

* Re: Fill string with multiple lines from standard_input
  2002-08-20 15:01         ` Stephen Leake
@ 2002-08-20 18:26           ` Vincent Smeets
  2002-08-20 19:46             ` tmoran
                               ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Vincent Smeets @ 2002-08-20 18:26 UTC (permalink / raw)



"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uznvh1snf.fsf@gsfc.nasa.gov...
> "Vincent Smeets" <No@Spam.org> writes:
>
> > As a second release, I want to rewrite my program to work line by line.
This
> > way, I will need to preserve more state in between the processing of the
> > lines, but this will too need the <CR>s as they are in the input stream!
>
> What is the advantage of working "line by line"? If it is to reduce
> the memory usage, then a better approach is to define a stream buffer
> size, and handle the end-of-buffer condition appropriately. "lines"
> don't mean much in this kind of application; in fact, as you have
> seen, using Ada.Text_IO to read lines actually breaks the application.

This will bring be back to my other problem. If I use the streams from
Ada.Text_IO.Text_Streams I will lose the <CR>s.

I can't use Ada.Streams.Stream_IO either because I can't read from the
standard input with that package. You can only read from files that are
opened first by Stream_IO.Open call. I would need the following function
like in Text_IO:
    function Standard_Input
        return Ada.Streams.Stream_IO.File_Type;

Thanks,
Vincent





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

* Re: Fill string with multiple lines from standard_input
  2002-08-20 18:26           ` Vincent Smeets
@ 2002-08-20 19:46             ` tmoran
  2002-08-21 12:50             ` Jean-Pierre Rosen
  2002-08-21 19:19             ` Randy Brukardt
  2 siblings, 0 replies; 29+ messages in thread
From: tmoran @ 2002-08-20 19:46 UTC (permalink / raw)


>If I use the streams from Ada.Text_IO.Text_Streams I will lose the <CR>s.
>
>I can't use Ada.Streams.Stream_IO either because I can't read from the
>standard input with that package. You can only read from files that are
  I suspect your problem is that Standard Input is not opened by the
_OS_ in binary mode, but rather in text mode.  You simply can't use
Standard Input for what you want - you'll have to open a file yourself.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-20 18:26           ` Vincent Smeets
  2002-08-20 19:46             ` tmoran
@ 2002-08-21 12:50             ` Jean-Pierre Rosen
  2002-08-21 19:19             ` Randy Brukardt
  2 siblings, 0 replies; 29+ messages in thread
From: Jean-Pierre Rosen @ 2002-08-21 12:50 UTC (permalink / raw)


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


"Vincent Smeets" <No@Spam.org> a �crit dans le message news:
aju1tq$qna$07$1@news.t-online.com...
> I can't use Ada.Streams.Stream_IO either because I can't read from the
> standard input with that package.
But you can with Ada.Text_IO.Text_Streams....

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





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

* Re: Fill string with multiple lines from standard_input
  2002-08-19 19:39       ` Vincent Smeets
  2002-08-20 15:01         ` Stephen Leake
@ 2002-08-21 14:37         ` Kevin Cline
  2002-08-21 19:47           ` Robert Dewar
  1 sibling, 1 reply; 29+ messages in thread
From: Kevin Cline @ 2002-08-21 14:37 UTC (permalink / raw)


"Vincent Smeets" <No@Spam.org> wrote in message news:<ajrisv$lc9$03$1@news.t-online.com>...
> I am working on a remote site and I want all my e-mail to be encrypted and
> forwarded. I am writing a program that will create a new mail with an
> attachment that contains the encrypted mail (with PGP).

Consider writing this in Perl.  You can probably learn enough Perl
to do this job, and then write the code in less time than you will
spend trying to get it to work in Ada.  My initial estimate is that
you can do this in less than 100 lines of Perl.  There are already
freely available Perl packages that understand mail and encryption,
but in Ada you will have to write all that code from scratch.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-20 18:26           ` Vincent Smeets
  2002-08-20 19:46             ` tmoran
  2002-08-21 12:50             ` Jean-Pierre Rosen
@ 2002-08-21 19:19             ` Randy Brukardt
  2002-08-25  0:34               ` AG
  2 siblings, 1 reply; 29+ messages in thread
From: Randy Brukardt @ 2002-08-21 19:19 UTC (permalink / raw)


Vincent Smeets wrote in message ...
>
>This will bring be back to my other problem. If I use the streams from
>Ada.Text_IO.Text_Streams I will lose the <CR>s.
>
>I can't use Ada.Streams.Stream_IO either because I can't read from the
>standard input with that package. You can only read from files that are
>opened first by Stream_IO.Open call. I would need the following
function
>like in Text_IO:
>    function Standard_Input
>        return Ada.Streams.Stream_IO.File_Type;


That is exactly what Ada.Text_IO.Text_Streams gives you. (I can't
imagine an implementor doing something else...)

Probably your problem is that the OS is eating the <CR>s from Standard
Input, and Ada never sees them. I would expect that you would find this
behavior with any file type that read from the Standard Input handle.

In the mail handling code I've written, I simply assume that the <CR>s
are where they are supposed to be by the RFCs, and put them back in as
needed. Mail that violates RFCs is almost certainly spam anyway; don't
worry about that causing problems, just dump it.

(Bare <CR>s and <LF>s are prohibited by the mail and MIME RFCs anyway,
no mail should have such characters, and what mail servers do with such
mail is undefined. <CR>s paired with <LF>s can always be inserted [and
should be inserted] if you get any bare line ending characters.)

            Randy Brukardt
            (Working on a spam mail filter for the IMS mail server,
written in Ada.)





>Thanks,
>Vincent
>
>





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

* Re: Fill string with multiple lines from standard_input
  2002-08-21 14:37         ` Kevin Cline
@ 2002-08-21 19:47           ` Robert Dewar
  2002-08-22  7:40             ` Kevin Cline
  2002-08-22 20:36             ` Kevin Cline
  0 siblings, 2 replies; 29+ messages in thread
From: Robert Dewar @ 2002-08-21 19:47 UTC (permalink / raw)


kcline17@hotmail.com (Kevin Cline) wrote in message news:<ba162549.0208210637.63f4f7cb@posting.google.com>...
> "Vincent Smeets" <No@Spam.org> wrote in message news:<ajrisv$lc9$03$1@news.t-online.com>...
> > I am working on a remote site and I want all my e-mail to be encrypted and
> > forwarded. I am writing a program that will create a new mail with an
> > attachment that contains the encrypted mail (with PGP).
> 
> Consider writing this in Perl.  You can probably learn enough Perl
> to do this job, and then write the code in less time than you will
> spend trying to get it to work in Ada.  My initial estimate is that
> you can do this in less than 100 lines of Perl.  There are already
> freely available Perl packages that understand mail and encryption,
> but in Ada you will have to write all that code from scratch.

That of course is completely wrong. Please do not take such statements in
posts to CLA as statements of fact, when mostly they just reflect what the
poster is or is not familiar with.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-21 19:47           ` Robert Dewar
@ 2002-08-22  7:40             ` Kevin Cline
  2002-08-23 19:49               ` Peter Richtmyer
  2002-08-22 20:36             ` Kevin Cline
  1 sibling, 1 reply; 29+ messages in thread
From: Kevin Cline @ 2002-08-22  7:40 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) wrote in message news:<5ee5b646.0208211147.6253fb4@posting.google.com>...
> kcline17@hotmail.com (Kevin Cline) wrote in message news:<ba162549.0208210637.63f4f7cb@posting.google.com>...
> > "Vincent Smeets" <No@Spam.org> wrote in message news:<ajrisv$lc9$03$1@news.t-online.com>...
> > > I am working on a remote site and I want all my e-mail to be encrypted and
> > > forwarded. I am writing a program that will create a new mail with an
> > > attachment that contains the encrypted mail (with PGP).
> > 
> > Consider writing this in Perl.  You can probably learn enough Perl
> > to do this job, and then write the code in less time than you will
> > spend trying to get it to work in Ada.  My initial estimate is that
> > you can do this in less than 100 lines of Perl.  There are already
> > freely available Perl packages that understand mail and encryption,
> > but in Ada you will have to write all that code from scratch.
> 
> That of course is completely wrong. Please do not take such statements in
> posts to CLA as statements of fact, when mostly they just reflect what the
> poster is or is not familiar with.

Excuse me for thinking outside the box in an attempt to help the
poster with his stated problem.  You've posted no evidence to refute my
claim.  A google search for 'Ada mail' and 'Ada PGP' turned up nothing useful.
A search for 'Perl mail' returned links to several Perl libraries
and applications that handle mail.  Searching for 'Perl PGP' returned
a reference to the Crypt::OpenPGP library.

So I'm holding to my statement.  This sort of application is
a few hours work for an experienced Perl programmer, 
but at least a couple of days work in Ada or C++.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-21 19:47           ` Robert Dewar
  2002-08-22  7:40             ` Kevin Cline
@ 2002-08-22 20:36             ` Kevin Cline
  2002-08-25  0:45               ` AG
  1 sibling, 1 reply; 29+ messages in thread
From: Kevin Cline @ 2002-08-22 20:36 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) wrote in message news:<5ee5b646.0208211147.6253fb4@posting.google.com>...
> kcline17@hotmail.com (Kevin Cline) wrote in message news:<ba162549.0208210637.63f4f7cb@posting.google.com>...
> > "Vincent Smeets" <No@Spam.org> wrote in message news:<ajrisv$lc9$03$1@news.t-online.com>...
> > > I am working on a remote site and I want all my e-mail to be encrypted and
> > > forwarded. I am writing a program that will create a new mail with an
> > > attachment that contains the encrypted mail (with PGP).
> > 
> > Consider writing this in Perl.  You can probably learn enough Perl
> > to do this job, and then write the code in less time than you will
> > spend trying to get it to work in Ada.  My initial estimate is that
> > you can do this in less than 100 lines of Perl.  There are already
> > freely available Perl packages that understand mail and encryption,
> > but in Ada you will have to write all that code from scratch.
> 
> That of course is completely wrong. Please do not take such statements in
> posts to CLA as statements of fact, when mostly they just reflect what the
> poster is or is not familiar with.

Really?  You've presented no evidence to contradict my claim.

Google searches for 'Ada mail' and 'Ada PGP' came up empty,
but searches for 'Perl mail' and 'Perl PGP' were fruitful.

So I am holding to my statement.  Perl excels for simple
text filtering applications like the one the OP is trying
to build.



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

* Re: Fill string with multiple lines from standard_input
  2002-08-22  7:40             ` Kevin Cline
@ 2002-08-23 19:49               ` Peter Richtmyer
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Richtmyer @ 2002-08-23 19:49 UTC (permalink / raw)


kcline17@hotmail.com (Kevin Cline) wrote in message news:<ba162549.0208212340.2cb0ba5c@posting.google.com>...

> ...You've posted no evidence to refute my claim. 
 
> ...So I'm holding to my statement.  

Robert should take this as quite a compliment. 
If Robert Dewar does not refute it... it must be true!  :-)

Perhaps the poster has been debugging too much Perl.
"If it works, it must be right!"      :-)

cheers,
Peter



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

* Re: Fill string with multiple lines from standard_input
  2002-08-21 19:19             ` Randy Brukardt
@ 2002-08-25  0:34               ` AG
  0 siblings, 0 replies; 29+ messages in thread
From: AG @ 2002-08-25  0:34 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> wrote in message
news:um7ptk6238ap6f@corp.supernews.com...

> Probably your problem is that the OS is eating the <CR>s from Standard
> Input, and Ada never sees them. I would expect that you would find this
> behavior with any file type that read from the Standard Input handle.

Strangely enough, that was the hypothetical question I've proposed
in another thread (called "best way to handle long strings")

> In the mail handling code I've written, I simply assume that the <CR>s
> are where they are supposed to be by the RFCs, and put them back in as
> needed.

Which pretty much means that they are not needed at all.
After all, if you can look at the code and insert missing
line-breaks as you see fit ... obviously they have little
to do with the original code. They must be redundant
or, otherwise, you would not be able to figure out where
to place the missing ones.





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

* Re: Fill string with multiple lines from standard_input
  2002-08-22 20:36             ` Kevin Cline
@ 2002-08-25  0:45               ` AG
  2002-08-26  0:47                 ` Kevin Cline
  0 siblings, 1 reply; 29+ messages in thread
From: AG @ 2002-08-25  0:45 UTC (permalink / raw)



"Kevin Cline" <kcline17@hotmail.com> wrote in message
news:ba162549.0208221236.3ed08fd4@posting.google.com...

> So I am holding to my statement.  Perl excels for simple
> text filtering applications

Hmmm, seems like "simple" above is the keyword.
Sure you can write a throw-away code in, say,
SQL to check or count or verify something.
That's hardly a serious argument to use SQL
in place of <<your favorite language here>>






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

* Re: Fill string with multiple lines from standard_input
  2002-08-25  0:45               ` AG
@ 2002-08-26  0:47                 ` Kevin Cline
  0 siblings, 0 replies; 29+ messages in thread
From: Kevin Cline @ 2002-08-26  0:47 UTC (permalink / raw)


"AG" <ang@xtra.co.nz> wrote in message news:<cKV99.1695$Fc4.326481@news.xtra.co.nz>...
> "Kevin Cline" <kcline17@hotmail.com> wrote in message
> news:ba162549.0208221236.3ed08fd4@posting.google.com...
> 
> > So I am holding to my statement.  Perl excels for simple
> > text filtering applications
> 
> Hmmm, seems like "simple" above is the keyword.
> Sure you can write a throw-away code in, say,
> SQL to check or count or verify something.
> That's hardly a serious argument to use SQL
> in place of <<your favorite language here>>

It's silly to argue that any ONE language is best for
every problem.  The OP's problem, partially encrypting and 
forwarding E-mail, is relatively easy in Perl, and if the OP
is going to be needing solutions to similar problems in the future,
he could save a lot of time by learning Perl.



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

end of thread, other threads:[~2002-08-26  0:47 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-14 19:34 Fill string with multiple lines from standard_input Vincent Smeets
2002-08-14 20:37 ` Stephen Leake
2002-08-15 17:57   ` Vincent Smeets
2002-08-15 20:47     ` Stephen Leake
2002-08-19 19:39       ` Vincent Smeets
2002-08-20 15:01         ` Stephen Leake
2002-08-20 18:26           ` Vincent Smeets
2002-08-20 19:46             ` tmoran
2002-08-21 12:50             ` Jean-Pierre Rosen
2002-08-21 19:19             ` Randy Brukardt
2002-08-25  0:34               ` AG
2002-08-21 14:37         ` Kevin Cline
2002-08-21 19:47           ` Robert Dewar
2002-08-22  7:40             ` Kevin Cline
2002-08-23 19:49               ` Peter Richtmyer
2002-08-22 20:36             ` Kevin Cline
2002-08-25  0:45               ` AG
2002-08-26  0:47                 ` Kevin Cline
2002-08-15  2:30 ` SteveD
2002-08-15 18:02   ` Vincent Smeets
2002-08-16  0:25     ` Robert Dewar
2002-08-15 19:07   ` Vincent Smeets
2002-08-15 21:49     ` chris.danx
2002-08-16 19:30       ` Ted Dennison
2002-08-17  2:26         ` Randy Brukardt
2002-08-17 10:24         ` Robert Dewar
2002-08-19 13:40           ` Ted Dennison
2002-08-20  0:03             ` Robert Dewar
2002-08-16 17:33 ` Alexei Polkhanov

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