Re: Readable file io

gruntz@oberon.ch
Tue, 6 Aug 1996 10:25:54 +0200

> Dear Oberon/F user:
>
> I am trying (again) to use Oberon/F. However, I need a little help with
> file input and output. Using any file type, could you please code the
> following:
>
> 1) Open a file for reading.
> 2) Read a real number from the file.
> 3) Close the file, releasing system resources.
>
> 4) Open a file for writing.
> 5) Write a real number to the file.
> 6) Close the file, releasing system resources.
>
> I already know how to solve this problem for an ASCII file. However, I
> am not happy with the solution, because it is too complex. I am wondering if
> a simpler solution exists with another file type. The only constraint on the
> file type is that it needs to be readable by a human, that is, you can
> exclude binary file.
>
> Thank you,
> Prof. Vinicius Fernando Arcaro
>

The simplest solution to your problem is to use ObxAscii, the example
module we provide which offers the interface you are looking for.
In the example below, procedure Write generates a new text, writes
an integer into the text and registers the text as file. (Module ObxAscii
can easily be adapted to write reals as well.)
Procedure Read opens this file, reads the integer and displays the result
in the log text.

MODULE Test;

IMPORT ObxAscii, DevLog;

PROCEDURE Write*;
VAR t: ObxAscii.Text;
BEGIN
t := ObxAscii.NewText();
ObxAscii.WriteInt(t, 123);
ObxAscii.Register(t, NIL, "Example")
END Write;

PROCEDURE Read*;
VAR t: ObxAscii.Text; i: LONGINT;
BEGIN
t := ObxAscii.Open(NIL, "Example");
ObxAscii.ReadInt(t, i);
DevLog.Int(i); DevLog.Ln
END Read;

END Test.

The file Example is an ascii file which can be read by any editor.
ObxAscii can easily be extended to support writing to already
existing files.

Hope, this helps,

- Dominik Gruntz

====================================================================
Dominik Gruntz Oberon microsystems, Inc.
gruntz@oberon.ch Technoparkstrasse 1
voice ++41-1-445-1751 CH-8005 Zurich
fax ++41-1-445-1752 http://www.oberon.ch/customers/omi
====================================================================