DIRECTORY Curve USING [StartSamples, defaultHandle, AddSample], ConvertUnsafe USING [ToRope], JaMFnsDefs, IO, FileIO USING [OpenFailed, Open], Rope USING [ROPE, Equal, Length]; ReadContourImpl: PROGRAM IMPORTS JaMFnsDefs, Rope, Curve, FileIO, IO, ConvertUnsafe EXPORTS = BEGIN stream: IO.Handle; Done: SIGNAL = CODE; ROPE: TYPE = Rope.ROPE; contourNumber: INTEGER _ 0; OpenInputFile: PROC = { ENABLE FileIO.OpenFailed => TRUSTED{ JaMFnsDefs.JaMExec["(open failed\n) .print"]; CONTINUE}; ls: LONG STRING _ [80]; rope: ROPE; JaMFnsDefs.PopString[ls]; rope _ ConvertUnsafe.ToRope[ls]; IF stream # NIL THEN stream.Close[]; stream _ NIL; IF rope.Length[] > 0 THEN stream _ FileIO.Open[rope, read]; FindNextContour[]; --reads past any junk at the front contourNumber _ 0; }; CloseInputFile: PROC = { IF stream # NIL THEN stream.Close[]; stream _ NIL; }; JFindContour: PROCEDURE = { ENABLE IO.EndOfStream =>{JaMFnsDefs.JaMExec["(not found \n) .print"]; CONTINUE}; cn: INTEGER _ JaMFnsDefs.PopInteger[]; FindContour[cn]; }; FindContour: PUBLIC PROCEDURE [cn: NAT] = { count: NAT _ 0; IO.SetIndex[stream,0]; FindNextContour[]; --reads past any junk at the front contourNumber _ 0; UNTIL count=cn DO FindNextContour[]; count _ count+1; ENDLOOP; }; FindNextContour: PUBLIC PROC = { rope: ROPE; UNTIL Rope.Equal[rope,"beginoutline",FALSE] DO rope _ IO.GetToken[stream]; contourNumber _ contourNumber+1; ENDLOOP; }; JInputSamples: PROC = { JaMFnsDefs.PushBoolean[InputSamples[]]; }; InputSamples: PUBLIC PROCEDURE RETURNS[endOfFile: BOOLEAN] = { x,y: REAL; nSamples: INTEGER; endOfFile _ FALSE; DO [x,y] _ GetFirst[! Done, IO.EndOfStream => ERROR]; Curve.StartSamples[Curve.defaultHandle, x,y]; nSamples _ 1; DO [x,y] _ GetNext[! Done => EXIT; IO.EndOfStream => {endOfFile _ TRUE; EXIT}]; Curve.AddSample[Curve.defaultHandle, x, y]; nSamples _ nSamples+1; ENDLOOP; contourNumber _ contourNumber+1; IF nSamples>6 OR endOfFile THEN EXIT; ENDLOOP; }; GetFirst: PROC RETURNS[x,y: REAL] = { r: ROPE; x _ IO.GetReal[stream ! IO.SyntaxError => SIGNAL Done]; y _ IO.GetReal[stream]; r _ IO.GetToken[stream]; IF ~Rope.Equal[r,"setcp",FALSE] THEN ERROR; }; GetNext: PROC RETURNS[x,y: REAL] = { r: ROPE; x _ IO.GetReal[stream ! IO.SyntaxError => SIGNAL Done]; y _ IO.GetReal[stream]; r _ IO.GetToken[stream]; IF ~Rope.Equal[r,"drawto",FALSE] THEN ERROR; }; JaMFnsDefs.Register[".openInput"L,OpenInputFile]; --open the input file (will close current file) JaMFnsDefs.Register[".closeInput"L,CloseInputFile]; --close the input file JaMFnsDefs.Register[".findContour"L,JFindContour]; --contour number .findContour JaMFnsDefs.Register[".inputSamples"L,JInputSamples]; --inputs current contour. returns endOfFile END. NReadContourImpl.mesa Written by: Maureen Stone November 9, 1983 4:56 pm ʘJ˜Jšœ™Jšœ2™2šÏk ˜ Jšœœ*˜5Jšœœ ˜J˜ Jšœ˜Jšœœ˜ Jšœœœ˜!—J˜Jšœ˜Jšœ3˜:Jšœ˜Jšœœ˜Jšœœœ˜Jšœœœ˜Jšœœ˜J˜šÏn œœ˜šœœ˜$Jšœ.œ˜8—Jšœœœ˜Jšœœ˜ Jšœ˜J˜ Jšœ œœ˜$Jšœ œ˜ Jšœœ"˜;JšœÏc"˜5J˜J˜J˜—šžœœ˜Jšœ œœ˜$Jšœ œ˜ J˜J˜—šž œ œ˜Jšœ@œ˜PJšœœ˜&J˜Jšœ˜J˜—šž œœœ˜+Jšœœ˜Jšœ˜JšœŸ"˜5J˜šœ ˜Jšœ˜J˜Jšœ˜—Jšœ˜—šžœ œ˜ Jšœœ˜ šœ œ˜.Jšœœ˜J˜ Jš˜—Jšœ˜—šž œœ˜J˜'Jšœ˜—š ž œœ œœ œ˜>Jšœœ˜ Jšœ œ˜Jšœ œ˜š˜Jšœ+œ˜2Jšœ-˜-J˜ š˜Jš œœœœœ˜LJšœ+˜+J˜Jšœ˜—J˜ Jšœ œ œœ˜%Jšœ˜—Jšœ˜—šžœœœœ˜%Jšœœ˜Jšœœœœ˜7Jšœœ˜Jšœœ˜Jšœœœœ˜+J˜—šžœœœœ˜$Jšœœ˜Jšœœœœ˜7Jšœœ˜Jšœœ˜Jšœœœœ˜,J˜—J˜Jšœ2Ÿ/˜aJšœ4Ÿ˜JJšœ3ŸÐciÏi ˜PJšœ5Ÿ+˜`J˜Jšœ˜J˜J˜—…— Œø