User`s guide
Instead of reading a number, the QUERY program reads an alphanumeric string
which is a particular key to find in the NAMES.DAT data base. Because the LAST-
NAME.KEY list is sorted, you can find a particular entry quickly by performing a
binary search, similar to looking up a name in the telephone directory. Start at both
ends of the list and examine the entry halfway in between and, if not matched, split
either the upper half or the lower half for the next search. You will quickly reach the
item you are looking for, in log2(n) steps, where you will find the corresponding
record number. Fetch and display this record at the console as the program illustrates.
At this point, you are just getting started. With a little more work, you can allow
a fixed grouping size, which differs from the 128-byte record shown above. You can
accomplish this by keeping track of the record number as well as the byte offset
within the record. Knowing the group size, you can randomly access the record
containing the proper group, offset to the beginning of the group within the record,
and read sequentially until the group size has been exhausted.
Finally, you can improve QUERY considerably by allowing Boolean expressions
that compute the set of records that satisfy several relationships, such as a LAST-
NAME between HARDY and LAUREL and an AGE less than 45. Display all the
records that fit this description. Finally, if your lists are getting too big to fit into
memory, randomly access your key files from the disk as well.
4.4 Construction of an RSX Program
This section describes the standard prefix of a Resident System Extension (RSX)
and illustrates the construction of an RSX with an example. (See Section 1.6.4 for a
discussion of how RSXs operate under CP/M 3.) RSX programs are usually written
in assembler, but you can use other languages if the interface between the language
and the calling conventions of the BDOS are set up properly.
4-20
4.3 A Sample Random Access Program CP/M 3 Programmer's Guide