home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ober1096.zip
/
libsrc
/
uxhandles.obe
< prev
next >
Wrap
Text File
|
1995-04-04
|
3KB
|
95 lines
(*===============================================================*)
(* Library Module for Gardens Point Oberon *)
(* Interface to Gardens Point Modula Library Module *)
(*===============================================================*)
FOREIGN MODULE UxHandles;
IS IN "uxhandles.o";
IMPORT GPMRTS, UxFiles;
(*
* This module complements UxFiles by giving stream access to
* handles including standard handles --- stdIn, stdOut, stdErr
*
* BEWARE that streams attached to standard handles stdOut and
* stdErr may require a FlushStream or CloseStream call to
* force output to appear on interactive terminals
*
* TYPE UxFiles.OpenMode = (ReadOnly, WriteOnly, ReadWrite);
*)
TYPE
FileDesc* = INTEGER(* [-1 .. 32767]*);
CONST
error* = -1;
stdIn* = 0;
stdOut* = 1;
stdErr* = 2;
PROCEDURE OpenFileHandle*(path : ARRAY OF CHAR;
mode : UxFiles.OpenMode) : FileDesc;
(*
* precondition : path must be a constant string, or be nul
* terminated if a variable array of chars.
* postcondition : returns error if cannot be opened, else
* the opened file handle.
*)
PROCEDURE CloseHandle*(handle : FileDesc;
VAR ok : BOOLEAN);
(*
* the file descriptor "handle is closed
*)
PROCEDURE StreamOfHandle*(fd : FileDesc) : UxFiles.File;
PROCEDURE CloseStream*(stream : UxFiles.File; VAR ok : BOOLEAN);
PROCEDURE FlushStream*(stream : UxFiles.File; VAR ok : BOOLEAN);
(*
* These procedures open, close and flush a stream on the
* nominated file handle, allowing UxFiles procs to be used.
* CloseStream is identical to UxFiles.Close
* FlushStream is often needed to force output
*
* Example -- to place a stream on a standard handle
*
* stdInFile := StreamOfHandle(stdIn);
*)
PROCEDURE RedirectHandle*(old : FileDesc; (* overwritten *)
new : FileDesc; (* replacement *)
VAR save : FileDesc; (* copy of old *)
VAR done : BOOLEAN);
(*
* precondition : old and new are open file descriptors.
* postcondition : input/output sent to "old" will go to the
* stream previously associated with "new"
* The descriptor "new" is closed. The handle
* previously "old" is duplicated in "save"
*)
PROCEDURE RestoreHandle*(old : FileDesc; (* overwritten *)
saved : FileDesc; (* replacement *)
VAR done : BOOLEAN);
(*
* precondition : old and new are open file descriptors.
* postcondition : input/output sent to "old" will go to the
* stream previously associated with "saved"
* The descriptor "saved" is closed, and the
* previous handle "old" is closed also
*
* Example of typical use -- redirecting standard error
*
* newFD := UxFiles.Open("foo.err", UxFiles.WriteOnly);
* -- and check that newFD is not error ...
* UxHandles.RedirectHandle(UxHandles.stdErr,newFD,errSav,ok);
* (* closes newFD, and does 2> foo.err *)
* -- now fork, exec or whatever ...
* UxHandles.RestoreHandle(UxHandles.stdErr,errSav,ok);
* (* stderr restored, foo.err is closed *)
*)
END UxHandles.