comp.lang.ada
 help / color / mirror / Atom feed
From: Pascal MALAISE <malaise@magic.fr>
Subject: Re: GNAT's Text_IO & empty files
Date: 1998/07/06
Date: 1998-07-06T19:53:43+00:00	[thread overview]
Message-ID: <35A12B47.1E9B74B7@magic.fr> (raw)
In-Reply-To: 35A0B7C5.1011D794@Maths.UniNe.CH


Gautier de Montmollin wrote:
> 
> When you create a text file and close it without writing
> anything in it, you get an empty line. This is due to an
> explicit statement in procedure Terminate_Line from Ada.Text_IO.
> 
> This causes an annoying compatibility problem a in DOS or Windows
> context, since you get a 1-line, 2-bytes text instead of a 0-line,
> 0-byte one.

What I see is a 1-line 0-bytes file (with gnat 3.10p on linux)
> ls -al toto
-rw-r--r--   1 malaise  users           1 Jul  6 20:40 toto
> od -x toto
0000000 000a
0000001

On which platform did you make your test on? Dos?
Which bytes do you get? CR LF? or LF ^Z?

Some Unix tools don't like a file ending in the middle of an "active"
line, (it is better to add an empty line at the end of text files).
This is what Gnat does. If you put en "T" in the file, you'll get
54 0a, and, if you put_line "T", you get 54 0a as well :-)
There is no concept of file terminator (EOF) on Unix.

From the original empty file (0a) on unix, unix2dos generates
0d 0a 1a (a CR LF sequence, which is the dos format of a new line, plus
the famous ^Z, which is a Dos convention for the end of file). I think
that it is what ftp in ASCII more would generate from a Unix machine to
a Dos one (LF becomes CR LF and ^Z is appended).
What would be gnat reaction reading such a file??

Creating such empty file on Dos (with an old Meridain, I don't have gnat
on dos)
generates an empty file, and with a put("T") generates a 1-byte file
with 54.


My conclusion is that it is a file formatting question (including file
terminator).
- Unix has a "kind" of standard and Gnat on Linux complies to it.
- Dos has another standard (CR/LF and CtrlZ) but many tools I tried on
Dos don't comply to it (even an ada compiler). Perhaps this convention
is becomming obsolete.
- If you remove this new_line, check that text_io is still able to read
such a file and that it can read a file with some text but no line
terminator as well.
- From the LRM "...the package Text_IO, which provides facilities for
input and output in human-readable form". Readable with what? :-) Some
editing tools of the same platform? Then there is a need for a
"standard" for ascii text on the platform.

-- 
Pascal MALAISE		| E-mail:
22 Avenue de CHOISY	|  (priv) malaise@magic.fr
75013 PARIS		|  (prof) malaise@fr.airsysatm.thomson-csf.com
FRANCE




  reply	other threads:[~1998-07-06  0:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-06  0:00 GNAT's Text_IO & empty files Gautier de Montmollin
1998-07-06  0:00 ` Pascal MALAISE [this message]
1998-07-07  0:00   ` Gautier
1998-07-07  0:00   ` Kevin Radke
1998-07-06  0:00 ` Robert Dewar
1998-07-07  0:00   ` Gautier
1998-07-07  0:00     ` Robert I. Eachus
1998-07-07  0:00     ` Robert Dewar
1998-07-07  0:00   ` Markus Kuhn
1998-07-07  0:00     ` Samuel Tardieu
1998-07-08  0:00       ` Aaro Koskinen
1998-07-09  0:00         ` Gautier.DeMontmollin
1998-07-09  0:00         ` Samuel Tardieu
1998-07-07  0:00     ` Gautier
1998-07-08  0:00     ` dennison
1998-07-07  0:00   ` Markus Kuhn
1998-07-07  0:00     ` Robert Dewar
1998-07-07  0:00     ` Michael F Brenner
replies disabled

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