Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The first argument passed to the MFS (the CODE argument) contains an integer value that indicates the operation that has been requested. For example, if the operation is "read a record," CODE will contain the value 1. If the operation is "delete a file," CODE will contain the value 15, and so forth.Note: standard

Info

Standard constant names for the CODE argument are provided in the $INSERT record FILE.SYSTEM.ONGOSUB. These standard names are used within this chapter for clarity.

The MFS must determine what operation is being performed, and branch or "dispatch" to the appropriate logic within the MFS.

Two methods are commonly used when coding an MFS dispatch routine.  They are:

Using ON...GOSUB in an MFS Dispatch Routine

The first method uses the BASIC+ ON ... GOSUB statement to branch to a local subroutine for each file operation. The CODE argument provides the index value for the ON...GOSUB statement. The GOSUB portion is followed by a list of 28 statement labels. Each statement label identifies the logic within the body of the MFS program for a particular file operation.

A typical statement begins like this:

Code Block
ON CODE GOSUB READ.RECORD, READO.RECORD, WRITE.RECORD, DELETE.RECORD, LOCK.RECORD ...

For example, if a record lock operation is being executed, the value of CODE will be 5. The ON ... GOSUB statement will branch to the fifth statement label, in this case LOCK.RECORD.

Very frequently, the MFS is concerned with only a small number of file operations, such as READ.RECORD and WRITE.RECORD. In this case, the logic for most remaining operations can be lumped under a single label in the MFS. The MFS might "stack" statement labels that have code in common, as in this example:

 

Code Block
READ.RECORD
   (record read logic here)
  RETURN
CREATE.FILE:
RENAME.FILE:
DELETE.FILE:
("do nothing" logic here)
RETURN

Using CASE Statements in an MFS Dispatch Routine

A second method to dispatch within the MFS is to use a CASE block. In this method, the value of CODE is tested in a series of CASE statements to determine the logic to be executed for the operation. For example, this code fragment illustrates a portion of the CASE logic:

 

Code Block
BEGIN CASE
CASE CODE = 1
  (read logic here)
CASE CODE = 2
  (read-only logic here)
CASE CODE = 3
  (write logic here)
  (etc.)
END CASE

 

 

 

...