Newsgroups: comp.lang.pascal
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!pshuang
From: pshuang@athena.mit.edu (Ping-Shun Huang)
Subject: Re: TURBO PASCAL: fancy file handling, please
In-Reply-To: amead@s.psych.uiuc.edu's message of 27 Jun 91 23:12:35 GMT
Message-ID: <PSHUANG.91Jun30230641@w20-575-109.mit.edu>
Sender: news@athena.mit.edu (News system)
Organization: Massachusetts Institute of Technology
References: <1991Jun27.231235.2861@ux1.cso.uiuc.edu>
Date: Mon, 1 Jul 91 03:06:48 GMT
Lines: 36

In article <1991Jun27.231235.2861@ux1.cso.uiuc.edu> amead@s.psych.uiuc.edu (alan mead) writes:

 > Is there a relatively simple way to treat a single file as a number of
 > concatenated files (of differing format)?  I wouldn't mind rewriting
 > the Seek() routine if I could do it in TP (rather then assembly).

Assumption: you may want to write aritrary number of TypeA, followed by
arbitrary number of TypeB, etc.  Obviously if you already write X of one
and Y of another, creating an appropriate RECORD would be an easy solution.

(a) I think Turbo Pascal 6.0/5.5(?) may support a List object which
permit you to store arbitrary types into a single disk file.

(b) I have not tried this, but I wonder if Turbo Pascal lets you ASSIGN
the same filename to two separate file variables, which could be of
different types.  If you padded out your data records so that the two
types are multiples of each other, with a little arithmetic (and some
sugar-coating procedures and functions you could write) you could do
what you want.

If you don't wish to pad out your records, or if TP won't let you ASSIGN
two file variables to the same filename, the more general solution would
be for you to open the file as a FILE OF BYTE and use BlockRead and
BlockWrite to read and write data.  What you would want to do is add a
tag field to the beginning of RECORD types A and B.  BlockRead a portion
of the file into a buffer as large the larger of A or B, then checks the
tag field to see what it really is.

Being able to seek to an arbitrary record would require sequentially
accessing all the objects in between to determine the type and therefore
how far to skip ahead in the file for the next object, or would require
that you maintain a separate index file -- shouldn't be hard.

--
Above text where applicable is (c) Copyleft 1991, all rights deserved by:
UNIX:/etc/ping instantiated (Ping Huang) [INTERNET: pshuang@athena.mit.edu]
