comp.lang.ada
 help / color / mirror / Atom feed
* A Text_IO Question
@ 1996-11-09  0:00 Andy Askey
  1996-11-11  0:00 ` johnherro
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Askey @ 1996-11-09  0:00 UTC (permalink / raw)



I'm converting a little C program to Ada and can't figure out if the
following is possible using Text_IO:

The C program writes a space holding dummy header to the top of the
file, process a lot of data, writes it out, counts up the lines and
calculates statistics on the data, moves the file pointer back to the
top of the file, and overwrites the dummy header with correct data.

I am just wondering if this is possible with Text_IO.  Every method I
tried moves the End of File mark right below the header when I rewrite
the correct data.

Any ideas?


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

Andy Askey
ajaskey@gnn.com





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

* Re: A Text_IO Question
  1996-11-09  0:00 A Text_IO Question Andy Askey
@ 1996-11-11  0:00 ` johnherro
  1996-11-11  0:00   ` Robert Dewar
  0 siblings, 1 reply; 3+ messages in thread
From: johnherro @ 1996-11-11  0:00 UTC (permalink / raw)



ajaskey@gnn.com (Andy Askey) writes:
> The C program writes a ... dummy header to the
> top of the file, process a lot of data, ... moves the
> file pointer back to the top of the file, and overwrites
> the dummy header ... I am just wondering if this is
> possible with Text_IO.

Unfortunately, no.  To achieve random access, you need to instantiate
Direct_IO.  There are two ways to consider solving your problem.  The
first is to instantiate Direct_IO for type Character.  The effect will
depend on the system you're running.  Instantiating Direct_IO for type
Character works great on a PC, and I've done it several times.  On a VAX
running VMS, however, you can create a random access file for type
Character, but you can't later read it as a plain text file.  The file
"attributes" are different, and the system remembers that you have a
random access file and not a plain text file.  DOS doesn't care.

The other thing to consider is using memory, if you have enough memory. 
For example, you might keep the header in memory, and the rest of the data
in a temporary file.  When you're all ready, write out the (real) header
from memory to your final Text_IO file, and then copy data from the
temporary file to the final Text_IO file.  Finally, delete the temporary
file.  I hope this helps.

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

* Re: A Text_IO Question
  1996-11-11  0:00 ` johnherro
@ 1996-11-11  0:00   ` Robert Dewar
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1996-11-11  0:00 UTC (permalink / raw)



iJohn Herro says, answering a question

ajaskey@gnn.com (Andy Askey) writes:
> The C program writes a ... dummy header to the
> top of the file, process a lot of data, ... moves the
> file pointer back to the top of the file, and overwrites
> the dummy header ... I am just wondering if this is
> possible with Text_IO.

Unfortunately, no.  To achieve random access, you need to instantiate
Direct_IO.  There are two ways to consider solving your problem.  The
first is to instantiate Direct_IO for type Character.  The effect will
depend on the system you're running.  Instantiating Direct_IO for type
Character works great on a PC, and I've done it several times.  On a VAX
running VMS, however, you can create a random access file for type
Character, but you can't later read it as a plain text file.  The file
"attributes" are different, and the system remembers that you have a
random access file and not a plain text file.  DOS doesn't care.


That's poor advice for Ada 95 at least. Using Stream_IO would be far
more appropriate, and will solve the given problem precisely, whereas
Direct_IO is quite inappropriate (it is likely to be slow, and the use
described by John is highly non-portable, there is no guarantee that when
you instnatiate direct_IO on charaer that the records will be single
charaters.





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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-09  0:00 A Text_IO Question Andy Askey
1996-11-11  0:00 ` johnherro
1996-11-11  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