Debian Codegraph @

texk/web2c/enctexdir/enctex2.ch

raw
1 % $Id: enctex2.ch 65809 2023-02-12 23:58:22Z karl $
2 % enctex2.ch: bulk of the encTeX implementation, common to all engines
3 % supporting encTeX.
4
5 % encTeX: \mubytein \mubyteout \mubytelog and \specialout
6 @x [17.236] l.5016
7 @d tracing_char_sub_def==int_par(tracing_char_sub_def_code)
8 @y
9 @d tracing_char_sub_def==int_par(tracing_char_sub_def_code)
10 @d mubyte_in==int_par(mubyte_in_code)
11 @d mubyte_out==int_par(mubyte_out_code)
12 @d mubyte_log==int_par(mubyte_log_code)
13 @d spec_out==int_par(spec_out_code)
14 @z
15
16 % encTeX: \mubytein \mubyteout \mubytelog and \specialout
17 @x [17.237] l.5080
18 tracing_char_sub_def_code:print_esc("tracingcharsubdef");
19 @y
20 tracing_char_sub_def_code:print_esc("tracingcharsubdef");
21 mubyte_in_code:print_esc("mubytein");
22 mubyte_out_code:print_esc("mubyteout");
23 mubyte_log_code:print_esc("mubytelog");
24 spec_out_code:print_esc("specialout");
25 @z
26
27 % encTeX: \mubytein \mubyteout \mubytelog and \specialout
28 @x [17.238] l.5200
29 @!@:tracing_char_sub_def_}{\.{\\tracingcharsubdef} primitive@>
30 end;
31 @y
32 @!@:tracing_char_sub_def_}{\.{\\tracingcharsubdef} primitive@>
33 end;
34 if enctex_p then
35 begin enctex_enabled_p:=true;
36 primitive("mubytein",assign_int,int_base+mubyte_in_code);@/
37 @!@:mubyte_in_}{\.{\\mubytein} primitive@>
38 primitive("mubyteout",assign_int,int_base+mubyte_out_code);@/
39 @!@:mubyte_out_}{\.{\\mubyteout} primitive@>
40 primitive("mubytelog",assign_int,int_base+mubyte_log_code);@/
41 @!@:mubyte_log_}{\.{\\mubytelog} primitive@>
42 primitive("specialout",assign_int,int_base+spec_out_code);@/
43 @!@:spec_out_}{\.{\\specialout} primitive@>
44 end;
45 @z
46
47 @x [18.262] - encTeX: control sequence to byte sequence
48 they may be unprintable.
49
50 @<Basic printing...@>=
51 procedure print_cs(@!p:integer); {prints a purported control sequence}
52 begin if p<hash_base then {single character}
53 @y
54 they may be unprintable.
55
56 The conversion from control sequence to byte sequence for enc\TeX is
57 implemented here. Of course, the simplest way is to implement an array
58 of string pointers with |hash_size| length, but we assume that only a
59 few control sequences will need to be converted. So |mubyte_cswrite|,
60 an array with only 128 items, is used. The items point to the token
61 lists. First token includes a csname number and the second points the
62 string to be output. The third token includes the number of another
63 csname and fourth token its pointer to the string etc. We need to do
64 the sequential searching in one of the 128 token lists.
65
66 @<Basic printing...@>=
67 procedure print_cs(@!p:integer); {prints a purported control sequence}
68 var q: pointer;
69 s: str_number;
70 begin
71 if active_noconvert and (not no_convert) and
72 (eq_type(p) = let) and (equiv(p) = normal+11) then { noconvert }
73 begin
74 no_convert := true;
75 return;
76 end;
77 s := 0;
78 if cs_converting and (not no_convert) then
79 begin
80 q := mubyte_cswrite [p mod 128] ;
81 while q <> null do
82 if info (q) = p then
83 begin
84 s := info (link(q)); q := null;
85 end else q := link (link (q));
86 end;
87 no_convert := false;
88 if s > 0 then print (s)
89 else if p<hash_base then {single character}
90 @z
91
92 @x [18.262] - encTeX: exit label for print_cs
93 print_char(" ");
94 end;
95 end;
96 @y
97 print_char(" ");
98 end;
99 exit: end;
100 @z
101
102 @x [18.265] - encTeX: \endmubyte primitive
103 primitive("endcsname",end_cs_name,0);@/
104 @!@:end_cs_name_}{\.{\\endcsname} primitive@>
105 @y
106 primitive("endcsname",end_cs_name,0);@/
107 @!@:end_cs_name_}{\.{\\endcsname} primitive@>
108 if enctex_p then
109 begin
110 primitive("endmubyte",end_cs_name,10);@/
111 @!@:end_mubyte_}{\.{\\endmubyte} primitive@>
112 end;
113 @z
114
115 @x [18.266] - encTeX: \endmubyte primitive
116 end_cs_name: print_esc("endcsname");
117 @y
118 end_cs_name: if chr_code = 10 then print_esc("endmubyte")
119 else print_esc("endcsname");
120 @z
121
122 @x [22.318] encTeX - native buffer printing
123 if j>0 then for i:=start to j-1 do
124 begin if i=loc then set_trick_count;
125 print(buffer[i]);
126 end
127 @y
128 i := start; mubyte_skeep := mubyte_keep;
129 mubyte_sstart := mubyte_start; mubyte_start := false;
130 if j>0 then while i < j do
131 begin
132 if i=loc then set_trick_count;
133 print_buffer(i);
134 end;
135 mubyte_keep := mubyte_skeep; mubyte_start := mubyte_sstart
136 @z
137
138 @x [24.332] encTeX: insert the added functions
139 appear on that line. (There might not be any tokens at all, if the
140 |end_line_char| has |ignore| as its catcode.)
141 @y
142 appear on that line. (There might not be any tokens at all, if the
143 |end_line_char| has |ignore| as its catcode.)
144
145 Some additional routines used by the enc\TeX extension have to be
146 declared at this point.
147
148 @p @t\4@>@<Declare additional routines for enc\TeX@>@/
149 @z
150
151 @x [24.341] - encTeX: more declarations in expand processor
152 var k:0..buf_size; {an index into |buffer|}
153 @!t:halfword; {a token}
154 @y
155 var k:0..buf_size; {an index into |buffer|}
156 @!t:halfword; {a token}
157 @!i,@!j: 0..buf_size; {more indexes for encTeX}
158 @!mubyte_incs: boolean; {control sequence is converted by mubyte}
159 @!p:pointer; {for encTeX test if noexpanding}
160 @z
161
162 @x [24.343] - encTeX: access the buffer via read_buffer
163 begin cur_chr:=buffer[loc]; incr(loc);
164 @y
165 begin
166 { Use |k| instead of |loc| for type correctness. }
167 k := loc;
168 cur_chr := read_buffer (k);
169 loc := k; incr (loc);
170 if (mubyte_token > 0) then
171 begin
172 state := mid_line;
173 cur_cs := mubyte_token - cs_token_flag;
174 goto found;
175 end;
176 @z
177
178 @x [24.354] - encTeX: access the buffer via read_buffer
179 else begin start_cs: k:=loc; cur_chr:=buffer[k]; cat:=cat_code(cur_chr);
180 incr(k);
181 @y
182 else begin start_cs:
183 mubyte_incs := false; k := loc; mubyte_skeep := mubyte_keep;
184 cur_chr := read_buffer (k); cat := cat_code (cur_chr);
185 if (mubyte_in>0) and (not mubyte_incs) and
186 ((mubyte_skip>0) or (cur_chr<>buffer[k])) then mubyte_incs := true;
187 incr (k);
188 if mubyte_token > 0 then
189 begin
190 state := mid_line;
191 cur_cs := mubyte_token - cs_token_flag;
192 goto found;
193 end;
194 @z
195
196 @x [24.354] - encTeX: noexpanding the marked control sequence
197 cur_cs:=single_base+buffer[loc]; incr(loc);
198 end;
199 found: cur_cmd:=eq_type(cur_cs); cur_chr:=equiv(cur_cs);
200 if cur_cmd>=outer_call then check_outer_validity;
201 @y
202 mubyte_keep := mubyte_skeep;
203 cur_cs:=single_base + read_buffer(loc); incr(loc);
204 end;
205 found: cur_cmd:=eq_type(cur_cs); cur_chr:=equiv(cur_cs);
206 if cur_cmd>=outer_call then check_outer_validity;
207 if write_noexpanding then
208 begin
209 p := mubyte_cswrite [cur_cs mod 128];
210 while p <> null do
211 if info (p) = cur_cs then
212 begin
213 cur_cmd := relax; cur_chr := 256; p := null;
214 end else p := link (link (p));
215 end;
216 @z
217
218 @x [24.355] - encTeX: deactivated when reading such \^^ab control sequences
219 limit:=limit-d; first:=first-d;
220 @y
221 limit:=limit-d; first:=first-d;
222 if mubyte_in>0 then mubyte_keep := k-loc;
223 @z
224
225 @x [24.356] - encTeX: access the buffer via read_buffer
226 begin repeat cur_chr:=buffer[k]; cat:=cat_code(cur_chr); incr(k);
227 until (cat<>letter)or(k>limit);
228 @<If an expanded...@>;
229 if cat<>letter then decr(k);
230 {now |k| points to first nonletter}
231 if k>loc+1 then {multiletter control sequence has been scanned}
232 begin cur_cs:=id_lookup(loc,k-loc); loc:=k; goto found;
233 end;
234 end
235 @y
236 begin
237 repeat cur_chr := read_buffer (k); cat := cat_code (cur_chr);
238 if mubyte_token>0 then cat := escape;
239 if (mubyte_in>0) and (not mubyte_incs) and (cat=letter) and
240 ((mubyte_skip>0) or (cur_chr<>buffer[k])) then mubyte_incs := true;
241 incr (k);
242 until (cat <> letter) or (k > limit);
243 @<If an expanded...@>;
244 if cat <> letter then
245 begin
246 decr (k); k := k - mubyte_skip;
247 end;
248 if k > loc + 1 then { multiletter control sequence has been scanned }
249 begin
250 if mubyte_incs then { multibyte in csname occurrs }
251 begin
252 i := loc; j := first; mubyte_keep := mubyte_skeep;
253 if j - loc + k > max_buf_stack then
254 begin
255 max_buf_stack := j - loc + k;
256 if max_buf_stack >= buf_size then
257 begin
258 max_buf_stack := buf_size;
259 overflow ("buffer size", buf_size);
260 end;
261 end;
262 while i < k do
263 begin
264 buffer [j] := read_buffer (i);
265 incr (i); incr (j);
266 end;
267 if j = first+1 then
268 cur_cs := single_base + buffer [first]
269 else
270 cur_cs := id_lookup (first, j-first);
271 end else cur_cs := id_lookup (loc, k-loc) ;
272 loc := k;
273 goto found;
274 end;
275 end
276 @z
277
278 @x [24.357] - encTeX: noexpanding the marked control sequence
279 else check_outer_validity;
280 @y
281 else check_outer_validity;
282 if write_noexpanding then
283 begin
284 p := mubyte_cswrite [cur_cs mod 128];
285 while p <> null do
286 if info (p) = cur_cs then
287 begin
288 cur_cmd := relax; cur_chr := 256; p := null;
289 end else p := link (link (p));
290 end;
291 @z
292
293 @x [24.363] encTeX - native buffer printing
294 if start<limit then for k:=start to limit-1 do print(buffer[k]);
295 @y
296 k := start;
297 while k < limit do begin print_buffer(k) end;
298 @z
299
300 @x [25.372] - encTeX: we need to distinguish \endcsname and \endmubyte
301 if cur_cmd<>end_cs_name then @<Complain about missing \.{\\endcsname}@>;
302 @y
303 if (cur_cmd<>end_cs_name) or (cur_chr<>0) then @<Complain about missing \.{\\endcsname}@>;
304 @z
305
306 @x [26.414] l.8358 - encTeX: accessing xord/xchr/xprn
307 if m=math_code_base then scanned_result(ho(math_code(cur_val)))(int_val)
308 @y
309 if m=xord_code_base then scanned_result(xord[cur_val])(int_val)
310 else if m=xchr_code_base then scanned_result(xchr[cur_val])(int_val)
311 else if m=xprn_code_base then scanned_result(xprn[cur_val])(int_val)
312 else if m=math_code_base then scanned_result(ho(math_code(cur_val)))(int_val)
313 @z
314
315 @x [29.534] l.10293 - enc\TeX: add enc\TeX banner after loading fmt file
316 begin wlog_cr; wlog('MLTeX v2.2 enabled');
317 end;
318 @y
319 begin wlog_cr; wlog('MLTeX v2.2 enabled');
320 end;
321 if enctex_enabled_p then
322 begin wlog_cr; wlog(encTeX_banner); wlog(', reencoding enabled');
323 if translate_filename then
324 begin wlog_cr;
325 wlog(' (\xordcode, \xchrcode, \xprncode overridden by TCX)');
326 end;
327 end;
328 @z
329
330 @x [48.1138] l.21648 - encTeX: \endmubyte primitive
331 begin print_err("Extra "); print_esc("endcsname");
332 @.Extra \\endcsname@>
333 help1("I'm ignoring this, since I wasn't doing a \csname.");
334 @y
335 begin
336 if cur_chr = 10 then
337 begin
338 print_err("Extra "); print_esc("endmubyte");
339 @.Extra \\endmubyte@>
340 help1("I'm ignoring this, since I wasn't doing a \mubyte.");
341 end else begin
342 print_err("Extra "); print_esc("endcsname");
343 @.Extra \\endcsname@>
344 help1("I'm ignoring this, since I wasn't doing a \csname.");
345 end;
346 @z
347
348 @x [49.1211] - encTeX: extra variables for \mubyte primitive
349 @!p,@!q:pointer; {for temporary short-term use}
350 @y
351 @!p,@!q,@!r:pointer; {for temporary short-term use}
352 @z
353
354 @x [49.1219] - encTeX: \mubyte and \noconvert primitives
355 primitive("futurelet",let,normal+1);@/
356 @!@:future_let_}{\.{\\futurelet} primitive@>
357 @y
358 primitive("futurelet",let,normal+1);@/
359 @!@:future_let_}{\.{\\futurelet} primitive@>
360 if enctex_p then
361 begin
362 primitive("mubyte",let,normal+10);@/
363 @!@:mubyte_}{\.{\\mubyte} primitive@>
364 primitive("noconvert",let,normal+11);@/
365 @!@:noconvert_}{\.{\\noconvert} primitive@>
366 end;
367 @z
368
369 @x [49.1220] - encTeX: \mubyte primitive
370 let: if chr_code<>normal then print_esc("futurelet")@+else print_esc("let");
371 @y
372 let: if chr_code<>normal then
373 if chr_code = normal+10 then print_esc("mubyte")
374 else if chr_code = normal+11 then print_esc("noconvert")
375 else print_esc("futurelet")
376 else print_esc("let");
377 @z
378
379 @x [49.1221] - encTeX: \mubyte primitive
380 let: begin n:=cur_chr;
381 @y
382 let: if cur_chr = normal+11 then do_nothing { noconvert primitive }
383 else if cur_chr = normal+10 then { mubyte primitive }
384 begin
385 selector:=term_and_log;
386 get_token;
387 mubyte_stoken := cur_tok;
388 if cur_tok <= cs_token_flag then mubyte_stoken := cur_tok mod 256;
389 mubyte_prefix := 60; mubyte_relax := false;
390 mubyte_tablein := true; mubyte_tableout := true;
391 get_x_token;
392 if cur_cmd = spacer then get_x_token;
393 if cur_cmd = sub_mark then
394 begin
395 mubyte_tableout := false; get_x_token;
396 if cur_cmd = sub_mark then
397 begin
398 mubyte_tableout := true; mubyte_tablein := false;
399 get_x_token;
400 end;
401 end else if (mubyte_stoken > cs_token_flag) and
402 (cur_cmd = mac_param) then
403 begin
404 mubyte_tableout := false;
405 scan_int; mubyte_prefix := cur_val; get_x_token;
406 if mubyte_prefix > 50 then mubyte_prefix := 52;
407 if mubyte_prefix <= 0 then mubyte_prefix := 51;
408 end
409 else if (mubyte_stoken > cs_token_flag) and (cur_cmd = relax) then
410 begin
411 mubyte_tableout := true; mubyte_tablein := false;
412 mubyte_relax := true; get_x_token;
413 end;
414 r := get_avail; p := r;
415 while cur_cs = 0 do begin store_new_token (cur_tok); get_x_token; end;
416 if (cur_cmd <> end_cs_name) or (cur_chr <> 10) then
417 begin
418 print_err("Missing "); print_esc("endmubyte"); print(" inserted");
419 help2("The control sequence marked <to be read again> should")@/
420 ("not appear in <byte sequence> between \mubyte and \endmubyte.");
421 back_error;
422 end;
423 p := link(r);
424 if (p = null) and mubyte_tablein then
425 begin
426 print_err("The empty <byte sequence>, ");
427 print_esc("mubyte"); print(" ignored");
428 help2("The <byte sequence> in")@/
429 ("\mubyte <token> <byte sequence>\endmubyte should not be empty.");
430 error;
431 end else begin
432 while p <> null do
433 begin
434 append_char (info(p) mod 256);
435 p := link (p);
436 end;
437 flush_list (r);
438 if (str_start [str_ptr] + 1 = pool_ptr) and
439 (str_pool [pool_ptr-1] = mubyte_stoken) then
440 begin
441 if mubyte_read [mubyte_stoken] <> null
442 and mubyte_tablein then { clearing data }
443 dispose_munode (mubyte_read [mubyte_stoken]);
444 if mubyte_tablein then mubyte_read [mubyte_stoken] := null;
445 if mubyte_tableout then mubyte_write [mubyte_stoken] := 0;
446 pool_ptr := str_start [str_ptr];
447 end else begin
448 if mubyte_tablein then mubyte_update; { updating input side }
449 if mubyte_tableout then { updating output side }
450 begin
451 if mubyte_stoken > cs_token_flag then { control sequence }
452 begin
453 dispose_mutableout (mubyte_stoken-cs_token_flag);
454 if (str_start [str_ptr] < pool_ptr) or mubyte_relax then
455 begin { store data }
456 r := mubyte_cswrite[(mubyte_stoken-cs_token_flag) mod 128];
457 p := get_avail;
458 mubyte_cswrite[(mubyte_stoken-cs_token_flag) mod 128] := p;
459 info (p) := mubyte_stoken-cs_token_flag;
460 link (p) := get_avail;
461 p := link (p);
462 if mubyte_relax then begin
463 info (p) := 0; pool_ptr := str_start [str_ptr];
464 end else info (p) := slow_make_string;
465 link (p) := r;
466 end;
467 end else begin { single character }
468 if str_start [str_ptr] = pool_ptr then
469 mubyte_write [mubyte_stoken] := 0
470 else
471 mubyte_write [mubyte_stoken] := slow_make_string;
472 end;
473 end else pool_ptr := str_start [str_ptr];
474 end;
475 end;
476 end else begin { let primitive }
477 n:=cur_chr;
478 @z
479
480 @x [49.1230] l.22936 - encTeX: \xordcode, \xchrcode, \xprncode primitives
481 primitive("catcode",def_code,cat_code_base);
482 @!@:cat_code_}{\.{\\catcode} primitive@>
483 @y
484 primitive("catcode",def_code,cat_code_base);
485 @!@:cat_code_}{\.{\\catcode} primitive@>
486 if enctex_p then
487 begin
488 primitive("xordcode",def_code,xord_code_base);
489 @!@:xord_code_}{\.{\\xordcode} primitive@>
490 primitive("xchrcode",def_code,xchr_code_base);
491 @!@:xchr_code_}{\.{\\xchrcode} primitive@>
492 primitive("xprncode",def_code,xprn_code_base);
493 @!@:xprn_code_}{\.{\\xprncode} primitive@>
494 end;
495 @z
496
497 @x [49.1231] l.22956 - encTeX: \xordcode, \xchrcode, \xprncode primitives
498 def_code: if chr_code=cat_code_base then print_esc("catcode")
499 @y
500 def_code: if chr_code=xord_code_base then print_esc("xordcode")
501 else if chr_code=xchr_code_base then print_esc("xchrcode")
502 else if chr_code=xprn_code_base then print_esc("xprncode")
503 else if chr_code=cat_code_base then print_esc("catcode")
504 @z
505
506 @x [49.1232] l.22969 - encTeX: setting a new value to xchr/xord/xprn
507 p:=cur_chr; scan_char_num; p:=p+cur_val; scan_optional_equals;
508 scan_int;
509 @y
510 p:=cur_chr; scan_char_num;
511 if p=xord_code_base then p:=cur_val
512 else if p=xchr_code_base then p:=cur_val+256
513 else if p=xprn_code_base then p:=cur_val+512
514 else p:=p+cur_val;
515 scan_optional_equals;
516 scan_int;
517 @z
518
519 @x [49.1232] l.22980 - encTeX: setting a new value to xchr/xord/xprn
520 if p<math_code_base then define(p,data,cur_val)
521 @y
522 if p<256 then xord[p]:=cur_val
523 else if p<512 then xchr[p-256]:=cur_val
524 else if p<768 then xprn[p-512]:=cur_val
525 else if p<math_code_base then define(p,data,cur_val)
526 @z
527
528 @x [49.1279] - encTeX: implement \noconvert
529 old_setting:=selector; selector:=new_string;
530 token_show(def_ref); selector:=old_setting;
531 @y
532 old_setting:=selector; selector:=new_string;
533 message_printing := true; active_noconvert := true;
534 token_show(def_ref);
535 message_printing := false; active_noconvert := false;
536 selector:=old_setting;
537 @z
538
539 % encTeX: |slow_print| is too eager to expand printed strings. To
540 % selectively suppress or enable expansion (needed to \noconvert)
541 % |print| will look at |message_printing|. So we bypass |slow_print|
542 % and go directly to |print| instead.
543 @x [49.1279] - encTeX: to handle \noconvert in messages go directly to |print|
544 slow_print(s); update_terminal;
545 @y
546 print(s); update_terminal;
547 @z
548
549 @x [49.1279] - encTeX: to handle \noconvert in messages go directly to |print|
550 begin print_err(""); slow_print(s);
551 @y
552 begin print_err(""); print(s);
553 @z
554
555 % encTeX: dump encTeX-specific data to fmt file.
556 @x [50.1302] l.23694
557 @<Dump ML\TeX-specific data@>;
558 @y
559 @<Dump ML\TeX-specific data@>;
560 @<Dump enc\TeX-specific data@>;
561 @z
562
563 % encTeX: undump encTeX-specific data from fmt file.
564 @x [50.1303] l.23694
565 @<Undump ML\TeX-specific data@>;
566 @y
567 @<Undump ML\TeX-specific data@>;
568 @<Undump enc\TeX-specific data@>;
569 @z
570
571 @x [51.1337] l.24371 - enc\TeX: add. enc\TeX banner after loading fmt file
572 begin wterm_ln('MLTeX v2.2 enabled');
573 end;
574 @y
575 begin wterm_ln('MLTeX v2.2 enabled');
576 end;
577 if enctex_enabled_p then
578 begin wterm(encTeX_banner); wterm_ln(', reencoding enabled.');
579 if translate_filename then begin
580 wterm_ln(' (\xordcode, \xchrcode, \xprncode overridden by TCX)');
581 end;
582 end;
583 @z
584
585 @x [53.1341] - encTeX: keep track of mubyte value for \write
586 @d write_stream(#) == info(#+1) {stream number (0 to 17)}
587 @y
588 @d write_stream(#) == type(#+1) {stream number (0 to 17)}
589 @d mubyte_zero == 64
590 @d write_mubyte(#) == subtype(#+1) {mubyte value + |mubyte_zero|}
591 @z
592
593 @x [53.1350] - encTeX: \write stores mubyte_out value
594 write_stream(tail):=cur_val;
595 @y
596 write_stream(tail):=cur_val;
597 if mubyte_out + mubyte_zero < 0 then write_mubyte(tail) := 0
598 else if mubyte_out + mubyte_zero >= 2*mubyte_zero then
599 write_mubyte(tail) := 2*mubyte_zero - 1
600 else write_mubyte(tail) := mubyte_out + mubyte_zero;
601 @z
602
603 @x [53.1353] - encTeX: \special stores specialout and mubyteout values
604 begin new_whatsit(special_node,write_node_size); write_stream(tail):=null;
605 p:=scan_toks(false,true); write_tokens(tail):=def_ref;
606 @y
607 begin new_whatsit(special_node,write_node_size);
608 if spec_out + mubyte_zero < 0 then write_stream(tail) := 0
609 else if spec_out + mubyte_zero >= 2*mubyte_zero then
610 write_stream(tail) := 2*mubyte_zero - 1
611 else write_stream(tail) := spec_out + mubyte_zero;
612 if mubyte_out + mubyte_zero < 0 then write_mubyte(tail) := 0
613 else if mubyte_out + mubyte_zero >= 2*mubyte_zero then
614 write_mubyte(tail) := 2*mubyte_zero - 1
615 else write_mubyte(tail) := mubyte_out + mubyte_zero;
616 if (spec_out = 2) or (spec_out = 3) then
617 if (mubyte_out > 2) or (mubyte_out = -1) or (mubyte_out = -2) then
618 write_noexpanding := true;
619 p:=scan_toks(false,true); write_tokens(tail):=def_ref;
620 write_noexpanding := false;
621 @z
622
623 @x [53.1355] - encTeX: \write prints \mubyteout value
624 else print_char("-");
625 @y
626 else print_char("-");
627 if (s = "write") and (write_mubyte (p) <> mubyte_zero) then
628 begin
629 print_char ("<"); print_int (write_mubyte(p)-mubyte_zero); print_char (">");
630 end;
631 @z
632
633 @x [53.1356] - encTeX: \special prints \specialout and \mubyteout values
634 special_node:begin print_esc("special");
635 @y
636 special_node:begin print_esc("special");
637 if write_stream(p) <> mubyte_zero then
638 begin
639 print_char ("<"); print_int (write_stream(p)-mubyte_zero);
640 if (write_stream(p)-mubyte_zero = 2) or
641 (write_stream(p)-mubyte_zero = 3) then
642 begin
643 print_char (":"); print_int (write_mubyte(p)-mubyte_zero);
644 end;
645 print_char (">");
646 end;
647 @z
648
649 @x [53.1368] - encTeX: conversions in \special
650 old_setting:=selector; selector:=new_string;
651 @y
652 old_setting:=selector; selector:=new_string;
653 spec_sout := spec_out; spec_out := write_stream(p) - mubyte_zero;
654 mubyte_sout := mubyte_out; mubyte_out := write_mubyte(p) - mubyte_zero;
655 active_noconvert := true;
656 mubyte_slog := mubyte_log;
657 mubyte_log := 0;
658 if (mubyte_out > 0) or (mubyte_out = -1) then mubyte_log := 1;
659 if (spec_out = 2) or (spec_out = 3) then
660 begin
661 if (mubyte_out > 0) or (mubyte_out = -1) then
662 begin
663 special_printing := true; mubyte_log := 1;
664 end;
665 if mubyte_out > 1 then cs_converting := true;
666 end;
667 @z
668
669 @x [53.1368] - encTeX: conversions in \special
670 for k:=str_start[str_ptr] to pool_ptr-1 do dvi_out(so(str_pool[k]));
671 @y
672 if (spec_out = 1) or (spec_out = 3) then
673 for k:=str_start[str_ptr] to pool_ptr-1 do
674 str_pool[k] := si(xchr[so(str_pool[k])]);
675 for k:=str_start[str_ptr] to pool_ptr-1 do dvi_out(so(str_pool[k]));
676 spec_out := spec_sout; mubyte_out := mubyte_sout; mubyte_log := mubyte_slog;
677 special_printing := false; cs_converting := false;
678 active_noconvert := false;
679 @z
680
681 @x [53.1370] l.24770 - encTeX
682 begin @<Expand macros in the token list
683 @y
684 begin
685 mubyte_sout := mubyte_out; mubyte_out := write_mubyte(p) - mubyte_zero;
686 if (mubyte_out > 2) or (mubyte_out = -1) or (mubyte_out = -2) then
687 write_noexpanding := true;
688 @<Expand macros in the token list
689 @z
690
691 @x [53.1370] - encTeX: conversion in parameter of \write
692 token_show(def_ref); print_ln;
693 @y
694 active_noconvert := true;
695 if mubyte_out > 1 then cs_converting := true;
696 mubyte_slog := mubyte_log;
697 if (mubyte_out > 0) or (mubyte_out = -1) then mubyte_log := 1
698 else mubyte_log := 0;
699 token_show(def_ref); print_ln;
700 cs_converting := false; write_noexpanding := false;
701 active_noconvert := false;
702 mubyte_out := mubyte_sout; mubyte_log := mubyte_slog;
703 @z
704
705 @x[54.1376] l.24903 - enc\TeX
706 @* \[54] System-dependent changes.
707 @y
708 @* \[54/enc\TeX] System-dependent changes for enc\TeX.
709
710 @d encTeX_banner == ' encTeX v. Jun. 2004'
711
712 @ The boolean variable |enctex_p| is set by web2c according to the given
713 command line option (or an entry in the configuration file) before any
714 \TeX{} function is called.
715
716 @<Global...@> =
717 @!enctex_p: boolean;
718
719
720 @ The boolean variable |enctex_enabled_p| is used to enable enc\TeX's
721 primitives. It is initialised to |false|. When loading a \.{FMT} it
722 is set to the value of the boolean |enctex_p| saved in the \.{FMT} file.
723 Additionally it is set to the value of |enctex_p| in Ini\TeX.
724
725 @<Glob...@>=
726 @!enctex_enabled_p:boolean; {enable encTeX}
727
728
729 @ @<Set init...@>=
730 enctex_enabled_p:=false;
731
732
733 @ Auxiliary functions/procedures for enc\TeX{} (by Petr Olsak) follow.
734 These functions implement the \.{\\mubyte} code to convert
735 the multibytes in |buffer| to one byte or to one control
736 sequence. These functions manipulate a mubyte tree: each node of
737 this tree is token list with n+1 tokens (first token consist the byte
738 from the byte sequence itself and the other tokens point to the
739 branches). If you travel from root of the tree to a leaf then you
740 find exactly one byte sequence which we have to convert to one byte or
741 control sequence. There are two variants of the leaf: the ``definitive
742 end'' or the ``middle leaf'' if a longer byte sequence exists and the mubyte
743 tree continues under this leaf. First variant is implemented as one
744 memory word where the link part includes the token to
745 which we have to convert and type part includes the number 60 (normal
746 conversion) or 1..52 (insert the control sequence).
747 The second variant of ``middle leaf'' is implemented as two memory words:
748 first one has a type advanced by 64 and link points to the second
749 word where info part includes the token to which we have to convert
750 and link points to the next token list with the branches of
751 the subtree.
752
753 The inverse: one byte to multi byte (for log printing and \.{\\write}
754 printing) is implemented via a pool. Each multibyte sequence is stored
755 in a pool as a string and |mubyte_write|[{\it printed char\/}] points
756 to this string.
757
758 @d new_mubyte_node ==
759 link (p) := get_avail; p := link (p); info (p) := get_avail; p := info (p)
760 @d subinfo (#) == subtype (#)
761
762 @<Basic printing...@>=
763 { read |buffer|[|i|] and convert multibyte. |i| should have been
764 of type 0..|buf_size|, but web2c doesn't like that construct in
765 argument lists. }
766 function read_buffer(var i:integer):ASCII_code;
767 var p: pointer;
768 last_found: integer;
769 last_type: integer;
770 begin
771 mubyte_skip := 0; mubyte_token := 0;
772 read_buffer := buffer[i];
773 if mubyte_in = 0 then
774 begin
775 if mubyte_keep > 0 then mubyte_keep := 0;
776 return ;
777 end;
778 last_found := -2;
779 if (i = start) and (not mubyte_start) then
780 begin
781 mubyte_keep := 0;
782 if (end_line_char >= 0) and (end_line_char < 256) then
783 if mubyte_read [end_line_char] <> null then
784 begin
785 mubyte_start := true; mubyte_skip := -1;
786 p := mubyte_read [end_line_char];
787 goto continue;
788 end;
789 end;
790 restart:
791 mubyte_start := false;
792 if (mubyte_read [buffer[i]] = null) or (mubyte_keep > 0) then
793 begin
794 if mubyte_keep > 0 then decr (mubyte_keep);
795 return ;
796 end;
797 p := mubyte_read [buffer[i]];
798 continue:
799 if type (p) >= 64 then
800 begin
801 last_type := type (p) - 64;
802 p := link (p);
803 mubyte_token := info (p); last_found := mubyte_skip;
804 end else if type (p) > 0 then
805 begin
806 last_type := type (p);
807 mubyte_token := link (p);
808 goto found;
809 end;
810 incr (mubyte_skip);
811 if i + mubyte_skip > limit then
812 begin
813 mubyte_skip := 0;
814 if mubyte_start then goto restart;
815 return;
816 end;
817 repeat
818 p := link (p);
819 if subinfo (info(p)) = buffer [i+mubyte_skip] then
820 begin
821 p := info (p); goto continue;
822 end;
823 until link (p) = null;
824 mubyte_skip := 0;
825 if mubyte_start then goto restart;
826 if last_found = -2 then return; { no found }
827 mubyte_skip := last_found;
828 found:
829 if mubyte_token < 256 then { multibyte to one byte }
830 begin
831 read_buffer := mubyte_token; mubyte_token := 0;
832 i := i + mubyte_skip;
833 if mubyte_start and (i >= start) then mubyte_start := false;
834 return;
835 end else begin { multibyte to control sequence }
836 read_buffer := 0;
837 if last_type = 60 then { normal conversion }
838 i := i + mubyte_skip
839 else begin { insert control sequence }
840 decr (i); mubyte_keep := last_type;
841 if i < start then mubyte_start := true;
842 if last_type = 52 then mubyte_keep := 10000;
843 if last_type = 51 then mubyte_keep := mubyte_skip + 1;
844 mubyte_skip := -1;
845 end;
846 if mubyte_start and (i >= start) then mubyte_start := false;
847 return;
848 end;
849 exit: end;
850
851 @ @<Declare additional routines for enc\TeX@>=
852 procedure mubyte_update; { saves new string to mubyte tree }
853 var j: pool_pointer;
854 p: pointer;
855 q: pointer;
856 in_mutree: integer;
857 begin
858 j := str_start [str_ptr];
859 if mubyte_read [so(str_pool[j])] = null then
860 begin
861 in_mutree := 0;
862 p := get_avail;
863 mubyte_read [so(str_pool[j])] := p;
864 subinfo (p) := so(str_pool[j]); type (p) := 0;
865 end else begin
866 in_mutree := 1;
867 p := mubyte_read [so(str_pool[j])];
868 end;
869 incr (j);
870 while j < pool_ptr do
871 begin
872 if in_mutree = 0 then
873 begin
874 new_mubyte_node; subinfo (p) := so(str_pool[j]); type (p) := 0;
875 end else { |in_mutree| = 1 }
876 if (type (p) > 0) and (type (p) < 64) then
877 begin
878 type (p) := type (p) + 64;
879 q := link (p); link (p) := get_avail; p := link (p);
880 info (p) := q;
881 new_mubyte_node; subinfo (p) := so(str_pool[j]); type (p) := 0;
882 in_mutree := 0;
883 end else begin
884 if type (p) >= 64 then p := link (p);
885 repeat
886 p := link (p);
887 if subinfo (info(p)) = so(str_pool[j]) then
888 begin
889 p := info (p);
890 goto continue;
891 end;
892 until link (p) = null;
893 new_mubyte_node; subinfo (p) := so(str_pool[j]); type (p) := 0;
894 in_mutree := 0;
895 end;
896 continue:
897 incr (j);
898 end;
899 if in_mutree = 1 then
900 begin
901 if type (p) = 0 then
902 begin
903 type (p) := mubyte_prefix + 64;
904 q := link (p); link (p) := get_avail; p := link (p);
905 link (p) := q; info (p) := mubyte_stoken;
906 return;
907 end;
908 if type (p) >= 64 then
909 begin
910 type (p) := mubyte_prefix + 64;
911 p := link (p); info (p) := mubyte_stoken;
912 return;
913 end;
914 end;
915 type (p) := mubyte_prefix;
916 link (p) := mubyte_stoken;
917 exit: end;
918 @#
919 procedure dispose_munode (p: pointer); { frees a mu subtree recursivelly }
920 var q: pointer;
921 begin
922 if (type (p) > 0) and (type (p) < 64) then free_avail (p)
923 else begin
924 if type (p) >= 64 then
925 begin
926 q := link (p); free_avail (p); p := q;
927 end;
928 q := link (p); free_avail (p); p := q;
929 while p <> null do
930 begin
931 dispose_munode (info (p));
932 q := link (p);
933 free_avail (p);
934 p := q;
935 end;
936 end;
937 end;
938 @#
939 procedure dispose_mutableout (cs: pointer); { frees record from out table }
940 var p, q, r: pointer;
941 begin
942 p := mubyte_cswrite [cs mod 128];
943 r := null;
944 while p <> null do
945 if info (p) = cs then
946 begin
947 if r <> null then link (r) := link (link (p))
948 else mubyte_cswrite[cs mod 128] := link (link (p));
949 q := link (link(p));
950 free_avail (link(p)); free_avail (p);
951 p := q;
952 end else begin
953 r := link (p); p := link (r);
954 end;
955 end;
956
957 @ The |print_buffer| procedure prints one character from |buffer|[|i|].
958 It also increases |i| to the next character in the buffer.
959
960 @<Basic printing...@>=
961 { print one char from |buffer|[|i|]. |i| should have been of type
962 0..|buf_size|, but web2c doesn't like that construct in argument lists. }
963 procedure print_buffer(var i:integer);
964 var c: ASCII_code;
965 begin
966 if mubyte_in = 0 then print (buffer[i]) { normal TeX }
967 else if mubyte_log > 0 then print_char (buffer[i])
968 else begin
969 c := read_buffer (i);
970 if mubyte_token > 0 then print_cs (mubyte_token-cs_token_flag)
971 else print (c);
972 end;
973 incr (i);
974 end;
975
976 @ Additional material to dump for enc\TeX. This includes whether
977 enc\TeX is enabled, and if it is we also have to dump the \.{\\mubyte}
978 arrays.
979
980 @<Dump enc\TeX-specific data@>=
981 dump_int(@"45435458); {enc\TeX's magic constant: "ECTX"}
982 if not enctex_p then dump_int(0)
983 else begin
984 dump_int(1);
985 dump_things(mubyte_read[0], 256);
986 dump_things(mubyte_write[0], 256);
987 dump_things(mubyte_cswrite[0], 128);
988 end;
989
990 @ Undumping the additional material we dumped for enc\TeX. This includes
991 conditionally undumping the \.{\\mubyte} arrays.
992
993 @<Undump enc\TeX-specific data@>=
994 undump_int(x); {check magic constant of enc\TeX}
995 if x<>@"45435458 then goto bad_fmt;
996 undump_int(x); {undump |enctex_p| flag into |enctex_enabled_p|}
997 if x=0 then enctex_enabled_p:=false
998 else if x<>1 then goto bad_fmt
999 else begin
1000 enctex_enabled_p:=true;
1001 undump_things(mubyte_read[0], 256);
1002 undump_things(mubyte_write[0], 256);
1003 undump_things(mubyte_cswrite[0], 128);
1004 end;
1005
1006
1007 @* \[54] System-dependent changes.
1008 @z