PFSInfoTest.mesa
Copyright Ó 1990, 1991 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on January 12, 1990 4:24:13 pm PST
Willie-s, October 7, 1991 6:27 pm PDT
DIRECTORY Commander, CommanderOps, IO, PFS, PFSNames, Rope;
PFSInfoTest: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, IO, PFS
=
BEGIN
ROPE: TYPE ~ Rope.ROPE;
Common Utoolities
TestFileInfo: PROC [cmd: Commander.Handle] RETURNS [result: ATOM ¬ NIL, msg: ROPE ¬ NIL] --Commander.CommandProc-- ~ {
argv: CommanderOps.ArgumentVector;
name, fullFName, attachedTo: PFS.PATH;
wantedUniqueID, uniqueID: PFS.UniqueID ¬ PFS.nullUniqueID;
bytes: INT;
mutability: PFS.Mutability;
fileType: PFS.FileType;
argv ¬ CommanderOps.Parse[cmd ! CommanderOps.Failed => {msg ¬ errorMsg; GOTO Abort}];
IF argv.argc NOT IN [2..3] THEN RETURN [$Failure, "Usage: PFS.FileInfo name [wantedUniqueID]"];
name ¬ PFS.PathFromRope[argv[1]];
IF argv.argc>2 THEN wantedUniqueID ¬ ParseUID[argv[2]];
[fullFName, attachedTo, uniqueID, bytes, mutability, fileType] ¬ PFS.FileInfo[name, wantedUniqueID !PFS.Error => IF cmd.procData.clientData#$Touchy THEN {msg ¬ IO.PutFR["PFS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ]; GOTO Abort}];
cmd.out.PutFL["full: %g, attachedTo: %g, unique: %g, bytes: %g, mut: %g, ft: %g\n", LIST[ [rope[PFS.RopeFromPath[fullFName]]], [rope[PFS.RopeFromPath[attachedTo]]], [rope[FmtUID[uniqueID]]], [integer[bytes]], [cardinal[mutability.ORD]], [cardinal[fileType]] ]];
RETURN;
EXITS Abort => result ¬ $Failure};
TestEnumerateForInfo: PROC [cmd: Commander.Handle] RETURNS [result: ATOM ¬ NIL, msg: ROPE ¬ NIL] --Commander.CommandProc-- ~ {
argv: CommanderOps.ArgumentVector;
pattern, lbound, hbound: PFS.PATH ¬ NIL;
Consume: PROC [fullFName, attachedTo: PFS.PATH, uniqueID: PFS.UniqueID, bytes: INT, mutability: PFS.Mutability, fileType: PFS.FileType] RETURNS [continue: BOOL ¬ TRUE] ~ {
cmd.out.PutFL["full: %g, attachedTo: %g, unique: %g, bytes: %g, mut: %g, ft: %g\n", LIST[ [rope[PFS.RopeFromPath[fullFName]]], [rope[PFS.RopeFromPath[attachedTo]]], [rope[FmtUID[uniqueID]]], [integer[bytes]], [cardinal[mutability.ORD]], [cardinal[fileType]] ]];
RETURN};
argv ¬ CommanderOps.Parse[cmd ! CommanderOps.Failed => {msg ¬ errorMsg; GOTO Abort}];
IF argv.argc NOT IN [2..4] THEN RETURN [$Failure, "Usage: PFS.EnumerateForInfo name [lbound] [hbound]"];
pattern ¬ PFS.PathFromRope[argv[1]];
IF argv.argc>2 THEN lbound ¬ PFS.PathFromRope[argv[2]];
IF argv.argc>3 THEN hbound ¬ PFS.PathFromRope[argv[3]];
PFS.EnumerateForInfo[pattern, Consume, lbound, hbound !PFS.Error => IF cmd.procData.clientData#$Touchy THEN {msg ¬ IO.PutFR["PFS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ]; GOTO Abort}];
RETURN;
EXITS Abort => result ¬ $Failure};
TestEnumerateForNames: PROC [cmd: Commander.Handle] RETURNS [result: ATOM ¬ NIL, msg: ROPE ¬ NIL] --Commander.CommandProc-- ~ {
argv: CommanderOps.ArgumentVector;
pattern, lbound, hbound: PFS.PATH ¬ NIL;
Consume: PROC [name: PFS.PATH] RETURNS [continue: BOOL ¬ TRUE] ~ {
cmd.out.PutFL["name: %g\n", LIST[ [rope[PFS.RopeFromPath[name]]] ]];
RETURN};
argv ¬ CommanderOps.Parse[cmd ! CommanderOps.Failed => {msg ¬ errorMsg; GOTO Abort}];
IF argv.argc NOT IN [2..4] THEN RETURN [$Failure, "Usage: PFS.EnumerateForNames name [lbound] [hbound]"];
pattern ¬ PFS.PathFromRope[argv[1]];
IF argv.argc>2 THEN lbound ¬ PFS.PathFromRope[argv[2]];
IF argv.argc>3 THEN hbound ¬ PFS.PathFromRope[argv[3]];
PFS.EnumerateForNames[pattern, Consume, lbound, hbound !PFS.Error => IF cmd.procData.clientData#$Touchy THEN {msg ¬ IO.PutFR["PFS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ]; GOTO Abort}];
RETURN;
EXITS Abort => result ¬ $Failure};
ParseUID: PROC [r: ROPE] RETURNS [uid: PFS.UniqueID ¬ PFS.nullUniqueID] ~ {
ENABLE IO.Error, IO.EndOfStream => CONTINUE;
in: IO.STREAM ~ IO.RIS[r];
uid.egmt.gmt ¬ in.GetTime[];
uid.egmt.usecs ¬ in.GetCard[];
uid.host.a ¬ in.GetCard[];
uid.host.b ¬ in.GetCard[];
RETURN};
FmtUID: PROC [uid: PFS.UniqueID] RETURNS [ROPE] ~ {
RETURN [IO.PutFLR["%g %g %g %g", LIST[[time[uid.egmt.gmt]], [cardinal[uid.egmt.usecs]], [cardinal[uid.host.a]], [cardinal[uid.host.b]] ]] ]};
Commander.Register["PFS.FileInfo", TestFileInfo, "PFS.FileInfo name [wantedUniqueID]"];
Commander.Register["PFS.EnumerateForInfo", TestEnumerateForInfo, "PFS.EnumerateForInfo name [lbound] [hbound]"];
Commander.Register["PFS.EnumerateForNames", TestEnumerateForNames, "PFS.EnumerateForNames name [lbound] [hbound]"];
Commander.Register["PFS.t.FileInfo", TestFileInfo, "PFS.FileInfo name [wantedUniqueID]", $Touchy];
Commander.Register["PFS.t.EnumerateForInfo", TestEnumerateForInfo, "PFS.EnumerateForInfo name [lbound] [hbound]", $Touchy];
Commander.Register["PFS.t.EnumerateForNames", TestEnumerateForNames, "PFS.EnumerateForNames name [lbound] [hbound]", $Touchy];
END.