1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 get "runoff_head"
25
26 external
27 $( HyphenateWord = "hyphenate_word_" $)
28
29
30
31
32
33 let Text () be
34 { if Nr = 0 do { Break (); Spacing (); Newline (1); return }
35 if Rawchar[1] = '*s' do Break ()
36 if Eq > 0 do { Equation (); return }
37 for i = 1 to Nr do Char[Nc + i] := Rawchar[i]
38 Nc := Nc + Nr
39 if Ce>0 do { Center (); return }
40 unless Fi do { Break (); return }
41
42
43
44 Fill ()
45
46
47 while Nc > 0 & Char!Nc = '*s' do Nc := Nc - 1
48 if Nc > 0 do
49 $( let x, y = Char!(Nc - 1), Char!Nc
50 if y = '.' | y = ':' | y = ';' | y = '!' | y = '?'
51 | (y = '"' | y = ')') & (x = '.' | x = '!' | x = '?') do
52 $( Nc := Nc + 1
53 Char!Nc := '*s'
54 $)
55 Nc := Nc + 1
56 Char!Nc := '*s'
57 $)
58 }
59
60 and Fill () be
61 $( if Nc < Ll - Un return
62
63 let Ne = 0
64 let Nc1, Ne1 = 0, 0
65 let Nco = 0
66
67 let Usable = Ll - Un
68 and Undent = In - Un
69
70 Char!(Nc + 1) := '*s'
71 for i = 1 to Nc + 1 do
72 $( test Char!i = '*s'
73 then $( if Ne le Usable | Ne1 = 0 do Nc1, Ne1 := i, Ne
74 if Ne ge Usable do
75 $( unless Hyphenating & Ne > Usable break
76 let x = TryToHyphenate (Nc1, i, Usable - Ne1)
77 while Nc1 < x do
78 $( Ne1 := Ne1 + Width (Char!Nc1)
79 Nc1 := Nc1 + 1
80 $)
81 break
82 $)
83 while i le Nc do
84 $( Ne := Ne + 1
85 unless Char!(i + 1) = '*s' break
86 i := i + 1
87 $)
88 $)
89 or Ne := Ne + Width (Char!i)
90
91 if Nco = 0 & Ne ge Undent do Nco := i + 1
92 $)
93 if Ne < Usable return
94
95
96 Spacing ()
97 if Print | Ft do
98 $( PrinterIndent ()
99 Blank (Un)
100 test Ad & Ne1 < Usable
101 then test Undent = 0
102 then Adjust (1, Nc1 - 1, Usable - Ne1)
103 or $( PadLeft := false
104 if Nco = 0 | Nco > Nc1 do Nco := Nc1
105 for i = 1 to Nco - 1 do WriteChar (Char!i)
106 Adjust (Nco, Nc1 - 1, Usable - Ne1)
107 $)
108 or for i = 1 to Nc1 - 1 do WriteChar (Char!i)
109 $)
110 Newline (1)
111
112
113 while Char!(Nc1 + 1) = '*s' & Nc1 < Nc do Nc1 := Nc1 + 1
114 Nc := Nc - Nc1
115 if Nc < 0 do Nc := 0
116 for i = 1 to Nc do Char!i := Char!(Nc1 + i)
117 Un := In
118 Fill ()
119 $)
120
121
122
123
124
125
126
127
128 and TryToHyphenate (Begin, End, Space) = valof
129 $( while Char!Begin = '*s' & Begin le Nc do Begin, Space := Begin + 1, Space - 1
130 let Len = End - Begin
131 if Space < 3 | Len < 4 resultis 0
132 let v, w = vec Maxline, vec Maxline / 4
133 for i = 1 to Len do v!i := Char!(Begin + i - 1)
134 v!0 := Len
135 Packstring (v, w)
136 let h = 0
137 call HyphenateWord (w string, lv Space, lv h)
138 if h le 0 | h ge Len resultis 0
139 for i = Nc + 1 to Begin + h by -1 do Char!(i + 2) := Char!i
140 Char!(Begin + h), Char!(Begin + h + 1) := '-', '*s'
141 Nc := Nc + 2
142 resultis Begin + h + 1
143 $)
144
145
146
147
148
149
150
151 and Adjust (Begin, End, Pad) be
152 $( let Gaps = 0
153
154 for i = Begin to End if Char!i = '*s' do
155 $( if i > Begin do Gaps := Gaps + 1
156 while Char!(i + 1) = '*s' & i < End do i := i + 1
157 $)
158 let s, k = 0, -1
159 unless Gaps = 0 do
160 $( s := Pad / Gaps
161 k := Pad - s * Gaps
162 $)
163
164 for i = Begin to End do
165 { WriteChar ( Char[i] )
166 if Char[i + 1] = '*s' & Char[i] ne '*s' & i < End do
167 { Blank (s)
168 test PadLeft
169 then if k > 0 do { WriteChar ('*s'); k := k - 1 }
170 else test k < Gaps then k := k + 1 or WriteChar ('*s')
171 }
172 }
173 PadLeft := not PadLeft
174 $)
175
176
177 and Width (Char) =
178 $8040 le Conv!Char le $8176 -* 1,
179 Conv!Char = '*b' -* -1,
180 0
181
182
183
184
185 and Break () be
186 { if Fi do Fill ()
187 while Nc > 0 & Char!Nc = '*s' do Nc := Nc - 1
188 if Nc > 0 do
189 $( Spacing ()
190 if Print | Ft do
191 $( PrinterIndent ()
192 Blank (Un)
193 for i = 1 to Nc do WriteChar ( Char[i] )
194 $)
195 Newline (1)
196 Un := In
197 $)
198 Nc := 0
199 }
200
201
202
203
204
205
206
207
208 and Spacing () be
209 { if Nl > 0 do
210 $( Newline (MinI (Ms - 1, LinesLeft + Fl))
211 if LinesLeft ge Ms logor Ft logor Flp do
212 $( Flp := false
213 return
214 $)
215 Eject ()
216 $)
217
218 if Ft return
219
220 if Waitsw & Print do $( Wait (); Waitsw := Stopsw $)
221
222 OddPage := Np rem 2 ne 0
223
224
225 if Printersw do Nl := Nl + 3
226 Newline (Ma1 - Nl)
227 for i = 1 to Maxheads do Title ((OddPage -> Oh, Eh)!i)
228
229 Newline (Ma2)
230 if LinesLeft + Fl le 0 do LinesLeft := 1 - Fl
231
232 if Pi = 0 return
233
234 if Pi ge LinesLeft do
235 $( Newline (LinesLeft + Fl)
236 if Pi > Pl * 10 do Pi := Pi rem (Pl * 10)
237 Pi := Pi - Pl
238 Flp := false
239 Spacing ()
240 return
241 $)
242 Newline (Pi)
243 Pi := 0
244 }
245
246 and Eject () be
247 { if Ft return
248 unless Fl = 0 do PrintFootnotes ()
249 if Nl = 0 return
250 Newline (NoPaging -> Ma3, Pl - Nl - Ma4 - (OddPage -> Of, Ef)!0)
251 for i = Maxheads to 1 by -1 do Title ((OddPage -> Of, Ef)!i)
252 test Printersw & ^ NoPaging
253 then for i = 1 to MultiplePagecount do WriteChar ('*f')
254 or Newline (NoPaging -> Ma4, Pl - Nl)
255 Nl := 0
256 LinesLeft := Pl
257 if Fr do Foot := 1
258 Np := NNp; NNp := NNp + 1
259 Print := Fp le Np le Lp & Passes le 1
260 }
261
262 and Center () be
263 { let Ne = 0
264 for i = 1 to Nc do Ne := Ne+Width (Char[i])
265 Spacing ()
266 PrinterIndent ()
267 Blank ( (Ll-In-Ne)/2 + In)
268 for i = 1 to Nc do WriteChar (Char[i])
269 Newline (1)
270 Nc := 0
271 Ce := Ce - 1
272 }
273
274
275
276
277
278
279
280 and Equation () be
281 { Spacing ()
282 Nrx := 1
283 let v = vec Maxline
284 Title (Readhead (v))
285 Eq := Eq - 1
286 }