Re: Readable File io

Marc Martin (marc.martin@kauai.ds.boeing.com)
6 Aug 1996 09:33:01 -0800

Subject: RE> Readable File io

>> 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.

>The simplest solution to your problem is to use ObxAscii, the example
>module we provide which offers the interface you are looking for.
>(Module ObxAscii can easily be adapted to write reals as well.)

I wonder if one man's "too complex" is another man's "easily adapted"...

I had to write 3 workarounds to get my ReadReal code to work like I wanted
to:

1) numbers without decimal points are interpreted as integers, so you need
to
convert these to reals after they've been read.
2) negative signs must be handled.
3) since I wanted to implement an IO model which ignores tabs but pays
attention
end-of-line characters, I set the scanner to "return ctrl characters"
and then
my ReadReal must handle any tabs.

The resulting code certainly could be interpreted as either "too complex" or
"easily adapted":

=============================================================
PROCEDURE RdReal*( f: File; VAR real: LONGREAL );
BEGIN
REPEAT
f.scan.Scan;
UNTILf.scan.type#TextMappers.tab;

IF f.scan.type = TextMappers.char) & (f.scan.char = "-") THEN
f.scan.Scan
END;

IF f.scan.type = TextMappers.real THEN
done := TRUE;
real := f.scan.real;
ELSIF f.scan.type = TextMappers.int THEN
done := TRUE;
real := f.scan.int;
ELSE
done := FALSE;
END;
END RdReal;
=============================================================

Personally, my vote is "too complex", but I don't worry about it much now
that it's written and working... ;-)

--
Marc Martin, marc.martin@boeing.com