comp.lang.ada
 help / color / mirror / Atom feed
* End_Of_Line, End_Of_File
@ 1996-11-30  0:00 Fernando Tricas
  1996-11-30  0:00 ` Robert Dewar
  1996-12-02  0:00 ` Peter Amey
  0 siblings, 2 replies; 7+ messages in thread
From: Fernando Tricas @ 1996-11-30  0:00 UTC (permalink / raw)



I'm trying to do a program similar to wc from Unix systems in Ada95 and
I've found the following problem when dealing with a file such as:

** begin file
a

** end file

that is a file composed of two lines, the second (and last) one one empty.

The problem is I do not know how to recognize when there is an End_Of_Line
followed by an End_Of_File or when there is and End_Of_File alone. The
problem seems to be that in Ada95 (I'm using gnat-3.01 compiler on a Unix
workstation) when End_Of_File returns true, End_Of_Line also returns true
and that need not be true. For example:

** begin file
** end file

That is, an empty text file.

Thank you and best regards,

--
Fernando Tricas
ftricas@posta.unizar.es





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

* Re: End_Of_Line, End_Of_File
  1996-11-30  0:00 End_Of_Line, End_Of_File Fernando Tricas
@ 1996-11-30  0:00 ` Robert Dewar
  1996-12-02  0:00   ` Fernando Tricas
  1996-12-10  0:00   ` Robert I. Eachus
  1996-12-02  0:00 ` Peter Amey
  1 sibling, 2 replies; 7+ messages in thread
From: Robert Dewar @ 1996-11-30  0:00 UTC (permalink / raw)



Fernando says

"The problem is I do not know how to recognize when there is an End_Of_Line
followed by an End_Of_File or when there is and End_Of_File alone. The
problem seems to be that in Ada95 (I'm using gnat-3.01 compiler on a Unix
workstation) when End_Of_File returns true, End_Of_Line also returns true
and that need not be true. For example:"


Well GNAT is doing exactly what the Ada 95 reference manual requires.
What you are really discovering is that Text_IO is not an easy tool
for this sort of programming. I recommend you use Stream_IO instead, then
you know exactly what you are reading.





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

* Re: End_Of_Line, End_Of_File
  1996-11-30  0:00 ` Robert Dewar
@ 1996-12-02  0:00   ` Fernando Tricas
  1996-12-02  0:00     ` Robert Dewar
  1996-12-10  0:00   ` Robert I. Eachus
  1 sibling, 1 reply; 7+ messages in thread
From: Fernando Tricas @ 1996-12-02  0:00 UTC (permalink / raw)





> Fernando says
> 
> "The problem is I do not know how to recognize when there is an End_Of_Line
> followed by an End_Of_File or when there is and End_Of_File alone. The

On 30 Nov 1996, Robert Dewar wrote:
> 
> Well GNAT is doing exactly what the Ada 95 reference manual requires.
> What you are really discovering is that Text_IO is not an easy tool
> for this sort of programming. I recommend you use Stream_IO instead, then
> you know exactly what you are reading.


I've solved the problem using instantiating Sequential_IO fot character
type and looking for chacarcter.latin_1.lf

Thank you for your help,

Fernando Tricas






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

* Re: End_Of_Line, End_Of_File
  1996-12-02  0:00   ` Fernando Tricas
@ 1996-12-02  0:00     ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-12-02  0:00 UTC (permalink / raw)



Fernando says

"I've solved the problem using instantiating Sequential_IO fot character
type and looking for chacarcter.latin_1.lf
"

Yes, you can do this, but it is likely to be gruesomely inefficient. It
is much better to use Stream_IO, reading a decent chunk of data at a time.
In addition, there is no guarantee that instantiation Sequential_IO will
work, nowhere in the RM does it guarantee anything about the format of
sequential_io files, and if they happen to correspond to some externally
written file, as opposed to a file written by sequential_io, that's good
luck, but cannot be counted on.

In practice, with almost all (all?) implementations of Ada, this 
particular instantiation of sequential_io will "work", but it is still
a poor way of doing things!





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

* Re: End_Of_Line, End_Of_File
  1996-11-30  0:00 End_Of_Line, End_Of_File Fernando Tricas
  1996-11-30  0:00 ` Robert Dewar
@ 1996-12-02  0:00 ` Peter Amey
  1996-12-02  0:00   ` Robert Dewar
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Amey @ 1996-12-02  0:00 UTC (permalink / raw)



> The problem is I do not know how to recognize when there is an End_Of_Line
> followed by an End_Of_File or when there is and End_Of_File alone. The
> problem seems to be that in Ada95 (I'm using gnat-3.01 compiler on a Unix
> workstation) when End_Of_File returns true, End_Of_Line also returns true
> and that need not be true. For example:


You might like to know that this isn't Ada95 specific: the text_io
supplied with Ada83 compilers from Alsys and DEC behave differently
on the example you give and give a different count of the number of lines 
in a file if if has blank lines before the end of file.  The VAX compiler 
sees these empty lines but the Alsys does not.



Peter






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

* Re: End_Of_Line, End_Of_File
  1996-12-02  0:00 ` Peter Amey
@ 1996-12-02  0:00   ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-12-02  0:00 UTC (permalink / raw)



Peter Amey says

"You might like to know that this isn't Ada95 specific: the text_io
supplied with Ada83 compilers from Alsys and DEC behave differently
on the example you give and give a different count of the number of lines
in a file if if has blank lines before the end of file.  The VAX compiler
sees these empty lines but the Alsys does not."


There is confusion here. This is a clear bug (the difference in behaviors
of the two compilers in Text_IO). This is nothing at all to do with Ada 83
or Ada 95.





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

* Re: End_Of_Line, End_Of_File
  1996-11-30  0:00 ` Robert Dewar
  1996-12-02  0:00   ` Fernando Tricas
@ 1996-12-10  0:00   ` Robert I. Eachus
  1 sibling, 0 replies; 7+ messages in thread
From: Robert I. Eachus @ 1996-12-10  0:00 UTC (permalink / raw)




In article <dewar.849368006@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:

  > Well GNAT is doing exactly what the Ada 95 reference manual
  > requires.  What you are really discovering is that Text_IO is not
  > an easy tool for this sort of programming. I recommend you use
  > Stream_IO instead, then you know exactly what you are reading.

  True.  However, if you need to be using Text_IO for other reasons.

  End_of_File is true if the next thing in the logical file is an end
of file, or if there is a (logical again, not physical) sequence of end
of line, end of page, end of file.  If you read past the (virtual) line
terrminator at the end of the file, then you have also read past an
end of page, so the line number is now 1.

  It really is tricky to implement this on a system so that there are
no "junk" characters in a file, and it is even tougher to copy a file
using just Text_IO, but it can be done.


--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-30  0:00 End_Of_Line, End_Of_File Fernando Tricas
1996-11-30  0:00 ` Robert Dewar
1996-12-02  0:00   ` Fernando Tricas
1996-12-02  0:00     ` Robert Dewar
1996-12-10  0:00   ` Robert I. Eachus
1996-12-02  0:00 ` Peter Amey
1996-12-02  0:00   ` Robert Dewar

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