RopeFileTest.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Michael Plass, April 7, 1992 9:44 am PDT
DIRECTORY PFS, RefText, Convert, Commander, CommanderOps, Rope,
IO, RopeFile, Process;
RopeFileTest: CEDAR PROGRAM
IMPORTS PFS, RefText, Convert, Commander, CommanderOps, Rope, IO, RopeFile, Process
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
Which:
TYPE ~ { fetch, map, move, bigmove };
Equal:
PROC [ropefile, rope:
ROPE, which: Which]
RETURNS [
BOOL] ~ {
SELECT which
FROM
fetch => RETURN [Rope.Equal[ropefile, rope]];
map => {
i: INT ¬ 0;
EachChar:
PROC [c:
CHAR]
RETURNS [quit:
BOOL ¬
FALSE] ~ {
IF c # Rope.Fetch[rope, i] THEN RETURN [TRUE];
i ¬ i + 1;
};
RETURN [NOT Rope.Map[base: ropefile, action: EachChar]]
};
move, bigmove => {
text1: REF TEXT ¬ RefText.New[IF which=move THEN 100 ELSE 10000];
text2: REF TEXT ¬ RefText.New[IF which=move THEN 100 ELSE 10000];
size: INT ~ Rope.Size[ropefile];
IF size # Rope.Size[rope] THEN RETURN [FALSE];
FOR i:
INT ¬ 0, i+text1.length
UNTIL i = size
DO
text1.length ¬ 0;
text1 ¬ RefText.AppendRope[text1, ropefile, i, text1.maxLength];
text2.length ¬ 0;
text2 ¬ RefText.AppendRope[text2, rope, i, text2.maxLength];
IF text1.length # text2.length THEN RETURN [FALSE];
FOR j:
NAT
IN [0..text1.length)
DO
IF text1[j] # text2[j] THEN RETURN [FALSE];
ENDLOOP;
IF i+text1.length > size THEN ERROR;
Process.CheckForAbort[];
ENDLOOP;
RETURN [TRUE]
};
ENDCASE => ERROR;
};
RopeFileTestCommand: Commander.CommandProc ~ {
which: Which ¬ fetch;
FOR arg:
ROPE ¬ CommanderOps.NextArgument[cmd], CommanderOps.NextArgument[cmd]
UNTIL arg =
NIL
DO
SELECT
TRUE
FROM
Rope.Equal[arg, "-f"] => {
RopeFile.LimitActive[Convert.IntFromRope[CommanderOps.NextArgument[cmd]]];
};
Rope.Equal[arg, "-fetch"] => {
which ¬ fetch;
};
Rope.Equal[arg, "-map"] => {
which ¬ map;
};
Rope.Equal[arg, "-move"] => {
which ¬ move;
};
Rope.Equal[arg, "-bigmove"] => {
which ¬ bigmove;
};
ENDCASE => {
path: PFS.PATH ~ PFS.PathFromRope[arg];
ropefile: ROPE ~ PFS.RopeOpen[fileName: path, checkMutability: FALSE, includeFormatting: TRUE].rope;
stream: IO.STREAM ~ PFS.StreamOpen[fileName: path, streamOptions: [includeFormatting: TRUE, closeFSOpenFileOnClose: TRUE]];
rope: ROPE ~ stream.GetRope[demand: FALSE];
IO.Close[stream];
IF
NOT Equal[ropefile, rope, which]
THEN {
badIndex: INT ~ Rope.Run[ropefile, 0, rope];
bad ¬ CONS[rope, bad];
bad ¬ CONS[ropefile, bad];
bad ¬ CONS[arg, bad];
CommanderOps.Failed[
IO.PutFLR["Mismatch at %g of %g (ropefile=%08xH, rope=%08xH)",
LIST[
[integer[badIndex]],
[rope[arg]],
[cardinal[LOOPHOLE[ropefile]]],
[cardinal[LOOPHOLE[rope]]]]]];
};
};
ENDLOOP;
};
Commander.Register["RopeFileTest", RopeFileTestCommand];
END.