comp.lang.ada
 help / color / mirror / Atom feed
* Re: End of Line Question
  1996-07-12  0:00   ` Kevin J. Weise
@ 1996-07-12  0:00     ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-07-12  0:00 UTC (permalink / raw)



Michael said

">You could test for this a couple of different ways.  In Ada83, package ASCII
>contains identifiers for all ASCII control characters.  So you could test:
>IF ch = ASCII.cr THEN ..."

In addition to the fact that you won't get them back, and they may not
be there anyway, there is one more thing wrong with the above, namely
the proper location for CR is really Ada.Characters.Latin_1.

ASCII is in Standard, but it is there for backwards compatibility, and
does not contain all the characters, whereas they are all found in the
new package.





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

* Re: End of Line Question
  1996-07-12  0:00 ` Mike Ibarra
@ 1996-07-12  0:00   ` Robert Dewar
  1996-07-12  0:00   ` Kevin J. Weise
  1996-07-15  0:00   ` Nasser Abbasi
  2 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-07-12  0:00 UTC (permalink / raw)



Mike said

"You could test for this a couple of different ways.  In Ada83, package ASCII
contains identifiers for all ASCII control characters.  So you could test:
IF ch = ASCII.cr THEN ..."


This is wrong on two counts, first of all reading with TExt_IO you will
not see carriage return characters.

Second of all, there is no guarantee that CR's appear at the end of each
line in any case, and, glaringly obviously!, all Unix systems use LF as
the end of line character, not CR.

So this suggestion is completely wrong -- stick to the end_of_line test,
that is precisely what it is there for.





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

* End of Line Question
@ 1996-07-12  0:00 Spasmo
  1996-07-12  0:00 ` Mike Ibarra
  1996-07-14  0:00 ` Andy Askey
  0 siblings, 2 replies; 7+ messages in thread
From: Spasmo @ 1996-07-12  0:00 UTC (permalink / raw)



Hi.

In Ada95/83 is there any way to test if the end of line has been reached
on the input?  I'm still in the process of learning Ada, but I haven't
found any info on that.  What I'm trying to do is read characters
one by one (via Ada.Text_IO.Get) and I would like to do so until
CR is pressed.  Unfortunately I find that Get ignores CRs entirely
so I can't test what I read.

I know that I could do use Ada.Text_IO.Get_Line, and process the
string, however I would prefer to use Get for this.

BTW, I'm using GNAT305S for DOS.


Thanks in advance.


--
Spasmo
"Here's a present just for you
When you open it, you'll be through"
	"Letter Bomb" by the Circle Jerks





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

* Re: End of Line Question
  1996-07-12  0:00 End of Line Question Spasmo
@ 1996-07-12  0:00 ` Mike Ibarra
  1996-07-12  0:00   ` Robert Dewar
                     ` (2 more replies)
  1996-07-14  0:00 ` Andy Askey
  1 sibling, 3 replies; 7+ messages in thread
From: Mike Ibarra @ 1996-07-12  0:00 UTC (permalink / raw)
  To: cosc19z5


You could test for this a couple of different ways.  In Ada83, package ASCII 
contains identifiers for all ASCII control characters.  So you could test:
IF ch = ASCII.cr THEN ...

Or you could just test for end of line:
WHILE ( not End_Of_Line ) LOOP...

Hope this helps
-- 
Michael Ibarra





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

* Re: End of Line Question
  1996-07-12  0:00 ` Mike Ibarra
  1996-07-12  0:00   ` Robert Dewar
@ 1996-07-12  0:00   ` Kevin J. Weise
  1996-07-12  0:00     ` Robert Dewar
  1996-07-15  0:00   ` Nasser Abbasi
  2 siblings, 1 reply; 7+ messages in thread
From: Kevin J. Weise @ 1996-07-12  0:00 UTC (permalink / raw)



Mike Ibarra <ibarra@mccabe.com> wrote:
>You could test for this a couple of different ways.  In Ada83, package ASCII 
>contains identifiers for all ASCII control characters.  So you could test:
>IF ch = ASCII.cr THEN ...

Sorry, Michael, can't do this.  The Ada83 LRM talks about line terminators and page 
terminators, but does not specify what they are (or should be).  Text_IO will 
definitely *not* return them to you.

>
>Or you could just test for end of line:
>WHILE ( not End_Of_Line ) LOOP...
>

This is the preferred method.  It is a function in Text_IO (i.e., 
Text_IO.End_of_Line).  There's also a version that accepts a file parameter, in case 
you're reading a real disk file and not from standard input.  Check out Chapter 14 
in the LRM.

>Hope this helps
>-- 
>Michael Ibarra
>

Kevin J. Weise                email:  kweise@sed.redstone.army.mil
COLSA Corporation             voice:  (205)842-9680

.. standard disclaimers apply






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

* Re: End of Line Question
  1996-07-12  0:00 End of Line Question Spasmo
  1996-07-12  0:00 ` Mike Ibarra
@ 1996-07-14  0:00 ` Andy Askey
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Askey @ 1996-07-14  0:00 UTC (permalink / raw)



cosc19z5@Bayou.UH.EDU (Spasmo) wrote:

>Hi.

>In Ada95/83 is there any way to test if the end of line has been reached
>on the input?  I'm still in the process of learning Ada, but I haven't
>found any info on that.  What I'm trying to do is read characters
>one by one (via Ada.Text_IO.Get) and I would like to do so until
>CR is pressed.  Unfortunately I find that Get ignores CRs entirely
>so I can't test what I read.

>I know that I could do use Ada.Text_IO.Get_Line, and process the
>string, however I would prefer to use Get for this.

If Ada95 implements stream like C++ does then you probably out to just
go that route.  The method I have been using forever is to read an
entire line into a string with get_line.  I then can parse the string
any way I want depending on with wind and barometric pressure.  Just
make sure your originally string is big enough and you probably want
to initialize it to blanks first.

package body read_it is
  str : string(1..1024);  -- pick a bigger number if you'd like
  len : integer;
  procedure get_it (hfile : text_io.file_type) is
  begin
      while not end_of_file(hfile) loop
        str := (others => ' ');
        get_line(hfile, str, len);
       -- use text_io to get numbers and enumerated types
       -- just grab the characters for text stuff
      end loop;
end;


--
May your karma be excellent for forgiving my spelling mishaps.

Andy Askey
ajaskey@gnn.com





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

* Re: End of Line Question
  1996-07-12  0:00 ` Mike Ibarra
  1996-07-12  0:00   ` Robert Dewar
  1996-07-12  0:00   ` Kevin J. Weise
@ 1996-07-15  0:00   ` Nasser Abbasi
  2 siblings, 0 replies; 7+ messages in thread
From: Nasser Abbasi @ 1996-07-15  0:00 UTC (permalink / raw)
  To: Mike Ibarra



As someone allready mentioned , you can use end_of_line, as
a full example:

-- shows how to read a line from stdin using get
-- nasser abbasi 7/13/96. Gnat Ada95 on Solaris 2.5

with Ada.Text_IO; use Ada.Text_IO;

procedure T is

 Line: String(1..80);  -- as an example,assumes no more than 80 will be typed
 Ch: Character;
 I : Integer ;

begin

 I := 0;   
 while(not End_Of_Line) loop
   Get(Ch);
   I:= I+1;
   line(I) := Ch;
 end loop;

 Put("There were" & Integer'Image(I) & " characters typed :" & Line(1..I));

end T;
-- 
Nasser Abbasi. C/C++/Ada Solaris. GeneAssist - A client/server application 
for Nucleic acid and protein sequence search and analysis. 
Perkin Elmer - Applied BioSystem division. email:  nasser@apldbio.com   
MSEE(control), MSCS, MSCE, FM (Fide Chess Master).







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

end of thread, other threads:[~1996-07-15  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-12  0:00 End of Line Question Spasmo
1996-07-12  0:00 ` Mike Ibarra
1996-07-12  0:00   ` Robert Dewar
1996-07-12  0:00   ` Kevin J. Weise
1996-07-12  0:00     ` Robert Dewar
1996-07-15  0:00   ` Nasser Abbasi
1996-07-14  0:00 ` Andy Askey

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