DIRECTORY BasicTime USING [GMT], FS USING [StreamOpen], IO USING [Close, EndOfStream, GetChar, PutChar, STREAM], RefText USING [New], Rope USING [ROPE, ToRefText], SunNFS USING [FType], UnixRemoteFile USING [Close, Create, CreateHandle, Delete, DestroyHandle, EachNameProc, Enumerate, FileDescriptor, GetInfo, Handle, Link, MkDir, Mode, Open, OpenReadStream, OpenWriteStream, Read, Rename, RetrieveFile, RmDir, SetInfo, StoreFile, SymLink, Write] ; UnixRemoteFileTest: CEDAR PROGRAM IMPORTS FS, IO, RefText, Rope, UnixRemoteFile ~ { FileDescriptor: TYPE ~ UnixRemoteFile.FileDescriptor; FType: TYPE ~ SunNFS.FType; GMT: TYPE ~ BasicTime.GMT; Handle: TYPE ~ UnixRemoteFile.Handle; Mode: TYPE ~ UnixRemoteFile.Mode; ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; 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]; }; }... UnixRemoteFileTest.mesa Copyright Σ 1987 by Xerox Corporation. All rights reserved. Demers, November 8, 1987 9:06:47 pm PST Types Procs Κ’˜codešœ™K™