comp.lang.ada
 help / color / mirror / Atom feed
From: weisek@source.asset.com (Kevin Weise)
Subject: Re: GNAT not 'getting' CR or LF?
Date: 30 Dec 1994 10:23:45 -0500
Date: 1994-12-30T10:23:45-05:00	[thread overview]
Message-ID: <3e18m1$9eu@source.asset.com> (raw)
In-Reply-To: 1994Dec29.230538.15695@nmt.edu

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



  reply	other threads:[~1994-12-30 15:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-29 23:05 GNAT not 'getting' CR or LF? Smilin' Ron Finkbine
1994-12-30 15:23 ` Kevin Weise [this message]
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
replies disabled

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