Category : Forth Source Code
Archive   : RNDMRECS.ZIP
Filename : EXAMPLE.SEQ

 
Output of file : EXAMPLE.SEQ contained in archive : RNDMRECS.ZIP
\\ Random disk records example

Load this file from F-PC 3.5x (after loading RNDMRECS.SEQ) to create
these definitions and test the record access. BUFS will display which
records are in your buffers. .CHAIN will show the parent files.

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³Warning! Don't load this if your directory contains the following files³
³ and you don't want to lose them: ³
³ ³
³ book.dat ³
³ price.dat ³
³ stock.dat ³
³ account.dat ³
³ stat.dat ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


AN EXAMPLE
ÍÍÍÍÍÍÍÍÍÍ

Just to give you an idea of how this all works, suppose you were
designing program for a mail-order book store. You might set up the
following files and records:

{

file: book.dat
file: price.dat
file: stock.dat
file: account.dat
file: stat.dat


\ initial parent record
\ offset size file name

0 48 book.dat record: title \ name of the book

0 2 book.dat record: price \ how much $ ?
\ two bytes will work for this if none of your book prices
\ exceeds $655.35

0 2 stock.dat record: stock \ how many of each book?

0 32 account.dat record: account \ customer name

0 2 stat.dat record: pointers \ misc. pointers, values

16 8 stat.dat record: purchases \ cumulative purchases

\ ( The eight bytes will give me room to track a dollar amount,
\ total # of orders, and the last order date: )

4 derive >#orders
6 derive >latest
}

At the risk of confusing things, I've combined three records into one
record structure (PURCHASES) to illustrate how you can cut down on the
number of data files if you so desire. Grouping the three data
structures together under one record name like this allows you to have an
unlimited number of each. If you would have defined them as distinct
records starting at different offsets in the same file, you would run the
risk of not allowing enough space for customer base growth, not to mention
having to create a large file before you have any data to enter.


Data structure:

ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿
³ ³ ³ ³
ÀÄÁÂÁÄÁÄÁÄÅÄÁÄÁÂÙ
³ ³ ³
³ ³ ÀÄ encoded date of last order
³
double- ³
precision ÀÄ # of orders
$ value

The way to retrieve the number of orders filled for customer #15 is to
execute:
15 purchases >#orders @


The alternative way of keeping these all in the same file would be to
decide on a maximum number of customers (10000 for this example) and do
the following:

0 2 stat.dat record: pointers \ this doesn't change
6 4 stat.dat record: purchases \ just the dollar amount now
40006 2 stat.dat record: #orders
60006 2 stat.dat record: latest

The trouble is, I've now limited myself to 10,000 customers and also am
starting out with a 60K file before my first order! This problem doesn't
arise of course if you don't combine records in a file.

If you combine many records. the word ALLOW will help you save some math.
Using it the above example becomes:

0 2 3 allow stat.dat record: pointers
4 10000 allow stat.dat record: purchases
2 10000 allow stat.dat record: #orders
2 stat.dat record: latest


For keeping track of books and customers, we have three records to work
with:

{
labeling pointers \ These are equivalent:

0 label: #accounts \ : #accounts 0 pointers ;
1 label: #titles \ : #titles 1 pointers ;
2 label: #books \ : #books 2 pointers ;
}

Now to enter some data.

Execute the following to create the necessary files on your disk:

{

book.dat establish
price.dat establish
stock.dat establish
account.dat establish
stat.dat establish

\ Zero out your customers and inventory:

#accounts off update
#titles off update
#books off update

\ You could define the following word to add new books:

: titles! ( -- )
begin cr ." Title: "
#titles @ the title expect
span @
while update
#titles +dsk
repeat ;

}

This allows you to enter book names until you press a without any
entry. You can add the prices later.

To type the name of book #1, enter: 1 the title type

To see how many titles you have entered: #titles ?

It couldn't get much simpler! You can exit F-PC (by typing BYE), restart
it again, and your data will still be there.


/\
/ \
/ \
/ \
/CAUTIONS\
\ÄÄÄÄÄÄÄÄ/
\ /
\ /
\ /
\/

The following situations have been carefully tested and found to exhibit
undesirable behavior:

1. If any files have been appended, FLUSH must be executed before
terminating F-PC. This is done automatically is you use BYE, but if
DOS seizes up or you crash your program you'll most likely end up with
lost clusters where your new records used to be.

2. If you load your program, FORGET part of it, then re-load, you may
wind up with a problem when you execute FLUSH or .CHAIN since FORGET
doesn't tell CHAIN which links were forgotten. To avoid problems
here, if you FORGET any PARENT FILES at all, forget them ALL and
execute CHAIN OFF before re-loading. In fact, it's probably a good
idea to put CHAIN OFF just before your first FILE: command.

3. If you do #2 (above) without FLUSHing between reloadings, you'll soon
use up all your DOS handles if you access any records in between.
This is because the original handles were forgotten before they were
closed. You will suddenly be unable to open your files.





  3 Responses to “Category : Forth Source Code
Archive   : RNDMRECS.ZIP
Filename : EXAMPLE.SEQ

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/