CtEncodeCommandsImpl.mesa
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 5, 1992 10:18 pm PDT
DIRECTORY Basics, CommanderOps, CtBasic, CtDispatch, CtEncode, FS, IO, Rope;
CtEncodeCommandsImpl: CEDAR PROGRAM
IMPORTS Basics, CommanderOps, CtDispatch, CtEncode, FS, IO
~ BEGIN
Commands
CtEncodeCmd: CtDispatch.CtProc ~ {
args: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
affect ¬ [[0, 0], [0, 0]];
IF args.argc # 1 THEN RETURN[error: "bad arguments"];
CtEncode.WriteEncoded[maps, args[0]];
};
CtDecodeCmd: CtDispatch.CtProc ~ {
args: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
IF args.argc # 1 THEN RETURN[error: "bad arguments"];
affect ¬
CtEncode.ReadEncoded[args[0], maps ! CtEncode.Error => {error ¬ reason; CONTINUE}].box;
};
CtPrintEncodedCmd: CtDispatch.CtProc ~ {
err: Rope.ROPE ¬ NIL;
args: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
IF args.argc # 1
THEN RETURN[error: "bad argument"]
ELSE {
ENABLE IO.EndOfStream => GOTO EOF;
in: IO.STREAM ¬
FS.StreamOpen[args[0] ! FS.Error => {err ¬ error.explanation; GOTO Bad}];
colorFlag: CARDINAL ¬ IO.GetByte[in];
xOrigin: CARDINAL ¬ Basics.Card16FromH[IO.GetHWord[in]];
yOrigin: CARDINAL ¬ Basics.Card16FromH[IO.GetHWord[in]];
w: CARDINAL ¬ Basics.Card16FromH[IO.GetHWord[in]];
h: CARDINAL ¬ Basics.Card16FromH[IO.GetHWord[in]];
IO.PutF1[cmd.out, "Color flag: %g\n", IO.card[colorFlag]];
IO.PutF1[cmd.out, "xOrigin: %g\n", IO.card[xOrigin]];
IO.PutF1[cmd.out, "yOrigin: %g\n", IO.card[yOrigin]];
IO.PutF1[cmd.out, "width: %g\n", IO.card[w]];
IO.PutF1[cmd.out, "height: %g\n", IO.card[h]];
FOR y: NAT IN [yOrigin..yOrigin+h) DO
IO.PutF1[cmd.out, "y = %g\n", IO.card[y]];
IF colorFlag = 0
THEN {
x: NAT ¬ 0;
WHILE x < w DO
run: CARDINAL ¬ IO.GetByte[in];
val: CARDINAL ¬ IO.GetByte[in];
IO.PutF[cmd.out, "%g of %g\n", IO.card[run], IO.card[val]];
x ¬ x+run;
ENDLOOP;
}
ELSE {
x: NAT ¬ 0;
WHILE x < w DO
run: CARDINAL ¬ IO.GetByte[in];
rgb: CtBasic.RGB ¬ [IO.GetByte[in], IO.GetByte[in], IO.GetByte[in]];
IO.PutFL[cmd.out, "%g of %g, %g, %g\n",
LIST[IO.card[run], IO.card[rgb.r], IO.card[rgb.g], IO.card[rgb.b]]];
x ¬ x+run;
ENDLOOP;
};
ENDLOOP;
EXITS
EOF => IO.PutRope[cmd.out, "Premature EndOfFile\n"];
Bad => RETURN[error: err];
};
};
Start Code
CtDispatch.RegisterCtOp["Encoding/Decoding:", NIL, NIL];
CtDispatch.RegisterCtOp["Encode", CtEncodeCmd, "Ct Encode <fileName> [-w <xywh>]"];
CtDispatch.RegisterCtOp["Decode", CtDecodeCmd, "Ct Decode <filename>"];
CtDispatch.RegisterCtOp["PrintEncoded", CtPrintEncodedCmd, "Ct PrintEncoded <filename>"];
END.