DIRECTORY Atom, IO, Rope, TiogaAccess; UnparserBuffer: CEDAR DEFINITIONS = BEGIN Handle: TYPE = REF HandleRec; NewHandle: PROC [output: BufferOutput, margin: INTEGER _ 80] RETURNS [Handle]; Init: PROC [h: Handle]; Setb: PROC [h: Handle]; Endb: PROC [h: Handle]; Bp: PROC[h: Handle, united: BOOL, offset: INTEGER]; Charb: PROC [h: Handle, ch: CHAR]; Ropeb: PROC [h: Handle, r: Rope.ROPE]; Atomb: PROC [h: Handle, a: ATOM]; Newlineb: PROC [h: Handle, offset: INTEGER]; Looksb: PROC [h: Handle, looks: Rope.ROPE]; HandleRec: TYPE = RECORD [ margin: INTEGER _ 80, width: ARRAY CHAR OF INTEGER _ ALL [1], spacers: LIST OF CHAR, output: BufferOutput, clientData: REF _ NIL, bufferWidth: PRIVATE INTEGER _ 0, bl, cl, br, cr, sr, srx: PRIVATE INTEGER _ 0, c: PRIVATE ARRAY [0 .. n) OF CHAR _ ALL['?], dl: PRIVATE ARRAY [0 .. n) OF Rope.ROPE _ ALL[NIL], b: PRIVATE ARRAY [0 .. n) OF RECORD [ type: {setb, breakpoint}, united: BOOL, offset: INTEGER, p: [0 .. n)] _ ALL[[setb, FALSE, 0, 0]], s: PRIVATE ARRAY [0 .. n) OF INTEGER _ ALL[0], indentation: PRIVATE INTEGER _ 0, depth: PRIVATE INTEGER _ 0, curLooks: PRIVATE TiogaAccess.Looks _ ALL[FALSE] ]; BufferOutputKind: TYPE = {stream, access}; BufferOutput: TYPE = RECORD [ variant: SELECT kind: BufferOutputKind FROM stream => [stream: IO.STREAM], access => [ access: TiogaAccess.Writer, format: ATOM _ NIL, nestWidth: INTEGER _ 1], ENDCASE]; n: INT = 256; END. |UnparserBuffer.mesa Created December 7, 1982 3:57 pm by Greg Nelson GNelson, December 6, 1983 2:03 am Spreitzer, February 9, 1986 11:59:56 pm PST Formatted output routines. Send a stream of characters through a buffer, delineate the stream into subsequences called objects. The objects can be nested. (Objects are called "groups" in CGN9.) For each object, specify within it a set of breakpoints. The routines will format the text as follows. (1) An object will be printed all on one line if possible. (2) If an object cannot fit on one line, new lines will be started at one or more of the object's breakpoints, so that no text overflows the right margin. (3) With each breakpoint there is associated an integer call the breakpoint's offset. If a new line is started at a breakpoint, then the new line will be indented by the sum of the breakpoint's offset plus the indentation of the first character of the smallest object that contains the breakpoint. (4) Each breakpoint is either united or ununited. If any breakpoint of an object is broken, then all that object's united breakpoints are broken. An ununited breakpoint is broken only if it is necessary to do so to prevent overflowing the right margin. With spacers = LIST[IO.SP]. Destroys any information in the internal buffers and makes the buffers all empty. Almost like allocating a new handle, but does not affect the public parts (margin, width, output, and clientData). Begin an object. End an object. Inserts a breakpoint. If the breakpoint breaks, the next line will be indented by offset from the beginning of the object to which this breakpoint belongs. Outputs the character Outputs the rope Outputs the pname of the atom Just like a breakpoint except that it is certain to break, thus the effect is to insert a new line into the output. Affects the looks of the following characters in the standard way. The following fields are public --- the client may read and write these synchronously with calls on routines in this interface. Shouldn't modify this unless between lines. Width of each element should evenly divide width of previous element. Width of last element must evenly divide every possible indentation. The following fields are private to the implementation --- the client should not read or write them. Size of various internal buffers; plenty large for reasonable margins. Should be a parameter of the module but .... ʘ˜codešœ™Kšœ/™/Kšœ!™!K™+—K˜Kšœ³™³K˜KšÏk œœ˜&K˜KšÐbxœœ œ˜$K˜Kš˜K˜Kšœœœ ˜K˜šÏn œœ œœ ˜NK™—K˜šŸœœ˜KšœÄ™Ä—K˜šŸœœ ˜Kšœ™—K˜šŸœœ ˜Kšœ™—K˜šŸœœœ œ˜3Kšœ›™›—K˜šŸœœœ˜"Kšœ™—K˜šŸœœœ˜&Kšœ™—K˜šŸœœœ˜!Kšœ™—K˜šŸœœœ˜,Kšœv™v—K˜šŸœœœ˜+K™B—K˜šœ œœ˜K™™K˜šœœ˜K™+—Kš œœœœœœ˜'šœ œœœ˜K™EK™D—Kšœ˜Kšœ œœ˜—K™™dK˜Kšœ œœ˜!Kšœœœ˜-Kš œœœ œœœ˜,Kš œœœ œœœœ˜3š œœœ œœ˜%K˜Kšœœ˜ Kšœœ˜Kšœœœ ˜(—Kš œœœ œœœ˜.Kšœ œœ˜!Kšœœœ˜Kšœ œœœ˜0—K˜—K˜Kšœœ˜*šœœœ˜šœ œ˜+Kšœœœ˜šœ ˜ Kšœ˜Kšœœœ˜Kšœ œ˜—Kšœ˜ ——K˜šœœ˜ Kšœt™t—K˜Kšœ˜˜K˜—K˜—…—š®