🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1613

Re: FST Record utilities wanted

#1613
From: John Hughes
Date: Thu, 13 Dec 1990 05:05
106 lines
4473 bytes
In article <50687@eerie.acsu.Buffalo.EDU> v056ped5@ubvmsd.cc.buffalo.edu writes:
>Does anyone have source code for random files and reading and writing records
>for use with the FST compiler. This seems like one of the most necessary 
>utilities for a language so powerful in data storage, yet it does not
>exist. I have gone to numerous books and magazine articles, but they all
>just show you what the definition module for such a utility should look 
>like. I need the implementation.
>
>Brian

Here is something I obtained from the FST bulletin board (which I haven't
been able to connect to for quite a while... Roger Carvalho, are you still
alive out there?). I have a much larger version that I created for myself,
but it's way to big to put into a follow-up. As a quick look-see at the
code will show, it's really not too hard to implement.

-----CUT HERE----CUT HERE----CUT HERE---------------------------------------
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-----------------------------------------
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------------------------------------------------------

Have fun.


-- 
|     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: <1990Dec13.050500.23993@coyote.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ncar!noao!coyote!jmh
References: <50687@eerie.acsu.Buffalo.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!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: <1990Dec13.050500.23993@coyote.uucp>
Date: 13 Dec 90 05:05:00 GMT
References: <50687@eerie.acsu.Buffalo.EDU>
Reply-To: jmh@coyote.UUCP (John Hughes)
Organization: Datalog Consulting, Tucson, AZ
Lines: 106