comp.lang.ada
 help / color / mirror / Atom feed
* GNAT not 'getting' CR or LF?
@ 1994-12-29 23:05 Smilin' Ron Finkbine
  1994-12-30 15:23 ` Kevin Weise
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Smilin' Ron Finkbine @ 1994-12-29 23:05 UTC (permalink / raw)


I am using the gnat system (DOS version) and am writing a 
Fortran scanner. I am having a problem with the Text_IO.get
function getting a character. It seems to ignore the carriage
return and linefeed characters.

What knowledge about gnat am I missing?

Thanks.

Ron



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

* Re: GNAT not 'getting' CR or LF?
  1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
@ 1994-12-30 15:23 ` Kevin Weise
  1994-12-30 17:39 ` Michael Feldman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Kevin Weise @ 1994-12-30 15:23 UTC (permalink / raw)


In article <1994Dec29.230538.15695@nmt.edu>,
Smilin' Ron Finkbine <finkbine@nmt.edu> wrote:
>I am using the gnat system (DOS version) and am writing a 
>Fortran scanner. I am having a problem with the Text_IO.get
>function getting a character. It seems to ignore the carriage
>return and linefeed characters.
>
>What knowledge about gnat am I missing?
>
I haven't looked closely at the Ada95 RM for Text_IO; but I know that in
Ada83, line terminators are considered implementation dependent, and
therefore (in the interest of portability) not returned to the user.
That is, if you are reading input one character at a time, then you
should not count on receiving any kind of line terminator character.
This is pretty easy to understand, Unix uses a newline (ASCII linefeed),
VAX/VMS uses a CR/LF (ASCII carriage return-linefeed combination) on
*one* kind of textfile, MS-DOS uses (I've never been certain if it was a
CR only or a CR-LF), some computers have no line terminator (but I don't
know of anyone using CDC Cybers anymore).  If you write a program that
expects, e.g. a newline as a line terminator, then that program does not
necessarily quickly/easily port to anything except a Unix look-alike.
To do what you want, I believe you have two major options:

1.  Test using Text_IO.End_of_Line before each character read (quick,
    but real dirty & inefficient) or,

2.  Buffer your own input, reading an entire line at a time using 
    Text_IO.Get_Line, and then appending your own line terminator
    character of choice after the last character of each line.  Then,
    you do character-at-a time fetches from this line buffer, filling it
    with the next line each time you return the last character.  (You
    would be wise to put a file terminator character of choice after 
    Text_IO.End_of_File, too.)

Both these options are truly portable.  My guess is, in order to
preserve semantics of existing software, Ada95 (and thus GNAT) works the
same way.
----------------------------------------------------------------
Kevin J. Weise			weisek@source.asset.com
COLSA Corporation		Voice - (205) 922-1512 ext. 2115
6726 Odyssey Drive		FAX   - (205) 971-0002
Huntsville, AL  35806
{Standard Disclaimers about my opinions & my employer's opinions}
{... which are in conflict often enough}
----------------------------------------------------------------
"Admire those who seek the truth;
  avoid those who find it."		Marcel Proust



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

* Re: GNAT not 'getting' CR or LF?
  1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
  1994-12-30 15:23 ` Kevin Weise
@ 1994-12-30 17:39 ` Michael Feldman
  1995-01-02  4:42 ` Robert Dewar
  1995-01-04 11:47 ` Joerg Rodemann
  3 siblings, 0 replies; 8+ messages in thread
From: Michael Feldman @ 1994-12-30 17:39 UTC (permalink / raw)


In article <1994Dec29.230538.15695@nmt.edu>,
Smilin' Ron Finkbine <finkbine@nmt.edu> wrote:
>I am using the gnat system (DOS version) and am writing a 
>Fortran scanner. I am having a problem with the Text_IO.get
>function getting a character. It seems to ignore the carriage
>return and linefeed characters.
>
>What knowledge about gnat am I missing?
>
Not a GNAT issue. Text_IO.Get is doing exactly what the LRM requires.
Quoting from 9XLRM A.10.7:

"After skipping any line terminators and any page terminators,
reads the next character from the specified input file..."

in other words, the procedure is designed to ignore the CRs and LFs.
The behavior is the same in Ada 83 and Ada 95.

To detect EOL in Ada, it's best and most portable to use the 
Text_IO.End_Of_Line function, since in Ada EOL is not treated as a 
character, but as an abstraction. This is Pascal-ish, not C-ish,
input behavior. For more details, see the LRM (Ada 83 or 95) or a good
textbook description of Text_IO.

Hope this helps.

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman -  chair, SIGAda Education Working Group
Professor, Dept. of Electrical Engineering and Computer Science
The George Washington University -  Washington, DC 20052 USA
202-994-5919 (voice) - 202-994-0227 (fax) - mfeldman@seas.gwu.edu (Internet)
------------------------------------------------------------------------
         Ada on the World-Wide Web: http://lglwww.epfl.ch/Ada/
------------------------------------------------------------------------
"Illegitimi non carborundum." (Don't let the bastards grind you down.)
------------------------------------------------------------------------



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

* Re: GNAT not 'getting' CR or LF?
  1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
  1994-12-30 15:23 ` Kevin Weise
  1994-12-30 17:39 ` Michael Feldman
@ 1995-01-02  4:42 ` Robert Dewar
  1995-01-03  2:56   ` Keith Thompson
  1995-01-04 11:47 ` Joerg Rodemann
  3 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1995-01-02  4:42 UTC (permalink / raw)


Get will certainly NOT see CR/LF etc, that is its spec.
For now, until Get_Immediate is implemented, the best thing
is simply to write an interface to the appropriate C routine getchar or
whatever.




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

* Re: GNAT not 'getting' CR or LF?
  1995-01-02  4:42 ` Robert Dewar
@ 1995-01-03  2:56   ` Keith Thompson
  1995-01-05  0:16     ` Kurt Bischoff
  0 siblings, 1 reply; 8+ messages in thread
From: Keith Thompson @ 1995-01-03  2:56 UTC (permalink / raw)


In <3e8079$552@gnat.cs.nyu.edu> dewar@cs.nyu.edu (Robert Dewar) writes:
> Get will certainly NOT see CR/LF etc, that is its spec.
> For now, until Get_Immediate is implemented, the best thing
> is simply to write an interface to the appropriate C routine getchar or
> whatever.

This might be true for an interactive application that needs to detect
individual keypresses (or better yet, use the POSIX/Ada interface if
your vendor supports it).

For the application in question (a Fortran scanner), I think the best
thing is just to use Text_IO.Get_Line and scan characters from the
input string.  Ada's Text_IO is perfectly adequate for this kind of thing.

-- 
Keith Thompson (The_Other_Keith)  kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
When you're a nail, every problem looks like a hammer.



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

* Re: GNAT not 'getting' CR or LF?
  1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
                   ` (2 preceding siblings ...)
  1995-01-02  4:42 ` Robert Dewar
@ 1995-01-04 11:47 ` Joerg Rodemann
  3 siblings, 0 replies; 8+ messages in thread
From: Joerg Rodemann @ 1995-01-04 11:47 UTC (permalink / raw)


Smilin' Ron Finkbine (finkbine@nmt.edu) wrote:
> I am using the gnat system (DOS version) and am writing a 
> Fortran scanner. I am having a problem with the Text_IO.get
> function getting a character. It seems to ignore the carriage
> return and linefeed characters.

Hello!

As you might have read last month I had the same problem with GNAT on
a Sun-Workstation. I tried to write a routine that reads one character
from stdin without making any difference between normal and special
characters (e. g. '\n'). 

Per chance I found a solution that worked pretty good for my needs. And
it proved really easy, too. All I had to do was to replace the GET-routine
from Text_IO with the same routine from IO. As it turned out, this
procedure does not distinguish between alphanumerical or special
characters. Especially it also returned the needed newline.

I do not have any knowledge whether this solution is just working correctly
on a Unix-machine or is also functioning under MS-Dos. On the other hand
it seems really easier to use getline for the problem you described, in my
opinion and as far as I understood your short description. 

> Thanks.

> Ron

So long

George

--
Joerg 'George' Rodemann                                     Kelternweg 46
Department of Physics                                     89075 Ulm/Donau
University of Ulm                                       Tel. (0731) 54407
e-mail:                                    rodemann@mathematik.uni-ulm.de



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

* Re: GNAT not 'getting' CR or LF?
  1995-01-03  2:56   ` Keith Thompson
@ 1995-01-05  0:16     ` Kurt Bischoff
  1995-01-06  3:21       ` Keith Thompson
  0 siblings, 1 reply; 8+ messages in thread
From: Kurt Bischoff @ 1995-01-05  0:16 UTC (permalink / raw)


In article <D1t6tx.G59@alsys.com> kst@alsys.com (Keith Thompson) writes:
>In <3e8079$552@gnat.cs.nyu.edu> dewar@cs.nyu.edu (Robert Dewar) writes:
>> Get will certainly NOT see CR/LF etc, that is its spec.
>> For now, until Get_Immediate is implemented, the best thing
>> is simply to write an interface to the appropriate C routine getchar or
>> whatever.
>
>This might be true for an interactive application that needs to detect
>individual keypresses (or better yet, use the POSIX/Ada interface if
>your vendor supports it).
>
>For the application in question (a Fortran scanner), I think the best
>thing is just to use Text_IO.Get_Line and scan characters from the
>input string.  Ada's Text_IO is perfectly adequate for this kind of thing.
>
>-- 
>Keith Thompson (The_Other_Keith)  kst@alsys.com
>TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
>10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
>When you're a nail, every problem looks like a hammer.

How about bringing out the big guns and using AFLEX and AYACC?
_____________
Kurt Bischoff, Odyssey Research, 301 Dates Drive, Ithaca, NY,  14850 
(607) 277-2020
bischoff@oracorp.com 



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

* Re: GNAT not 'getting' CR or LF?
  1995-01-05  0:16     ` Kurt Bischoff
@ 1995-01-06  3:21       ` Keith Thompson
  0 siblings, 0 replies; 8+ messages in thread
From: Keith Thompson @ 1995-01-06  3:21 UTC (permalink / raw)


In <1995Jan5.001630.20954@oracorp.com> bischoff@oracorp.com (Kurt Bischoff) writes:
> In article <D1t6tx.G59@alsys.com> kst@alsys.com (Keith Thompson) writes:
> >For the application in question (a Fortran scanner), I think the best
> >thing is just to use Text_IO.Get_Line and scan characters from the
> >input string.  Ada's Text_IO is perfectly adequate for this kind of thing.

> How about bringing out the big guns and using AFLEX and AYACC?

Can AFLEX handle Fortran's bizarre tokenization rules?  If so, I'm
impressed (I think).

-- 
Keith Thompson (The_Other_Keith)  kst@thomsoft.com (kst@alsys.com still works)
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
When you're a nail, every problem looks like a hammer.



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

end of thread, other threads:[~1995-01-06  3:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
1994-12-30 15:23 ` Kevin Weise
1994-12-30 17:39 ` Michael Feldman
1995-01-02  4:42 ` Robert Dewar
1995-01-03  2:56   ` Keith Thompson
1995-01-05  0:16     ` Kurt Bischoff
1995-01-06  3:21       ` Keith Thompson
1995-01-04 11:47 ` Joerg Rodemann

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