Previous

10.3. Transput declarations

{``So it does!'' said Pooh, ``It goes in!'' ``So it does!'' said Piglet, ``And it comes out!'' ``Doesn't it?'' said Eeyore, ``It goes in and out like anything,'' Winnie-the-Pooh, A.A. Milne.}
{Three ways of "transput" (i.e., input and output) are provided by the standard-prelude, viz., formatless transput {10.3.3 }, formatted transput {10.3.5 } and binary transput {10.3.6}.}

10.3.1. Books, channels and files

{"Books", "channels" and "files" model the transput devices of the physical machine used in the implementation.}

10.3.1.1. Books and backfiles

{

aa) All information within the system is to be found in a number of "books". A book {a}is a structured value including a field text of the mode specified by FLEXTEXT {b}which refers to information in the form of characters. The text has a variable number of pages, each of which may have a variable number of lines, each of which may have a variable number of characters. Positions within the text are indicated by a page number, a line number and a character number. The book includes a field lpos which indicates the "logical end" of the book, i.e., the position up to which it has been filled with information, a string idf, which identifies the book and which may possibly include other information, e.g., ownership, and fields putting and users which permit the book to be opened {10.3.1.4.d } on more than one file simultaneously only if putting is not possible on any of them.

bb) The books in the system are accessed via a chain of backfiles. The chain of books available for opening {10.3.1.4.dd } is referenced by chainbfile. A given book may be referenced by more than one backfile on this chain, thus allowing simultaneous access to a single book by more than one process {10.2.4 }. However such access can only be for reading a book, since only one process may access a book such that it may be written to {aa}. The chain of books which have been locked {10.3.1.4.o } is referenced by lockedbfile.

cc) Simultaneous access by more than one process to the chain of backfiles is prevented by use of the semaphore bfileprotect, which provides mutual exclusion between such processes.

dd) Books may be created (e.g., by input) or destroyed (e.g., after output) by tasks (e.g., the operating system) in the system-task-list {10.4.2 }, such books being then added to or removed from the chain of backfiles.}

a)

MODE {?} BOOK=
  STRUCT (FLEXTEXT text,
    POS lpos ¢ logical end of book ¢,
    STRING idf ¢ identification ¢,
    BOOL putting ¢ TRUE if the book may be written to ¢,
    INT users ¢ the number of times the book is opened ¢);

b)

MODE {?} TEXT = REF [ ] [ ] [ ] CHAR, MODE {?} FLEXTEXT = REF FLEX [ ] FLEX [ ] FLEX [ ] CHAR;

c)

MODE {?} POS = STRUCT (INT p, l, c);
d)
PRIO {?} BEYOND=5,
OP BEYOND = (POS a, b) BOOL:
  IF p OF a < p OF b THEN FALSE
  ELIF p OF a > p OF b THEN TRUE
  ELIF l OF a < l OF b THEN FALSE
  ELIF l OF a > l OF b THEN TRUE
  ELSE c OF a > c OF b
  FI;

e) MODE {?}BFILE = STRUCT(REF BOOK book, REF BFILE next);

f) REF BFILE {?}chainbfile := NIL;

g) REF BFILE {?}lockedbfile := NIL;

h) SEMA {?}bfileprotect = (SEMA s; {F}f OF s := ©PRIM#HEAP INT := 1; s);
 
Next