comp.lang.ada
 help / color / mirror / Atom feed
* Mixing reading and writing to a text file
@ 2007-08-02  7:43 msimonides
  2007-08-03  1:26 ` Randy Brukardt
  0 siblings, 1 reply; 3+ messages in thread
From: msimonides @ 2007-08-02  7:43 UTC (permalink / raw)


I'm facing a situation, where I need to access a text file for both
input and output.

This file is used for storing a sequence of different records (of
various lengths - it's not possible to define the upper bound)
defining operations that need to be performed. Some errors could occur
and the processing might be aborted. In this case it is crucial to
store state of the processing (in the simplest case only the number of
the last record processed) must be saved, so that it may be resumed
later.

The task seems simple as I have complete control over the file format.
I'd rather use human-readable format but a binary one is also
acceptable.

The problem I have is with writing the state information back to file.
Ada.Text_IO and Ada.Streams.Stream_IO only allow opening file for
input or for output. In the latter case the file is being truncated
(as far as I understand the ARM).

Currently I'm mixing Text_IO and Direct_IO: Text_IO is used for
reading and writing the file initially and Direct_IO is used to
overwrite the first dozen characters that specify state.
This approach has many deficiencies, of course, like reopening the
file in different mode (which might fail due to permissions).
My first question is: can I freely mix Text_IO and Direct_IO at all?

The main question is: How should I approach this problem?

I've considered using Ada/POSIX binding like Florist but I'm not sure
whether it would be portable to Windows (currently there's no such
requirement in our project, but I don't want to close this path).
--
Marcin Simonides




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

end of thread, other threads:[~2007-08-06  7:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-02  7:43 Mixing reading and writing to a text file msimonides
2007-08-03  1:26 ` Randy Brukardt
2007-08-06  7:35   ` msimonides

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