PfsParseTest.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer March 30, 1992 6:35 am PST
DIRECTORY Commander, CommanderOps, Convert, IO, PFS, PFSNames, Rope;
PfsParseTest: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, Convert, IO, PFS, PFSNames, Rope
= BEGIN
ROPE: TYPE ~ Rope.ROPE;
Shorten: Commander.CommandProc ~ {
argv: CommanderOps.ArgumentVector ~ CommanderOps.Parse[cmd];
FOR i: NAT IN [1..argv.argc) DO
arg: ROPE ~ argv[i];
{ENABLE PFS.Error => {
cmd.err.PutF["%g => PFS.Error[%g, %g]\n", [rope[arg]], [atom[error.code]], [rope[error.explanation]] ];
CONTINUE};
full: PFS.PATH ~ PFS.PathFromRope[argv[i]];
n: INT ~ full.ComponentCount[];
l: LIST OF PFSNames.Component ← NIL;
part: PFS.PATH;
res: ROPE;
FOR j: INT DECREASING IN (0..n) DO
l ← CONS[full.Fetch[j], l];
ENDLOOP;
part ← PFSNames.ConstructName[l, TRUE, full.IsADirectory[], FALSE];
res ← PFS.RopeFromPath[part];
cmd.out.PutF["\"%q\" => \"%q\"\n", [rope[arg]], [rope[res]] ];
}ENDLOOP;
RETURN};
Parse: Commander.CommandProc ~ {
argv: CommanderOps.ArgumentVector ~ CommanderOps.Parse[cmd];
FOR i: NAT IN [1..argv.argc) DO
arg: ROPE ~ argv[i];
{ENABLE PFS.Error => {
cmd.err.PutF["%g => PFS.Error[%g, %g]\n", [rope[arg]], [atom[error.code]], [rope[error.explanation]] ];
CONTINUE};
full: PFS.PATH ~ PFS.PathFromRope[argv[i]];
res: ROPEPFS.RopeFromPath[full];
cmd.out.PutF["\"%q\" => \"%q\"\n", [rope[arg]], [rope[res]] ];
}ENDLOOP;
RETURN};
FindBackward: Commander.CommandProc ~ {
argv: CommanderOps.ArgumentVector ~ CommanderOps.Parse[cmd];
IF argv.argc#5 THEN RETURN [$Failure, "Usage: rope-find-backward s1 s2 pos1 case"];
{pos1: INT ~ Convert.IntFromRope[argv[3]];
case: BOOL ~ Convert.BoolFromRope[argv[4]];
ans: INT ~ Rope.FindBackward[argv[1], argv[2], pos1, case];
cmd.out.Put1[[integer[ans]] ];
RETURN}};
Commander.Register["pfs-parse-test", Parse];
Commander.Register["pfs-shorten", Shorten];
Commander.Register["rope-find-backward", FindBackward];
END.