File: InvertAxis.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Christophe Cuenod August 18, 1987 2:33:42 pm PDT
DIRECTORY
Commander USING [CommandProc, Register],
Rope USING [ROPE, Equal],
FS USING [StreamOpen],
IO USING [ CharClass, Close, EndOf, EndOfStream, GetChar, GetTokenRope, PutChar, PutF, PutRope, RIS, rope, STREAM];
InvertAxis: CEDAR PROGRAM
IMPORTS IO, Commander, Rope, FS =
BEGIN
ROPE: TYPE = Rope.ROPE;
CmdTokenBreak: PROC [char: CHAR] RETURNS [IO.CharClass] = {
IF char = '← THEN RETURN [break];
IF char = ' OR char = '\t OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr];
RETURN [other];
};
GetCmdToken: PROC [stream: IO.STREAM] RETURNS [rope: ROPE] = {
rope ← NIL;
rope ← stream.GetTokenRope[CmdTokenBreak ! IO.EndOfStream => CONTINUE].token;
};
InvertAxisProc: Commander.CommandProc = BEGIN
c: CHAR;
stream: IO.STREAMIO.RIS[cmd.commandLine];
outputName: ROPE ← GetCmdToken[stream];
gets: ROPE ← GetCmdToken[stream];
inputName: ROPE ← GetCmdToken[stream];
IF outputName # NIL AND gets.Equal["←"] AND inputName # NIL THEN {
in: IO.STREAMFS.StreamOpen[inputName];
out: IO.STREAMFS.StreamOpen[outputName,$create];
WHILE NOT IO.EndOf[in] DO
c ← IO.GetChar[in];
SELECT c FROM
='X  => IO.PutChar[out, 'Y];
='Y  => IO.PutChar[out, 'X];
ENDCASE => IO.PutChar[out, c];
ENDLOOP;
IO.Close[out];
IO.PutF[cmd.out, "\n%g written\n",IO.rope[outputName]];
}
ELSE {
cmd.out.PutRope["Usage: InvertAxis OutputFile ← InputFile\n"];
};
END;
Commander.Register[
key: "InvertAxis", proc: InvertAxisProc, doc: "Exchange the X and Y axis of a gerber file.\n"];
END.