<> <> <> <> DIRECTORY GriffinMenusInterface USING [MenuItemFromRope, PlaceObjectCP, Close], JaM, IO, FS, Rope USING [ROPE, Equal, Length]; LogToGriffinImpl: PROGRAM IMPORTS JaM, Rope, IO, FS, GriffinMenusInterface EXPORTS = BEGIN stream: IO.STREAM; Done: SIGNAL = CODE; ROPE: TYPE = Rope.ROPE; objectNumber: INTEGER _ 0; OpenInputFile: SAFE PROC[state: JaM.State] = TRUSTED { ENABLE FS.Error => TRUSTED { JaM.ExecuteRope[state,"(FS.StreamOpen failed\n) .print"]; CONTINUE}; rope: ROPE _ JaM.PopRope[state]; IF stream # NIL THEN stream.Close[]; stream _ NIL; IF rope.Length[] > 0 THEN stream _ FS.StreamOpen[fileName: rope, accessOptions: $read]; FindNextObject[]; --reads past any junk at the front objectNumber _ 0; }; CloseInputFile: SAFE PROC[state: JaM.State] = TRUSTED { IF stream # NIL THEN stream.Close[]; stream _ NIL; }; JFindObject: SAFE PROCEDURE[state: JaM.State] = TRUSTED { ENABLE IO.EndOfStream =>{JaM.ExecuteRope[state,"(not found \n) .print"]; CONTINUE}; cn: INTEGER _ JaM.PopInt[state]; FindObject[cn]; }; FindObject: PUBLIC PROCEDURE [cn: NAT] = { count: NAT _ 0; IO.SetIndex[stream,0]; FindNextObject[]; --reads past any junk at the front objectNumber _ 0; UNTIL count=cn DO FindNextObject[]; count _ count+1; ENDLOOP; }; FindNextObject: PUBLIC PROC = { rope: ROPE; UNTIL Rope.Equal[rope,"beginoutline",FALSE] DO [rope, ] _ stream.GetTokenRope[]; objectNumber _ objectNumber+1; ENDLOOP; }; JInputCubics: SAFE PROC[state: JaM.State] = TRUSTED { JaM.PushBool[state,InputCubics[]]; }; InputCubics: PUBLIC PROCEDURE RETURNS[endOfFile: BOOLEAN] = {OPEN GriffinMenusInterface; x0,y0,x1,y1,x2,y2,x3,y3: REAL; endOfFile _ FALSE; [x0,y0] _ GetFirst[ ! IO.Error => {FindNextObject[]; RETRY}; IO.EndOfStream => ERROR]; GriffinMenusInterface.PlaceObjectCP[[x0,y0]]; DO [x0,y0,x1,y1,x2,y2,x3,y3] _ GetCurve[! Done => EXIT; IO.EndOfStream => { endOfFile _ TRUE; EXIT}]; GriffinMenusInterface.PlaceObjectCP[[x1,y1]]; GriffinMenusInterface.PlaceObjectCP[[x2,y2]]; GriffinMenusInterface.PlaceObjectCP[[x3,y3]]; ENDLOOP; objectNumber _ objectNumber+1; GriffinMenusInterface.Close[GriffinMenusInterface.MenuItemFromRope["Close"]]; }; GetFirst: PROC RETURNS[x,y: REAL] = { r: ROPE; x _ IO.GetReal[stream]; y _ IO.GetReal[stream]; [r, ] _ IO.GetTokenRope[stream]; IF ~Rope.Equal[r,"setcp",FALSE] THEN ERROR; }; GetCurve: PROC RETURNS[x0,y0,x1,y1,x2,y2,x3,y3: REAL] = { r: ROPE; x0 _ IO.GetReal[stream ! IO.Error => SIGNAL Done]; y0 _ IO.GetReal[stream]; x1 _ IO.GetReal[stream]; y1 _ IO.GetReal[stream]; x2 _ IO.GetReal[stream]; y2 _ IO.GetReal[stream]; x3 _ IO.GetReal[stream]; y3 _ IO.GetReal[stream]; [r, ] _ stream.GetTokenRope[]; IF ~Rope.Equal[r,"bezier",FALSE] THEN ERROR; }; Init: SAFE PROC[state: JaM.State] = TRUSTED { JaM.Register[state,"Griffin.openInput",OpenInputFile]; --open the input file (will close current file) JaM.Register[state,"Griffin.closeInput",CloseInputFile]; --close the input file JaM.Register[state,"Griffin.findObject",JFindObject]; --object number .findObject JaM.Register[state,"Griffin.inputCubics",JInputCubics]; --inputs current object. returns endOfFile }; JaM.RegisterInit["LogToGriffinImpl",Init]; END.