comp.lang.ada
 help / color / mirror / Atom feed
From: msimonides@power.com.pl
Subject: Mixing reading and writing to a text file
Date: Thu, 02 Aug 2007 00:43:26 -0700
Date: 2007-08-02T00:43:26-07:00	[thread overview]
Message-ID: <1186040606.842876.191850@57g2000hsv.googlegroups.com> (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




             reply	other threads:[~2007-08-02  7:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-02  7:43 msimonides [this message]
2007-08-03  1:26 ` Mixing reading and writing to a text file Randy Brukardt
2007-08-06  7:35   ` msimonides
replies disabled

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