<> <> <> <> <> <> <<>> DIRECTORY BasicTime USING [GMT], FS USING [ErrorDesc, FileType, Lock, OpenFile, tUnspecified], FSBackdoor USING [], FSOpenFile USING [ProcFile, ProcFileObj], Rope USING [Concat, ROPE], YggFile USING [bytesPerPage]; FSDummyImpl: CEDAR PROGRAM IMPORTS Rope EXPORTS FS, FSBackdoor = { <> ProcFile: TYPE = FSOpenFile.ProcFile; ProcFileObj: TYPE = FSOpenFile.ProcFileObj; <> Error: PUBLIC ERROR [error: FS.ErrorDesc] = CODE; BytesForPages: PUBLIC PROC[pages: INT] RETURNS [bytes: INT] = { RETURN [YggFile.bytesPerPage*pages] }; GetClass: PUBLIC PROC [file: FS.OpenFile] RETURNS [a: ATOM] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.GetClass = NIL THEN NotImplemented[] ELSE a _ p.fileProcs.GetClass[p.clientFile]; ENDCASE => InvalidOpenFile[]; }; SameFile: PUBLIC PROC [file1, file2: FS.OpenFile] RETURNS [same: BOOL] = { WITH file1 SELECT FROM p1: ProcFile => WITH file2 SELECT FROM p2: ProcFile => IF p1.fileProcs = p2.fileProcs THEN { IF p1.fileProcs.SameFile = NIL THEN NotImplemented[] ELSE RETURN [p1.fileProcs.SameFile[p1.clientFile, p2.clientFile]]; } ELSE RETURN [FALSE]; ENDCASE; ENDCASE; InvalidOpenFile[]; }; GetName: PUBLIC PROC [file: FS.OpenFile] RETURNS [fullFName, attachedTo: Rope.ROPE] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.GetName = NIL THEN NotImplemented[] ELSE [fullFName, attachedTo] _ p.fileProcs.GetName[p.clientFile]; ENDCASE => InvalidOpenFile[]; }; GetInfo: PUBLIC PROC [file: FS.OpenFile] RETURNS [keep: CARDINAL, pages, bytes: INT, created: BasicTime.GMT, lock: FS.Lock, fileType: FS.FileType _ FS.tUnspecified] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.GetInfo = NIL THEN NotImplemented[] ELSE [keep, pages, bytes, created, lock, fileType] _ p.fileProcs.GetInfo[p.clientFile]; ENDCASE => InvalidOpenFile[]; }; SetPageCount: PUBLIC PROC [file: FS.OpenFile, pages: INT] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.SetPageCount = NIL THEN NotImplemented[] ELSE p.fileProcs.SetPageCount[p.clientFile, pages]; ENDCASE => InvalidOpenFile[]; }; SetByteCountAndCreatedTime: PUBLIC PROC [file: FS.OpenFile, bytes: INT, created: BasicTime.GMT] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.SetByteCountAndCreatedTime = NIL THEN NotImplemented[] ELSE p.fileProcs.SetByteCountAndCreatedTime[p.clientFile, bytes, created]; ENDCASE => InvalidOpenFile[]; }; Read: PUBLIC PROC [file: FS.OpenFile, from, nPages: INT, to: LONG POINTER] = TRUSTED { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.Read = NIL THEN NotImplemented[] ELSE p.fileProcs.Read[p.clientFile, from, nPages, to]; ENDCASE => InvalidOpenFile[]; }; Write: PUBLIC PROC [file: FS.OpenFile, to: INT, nPages: INT, from: LONG POINTER] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.Write = NIL THEN NotImplemented[] ELSE p.fileProcs.Write[p.clientFile, to, nPages, from]; ENDCASE => InvalidOpenFile[]; }; Close: PUBLIC PROC [file: FS.OpenFile] = { WITH file SELECT FROM p: ProcFile => IF p.fileProcs.Close = NIL THEN NotImplemented[] ELSE p.fileProcs.Close[p.clientFile]; ENDCASE => InvalidOpenFile[]; }; <> FileProcs: PUBLIC TYPE = RECORD [ GetClass: PROC [REF] RETURNS [ATOM], SameFile: PROC [REF, REF] RETURNS [BOOL], GetName: PROC [REF] RETURNS [Rope.ROPE, Rope.ROPE], GetInfo: PROC [REF] RETURNS [CARDINAL, INT, INT, BasicTime.GMT, FS.Lock, FS.FileType], SetPageCount: PROC [REF, INT], SetByteCountAndCreatedTime: PROC [REF, INT, BasicTime.GMT], Read: UNSAFE PROC [REF, INT, INT, LONG POINTER], Write: PROC [REF, INT, INT, LONG POINTER], Close: PROC [REF] ]; CreateFileProcs: PUBLIC PROC [ GetClass: PROC [REF] RETURNS [ATOM], SameFile: PROC [REF, REF] RETURNS [BOOL], GetName: PROC [REF] RETURNS [Rope.ROPE, Rope.ROPE], GetInfo: PROC [REF] RETURNS [CARDINAL, INT, INT, BasicTime.GMT, FS.Lock, FS.FileType], SetPageCount: PROC [REF, INT], SetByteCountAndCreatedTime: PROC [REF, INT, BasicTime.GMT], Read: UNSAFE PROC [REF, INT, INT, LONG POINTER], Write: PROC [REF, INT, INT, LONG POINTER], Close: PROC [REF] ] RETURNS [REF FileProcs] = { RETURN [ NEW [ FileProcs _ [GetClass, SameFile, GetName, GetInfo, SetPageCount, SetByteCountAndCreatedTime, Read, Write, Close] ] ]; }; CreateProcsOpenFile: PUBLIC PROC [clientFile: REF, fileProcs: REF FileProcs] RETURNS [FS.OpenFile] = { RETURN [ [ NEW [ ProcFileObj _ [fileProcs, clientFile] ] ] ]; }; GetClientFileAndProcs: PUBLIC PROC [file: FS.OpenFile] RETURNS [clientFile: REF, fileProcs: REF FileProcs] = { clientFile _ fileProcs _ NIL; WITH file SELECT FROM p: ProcFile => { clientFile _ p.clientFile; fileProcs _ p.fileProcs; }; ENDCASE; }; <> NotImplemented: PROC [] = { ERROR Error [ [client, $notImplemented, "Operation not implemented for this file"] ]; }; InvalidOpenFile: PROC [closed: BOOL _ FALSE] = { ERROR Error [ [client, $invalidOpenFile, Rope.Concat["File presented ", IF closed THEN "is closed." ELSE "is invalid"] ]]; }; <> }. <<>>