Article View: comp.lang.modula2
Article #1647Re: FST Record utilities wanted
From: John Hughes
Date: Tue, 25 Dec 1990 02:32
Date: Tue, 25 Dec 1990 02:32
112 lines
4443 bytes
4443 bytes
In article <52912@eerie.acsu.Buffalo.EDU> v056ped5@ubvmsd.cc.buffalo.edu writes:
>In article <413.277230D0@puddle.fidonet.org>, Patrick.Verkaik@p11.f39.n512.z2.fidonet.org (Patrick Verkaik) writes...
>>
>>I think you'll get the source code if you register...
>>
>>Patrick
>>
>
>No, it is simply not included. Why is that whenever anyone
>asks a question in almost any newsgroup, someone needs to
>give the "Time-Life read the book" answer?
I don't know... I find that somewhat annoying as well. I did send (or attempt
to send) some code related to random record handling for FST, but for the
benefit of any other who are interested in seeing how this is done, here is
a simplle set of modules from the FST BBS.
-------snip----snip-----snip---chop----tear----cut----shred-----------
DEFINITION MODULE RandomIO;
(*
Routines for reading and writing files with fixed-length records,
allowing direct access to a specific record in the file by record
number. The first file in the record is record #0.
This module uses procedures from and works in co-operation with
module FileSystem. A random file is opened with FileSystem.Lookup
and closed with FileSystem.Close, and any other procedure from
FileSystem may be used to manipulate the file.
Copyright (C) 1988 Jeff Zeitlin. All rights reserved.
*)
FROM FileSystem IMPORT File;
FROM SYSTEM IMPORT BYTE;
PROCEDURE ReadRecord(VAR F : File;
recnum : CARDINAL;
VAR record : ARRAY OF BYTE);
PROCEDURE WriteRecord(VAR F : File;
recnum : CARDINAL;
VAR record : ARRAY OF BYTE);
END RandomIO.
-------cut here----cut here-----cut here----cut here------------------
IMPLEMENTATION MODULE RandomIO;
(*
Routines for reading and writing files with fixed-length records,
allowing direct access to a specific record in the file by record
number. The first file in the record is record #0.
This module uses procedures from and works in co-operation with
module FileSystem. A random file is opened with FileSystem.Lookup
and closed with FileSystem.Close, and any other procedure from
FileSystem may be used to manipulate the file.
Copyright (C) 1988 Jeff Zeitlin. All rights reserved.
*)
FROM FileSystem IMPORT File, SetLPos, ReadNBytes, WriteNBytes;
FROM SYSTEM IMPORT BYTE, WORD, ADDRESS, ADR;
PROCEDURE ReadRecord(VAR F : File;
recnum : CARDINAL;
VAR record : ARRAY OF BYTE);
VAR
NumBytes : CARDINAL;
NumRead : CARDINAL;
FilePos : LONGCARD;
BEGIN
NumBytes := HIGH(record) + 1;
FilePos := LONG(recnum) * LONG(NumBytes);
SetLPos(F,FilePos);
ReadNBytes(F,ADR(record),NumBytes,NumRead);
END ReadRecord;
PROCEDURE WriteRecord(VAR F : File;
recnum : CARDINAL;
VAR record : ARRAY OF BYTE);
VAR
NumBytes : CARDINAL;
NumWritten : CARDINAL;
FilePos : LONGCARD;
BEGIN
NumBytes := HIGH(record) + 1;
FilePos := LONG(recnum) * LONG(NumBytes);
SetLPos(F,FilePos);
WriteNBytes(F,ADR(record),NumBytes,NumWritten);
END WriteRecord;
END RandomIO.
================END====END====END====END====END=======================
The tabs came out a little wierd, but it looks OK otherwise. Give it
a try.
--
| John M. Hughes | "...unfolding in consciousness at the |
| noao!jmh%moondog@coyote | deliberate speed of pondering." - Daniel Dennet |
| jmh%coyote@noao.edu |--------------------------------------------------|
| noao!coyote!jmh | P.O. Box 43305 Tucson, AZ 85733 |
Technical Details
Message-ID:
<1990Dec25.023258.20317@coyote.uucp>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!noao!coyote!jmhReferences:
<413.277230D0@puddle.fidonet.org> <52912@eerie.acsu.Buffalo.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!noao!coyote!jmh From: jmh@coyote.uucp (John Hughes) Newsgroups: comp.lang.modula2 Subject: Re: FST Record utilities wanted Message-ID: <1990Dec25.023258.20317@coyote.uucp> Date: 25 Dec 90 02:32:58 GMT References: <413.277230D0@puddle.fidonet.org> <52912@eerie.acsu.Buffalo.EDU> Reply-To: jmh@coyote.UUCP (John Hughes) Organization: Datalog Consulting, Tucson, AZ Lines: 112