<> <> <> 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.STREAM _ IO.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.STREAM _ FS.StreamOpen[inputName]; out: IO.STREAM _ FS.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.