Pascal News
Pascal News
Pascal News
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
120<br />
121<br />
122<br />
123<br />
124<br />
125<br />
126<br />
127<br />
128 var<br />
129<br />
130<br />
131<br />
132<br />
133<br />
134<br />
135<br />
136<br />
137<br />
138<br />
139<br />
140<br />
141<br />
142<br />
143<br />
144<br />
145<br />
146<br />
147<br />
148<br />
149<br />
150<br />
151<br />
152<br />
153<br />
154<br />
155<br />
156<br />
157<br />
158<br />
159<br />
160<br />
161<br />
162<br />
163<br />
164<br />
165<br />
166<br />
167<br />
168<br />
169<br />
170<br />
171<br />
172<br />
173<br />
174<br />
175<br />
176<br />
177<br />
178<br />
179<br />
end;<br />
refhead = 'head;<br />
head = record<br />
next : refhead;<br />
first : reflink;<br />
end;<br />
maxposition, minposition, width, w, charp : integer;<br />
startposition, beginposition, endposition : integer;<br />
pagewidth, p, i, j, stemlength, vertnodelength : integer;<br />
endloop : boolean;<br />
line: packed array [1 •• 512) of char;<br />
L, oldL : ref1ink;<br />
lines, slines, H, D : refhead;<br />
procedure cout (c : char);<br />
(* Cout places a character in the line buffer at the<br />
current character position. The pointer charp is<br />
incremented by this action to reflect the change. *)<br />
begin (* Cout *)<br />
charp := charp + 1;<br />
line[charp) := c;<br />
end; (* Cout *)<br />
procedure cdump;<br />
(* Cdump dumps all characters that have accumulated in<br />
the line buffer. No characters are omitted and no<br />
cr-lf is appended. *)<br />
begin (* Cdump *)<br />
if charp > 0 then for charp := 1 to charp do<br />
write (treefile,line[charp);<br />
charp := 0;<br />
end; (* Cdump *)<br />
procedure ctrim;<br />
(* Ctrim dumps all characters that have accumulated in<br />
the line buffer with trailing spaces removed. A<br />
WRITELN is used to end the line. *)<br />
begin (* Ctrim *)<br />
while (charp > 0) and (line[charp) = ' ') do<br />
charp := charp - 1;<br />
if charp > 0 then for charp := 1 to charp do<br />
write (treefile,line[charp);<br />
charp := 0;<br />
writeln (treefile);<br />
end; (* Ctrim *)<br />
function position (N : nodeptr; var H : refhead; pos : integer)<br />
: refl ink;<br />
(* Position is a recursive function that positions all the<br />
nodes of the tree on the print page. In doing so, it<br />
180<br />
181<br />
182<br />
183<br />
184<br />
185<br />
186<br />
187<br />
188<br />
189<br />
190<br />
191<br />
192<br />
193<br />
194<br />
195<br />
196<br />
197<br />
198<br />
199<br />
200<br />
201<br />
202<br />
203<br />
204<br />
205<br />
206<br />
207<br />
208<br />
209<br />
210<br />
211<br />
212<br />
213<br />
214<br />
215<br />
216<br />
217<br />
218<br />
219<br />
220<br />
221<br />
222<br />
223<br />
224<br />
225<br />
226<br />
227<br />
228<br />
229<br />
230<br />
231<br />
232<br />
233<br />
234<br />
235<br />
236<br />
237<br />
238<br />
239<br />
var<br />
constructs an auxiliary data structure that is connected<br />
by line number along the edge and position from left to<br />
right. In addition, it stores some of the original tree<br />
connections for a~c printing. *)<br />
over, lastover, nodecount<br />
Nlower : nodeptr;<br />
L, left, right : reflink;<br />
needright : boolean;<br />
integer;<br />
begin (* position *)<br />
if N = nil then (* Be defensive about illegal nodes. *)<br />
position := nil<br />
else<br />
begin (* Create a new node in our tree. *)<br />
new (L);<br />
position := L;<br />
L' • pnod e : = N;<br />
LA.ustem := false;<br />
if H = nil then<br />
begin (* A new line has been reached. *)<br />
new (H);<br />
H·.next := nil;<br />
L·.next := nil;<br />
end<br />
else<br />
begin (* Shift position if conflicting. *)<br />
L·.next := H·.first;<br />
if H·.first·:po~ < ~os + 2 then<br />
pos := H .flrst .pos - 2;<br />
end;<br />
H·.first := L;<br />
nodecount := 0;<br />
over := 1;<br />
repeat (* Count the number of lower nodes. *)"<br />
Nlower : = lowerr,ode (N ,over) ;<br />
if ((Nlower N) and (Nlower nil» then<br />
nodecouY'-;': := nodecount + 1;<br />
over := 0"; ,.. + 1;<br />
until Nlower = N;<br />
if nodecount > ~ then<br />
begin (* There are lower nodes, loop to position. *)<br />
L·.lstem := true;<br />
lastover := nodecount - 1;<br />
nodecount := over;<br />
over := - lastover;<br />
.....<br />
'"<br />
00<br />
.....<br />
needright := true;<br />
repeat (* Recursively evaluate lower positions. *)<br />
repeat (* Find one that is non-nil. *) ~<br />
if nodecount > 0 then :;:<br />
Nlower := lowernode (N,nodecount)<br />
else<br />
Nlower := N;<br />
nodecount := nodecount - 1;<br />
until Nlower nil;<br />
if Nlower N then<br />
begin<br />
left :=<br />
pOSition (N10wer, HA.next, pos + over);