<> <> <> <> DIRECTORY Ascii, IO, Rope, TSObject, TSGlue, TSTypes, TSDumper, JaMFnsDefs; TSDumperImpl: CEDAR PROGRAM IMPORTS TSObject, IO, TSTypes, JaMFnsDefs EXPORTS TSDumper = BEGIN OPEN TSTypes, TSGlue; ROPE: TYPE = Rope.ROPE; stream: IO.STREAM _ NIL; Stream: PROC RETURNS [IO.STREAM] = {IF stream=NIL THEN [out:stream]_IO.CreateViewerStreams["Boxes.log"]; RETURN[stream]}; oneLine: NAT _ 0; -- non-zero puts stuff on one line SameLine: PROC = {oneLine_oneLine+1}; Indent: PROC [i: NAT] = {IF oneLine=0 THEN THROUGH [0..i) DO Pc['.]; Pc[Ascii.TAB] ENDLOOP}; DumpList: PUBLIC PROC [list: TSObject.ItemList, indent: NAT _ 0] = { oldOneLine: NAT _ oneLine; lastThingWasCharBox: BOOLEAN _ FALSE; source: TSObject.ListReader; FinishCharBox: PROC = { IF lastThingWasCharBox THEN {Pc['"]; Pl[" Chars"]; lastThingWasCharBox _ FALSE} }; DumpException: PROC[x: REF ANY] = { FinishCharBox[]; Indent[indent]; SELECT TRUE FROM ISTYPE[x, TSObject.Glue] => { glue: TSObject.Glue _ NARROW[x]; Pd[glue.space]; Pr["plus"]; Pd[glue.stretch]; Pr["minus"]; Pd[glue.shrink]; Pl["glue"]; }; ISTYPE[x, TSObject.Box] => TRUSTED { box: TSObject.Box _ NARROW[x]; Pd[box.extent[left]]; Pr["+"]; Pd[box.extent[right]]; Pr["wide"]; Pd[box.extent[up]]; Pr["high"]; Pd[box.extent[down]]; Pr["deep"]; WITH b: box SELECT FROM char => { Pc['"]; Pc[source.CurrentChar[]]; Pc['"]; Pl[" CharBox"]; }; list => { IF b.direction = down THEN Pr["vbox"] ELSE Pr["hbox"]; Stream[].Put[IO.real[b.glueset.value]]; Pl[" glueset"]; DumpList[b.items, indent+1]; Indent[indent+1]; Pl["endbox"]; }; rule => Pl["rule"]; ENDCASE => Pl["box"]; }; ISTYPE[x, TSObject.Kerf] => { k: TSObject.Kerf _ NARROW[x]; p: LIST OF REF ANY _ k.prebreak; SameLine[]; WHILE p # NIL DO DumpException[p.first]; p _ p.rest; ENDLOOP; Pl["pre"]; p _ k.join; WHILE p # NIL DO DumpException[p.first]; p _ p.rest; ENDLOOP; Pl["join"]; p _ k.postbreak; WHILE p # NIL DO DumpException[p.first]; p _ p.rest; ENDLOOP; Pl["post"]; oneLine _ oldOneLine; Stream[].Put[IO.real[k.penalty]]; Pl[" penalty"]; }; ISTYPE[x, TSObject.Kern] => { Pd[NARROW[x, TSObject.Kern]^]; Pl["kern"]; }; ENDCASE => {Pl["Unknown list entry"]}; }; source _ list.CreateReader[]; UNTIL source.End[] DO SELECT source.CurrentTag[] FROM char => { IF NOT lastThingWasCharBox THEN {Indent[indent]; Pc['"]}; Pc[source.CurrentChar[]]; lastThingWasCharBox _ TRUE }; space => { IF NOT lastThingWasCharBox THEN {Indent[indent]; Pc['"]}; Pc['\\];Pc[' ]; lastThingWasCharBox _ TRUE }; hyphen => { IF NOT lastThingWasCharBox THEN {Indent[indent]; Pc['"]}; Pc['\\];Pc['-]; lastThingWasCharBox _ TRUE }; exception => DumpException[source.CurrentItem[]]; ENDCASE => ERROR; source.Next[]; ENDLOOP; FinishCharBox[]; oneLine _ oldOneLine; IF indent = 0 THEN Pl[""]; }; Pc: PROC[c: CHAR] = {IO.PutChar[Stream[],c]}; Pr: PROC[r: ROPE] = {IO.PutRope[Stream[],r]; Pc[' ]}; Pl: PROC[r: ROPE] = TRUSTED {IO.PutRope[Stream[],r]; IF JaMFnsDefs.GetJaMBreak[] THEN ERROR ABORTED; IF oneLine=0 THEN IO.PutRope[Stream[]," "] ELSE Pc[' ]}; Pd: PROC[d: Dimn] = {OPEN IO; Put[Stream[],real[DimnRatio[d,pt]], rope[" pt "]]}; DumpReset: PUBLIC PROC [] = {stream _ NIL}; DumpText: PUBLIC PROC [t: REF READONLY TEXT] = { {OPEN IO; Put[Stream[],text[t],char[CR]]}; }; END.