Types
FileDescriptor: TYPE ~ UnixRemoteFile.FileDescriptor;
FType: TYPE ~ SunNFS.FType;
GMT: TYPE ~ BasicTime.GMT;
Handle: TYPE ~ UnixRemoteFile.UnixServerHandle;
Mode: TYPE ~ UnixRemoteFile.Mode;
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Procs
defaultHandle: Handle ← NIL;
SetDefaultHandle:
PROC [serverName:
ROPE] ~ {
ClearDefaultHandle[];
defaultHandle ← UnixRemoteFile.CreateHandle[serverName];
};
ClearDefaultHandle:
PROC ~ {
IF defaultHandle # NIL THEN UnixRemoteFile.DestroyHandle[defaultHandle];
defaultHandle ← NIL;
};
FixHandle:
PROC [h: Handle]
RETURNS [Handle] ~
INLINE {
RETURN [IF h # NIL THEN h ELSE defaultHandle] };
OpenIt:
PROC [h: Handle, path:
ROPE]
RETURNS [fD: FileDescriptor] ~ {
h ← FixHandle[h];
RETURN[UnixRemoteFile.Open[h, path]] };
CloseIt:
PROC [h: Handle, fD: FileDescriptor] ~ {
h ← FixHandle[h];
UnixRemoteFile.Close[h, fD] };
CreateIt:
PROC [h: Handle, path:
ROPE, mode: Mode]
RETURNS [fD: FileDescriptor] ~ {
h ← FixHandle[h];
RETURN [UnixRemoteFile.Create[h, path, mode]] };
DeleteIt:
PROC [h: Handle, path:
ROPE] ~ {
h ← FixHandle[h];
UnixRemoteFile.Delete[h, path] };
listOfNames: LIST OF ROPE ← NIL;
EnumerateIt:
PROC [h: Handle, dirPath, pattern:
ROPE] ~ {
EachName: UnixRemoteFile.EachNameProc ~ {
listOfNames ← CONS[name, listOfNames];
RETURN [TRUE];
};
h ← FixHandle[h];
listOfNames ← NIL;
UnixRemoteFile.Enumerate[h, dirPath, pattern, EachName];
};
MkDirIt:
PROC [h: Handle, path:
ROPE, mode: Mode] ~ {
h ← FixHandle[h];
UnixRemoteFile.MkDir[h, path, mode] };
RmDirIt:
PROC [h: Handle, path:
ROPE] ~ {
h ← FixHandle[h];
UnixRemoteFile.RmDir[h, path] };
LinkIt:
PROC [h: Handle, toPath, asPath:
ROPE] ~ {
h ← FixHandle[h];
UnixRemoteFile.Link[h, toPath, asPath] };
SymLinkIt:
PROC [h: Handle, toPath, asPath:
ROPE] ~ {
h ← FixHandle[h];
UnixRemoteFile.SymLink[h, toPath, asPath] };
RenameIt:
PROC [h: Handle, fromPath, toPath:
ROPE] ~ {
h ← FixHandle[h];
UnixRemoteFile.Rename[h, fromPath, toPath] };
GetInfoIt:
PROC [h: Handle, fD: FileDescriptor]
RETURNS [type: FType, size:
CARD, mode: Mode, mTime:
GMT] ~ {
h ← FixHandle[h];
[type, size, mode, mTime] ← UnixRemoteFile.GetInfo[h, fD] };
SetInfoIt:
PROC [h: Handle, fD: FileDescriptor, mode: Mode, mTime:
GMT] ~ {
h ← FixHandle[h];
UnixRemoteFile.SetInfo[h, fD, mode, mTime] };
ReadIt:
PROC [h: Handle, fD: FileDescriptor, offset, count:
CARD]
RETURNS [block:
REF
TEXT, bytesRead:
CARD] ~ {
h ← FixHandle[h];
block ← RefText.New[count];
bytesRead ← UnixRemoteFile.Read[h, fD, offset, count, 0, block] };
WriteIt:
PROC [h: Handle, fD: FileDescriptor, offset:
CARD, r:
ROPE]
RETURNS [bytesWritten:
CARD] ~ {
block: REF TEXT ← Rope.ToRefText[r];
h ← FixHandle[h];
bytesWritten ← UnixRemoteFile.Write[h, fD, offset, block.length, 0, block];
};
GetIt:
PROC [h: Handle, path:
ROPE, local:
ROPE] ~ {
from, to: STREAM;
h ← FixHandle[h];
from ← UnixRemoteFile.OpenReadStream[h, path];
to ← FS.StreamOpen[local, $create];
DO
c: CHAR;
c ← IO.GetChar[from ! IO.EndOfStream => EXIT];
IO.PutChar[to, c];
ENDLOOP;
IO.Close[to];
IO.Close[from];
};
PutIt:
PROC [h: Handle, path:
ROPE, mode: Mode, local:
ROPE] ~ {
from, to: STREAM;
h ← FixHandle[h];
to ← UnixRemoteFile.OpenWriteStream[h, path, mode];
from ← FS.StreamOpen[local];
DO
c: CHAR;
c ← IO.GetChar[from ! IO.EndOfStream => EXIT];
IO.PutChar[to, c];
ENDLOOP;
IO.Close[to];
IO.Close[from];
};
RetrieveIt:
PROC [h: Handle, path:
ROPE, local:
ROPE] ~ {
to: STREAM;
h ← FixHandle[h];
to ← FS.StreamOpen[local, $create];
UnixRemoteFile.RetrieveFile[h, path, to];
IO.Close[to];
};
StoreIt:
PROC [h: Handle, path:
ROPE, local:
ROPE, mode: Mode ← 0666B] ~ {
from: STREAM;
h ← FixHandle[h];
from ← FS.StreamOpen[local];
UnixRemoteFile.StoreFile[h, path, mode, from];
IO.Close[from];
};
}...