Go to the first, previous, next, last section, table of contents.


Oakwood Compliant Modules

In order to support the Oakwood Guildlines, OOC provides a set of basic library modules that comply with the Oakwood specification. (Note that all Oakwood modules may not be available.) All Oakwood compliant modules begin with the prefix "Oak".

Module OakStrings

Module `OakStrings' provides a set of operations on strings (i.e., on string constants and character arrays, both of which contain the character 0X as a terminator). All positions in strings start at 0.

(The Oakwood Guildlines remark that string assignments and string comparisons are already supported by the language Oberon-2.)

Procedures

Function: Length (s: ARRAY OF CHAR): INTEGER
Returns the number of characters in s up to and excluding the first 0X.

Procedure: Insert (src: ARRAY OF CHAR; pos: INTEGER; VAR dst: ARRAY OF CHAR)
Inserts the string src into the string dst at position pos (0<=pos<=Length(dst)). If pos=Length(dst), src is appended to dst. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.

Procedure: Append (s: ARRAY OF CHAR; VAR dst: ARRAY OF CHAR)
Has the same effect as Insert(s, Length(dst), dst).

Procedure: Delete (VAR s: ARRAY OF CHAR; pos, n: INTEGER)
Deletes n characters from s starting at position pos (0<=pos<=Length(s)). If n>Length(s)-pos, the new length of s is pos.

Procedure: Replace (src: ARRAY OF CHAR; pos: INTEGER; VAR dst: ARRAY OF CHAR)
Has the same effect as Delete(dst, pos, Length(src)) followed by
Insert(src, pos, dst).

Procedure: Extract (src: ARRAY OF CHAR; pos, n: INTEGER; VAR dst: ARRAY OF CHAR)
Extracts a substring dst with n characters from position pos (0<=pos<= Length(src)) in src. If n>Length(src)-pos, dst is only the part of src from pos to the end of src, i.e. Length(src)-1. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.

Function: Pos (pat, s: ARRAY OF CHAR; pos: INTEGER): INTEGER
Returns the position of the first occurrence of pat in s. Searching starts at position pos. If pat is not found, `-1' is returned.

Procedure: Cap (VAR s: ARRAY OF CHAR)
Replaces each lower case letter within s by its upper case equivalent.

Module OakFiles

Module `OakFiles' provides operations on files and the file directory.

The Oakwood Guildlines define the type File as representing a stream of bytes ususally stored on an external medium. A File has a certain length as well as the date and time of its last modification.

A file directory is a mapping from file names to files. A file that is not registered in the directory is considered temporary.

The type Rider holds a read/write position in a file (positions start with 0). There may be multiple riders set to the same file. The field eof is set to TRUE if an attempt was made to read beyond the end of the file. The field res reports the success of ReadBytes and WriteBytes operations. Writing data overwrites old data at the rider position. When data is written beyond the end of the file, the file length increases.

Operations for Unformatted Input and Output

In general, all operations must use the following format for external representation:

Example:

  VAR f: Files.File; r: Files.Rider; ch: CHAR;

Reading from an existing file:

  f := Files.Old ("xxx");
  IF f # NIL THEN
    Files.Set (r, f, 0);
    Files.Read (r, ch);
    WHILE ~ r.eof DO
      Files.Read (r, ch)
    END
  END

Writing to a new file yyy:

  f := Files.New ("yyy");
  Files.Set (r, f, 0);
  Files.WriteInt (r, 8);
  Files.WriteString (r, " bytes");
  Files.Register (f)

Please note: This module implements virtual file descriptors; that is, an unlimited number of files can be open at the same time. These files share the limited number of file descriptors provided by the operating system.

Remarks

The Oakwood Guildlines provide the following specifications:

WriteNum and ReadNum, should use the following encoding algorithms for conversion to and from external format:

PROCEDURE WriteNum (VAR r: Rider; x: LONGINT);
BEGIN
   WHILE (x < - 64) OR (x > 63) DO 
       Write(r, CHR(x MOD 128 + 128)); x := x DIV 128
   END;
   Write(r, CHR(x MOD 128))
END WriteNum;

PROCEDURE ReadNum (VAR r: Rider; VAR x: LONGINT);
   VAR s: SHORTINT; ch: CHAR; n: LONGINT;
BEGIN 
   s := 0; n := 0;
   Read(r, ch);
   WHILE ORD(ch) >= 128 DO
      INC(n, ASH(ORD(ch) - 128, s) );
      INC(s, 7);
      Read(r, ch)
   END;
   x := n + ASH(ORD(ch) MOD 64 - ORD(ch) DIV 64 * 64, s)
END ReadNum;

The reason for the specification of the file name in the operation New is to allow allocation of the file on the correct medium from the beginning (if the operating system supports multiple media).

The operations Read, Write, ReadBytes and WriteBytes require the existence of a type SYSTEM.BYTE with the following characteristics:

Types

Data type: File = POINTER TO FileDesc

Record: FileDesc = RECORD

Record: Rider = RECORD
Field: eof-: BOOLEAN
Set to TRUE if an attempt was made to read beyond the end of the file.
Field: res-: INTEGER
See ReadBytes and WriteBytes below for possible values of res.

Operations on Files and the File Directory

Function: Old (name: ARRAY OF CHAR): File
Old(name) searches for the name in the directory and returns the corresponding file. If the name is not found, it returns NIL.

Function: New (name: ARRAY OF CHAR): File
New(name) creates and returns a new file. The name is remembered for the later use of the operation Register. The file is only entered into the directory when Register is called.

Procedure: Register (f: File)
Register(f) enters the file f into the directory together with the name provided in the operation New that created f. The file buffers are written back. Any existing mapping of this name to another file is overwritten.

Procedure: Close (VAR f: File)
Close(f) writes back the file buffers of f. The file is still accessible by its handle f and the riders positioned on it. If a file is not modified, it is not necessary to close it.

Please note: The above holds only for permanentClose=FALSE. Otherwise, the buffers are flushed and the file handle is deallocated (and f is set to NIL); at this time, all riders on this file become invalid. This behaviour, and the variable permanentClose, are not part of The Oakwood Guidelines.

Procedure: Purge (f: File)
Purge(f) resets the length of file f to 0.

Procedure: Delete (name: ARRAY OF CHAR; VAR res: INTEGER)
Delete(name, res) removes the directory entry for the file name without deleting the file. If res=0 the file has been successfully deleted. If there are variables referring to the file while Delete is called, they can still be used.

Procedure: Rename (old, new: ARRAY OF CHAR; VAR res: INTEGER)
Rename(old, new, res) renames the directory entry old to new. If res=0, the file has been successfully renamed. If there are variables referring to the file while Rename is called, they can still be used.

Function: Length (f: File): LONGINT
Length(f) returns the number of bytes in file f.

Procedure: GetDate (f: File; VAR t, d: LONGINT)
GetDate(f, t, d) returns the time t and date d of the last modification of file f.

The encoding is as follows:

hour = t DIV 4096; 
minute = t DIV 64 MOD 64; 
second = t MOD 64; 

year = d DIV 512; 
month = d DIV 32 MOD 16; 
day = d MOD 32.

Operations on Riders

Procedure: Set (VAR r: Rider; f: File; pos: LONGINT)
Set(r, f, pos) sets the rider r to position pos in file f. The field r.eof is set to FALSE. The operation requires that 0 <= pos <= Length(f).

Function: Pos (VAR r: Rider): LONGINT
Pos(r) returns the position of the rider r.

Function: Base (VAR r: Rider): File
Base(r) returns the file to which the rider r has been set.

Reading

Procedure: Read (VAR r: Rider; VAR x: SYSTEM.BYTE)
Read(r, x) reads the next byte x from rider r and advances r accordingly.

Procedure: ReadInt (VAR r: Rider; VAR i: INTEGER)
ReadInt(r, i) reads a integer number i from rider r and advances r accordingly.

Procedure: ReadLInt (VAR r: Rider; VAR i: LONGINT)
ReadLInt(r, i) reads a long integer number i from rider r and advances r accordingly.

Procedure: ReadReal (VAR r: Rider; VAR x: REAL)
ReadReal(r, x) reads a real number x from rider r and advances r accordingly.

Procedure: ReadLReal (VAR r: Rider; VAR x: LONGREAL)
ReadLReal(r, x) reads a long real number x from rider r and advances r accordingly.

Procedure: ReadNum (VAR r: Rider; VAR i: LONGINT)
ReadNum(r, i reads an integer number i from rider r and advances r accordingly. The number i is compactly encoded (see the "Remarks" section above).

Procedure: ReadString (VAR r: Rider; VAR s: ARRAY OF CHAR)
ReadString(r, s) reads a sequence of characters (including the terminating 0X) from rider r and returns it in s. The rider is advanced accordingly. The actual parameter corresponding to s must be long enough to hold the character sequence plus the terminating 0X.

Procedure: ReadSet (VAR r: Rider; VAR s: SET)
ReadSet(r, s) reads a set s from rider r and advances r accordingly.

Procedure: ReadBool (VAR r: Rider; VAR b: BOOLEAN)
ReadBool(r, b) reads a Boolean value b from rider r and advances r accordingly.

Procedure: ReadBytes (VAR r: Rider; VAR buf: ARRAY OF SYSTEM.BYTE; n: LONGINT)
ReadBytes(r, buf, n) reads n bytes into buffer buf starting at the rider position r. The rider is advanced accordingly. If less than n bytes could be read, r.res contains the number of requested but unread bytes.

Writing

Procedure: Write (VAR r: Rider; x: SYSTEM.BYTE)
Write(r, x) writes the byte x to rider r and advances r accordingly.

Procedure: WriteInt (VAR r: Rider; i: INTEGER)
WriteInt(r, i) writes the integer number i to rider r and advances r accordingly.

Procedure: WriteLInt (VAR r: Rider; i: LONGINT)
WriteLInt(r, i) writes the long integer number i to rider r and advances r accordingly.

Procedure: WriteReal (VAR r: Rider; x: REAL)
WriteReal(r, x) writes the real number x to rider r and advances r accordingly.

Procedure: WriteLReal (VAR r: Rider; x: LONGREAL)
WriteLReal(r, x) write the long real number x to rider r and advance r accordingly.

Procedure: WriteNum (VAR r: Rider; i: LONGINT)
WriteNum(r, i) writes the integer number i to rider r and advances r accordingly. The number i is compactly encoded (see the "Remarks" section above).

Procedure: WriteString (VAR r: Rider; s: ARRAY OF CHAR)
WriteString(r, s) writes the sequence of characters s (including the terminating 0X) to rider r and advances r accordingly.

Procedure: WriteSet (VAR r: Rider; s: SET)
WriteSet(r, s) writes the set s to rider r and advances r accordingly.

Procedure: WriteBool (VAR r: Rider; b: BOOLEAN)
WriteBool(r, b) writes the Boolean value b to rider r and advances r accordingly.

Procedure: WriteBytes (VAR r: Rider; VAR buf: ARRAY OF SYSTEM.BYTE; n: LONGINT)
WriteBytes(r, buf, n) writes the first n bytes from buf to rider r and advances r accordingly. r.res contains the number of bytes that could not be written (e.g., due to a disk full error).

Module OakIn

Module `OakIn' provides a set of basic routines for formatted input of characters, character sequences, numbers, and names. It assumes a standard input stream with a current position that can be reset to the beginning of the stream. A call to procedure Open initializes module `OakIn' and sets it to read from the standard input channel StdChannels.stdin (see section Module StdChannels)

Module `OakIn' has a concept of a current position, which is the character position in the input stream from where the next symbol is read. Open (re)sets it to the beginning of the input stream. After reading a symbol, the current position is set to the position immediately after this symbol. Before the first call to Open, the current position is undefined.

Variables

Read-only Variable: Done: BOOLEAN
Indicates the success of an input operation. If Done is TRUE after an input operation, the operation was successful and its result is valid. An unsuccessful input operation sets Done to FALSE; it remains FALSE until the next call to Open. In particular, Done is set to FALSE if an attempt is made to read beyond the end of the input stream.

Procedures

Procedure: Open
(Re)sets the current position to the beginning of the input stream. Done indicates if the operation was successful.

Procedure: Char (VAR ch: CHAR)
Returns the character ch at the current position.

Procedure: LongInt (VAR n: LONGINT)
Returns the long integer constant n at the current position according to the format:
IntConst = digit {digit} | digit {hexDigit} "H".

Procedure: Int (VAR n: INTEGER)
Returns the integer constant n at the current position according to the format:
IntConst = digit {digit} | digit {hexDigit} "H".

Procedure: LongReal (VAR n: LONGREAL)
Returns the long real constant n at the current position according to the format:
LongRealConst = digit {digit} ["." {digit} 
                [("D" | "E") ("+" | "-") digit {digit}]].

Procedure: Real (VAR n: REAL)
Returns the real constant n at the current position according to the format:
RealConst = digit {digit} ["." {digit} 
            ["E" ("+" | "-") digit {digit}]].

Procedure: String (VAR s: ARRAY OF CHAR)
Returns the string s at the current position according to the format:
StringConst = '"' char {char} '"'.

The string must not contain characters less than blank such as EOL or TAB.

Procedure: Name (VAR s: ARRAY OF CHAR)
Returns the name s at the current position according to the file name format of the underlying operating system (e.g., "lib/My.Mod" under Unix). Note: This implementation defines a name as `Name = char {char}', where `char' is any character greater than blank.

Module OakOut

Module `OakOut' provides a set of basic routines for formatted output of characters, numbers, and strings. It assumes a standard output stream to which the symbols are written.

Procedure: Open
Initializes the output stream.

Procedure: Char (ch: CHAR)
Writes the character ch to the end of the output stream.

Procedure: String (s: ARRAY OF CHAR)
Writes the null-terminated character sequence s to the end of the output stream (without 0X).

Procedure: Int (i, n: LONGINT)
Writes the integer number i to the end of the output stream. If the textual representation of i requires m characters, i is right adjusted in a field of Max(n, m) characters padded with blanks at the left end. A plus sign is not written.

Procedure: Real (x: REAL; n: INTEGER)
Writes the real number x to the end of the output stream using an exponential form. If the textual representation of x requires m characters (including a two-digit signed exponent), x is right adjusted in a field of Max(n, m) characters padded with blanks at the left end. A plus sign of the mantissa is not written.

Procedure: LongReal (x: LONGREAL; n: INTEGER)
Writes the long real number x to the end of the output stream using an exponential form. If the textual representation of x requires m characters (including a three-digit signed exponent), x is right adjusted in a field of Max(n, m) characters padded with blanks at the left end. A plus sign of the mantissa is not written.

Procedure: Ln
Writes an end-of-line symbol to the end of the output stream.

Modules OakMath and OakMathL

Constants

The Oakwood Guildlines requires the definition of the following mathematical constants (i.e., implementation-defined approximations):

Constant: pi

Constant: e

Procedures

Function: sqrt (x: REAL): REAL
Function: sqrt (x: LONGREAL): LONGREAL
sqrt(x) returns the square root of x, where x must be positive.

Function: sin (x: REAL): REAL
Function: sin (x: LONGREAL): LONGREAL
sin(x) returns the sine value of x, where x is in radians.

Function: cos (x: REAL): REAL
Function: cos (x: LONGREAL): LONGREAL
cos(x) returns the cosine value of x, where x is in radians.

Function: tan (x: REAL): REAL
Function: tan (x: LONGREAL): LONGREAL
tan(x) returns the tangent value of x, where x is in radians.

Function: arcsin (x: REAL): REAL
Function: arcsin (x: LONGREAL): LONGREAL
arcsin(x) returns the arcsine value in radians of x, where x is in the sine value.

Function: arccos (x: REAL): REAL
Function: arccos (x: LONGREAL): LONGREAL
arcos(x) returns the arcos value in radians of x, where x is in the cosine value.

Function: arctan (x: REAL): REAL
Function: arctan (x: LONGREAL): LONGREAL
arctan(x) returns the arctan value in radians of x, where x is in the tangent value.

Function: power (x, base: REAL): REAL
Function: power (x, base: LONGREAL): LONGREAL
power(x, base) returns the x to the power base.

Function: round (x: REAL): REAL
Function: round (x: LONGREAL): LONGREAL
round(x) if fraction part of x is in range 0.0 to 0.5, then the result is the largest integer not greater than x, otherwise the result is x rounded up to the next highest whole number. Note that integer values cannot always be exactly represented in LONGREAL or REAL format.

Function: ln (x: REAL): REAL
Function: ln (x: LONGREAL): LONGREAL
ln(x) returns the natural logarithm (base e) of x.

Function: exp (x: REAL): REAL
Function: exp (x: LONGREAL): LONGREAL
exp(x) is the exponential of x base e. x must not be so small that this exponential underflows nor so large that it overflows.

Function: log (x, base: REAL): REAL
Function: log (x, base: LONGREAL): LONGREAL
log(x, base) is the logarithm of x base base. All positive arguments are allowed. The base base must be positive.

Function: arctan2 (xn, xd: REAL): REAL
Function: arctan2 (xn, xd: LONGREAL): LONGREAL
arctan2(xn,xd) is the quadrant-correct arc tangent `atan(xn/xd)'. If the denominator xd is zero, then the numerator xn must not be zero. All arguments are legal except xn = xd = 0.

Function: sinh (x: REAL): REAL
Function: sinh (x: LONGREAL): LONGREAL
sinh(x) is the hyperbolic sine of x. The argument x must not be so large that exp(|x|) overflows.

Function: cosh (x: REAL): REAL
Function: cosh (x: LONGREAL): LONGREAL
cosh(x) is the hyperbolic cosine of x. The argument x must not be so large that exp(|x|) overflows.

Function: tanh (x: REAL): REAL
Function: tanh (x: LONGREAL): LONGREAL
tanh(x) is the hyperbolic tangent of x. All arguments are legal.

Function: arcsinh (x: REAL): REAL
Function: arcsinh (x: LONGREAL): LONGREAL
arcsinh(x) is the arc hyperbolic sine of x. All arguments are legal.

Function: arccosh (x: REAL): REAL
Function: arccosh (x: LONGREAL): LONGREAL
arccosh(x) is the arc hyperbolic cosine of x. All arguments greater than or equal to 1 are legal.

Function: arctanh (x: REAL): REAL
Function: arctanh (x: LONGREAL): LONGREAL
arctanh(x) is the arc hyperbolic tangent of x. |x| < 1 - sqrt(em), where `em' is machine epsilon. Note that |x| must not be so close to 1 that the result is less accurate than half precision.


Go to the first, previous, next, last section, table of contents.