| 1 |
% ompar.ch: Local paragraph information |
| 2 |
% |
| 3 |
% This file is part of the Omega project, which |
| 4 |
% is based on the web2c distribution of TeX. |
| 5 |
% |
| 6 |
% Copyright (c) 1994--2000 John Plaice and Yannis Haralambous |
| 7 |
% |
| 8 |
% This library is free software; you can redistribute it and/or |
| 9 |
% modify it under the terms of the GNU Library General Public |
| 10 |
% License as published by the Free Software Foundation; either |
| 11 |
% version 2 of the License, or (at your option) any later version. |
| 12 |
% |
| 13 |
% This library is distributed in the hope that it will be useful, |
| 14 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
% Library General Public License for more details. |
| 17 |
% |
| 18 |
% You should have received a copy of the GNU Library General Public |
| 19 |
% License along with this library; if not, write to the Free Software |
| 20 |
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
% |
| 22 |
%------------------------- |
| 23 |
@x |
| 24 |
@p function copy_node_list(@!p:pointer):pointer; {makes a duplicate of the |
| 25 |
node list that starts at |p| and returns a pointer to the new list} |
| 26 |
var h:pointer; {temporary head of copied list} |
| 27 |
@!q:pointer; {previous position in new list} |
| 28 |
@!r:pointer; {current node being fabricated for new list} |
| 29 |
@!words:0..5; {number of words remaining to be copied} |
| 30 |
@y |
| 31 |
@p function copy_node_list(@!p:pointer):pointer; {makes a duplicate of the |
| 32 |
node list that starts at |p| and returns a pointer to the new list} |
| 33 |
var h:pointer; {temporary head of copied list} |
| 34 |
@!q:pointer; {previous position in new list} |
| 35 |
@!r:pointer; {current node being fabricated for new list} |
| 36 |
@!words:0..8; {number of words remaining to be copied} |
| 37 |
@z |
| 38 |
|
| 39 |
@x [15] m.208 l.4170 |
| 40 |
@d min_internal=char_ghost+1 {the smallest code that can follow \.{\\the}} |
| 41 |
@y |
| 42 |
@d assign_local_box=char_ghost+1 |
| 43 |
{box for guillemets \.{\\localleftbox} or \.{\\localrightbox}} |
| 44 |
@d min_internal=assign_local_box+1 {the smallest code that can follow \.{\\the}} |
| 45 |
@z |
| 46 |
%------------------------- |
| 47 |
@x [16] m.212 l.4306 |
| 48 |
@!aux_field: memory_word; |
| 49 |
@y |
| 50 |
@!aux_field: memory_word; |
| 51 |
@!local_par_field: pointer; |
| 52 |
@!local_par_bool_field: boolean; |
| 53 |
@z |
| 54 |
%------------------------- |
| 55 |
@x [16] m.213 l.4318 |
| 56 |
@d mode_line==cur_list.ml_field {source file line number at beginning of list} |
| 57 |
@y |
| 58 |
@d mode_line==cur_list.ml_field {source file line number at beginning of list} |
| 59 |
@d local_par==cur_list.local_par_field |
| 60 |
{pointer to whatsit for local stuff} |
| 61 |
@d local_par_bool==cur_list.local_par_bool_field |
| 62 |
{has local stuff been changed in this group?} |
| 63 |
@z |
| 64 |
%------------------------- |
| 65 |
@x [16] m.215 l.4344 |
| 66 |
prev_graf:=0; shown_mode:=0; |
| 67 |
@y |
| 68 |
prev_graf:=0; shown_mode:=0; |
| 69 |
local_par:=null; local_par_bool:=false; |
| 70 |
@z |
| 71 |
%------------------------- |
| 72 |
@x [16] m.216 l.4351 |
| 73 |
@ When \TeX's work on one level is interrupted, the state is saved by |
| 74 |
calling |push_nest|. This routine changes |head| and |tail| so that |
| 75 |
a new (empty) list is begun; it does not change |mode| or |aux|. |
| 76 |
|
| 77 |
@p procedure push_nest; {enter a new semantic level, save the old} |
| 78 |
begin if nest_ptr>max_nest_stack then |
| 79 |
begin max_nest_stack:=nest_ptr; |
| 80 |
if nest_ptr=nest_size then overflow("semantic nest size",nest_size); |
| 81 |
@:TeX capacity exceeded semantic nest size}{\quad semantic nest size@> |
| 82 |
end; |
| 83 |
nest[nest_ptr]:=cur_list; {stack the record} |
| 84 |
incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line; |
| 85 |
@y |
| 86 |
@ @p @<LOCAL: Declare |make_local_par_node|@>; |
| 87 |
|
| 88 |
@ When \TeX's work on one level is interrupted, the state is saved by |
| 89 |
calling |push_nest|. This routine changes |head| and |tail| so that |
| 90 |
a new (empty) list is begun; it does not change |mode| or |aux|. |
| 91 |
|
| 92 |
@p procedure push_nest; {enter a new semantic level, save the old} |
| 93 |
begin if nest_ptr>max_nest_stack then |
| 94 |
begin max_nest_stack:=nest_ptr; |
| 95 |
if nest_ptr=nest_size then overflow("semantic nest size",nest_size); |
| 96 |
@:TeX capacity exceeded semantic nest size}{\quad semantic nest size@> |
| 97 |
end; |
| 98 |
nest[nest_ptr]:=cur_list; {stack the record} |
| 99 |
incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line; |
| 100 |
local_par:=make_local_par_node; local_par_bool:=false; |
| 101 |
@z |
| 102 |
%------------------------- |
| 103 |
@x [16] m.217 l.4366 |
| 104 |
begin free_avail(head); decr(nest_ptr); cur_list:=nest[nest_ptr]; |
| 105 |
@y |
| 106 |
begin |
| 107 |
if local_par<>null then begin |
| 108 |
if local_par_bool then begin end {|tail_append(local_par)|} |
| 109 |
else free_node(local_par,local_par_size); |
| 110 |
end; |
| 111 |
free_avail(head); decr(nest_ptr); cur_list:=nest[nest_ptr]; |
| 112 |
@z |
| 113 |
%------------------------- |
| 114 |
@x [17] m.230 l.4860 |
| 115 |
@d box_base=toks_base+number_regs {table of |number_regs| box registers} |
| 116 |
@y |
| 117 |
@d local_left_box_base=toks_base+number_regs |
| 118 |
@d local_right_box_base=local_left_box_base+1 |
| 119 |
@d box_base=local_right_box_base+1 {table of |number_regs| box registers} |
| 120 |
@z |
| 121 |
%------------------------- |
| 122 |
@x [17] m.230 l.4888 |
| 123 |
@d box(#)==equiv(box_base+#) |
| 124 |
@y |
| 125 |
@d local_left_box==equiv(local_left_box_base) |
| 126 |
@d local_right_box==equiv(local_right_box_base) |
| 127 |
@d box(#)==equiv(box_base+#) |
| 128 |
@z |
| 129 |
%------------------------- |
| 130 |
@x [17] m.236 l.4954 |
| 131 |
@d int_pars=55 {total number of integer parameters} |
| 132 |
@y |
| 133 |
@d local_inter_line_penalty_code=55 {local \.{\\interlinepenalty}} |
| 134 |
@d local_broken_penalty_code=56 {local \.{\\brokenpenalty}} |
| 135 |
@d no_local_whatsits_code=57 {counts local whatsits} |
| 136 |
@d int_pars=58 {total number of integer parameters} |
| 137 |
@z |
| 138 |
%------------------------- |
| 139 |
@x [17] m.236 l.5011 |
| 140 |
@d new_line_char==int_par(new_line_char_code) |
| 141 |
@y |
| 142 |
@d new_line_char==int_par(new_line_char_code) |
| 143 |
@d local_inter_line_penalty==int_par(local_inter_line_penalty_code) |
| 144 |
@d local_broken_penalty==int_par(local_broken_penalty_code) |
| 145 |
@d no_local_whatsits==int_par(no_local_whatsits_code) |
| 146 |
@z |
| 147 |
%------------------------- |
| 148 |
@x [19] m.269 l.5860 |
| 149 |
@d max_group_code=16 |
| 150 |
@y |
| 151 |
@d local_box_group=17 {code for `\.{\\localleftbox...\\localrightbox}'} |
| 152 |
@d max_group_code=17 |
| 153 |
@z |
| 154 |
%------------------------- |
| 155 |
@x [38] m.814 l.15994 |
| 156 |
@!just_box:pointer; {the |hlist_node| for the last line of the new paragraph} |
| 157 |
@y |
| 158 |
@!just_box:pointer; {the |hlist_node| for the last line of the new paragraph} |
| 159 |
@!internal_pen_inter:integer; {running \.{\\localinterlinepenalty}} |
| 160 |
@!internal_pen_broken:integer; {running \.{\\localbrokenpenalty}} |
| 161 |
@!internal_left_box:pointer; {running \.{\\localleftbox}} |
| 162 |
@!internal_left_box_width:integer; {running \.{\\localleftbox} width} |
| 163 |
@!init_internal_left_box:pointer; {running \.{\\localleftbox}} |
| 164 |
@!init_internal_left_box_width:integer; {running \.{\\localleftbox} width} |
| 165 |
@!internal_right_box:pointer; {running \.{\\localrightbox}} |
| 166 |
@!internal_right_box_width:integer; {running \.{\\localrightbox} width} |
| 167 |
@!temp_no_whatsits:integer; {used when closing group} |
| 168 |
|
| 169 |
@ @<Set init...@>= |
| 170 |
temp_no_whatsits:=0; |
| 171 |
@z |
| 172 |
%------------------------- |
| 173 |
@x [38] m.821 l.16110 |
| 174 |
@ The passive node for a given breakpoint contains only four fields: |
| 175 |
|
| 176 |
\yskip\hang|link| points to the passive node created just before this one, |
| 177 |
if any, otherwise it is |null|. |
| 178 |
|
| 179 |
\yskip\hang|cur_break| points to the position of this breakpoint in the |
| 180 |
horizontal list for the paragraph being broken. |
| 181 |
|
| 182 |
\yskip\hang|prev_break| points to the passive node that should precede this |
| 183 |
one in an optimal path to this breakpoint. |
| 184 |
|
| 185 |
\yskip\hang|serial| is equal to |n| if this passive node is the |n|th |
| 186 |
one created during the current pass. (This field is used only when |
| 187 |
printing out detailed statistics about the line-breaking calculations.) |
| 188 |
|
| 189 |
\yskip\noindent |
| 190 |
There is a global variable called |passive| that points to the most |
| 191 |
recently created passive node. Another global variable, |printed_node|, |
| 192 |
is used to help print out the paragraph when detailed information about |
| 193 |
the line-breaking computation is being displayed. |
| 194 |
|
| 195 |
@d passive_node_size=2 {number of words in passive nodes} |
| 196 |
@d cur_break==rlink {in passive node, points to position of this breakpoint} |
| 197 |
@d prev_break==llink {points to passive node that should precede this one} |
| 198 |
@d serial==info {serial number for symbolic identification} |
| 199 |
@y |
| 200 |
@ The passive node for a given breakpoint contains EIGHT fields: |
| 201 |
|
| 202 |
\yskip\hang|link| points to the passive node created just before this one, |
| 203 |
if any, otherwise it is |null|. |
| 204 |
|
| 205 |
\yskip\hang|cur_break| points to the position of this breakpoint in the |
| 206 |
horizontal list for the paragraph being broken. |
| 207 |
|
| 208 |
\yskip\hang|prev_break| points to the passive node that should precede this |
| 209 |
one in an optimal path to this breakpoint. |
| 210 |
|
| 211 |
\yskip\hang|serial| is equal to |n| if this passive node is the |n|th |
| 212 |
one created during the current pass. (This field is used only when |
| 213 |
printing out detailed statistics about the line-breaking calculations.) |
| 214 |
|
| 215 |
\yskip\hang|passive_pen_inter| holds the current \.{\\localinterlinepenalty} |
| 216 |
|
| 217 |
\yskip\hang|passive_pen_broken| holds the current \.{\\localbrokenpenalty} |
| 218 |
|
| 219 |
\yskip\noindent |
| 220 |
There is a global variable called |passive| that points to the most |
| 221 |
recently created passive node. Another global variable, |printed_node|, |
| 222 |
is used to help print out the paragraph when detailed information about |
| 223 |
the line-breaking computation is being displayed. |
| 224 |
|
| 225 |
@d passive_node_size=10 {number of words in passive nodes} |
| 226 |
@d cur_break==rlink {in passive node, points to position of this breakpoint} |
| 227 |
@d prev_break==llink {points to passive node that should precede this one} |
| 228 |
@d serial==info {serial number for symbolic identification} |
| 229 |
@d passive_pen_inter(#)==mem[#+2].int |
| 230 |
@d passive_pen_broken(#)==mem[#+3].int |
| 231 |
@d passive_left_box(#)==mem[#+4].int |
| 232 |
@d passive_left_box_width(#)==mem[#+5].int |
| 233 |
@d passive_last_left_box(#)==mem[#+6].int |
| 234 |
@d passive_last_left_box_width(#)==mem[#+7].int |
| 235 |
@d passive_right_box(#)==mem[#+8].int |
| 236 |
@d passive_right_box_width(#)==mem[#+9].int |
| 237 |
@z |
| 238 |
%------------------------- |
| 239 |
@x [38] m.835 l.16407 |
| 240 |
@<If a line number class...@>= |
| 241 |
begin l:=line_number(r); |
| 242 |
if l>old_l then |
| 243 |
begin {now we are no longer in the inner loop} |
| 244 |
@y |
| 245 |
@<If a line number class...@>= |
| 246 |
begin l:=line_number(r); |
| 247 |
if l>old_l then |
| 248 |
begin {now we are no longer in the inner loop} |
| 249 |
@z |
| 250 |
%------------------------- |
| 251 |
@x [38] m.844 l.16595 |
| 252 |
@<Insert a new active node from |best_place[fit_class]| to |cur_p|@>= |
| 253 |
begin q:=get_node(passive_node_size); |
| 254 |
link(q):=passive; passive:=q; cur_break(q):=cur_p; |
| 255 |
@!stat incr(pass_number); serial(q):=pass_number;@+tats@;@/ |
| 256 |
prev_break(q):=best_place[fit_class];@/ |
| 257 |
@y |
| 258 |
@<Insert a new active node from |best_place[fit_class]| to |cur_p|@>= |
| 259 |
begin q:=get_node(passive_node_size); |
| 260 |
link(q):=passive; passive:=q; cur_break(q):=cur_p; |
| 261 |
@!stat incr(pass_number); serial(q):=pass_number;@+tats@;@/ |
| 262 |
prev_break(q):=best_place[fit_class];@/ |
| 263 |
{Here we keep track of the subparagraph penalties in the break nodes} |
| 264 |
passive_pen_inter(q):=internal_pen_inter; |
| 265 |
passive_pen_broken(q):=internal_pen_broken; |
| 266 |
passive_last_left_box(q):=internal_left_box; |
| 267 |
passive_last_left_box_width(q):=internal_left_box_width; |
| 268 |
if prev_break(q)<>null then begin |
| 269 |
passive_left_box(q):=passive_last_left_box(prev_break(q)); |
| 270 |
passive_left_box_width(q):=passive_last_left_box_width(prev_break(q)); |
| 271 |
end |
| 272 |
else begin |
| 273 |
passive_left_box(q):=init_internal_left_box; |
| 274 |
passive_left_box_width(q):=init_internal_left_box_width; |
| 275 |
end; |
| 276 |
passive_right_box(q):=internal_right_box; |
| 277 |
passive_right_box_width(q):=internal_right_box_width; |
| 278 |
@z |
| 279 |
%------------------------- |
| 280 |
@x [38] m.851 l.16706 |
| 281 |
@<Consider the demerits for a line from |r| to |cur_p|...@>= |
| 282 |
begin artificial_demerits:=false;@/ |
| 283 |
@^inner loop@> |
| 284 |
shortfall:=line_width-cur_active_width[1]; {we're this much too short} |
| 285 |
@y |
| 286 |
@<Consider the demerits for a line from |r| to |cur_p|...@>= |
| 287 |
begin artificial_demerits:=false;@/ |
| 288 |
@^inner loop@> |
| 289 |
shortfall:=line_width-cur_active_width[1]; {we're this much too short} |
| 290 |
if break_node(r)=null then |
| 291 |
shortfall:=shortfall-init_internal_left_box_width |
| 292 |
else shortfall:=shortfall-passive_last_left_box_width(break_node(r)); |
| 293 |
shortfall:=shortfall-internal_right_box_width; |
| 294 |
@z |
| 295 |
%------------------------- |
| 296 |
@x [39] m.863 l.16932 |
| 297 |
loop@+ begin if threshold>inf_bad then threshold:=inf_bad; |
| 298 |
if second_pass then @<Initialize for hyphenating a paragraph@>; |
| 299 |
@<Create an active breakpoint representing the beginning of the paragraph@>; |
| 300 |
cur_p:=link(temp_head); auto_breaking:=true;@/ |
| 301 |
prev_p:=cur_p; {glue at beginning is not a legal breakpoint} |
| 302 |
@y |
| 303 |
loop@+ begin if threshold>inf_bad then threshold:=inf_bad; |
| 304 |
if second_pass then @<Initialize for hyphenating a paragraph@>; |
| 305 |
@<Create an active breakpoint representing the beginning of the paragraph@>; |
| 306 |
cur_p:=link(temp_head); auto_breaking:=true;@/ |
| 307 |
prev_p:=cur_p; {glue at beginning is not a legal breakpoint} |
| 308 |
@<LOCAL: Initialize with first |local_paragraph| node@>; |
| 309 |
@z |
| 310 |
%------------------------- |
| 311 |
@x [39] m.877 l.17206 |
| 312 |
procedure post_line_break(@!final_widow_penalty:integer); |
| 313 |
label done,done1; |
| 314 |
@y |
| 315 |
procedure post_line_break(@!final_widow_penalty:integer); |
| 316 |
label done,done1; |
| 317 |
@z |
| 318 |
%------------------------- |
| 319 |
@x [39] m.879 l.17257 |
| 320 |
if non_discardable(q) then goto done1; |
| 321 |
if type(q)=kern_node then if subtype(q)<>explicit then goto done1; |
| 322 |
@y |
| 323 |
if @<LOCAL: local paragraph node@> then begin end |
| 324 |
else begin |
| 325 |
if non_discardable(q) then goto done1; |
| 326 |
if type(q)=kern_node then if subtype(q)<>explicit then goto done1; |
| 327 |
end; |
| 328 |
@z |
| 329 |
%------------------------- |
| 330 |
@x [39] m.881 l.17289 |
| 331 |
q:=cur_break(cur_p); disc_break:=false; post_disc_break:=false; |
| 332 |
if q<>null then {|q| cannot be a |char_node|} |
| 333 |
if type(q)=glue_node then |
| 334 |
begin delete_glue_ref(glue_ptr(q)); |
| 335 |
glue_ptr(q):=right_skip; |
| 336 |
subtype(q):=right_skip_code+1; add_glue_ref(right_skip); |
| 337 |
goto done; |
| 338 |
end |
| 339 |
else begin if type(q)=disc_node then |
| 340 |
@<Change discretionary to compulsory and set |
| 341 |
|disc_break:=true|@> |
| 342 |
else if (type(q)=math_node)or(type(q)=kern_node) then width(q):=0; |
| 343 |
end |
| 344 |
else begin q:=temp_head; |
| 345 |
while link(q)<>null do q:=link(q); |
| 346 |
end; |
| 347 |
@<Put the \(r)\.{\\rightskip} glue after node |q|@>; |
| 348 |
@y |
| 349 |
q:=cur_break(cur_p); disc_break:=false; post_disc_break:=false; |
| 350 |
if q<>null then {|q| cannot be a |char_node|} |
| 351 |
if type(q)=glue_node then begin |
| 352 |
if passive_right_box(cur_p)<>null then begin |
| 353 |
r:=temp_head; |
| 354 |
while link(r)<>q do r:=link(r); |
| 355 |
s:=copy_node_list(passive_right_box(cur_p)); |
| 356 |
link(r):=s; |
| 357 |
link(s):=q; |
| 358 |
end; |
| 359 |
delete_glue_ref(glue_ptr(q)); |
| 360 |
glue_ptr(q):=right_skip; |
| 361 |
subtype(q):=right_skip_code+1; add_glue_ref(right_skip); |
| 362 |
goto done; |
| 363 |
end |
| 364 |
else begin if type(q)=disc_node then |
| 365 |
@<Change discretionary to compulsory and set |
| 366 |
|disc_break:=true|@> |
| 367 |
else if (type(q)=math_node)or(type(q)=kern_node) then width(q):=0; |
| 368 |
end |
| 369 |
else begin q:=temp_head; |
| 370 |
while link(q)<>null do q:=link(q); |
| 371 |
end; |
| 372 |
if passive_right_box(cur_p)<>null then begin |
| 373 |
r:=copy_node_list(passive_right_box(cur_p)); |
| 374 |
link(r):=link(q); |
| 375 |
link(q):=r; |
| 376 |
q:=r; |
| 377 |
end; |
| 378 |
@<Put the \(r)\.{\\rightskip} glue after node |q|@>; |
| 379 |
@z |
| 380 |
%------------------------- |
| 381 |
@x [39] m.887 l.17352 |
| 382 |
@<Put the \(l)\.{\\leftskip} glue at the left...@>= |
| 383 |
r:=link(q); link(q):=null; q:=link(temp_head); link(temp_head):=r; |
| 384 |
if left_skip<>zero_glue then |
| 385 |
begin r:=new_param_glue(left_skip_code); |
| 386 |
link(r):=q; q:=r; |
| 387 |
end |
| 388 |
@y |
| 389 |
@<Put the \(l)\.{\\leftskip} glue at the left...@>= |
| 390 |
r:=link(q); link(q):=null; q:=link(temp_head); link(temp_head):=r; |
| 391 |
if passive_left_box(cur_p)<>null then begin |
| 392 |
r:=copy_node_list(passive_left_box(cur_p)); |
| 393 |
s:=link(q); |
| 394 |
link(r):=q; |
| 395 |
q:=r; |
| 396 |
if (cur_line=prev_graf+1) and (s<>null) then |
| 397 |
if type(s)=hlist_node then |
| 398 |
if list_ptr(s)=null then begin |
| 399 |
q:=link(q); |
| 400 |
link(r):=link(s); |
| 401 |
link(s):=r; |
| 402 |
end; |
| 403 |
end; |
| 404 |
if left_skip<>zero_glue then |
| 405 |
begin r:=new_param_glue(left_skip_code); |
| 406 |
link(r):=q; q:=r; |
| 407 |
end |
| 408 |
@z |
| 409 |
%------------------------- |
| 410 |
@x [39] m.890 l.17391 |
| 411 |
@<Append a penalty node, if a nonzero penalty is appropriate@>= |
| 412 |
if cur_line+1<>best_line then |
| 413 |
begin pen:=inter_line_penalty; |
| 414 |
if cur_line=prev_graf+1 then pen:=pen+club_penalty; |
| 415 |
if cur_line+2=best_line then pen:=pen+final_widow_penalty; |
| 416 |
if disc_break then pen:=pen+broken_penalty; |
| 417 |
@y |
| 418 |
@<Append a penalty node, if a nonzero penalty is appropriate@>= |
| 419 |
if cur_line+1<>best_line then begin |
| 420 |
if passive_pen_inter(cur_p)<>0 then |
| 421 |
pen:=passive_pen_inter(cur_p) |
| 422 |
else pen:=inter_line_penalty; |
| 423 |
if cur_line=prev_graf+1 then pen:=pen+club_penalty; |
| 424 |
if cur_line+2=best_line then pen:=pen+final_widow_penalty; |
| 425 |
if disc_break then |
| 426 |
if passive_pen_broken(cur_p)<>0 then |
| 427 |
pen:=pen+passive_pen_broken(cur_p) |
| 428 |
else pen:=pen+broken_penalty; |
| 429 |
@z |
| 430 |
%------------------------- |
| 431 |
@x [47] m.1063 l.20580 |
| 432 |
non_math(left_brace): new_save_level(simple_group); |
| 433 |
any_mode(begin_group): new_save_level(semi_simple_group); |
| 434 |
any_mode(end_group): if cur_group=semi_simple_group then unsave |
| 435 |
else off_save; |
| 436 |
@y |
| 437 |
non_math(left_brace): begin |
| 438 |
new_save_level(simple_group); |
| 439 |
eq_word_define(int_base+no_local_whatsits_code,0); |
| 440 |
end; |
| 441 |
any_mode(begin_group): begin |
| 442 |
new_save_level(semi_simple_group); |
| 443 |
eq_word_define(int_base+no_local_whatsits_code,0); |
| 444 |
end; |
| 445 |
any_mode(end_group): |
| 446 |
if cur_group=semi_simple_group then begin |
| 447 |
temp_no_whatsits:=no_local_whatsits; |
| 448 |
unsave; |
| 449 |
if temp_no_whatsits<>0 then |
| 450 |
if abs(mode)=hmode then @<LOCAL: Add local paragraph node@>; |
| 451 |
end |
| 452 |
else off_save; |
| 453 |
@z |
| 454 |
%------------------------- |
| 455 |
@x [47] m.1068 l.20653 |
| 456 |
procedure handle_right_brace; |
| 457 |
var p,@!q:pointer; {for short-term use} |
| 458 |
@!d:scaled; {holds |split_max_depth| in |insert_group|} |
| 459 |
@!f:integer; {holds |floating_penalty| in |insert_group|} |
| 460 |
begin case cur_group of |
| 461 |
simple_group: unsave; |
| 462 |
@y |
| 463 |
procedure handle_right_brace; |
| 464 |
var p,@!q:pointer; {for short-term use} |
| 465 |
@!d:scaled; {holds |split_max_depth| in |insert_group|} |
| 466 |
@!f:integer; {holds |floating_penalty| in |insert_group|} |
| 467 |
begin case cur_group of |
| 468 |
simple_group: begin |
| 469 |
temp_no_whatsits:=no_local_whatsits; |
| 470 |
unsave; |
| 471 |
if temp_no_whatsits<>0 then |
| 472 |
if abs(mode)=hmode then @<LOCAL: Add local paragraph node@>; |
| 473 |
end; |
| 474 |
@z |
| 475 |
%------------------------- |
| 476 |
@x [47] m.1091 l.21055 |
| 477 |
push_nest; mode:=hmode; space_factor:=1000; set_cur_lang; clang:=cur_lang; |
| 478 |
prev_graf:=(norm_min(left_hyphen_min)*@'100+norm_min(right_hyphen_min)) |
| 479 |
*@'200000+cur_lang; |
| 480 |
if indented then |
| 481 |
begin tail:=new_null_box; link(head):=tail; width(tail):=par_indent;@+ |
| 482 |
end; |
| 483 |
@y |
| 484 |
push_nest; mode:=hmode; space_factor:=1000; set_cur_lang; clang:=cur_lang; |
| 485 |
prev_graf:=(norm_min(left_hyphen_min)*@'100+norm_min(right_hyphen_min)) |
| 486 |
*@'200000+cur_lang; |
| 487 |
@<LOCAL: Add local paragraph node@>; |
| 488 |
if indented then begin |
| 489 |
tail:=new_null_box; link(link(head)):=tail; width(tail):=par_indent;@+ |
| 490 |
end; |
| 491 |
@z |
| 492 |
%------------------------- |
| 493 |
@x [47] m.1096 l.21116 |
| 494 |
procedure end_graf; |
| 495 |
begin if mode=hmode then |
| 496 |
begin if head=tail then pop_nest {null paragraphs are ignored} |
| 497 |
@y |
| 498 |
procedure end_graf; |
| 499 |
begin if mode=hmode then |
| 500 |
begin if (head=tail) or (link(head)=tail) then pop_nest |
| 501 |
{null paragraphs are ignored, all contain a |local_paragraph| node} |
| 502 |
@z |
| 503 |
%------------------------- |
| 504 |
@x [47] m.1114 l.21322 |
| 505 |
primitive("-",discretionary,1); |
| 506 |
@!@:Single-character primitives -}{\quad\.{\\-}@> |
| 507 |
primitive("discretionary",discretionary,0); |
| 508 |
@!@:discretionary_}{\.{\\discretionary} primitive@> |
| 509 |
|
| 510 |
@ @<Cases of |print_cmd_chr|...@>= |
| 511 |
discretionary: if chr_code=1 then |
| 512 |
print_esc("-")@+else print_esc("discretionary"); |
| 513 |
|
| 514 |
@ @<Cases of |main_control| that build...@>= |
| 515 |
hmode+discretionary,mmode+discretionary: append_discretionary; |
| 516 |
@y |
| 517 |
primitive("-",discretionary,1); |
| 518 |
@!@:Single-character primitives -}{\quad\.{\\-}@> |
| 519 |
primitive("discretionary",discretionary,0); |
| 520 |
@!@:discretionary_}{\.{\\discretionary} primitive@> |
| 521 |
primitive("localleftbox",assign_local_box,0); |
| 522 |
@!@:assign_local_box}{\.{\\localleftbox} primitive@> |
| 523 |
primitive("localrightbox",assign_local_box,1); |
| 524 |
@!@:assign_local_box}{\.{\\localrightbox} primitive@> |
| 525 |
|
| 526 |
@ @<Cases of |print_cmd_chr|...@>= |
| 527 |
discretionary: if chr_code=1 then |
| 528 |
print_esc("-")@+else print_esc("discretionary"); |
| 529 |
assign_local_box: if chr_code=0 then print_esc("localleftbox") |
| 530 |
else print_esc("localrightbox"); |
| 531 |
|
| 532 |
@ @<Cases of |main_control| that build...@>= |
| 533 |
hmode+discretionary,mmode+discretionary: append_discretionary; |
| 534 |
any_mode(assign_local_box): append_local_box(cur_chr); |
| 535 |
@z |
| 536 |
%------------------------- |
| 537 |
@x [47] m.1117 l.21338 |
| 538 |
procedure append_discretionary; |
| 539 |
@y |
| 540 |
procedure append_local_box(kind:integer); |
| 541 |
begin |
| 542 |
incr(save_ptr); saved(-1):=kind; new_save_level(local_box_group); |
| 543 |
scan_left_brace; push_nest; mode:=-hmode; space_factor:=1000; |
| 544 |
end; |
| 545 |
|
| 546 |
procedure append_discretionary; |
| 547 |
@z |
| 548 |
%------------------------- |
| 549 |
@x [47] m.1118 l.21355 |
| 550 |
disc_group: build_discretionary; |
| 551 |
@y |
| 552 |
disc_group: build_discretionary; |
| 553 |
local_box_group: build_local_box; |
| 554 |
@z |
| 555 |
%------------------------- |
| 556 |
@x [47] m.1119 l.21358 |
| 557 |
procedure build_discretionary; |
| 558 |
@y |
| 559 |
procedure build_local_box; |
| 560 |
var p:pointer; |
| 561 |
kind:integer; |
| 562 |
begin |
| 563 |
unsave; |
| 564 |
kind:=saved(-1); |
| 565 |
decr(save_ptr); |
| 566 |
p:=link(head); pop_nest; |
| 567 |
p:=hpack(p,natural); |
| 568 |
if kind=0 then |
| 569 |
eq_define(local_left_box_base,box_ref,p) |
| 570 |
else |
| 571 |
eq_define(local_right_box_base,box_ref,p); |
| 572 |
if abs(mode)=hmode then |
| 573 |
@<LOCAL: Add local paragraph node@>; |
| 574 |
eq_word_define(int_base+no_local_whatsits_code,no_local_whatsits+1); |
| 575 |
end; |
| 576 |
|
| 577 |
procedure build_discretionary; |
| 578 |
@z |
| 579 |
%------------------------- |
| 580 |
@x [47] m.1200 l.22453 |
| 581 |
procedure resume_after_display; |
| 582 |
begin if cur_group<>math_shift_group then confusion("display"); |
| 583 |
@:this can't happen display}{\quad display@> |
| 584 |
unsave; prev_graf:=prev_graf+3; |
| 585 |
push_nest; mode:=hmode; space_factor:=1000; set_cur_lang; clang:=cur_lang; |
| 586 |
prev_graf:=(norm_min(left_hyphen_min)*@'100+norm_min(right_hyphen_min)) |
| 587 |
*@'200000+cur_lang; |
| 588 |
@y |
| 589 |
procedure resume_after_display; |
| 590 |
begin if cur_group<>math_shift_group then confusion("display"); |
| 591 |
@:this can't happen display}{\quad display@> |
| 592 |
unsave; prev_graf:=prev_graf+3; |
| 593 |
push_nest; mode:=hmode; space_factor:=1000; set_cur_lang; clang:=cur_lang; |
| 594 |
prev_graf:=(norm_min(left_hyphen_min)*@'100+norm_min(right_hyphen_min)) |
| 595 |
*@'200000+cur_lang; |
| 596 |
@<LOCAL: Add local paragraph node@>; |
| 597 |
@z |
| 598 |
%------------------------- |
| 599 |
@x [49] m.1228 l.22908 |
| 600 |
assign_int: begin p:=cur_chr; scan_optional_equals; scan_int; |
| 601 |
word_define(p,cur_val); |
| 602 |
@y |
| 603 |
assign_int: begin p:=cur_chr; scan_optional_equals; scan_int; |
| 604 |
word_define(p,cur_val); |
| 605 |
{If we are defining subparagraph penalty levels while we are |
| 606 |
in hmode, then we put out a whatsit immediately, otherwise |
| 607 |
we leave it alone. This mechanism might not be sufficiently |
| 608 |
powerful, and some other algorithm, searching down the stack, |
| 609 |
might be necessary. Good first step.} |
| 610 |
if (abs(mode)=hmode) and |
| 611 |
((p=(int_base+local_inter_line_penalty_code)) or |
| 612 |
(p=(int_base+local_broken_penalty_code))) then begin |
| 613 |
@<LOCAL: Add local paragraph node@>; |
| 614 |
eq_word_define(int_base+no_local_whatsits_code,no_local_whatsits+1); |
| 615 |
local_par_bool:=true; |
| 616 |
end; |
| 617 |
@z |
| 618 |
%------------------------- |
| 619 |
@x [53] m.1344 l.24533 |
| 620 |
@d set_language_code=5 {command modifier for \.{\\setlanguage}} |
| 621 |
@y |
| 622 |
@d set_language_code=5 {command modifier for \.{\\setlanguage}} |
| 623 |
@d local_par_node=6 {|subtype| in whatsits for local paragraph node} |
| 624 |
@z |
| 625 |
%------------------------- |
| 626 |
@x [53] m.1344 l.24546 |
| 627 |
primitive("setlanguage",extension,set_language_code);@/ |
| 628 |
@!@:set_language_}{\.{\\setlanguage} primitive@> |
| 629 |
@y |
| 630 |
primitive("setlanguage",extension,set_language_code);@/ |
| 631 |
@!@:set_language_}{\.{\\setlanguage} primitive@> |
| 632 |
primitive("localinterlinepenalty",assign_int,local_inter_line_penalty_code);@/ |
| 633 |
primitive("localbrokenpenalty",assign_int,local_broken_penalty_code);@/ |
| 634 |
@z |
| 635 |
%------------------------- |
| 636 |
@x [53] m.1356 l.24660 |
| 637 |
language_node:begin print_esc("setlanguage"); |
| 638 |
print_int(what_lang(p)); print(" (hyphenmin "); |
| 639 |
print_int(what_lhm(p)); print_char(","); |
| 640 |
print_int(what_rhm(p)); print_char(")"); |
| 641 |
end; |
| 642 |
@y4 |
| 643 |
language_node:begin print_esc("setlanguage"); |
| 644 |
print_int(what_lang(p)); print(" (hyphenmin "); |
| 645 |
print_int(what_lhm(p)); print_char(","); |
| 646 |
print_int(what_rhm(p)); print_char(")"); |
| 647 |
end; |
| 648 |
@<LOCAL: print out |local_paragraph| node@>; |
| 649 |
@z |
| 650 |
%------------------------- |
| 651 |
@x [53] m.1357 l.24685 |
| 652 |
othercases confusion("ext2") |
| 653 |
@y |
| 654 |
local_par_node: begin r:=get_node(local_par_size); |
| 655 |
words:=local_par_size; |
| 656 |
end; |
| 657 |
othercases confusion("ext2") |
| 658 |
@z |
| 659 |
%------------------------- |
| 660 |
@x [53] m.1358 l.24696 |
| 661 |
othercases confusion("ext3") |
| 662 |
@y |
| 663 |
local_par_node: free_node(p,local_par_size); |
| 664 |
othercases confusion("ext3") |
| 665 |
@z |
| 666 |
%------------------------- |
| 667 |
@x [53] m.1362 l.24711 |
| 668 |
@<Advance \(p)past a whatsit node in the \(l)|line_break| loop@>=@+ |
| 669 |
adv_past(cur_p) |
| 670 |
@y |
| 671 |
@<Advance \(p)past a whatsit node in the \(l)|line_break| loop@>=@+ |
| 672 |
adv_past(cur_p) else @<LOCAL: Advance past a |local_paragraph| node@> |
| 673 |
@z |
| 674 |
%------------------------- |
| 675 |
@x [53] m.1373 l.24820 |
| 676 |
procedure out_what(@!p:pointer); |
| 677 |
var j:small_number; {write stream number} |
| 678 |
begin case subtype(p) of |
| 679 |
open_node,write_node,close_node:@<Do some work that has been queued up |
| 680 |
for \.{\\write}@>; |
| 681 |
special_node:special_out(p); |
| 682 |
language_node:do_nothing; |
| 683 |
othercases confusion("ext4") |
| 684 |
@y |
| 685 |
procedure out_what(@!p:pointer); |
| 686 |
var j:small_number; {write stream number} |
| 687 |
begin case subtype(p) of |
| 688 |
open_node,write_node,close_node:@<Do some work that has been queued up |
| 689 |
for \.{\\write}@>; |
| 690 |
special_node:special_out(p); |
| 691 |
language_node:do_nothing; |
| 692 |
local_par_node:do_nothing; |
| 693 |
othercases confusion("ext4") |
| 694 |
@z |
| 695 |
%------------------------- |
| 696 |
@x [53] m.1378 l.24900 |
| 697 |
@ @<Finish the extensions@>= |
| 698 |
for k:=0 to 15 do if write_open[k] then a_close(write_file[k]) |
| 699 |
@y |
| 700 |
@ @<Finish the extensions@>= |
| 701 |
for k:=0 to 15 do if write_open[k] then a_close(write_file[k]) |
| 702 |
|
| 703 |
@ |
| 704 |
@d local_pen_inter(#)==mem[#+1].int {\.{\\localinterlinepenalty}} |
| 705 |
@d local_pen_broken(#)==mem[#+2].int {\.{\\localbrokenpenalty}} |
| 706 |
@d local_box_left(#)==mem[#+3].int {\.{\\localleftbox}} |
| 707 |
@d local_box_left_width(#)==mem[#+4].int |
| 708 |
@d local_box_right(#)==mem[#+5].int {\.{\\localleftbox}} |
| 709 |
@d local_box_right_width(#)==mem[#+6].int |
| 710 |
@d local_par_size==7 |
| 711 |
|
| 712 |
@<LOCAL: Declare |make_local_par_node|@>= |
| 713 |
function make_local_par_node:pointer; |
| 714 |
{This function creates a |local_paragraph| node} |
| 715 |
var p:pointer; |
| 716 |
begin |
| 717 |
p:=get_node(local_par_size); type(p):=whatsit_node; |
| 718 |
subtype(p):=local_par_node; link(p):=null; |
| 719 |
local_pen_inter(p):=local_inter_line_penalty; |
| 720 |
local_pen_broken(p):=local_broken_penalty; |
| 721 |
if local_left_box=null then begin |
| 722 |
local_box_left(p):=null; |
| 723 |
local_box_left_width(p):=0; |
| 724 |
end |
| 725 |
else begin |
| 726 |
local_box_left(p):=copy_node_list(local_left_box); |
| 727 |
local_box_left_width(p):=width(local_left_box); |
| 728 |
end; |
| 729 |
if local_right_box=null then begin |
| 730 |
local_box_right(p):=null; |
| 731 |
local_box_right_width(p):=0; |
| 732 |
end |
| 733 |
else begin |
| 734 |
local_box_right(p):=copy_node_list(local_right_box); |
| 735 |
local_box_right_width(p):=width(local_right_box); |
| 736 |
end; |
| 737 |
make_local_par_node:=p; |
| 738 |
end |
| 739 |
|
| 740 |
@ @<LOCAL: Initialize with first |local_paragraph| node@>= |
| 741 |
if subtype(cur_p)=local_par_node then begin |
| 742 |
internal_pen_inter:=local_pen_inter(cur_p); |
| 743 |
internal_pen_broken:=local_pen_broken(cur_p); |
| 744 |
init_internal_left_box:=local_box_left(cur_p); |
| 745 |
init_internal_left_box_width:=local_box_left_width(cur_p); |
| 746 |
internal_left_box:=init_internal_left_box; |
| 747 |
internal_left_box_width:=init_internal_left_box_width; |
| 748 |
internal_right_box:=local_box_right(cur_p); |
| 749 |
internal_right_box_width:=local_box_right_width(cur_p); |
| 750 |
end |
| 751 |
|
| 752 |
@ @<LOCAL: Advance past a |local_paragraph| node@>= |
| 753 |
if subtype(cur_p)=local_par_node then begin |
| 754 |
internal_pen_inter:=local_pen_inter(cur_p); |
| 755 |
internal_pen_broken:=local_pen_broken(cur_p); |
| 756 |
internal_left_box:=local_box_left(cur_p); |
| 757 |
internal_left_box_width:=local_box_left_width(cur_p); |
| 758 |
internal_right_box:=local_box_right(cur_p); |
| 759 |
internal_right_box_width:=local_box_right_width(cur_p); |
| 760 |
end |
| 761 |
|
| 762 |
@ @<LOCAL: print out |local_paragraph| node@>= |
| 763 |
local_par_node: begin |
| 764 |
print_esc("whatsit"); |
| 765 |
append_char("."); |
| 766 |
print_ln; print_current_string; |
| 767 |
print_esc("localinterlinepenalty"); print("="); |
| 768 |
print_int(local_pen_inter(p)); |
| 769 |
print_ln; print_current_string; |
| 770 |
print_esc("localbrokenpenalty"); print("="); |
| 771 |
print_int(local_pen_broken(p)); |
| 772 |
print_ln; print_current_string; |
| 773 |
print_esc("localleftbox"); |
| 774 |
if local_box_left(p)=null then print("=null") |
| 775 |
else begin |
| 776 |
append_char("."); |
| 777 |
show_node_list(local_box_left(p)); |
| 778 |
decr(pool_ptr); |
| 779 |
end; |
| 780 |
print_ln; print_current_string; |
| 781 |
print_esc("localrightbox"); |
| 782 |
if local_box_right(p)=null then print("=null") |
| 783 |
else begin |
| 784 |
append_char("."); |
| 785 |
show_node_list(local_box_right(p)); |
| 786 |
decr(pool_ptr); |
| 787 |
end; |
| 788 |
decr(pool_ptr); |
| 789 |
end |
| 790 |
|
| 791 |
@ @<LOCAL: Add local paragraph node@>= |
| 792 |
begin tail_append(make_local_par_node) end |
| 793 |
|
| 794 |
@ @<LOCAL: local paragraph node@>= |
| 795 |
((type(q)=whatsit_node) and (subtype(q)=local_par_node)) |
| 796 |
|
| 797 |
@z |
| 798 |
%------------------------- |