1/****************************************************************************\
2 Part of the XeTeX typesetting system
3 Copyright (c) 1994-2008 by SIL International
4 Copyright (c) 2009-2012 by Jonathan Kew
5 Copyright (c) 2012 by Khaled Hosny
6
7 SIL Author(s): Jonathan Kew
8
9Permission is hereby granted, free of charge, to any person obtaining
10a copy of this software and associated documentation files (the
11"Software"), to deal in the Software without restriction, including
12without limitation the rights to use, copy, modify, merge, publish,
13distribute, sublicense, and/or sell copies of the Software, and to
14permit persons to whom the Software is furnished to do so, subject to
15the following conditions:
16
17The above copyright notice and this permission notice shall be
18included in all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
24FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28Except as contained in this notice, the name of the copyright holders
29shall not be used in advertising or otherwise to promote the sale,
30use or other dealings in this Software without prior written
31authorization from the copyright holders.
32\****************************************************************************/
33
34@x
35\let\maybe=\iffalse
36@y
37\let\maybe=\iftrue
38@z
39
40@x [1] m.2 l.188 - banner
41@d banner==TeX_banner
42@d banner_k==TeX_banner_k
43@y
44@d banner==XeTeX_banner
45@d banner_k==XeTeX_banner
46@z
47
48@x [2.20] l.579 - printable characters
49xchr: array [ASCII_code] of text_char;
50   { specifies conversion of output characters }
51xprn: array [ASCII_code] of ASCII_code;
52   { non zero iff character is printable }
53@y
54@!xchr: ^text_char;
55  {dummy variable so tangle doesn't complain; not actually used}
56@z
57
58@x [2.23] l.723 - Translate characters if desired, otherwise allow them all.
59{Initialize |xchr| to the identity mapping.}
60for i:=0 to @'37 do xchr[i]:=i;
61for i:=@'177 to @'377 do xchr[i]:=i;
62@y
63@z
64
65@x [2.24] l.733 - Don't reinitialize xord.
66for i:=0 to @'176 do xord[xchr[i]]:=i;
67{Set |xprn| for printable ASCII, unless |eight_bit_p| is set.}
68for i:=0 to 255 do xprn[i]:=(eight_bit_p or ((i>=" ")and(i<="~")));
69
70{The idea for this dynamic translation comes from the patch by
71 Libor Skarvada \.{<libor@@informatics.muni.cz>}
72 and Petr Sojka \.{<sojka@@informatics.muni.cz>}. I didn't use any of the
73 actual code, though, preferring a more general approach.}
74
75{This updates the |xchr|, |xord|, and |xprn| arrays from the provided
76 |translate_filename|.  See the function definition in \.{texmfmp.c} for
77 more comments.}
78if translate_filename then read_tcx_file;
79@y
80@z
81
82@x [3.26] l.789 - name_of_file is no longer an array
83@!name_of_file:^text_char;
84@y
85@!name_of_file:^UTF8_code; {we build filenames in utf8 to pass to the OS}
86@z
87
88@x
89@!name_of_file16:array[1..file_name_size] of UTF16_code;@;@/
90@y
91@!name_of_file16:^UTF16_code;
92@z
93
94@x [3.30] l.888 - Array size of input buffer is determined at runtime.
95@!buffer:^ASCII_code; {lines of characters being read}
96@y
97@!buffer:^UnicodeScalar; {lines of characters being read}
98@z
99
100@x [3.32] l.961 - `term_in' and `term_out' are standard input and output.
101@d term_in==stdin {the terminal as an input file}
102@y
103@z
104
105@x [3.32] l.961
106@!bound_default:integer; {temporary for setup}
107@y
108@!term_in:unicode_file;
109@#
110@!bound_default:integer; {temporary for setup}
111@z
112
113@x [5.61] l.1556 - Print rest of banner, eliminate misleading `(no format preloaded)'.
114if translate_filename then begin
115  wterm(' (');
116  fputs(translate_filename, stdout);
117  wterm_ln(')');
118@y
119if translate_filename then begin
120  wterm(' (WARNING: translate-file "');
121  fputs(translate_filename, stdout);
122  wterm_ln('" ignored)');
123@z
124
125@x [6.84] l.1904 - Implement the switch-to-editor option.
126    begin edit_name_start:=str_start[edit_file.name_field];
127    edit_name_length:=str_start[edit_file.name_field+1] -
128                      str_start[edit_file.name_field];
129@y
130    begin edit_name_start:=str_start_macro(edit_file.name_field);
131    edit_name_length:=str_start_macro(edit_file.name_field+1) -
132                      str_start_macro(edit_file.name_field);
133@z
134
135@x [8.110] l.2423
136@d max_halfword==@"FFFFFFF {largest allowable value in a |halfword|}
137@y
138@d max_halfword==@"3FFFFFFF {largest allowable value in a |halfword|}
139@z
140
141@x [15.209] l.4165
142@d shorthand_def=95 {code definition ( \.{\\chardef}, \.{\\countdef}, etc.~)}
143@y
144@d shorthand_def=97 {code definition ( \.{\\chardef}, \.{\\countdef}, etc.~)}
145@z
146
147@x [17.222] l.4523 - frozen_special, for source specials.
148@d frozen_null_font=frozen_control_sequence+11
149@y
150@d frozen_primitive=frozen_control_sequence+11
151  {permanent `\.{\\primitive}'}
152@d frozen_null_font=frozen_control_sequence+12
153@z
154
155@x [17.230] l.4731
156@d char_sub_code_base=math_code_base+256 {table of character substitutions}
157@d int_base=char_sub_code_base+256 {beginning of region 5}
158@y
159@d char_sub_code_base=math_code_base+number_usvs {table of character substitutions}
160@d int_base=char_sub_code_base+number_usvs {beginning of region 5}
161@z
162
163@x [17.236] l.4960 - first web2c, then e-TeX additional integer parameters
164@d int_pars=web2c_int_pars {total number of integer parameters}
165@#
166@d etex_int_base=tex_int_pars {base for \eTeX's integer parameters}
167@y
168@d etex_int_base=web2c_int_pars {base for \eTeX's integer parameters}
169@z
170
171@x [22.304] l.6536 - texarray; additions for file:line:error style.
172@!input_file : ^alpha_file;
173@y
174@!input_file : ^unicode_file;
175@z
176
177@x [29.516] l.9992 - filenames: more_name
178begin if (c=" ") and stop_at_space and (not quoted_filename) then
179  more_name:=false
180else  if c="""" then begin
181  quoted_filename:=not quoted_filename;
182@y
183begin if stop_at_space and (c=" ") and (file_name_quote_char=0) then
184  more_name:=false
185else if stop_at_space and (file_name_quote_char<>0) and (c=file_name_quote_char) then begin
186  file_name_quote_char:=0;
187  more_name:=true;
188  end
189else if stop_at_space and (file_name_quote_char=0) and ((c="""") or (c="'")) then begin
190  file_name_quote_char:=c;
191  quoted_filename:=true;
192@z
193
194@x [29.517] l.10002 - end_name: string recycling
195@!j,@!s,@!t: pool_pointer; {running indices}
196@!must_quote:boolean; {whether we need to quote a string}
197@y
198@!j: pool_pointer; {running index}
199@z
200@x [29.517] l.10002 - end_name: string recycling
201str_room(6); {Room for quotes, if needed.}
202{add quotes if needed}
203if area_delimiter<>0 then begin
204  {maybe quote |cur_area|}
205  must_quote:=false;
206  s:=str_start[str_ptr];
207  t:=str_start[str_ptr]+area_delimiter;
208  j:=s;
209  while (not must_quote) and (j<t) do begin
210    must_quote:=str_pool[j]=" "; incr(j);
211    end;
212  if must_quote then begin
213    for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
214    str_pool[t+1]:="""";
215    for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
216    str_pool[s]:="""";
217    if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
218    area_delimiter:=area_delimiter+2;
219    pool_ptr:=pool_ptr+2;
220    end;
221  end;
222{maybe quote |cur_name|}
223s:=str_start[str_ptr]+area_delimiter;
224if ext_delimiter=0 then t:=pool_ptr else t:=str_start[str_ptr]+ext_delimiter-1;
225must_quote:=false;
226j:=s;
227while (not must_quote) and (j<t) do begin
228  must_quote:=str_pool[j]=" "; incr(j);
229  end;
230if must_quote then begin
231  for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
232  str_pool[t+1]:="""";
233  for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
234  str_pool[s]:="""";
235  if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
236  pool_ptr:=pool_ptr+2;
237  end;
238if ext_delimiter<>0 then begin
239  {maybe quote |cur_ext|}
240  s:=str_start[str_ptr]+ext_delimiter-1;
241  t:=pool_ptr;
242  must_quote:=false;
243  j:=s;
244  while (not must_quote) and (j<t) do begin
245    must_quote:=str_pool[j]=" "; incr(j);
246    end;
247  if must_quote then begin
248    str_pool[t+1]:="""";
249    for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
250    str_pool[s]:="""";
251    pool_ptr:=pool_ptr+2;
252    end;
253  end;
254@y
255@z
256
257@x [29.517] l.10011 - end_name: string recycling
258    for j:=str_start[str_ptr+1] to pool_ptr-1 do
259@y
260    for j:=str_start_macro(str_ptr+1) to pool_ptr-1 do
261@z
262
263@x [29.517] l.10016 - end_name: string recycling
264    for j:=str_start[str_ptr+1] to pool_ptr-1 do
265@y
266    for j:=str_start_macro(str_ptr+1) to pool_ptr-1 do
267@z
268
269@x [29.518] l.10042 - print_file_name: quote if spaces in names.
270@d check_quoted(#) == {check if string |#| needs quoting}
271if #<>0 then begin
272  j:=str_start[#];
273  while (not must_quote) and (j<str_start[#+1]) do begin
274    must_quote:=str_pool[j]=" "; incr(j);
275@y
276@d check_quoted(#) == {check if string |#| needs quoting}
277if #<>0 then begin
278  j:=str_start_macro(#);
279  while ((not must_quote) or (quote_char=0)) and (j<str_start_macro(#+1)) do begin
280    if str_pool[j]=" " then must_quote:=true
281    else if (str_pool[j]="""") or (str_pool[j]="'") then begin
282      must_quote:=true;
283      quote_char:="""" + "'" - str_pool[j];
284    end;
285    incr(j);
286@z
287
288@x [29.518] l.10042 - print_file_name: quote if spaces in names.
289@d print_quoted(#) == {print string |#|, omitting quotes}
290if #<>0 then
291  for j:=str_start[#] to str_start[#+1]-1 do
292    if so(str_pool[j])<>"""" then
293      print(so(str_pool[j]))
294@y
295@d print_quoted(#) == {print string |#|, omitting quotes}
296if #<>0 then
297  for j:=str_start_macro(#) to str_start_macro(#+1)-1 do begin
298    if str_pool[j]=quote_char then begin
299      print(quote_char);
300      quote_char:="""" + "'" - quote_char;
301      print(quote_char);
302    end;
303    print(str_pool[j]);
304  end
305@z
306
307@x [29.518] l.10042 - print_file_name: quote if spaces in names.
308@!j:pool_pointer; {index into |str_pool|}
309begin
310must_quote:=false;
311check_quoted(a); check_quoted(n); check_quoted(e);
312{FIXME: Alternative is to assume that any filename that has to be quoted has
313 at least one quoted component...if we pick this, a number of insertions
314 of |print_file_name| should go away.
315|must_quote|:=((|a|<>0)and(|str_pool|[|str_start|[|a|]]=""""))or
316              ((|n|<>0)and(|str_pool|[|str_start|[|n|]]=""""))or
317              ((|e|<>0)and(|str_pool|[|str_start|[|e|]]=""""));}
318if must_quote then print_char("""");
319print_quoted(a); print_quoted(n); print_quoted(e);
320if must_quote then print_char("""");
321@y
322@!quote_char: integer; {current quote char (single or double)}
323@!j:pool_pointer; {index into |str_pool|}
324begin
325must_quote:=false;
326quote_char:=0;
327check_quoted(a); check_quoted(n); check_quoted(e);
328if must_quote then begin
329  if quote_char=0 then quote_char:="""";
330  print_char(quote_char);
331end;
332print_quoted(a); print_quoted(n); print_quoted(e);
333if quote_char<>0 then print_char(quote_char);
334@z
335
336@x [29.519] l.10051 - have append_to_name skip quotes.
337@d append_to_name(#)==begin c:=#; if not (c="""") then begin incr(k);
338  if k<=file_name_size then name_of_file[k]:=xchr[c];
339  end end
340@y
341@d append_to_name(#)==begin c:=#; incr(k);
342  if k<=file_name_size then begin
343      if (c < 128) then name_of_file[k]:=c
344      else if (c < @"800) then begin
345        name_of_file[k]:=@"C0 + c div @"40; incr(k);
346        name_of_file[k]:=@"80 + c mod @"40;
347      end else begin
348		name_of_file[k]:=@"E0 + c div @"1000; incr(k);
349		name_of_file[k]:=@"80 + (c mod @"1000) div @"40; incr(k);
350		name_of_file[k]:=@"80 + (c mod @"1000) mod @"40;
351      end
352    end
353  end
354@z
355
356@x [29.519] l.10047 - pack_file_name, leave room for the extra null
357name_of_file:= xmalloc_array (ASCII_code, length(a)+length(n)+length(e)+1);
358@y
359name_of_file:= xmalloc_array (UTF8_code, (length(a)+length(n)+length(e))*3+1);
360@z
361
362@x [29.523] l.10095 - Change to pack_buffered_name as with pack_file_name.
363name_of_file := xmalloc_array (ASCII_code, n+(b-a+1)+format_ext_length+1);
364for j:=1 to n do append_to_name(xord[ucharcast(TEX_format_default[j])]);
365@y
366name_of_file := xmalloc_array (UTF8_code, n+(b-a+1)+format_ext_length+1);
367for j:=1 to n do append_to_name(TEX_format_default[j]);
368@z
369
370@x [29.523] l.10095 - Change to pack_buffered_name as with pack_file_name.
371  append_to_name(xord[ucharcast(TEX_format_default[j])]);
372@y
373  append_to_name(TEX_format_default[j]);
374@z
375
376@x [29.525] l.10174 - make_name_string
377  k:=1;
378  while (k<=name_length)and(more_name(name_of_file[k])) do
379@y
380  k:=0;
381  while (k<name_length16)and(more_name(name_of_file16[k])) do
382@z
383
384@x [29.526] l.10194 - stop scanning file name if we're at end-of-line.
385  {If |cur_chr| is a space and we're not scanning a token list, check
386   whether we're at the end of the buffer. Otherwise we end up adding
387   spurious spaces to file names in some cases.}
388  if (cur_chr=" ") and (state<>token_list) and (loc>limit) then goto done;
389@y
390@z
391
392@x [29.536] l.10331
393  wlog(' (');
394  fputs(translate_filename, log_file);
395  wlog(')');
396@y
397  wlog(' (WARNING: translate-file "');
398  fputs(translate_filename, log_file);
399  wlog('" ignored)');
400@z
401
402@x [29.537] l.10338 - start_input
403var temp_str: str_number;
404begin scan_file_name; {set |cur_name| to desired file name}
405@y
406var temp_str: str_number;
407@!k:0..file_name_size; {index into |name_of_file16|}
408begin scan_file_name; {set |cur_name| to desired file name}
409@z
410
411@x [29.537] l.10338 - start_input
412     and a_open_in(cur_file, kpse_tex_format) then
413    goto done;
414@y
415     and u_open_in(cur_file, kpse_tex_format, XeTeX_default_input_mode, XeTeX_default_input_encoding) then
416    {At this point |name_of_file| contains the actual name found, as a UTF8 string.
417     We convert to UTF16, then extract the |cur_area|, |cur_name|, and |cur_ext| from it.}
418    begin
419    make_utf16_name;
420    name_in_progress:=true;
421    begin_name;
422    stop_at_space:=false;
423    k:=0;
424    while (k<name_length16)and(more_name(name_of_file16[k])) do
425      incr(k);
426    stop_at_space:=true;
427    end_name;
428    name_in_progress:=false;
429    goto done;
430    end;
431@z
432
433@x [30.549] l.10682 - texarray
434@!font_bc: ^eight_bits;
435  {beginning (smallest) character code}
436@!font_ec: ^eight_bits;
437  {ending (largest) character code}
438@y
439@!font_bc: ^UTF16_code;
440  {beginning (smallest) character code}
441@!font_ec: ^UTF16_code;
442  {ending (largest) character code}
443@z
444
445@x [30.549] l.10682 - texarray
446@!font_false_bchar: ^nine_bits;
447  {|font_bchar| if it doesn't exist in the font, otherwise |non_char|}
448@y
449@!font_false_bchar: ^nine_bits;
450  {|font_bchar| if it doesn't exist in the font, otherwise |non_char|}
451@#
452@!font_layout_engine: ^void_pointer; {either an CFDictionaryRef or a XeTeXLayoutEngine}
453@!font_mapping: ^void_pointer; { |TECkit_Converter| or 0 }
454@!font_flags: ^char; { flags:
455  0x01: |font_colored|
456  0x02: |font_vertical| }
457@!font_letter_space: ^scaled; { letterspacing to be applied to the font }
458@!loaded_font_mapping: void_pointer; { used by |load_native_font| to return mapping, if any }
459@!loaded_font_flags: char; { used by |load_native_font| to return flags }
460@!loaded_font_letter_space: scaled;
461@!loaded_font_design_size: scaled;
462@!mapped_text: ^UTF16_code; { scratch buffer used while applying font mappings }
463@!xdv_buffer: ^char; { scratch buffer used in generating XDV output }
464@z
465
466@x [30.561] l.10939 - Check lengths
467else print(" not loadable: Metric (TFM) file not found");
468@y
469else print(" not loadable: Metric (TFM) file or installed font not found");
470@z
471
472@x
473@ We need a few subroutines for |new_character|.
474
475@p @t\4@>@<Declare subroutines for |new_character|@>@;
476@y
477@ The subroutines for |new_character| have been moved.
478@z
479
480@x [30.582] l.11276 - MLTeX: call |effective_char| in |new_character|
481@p function new_character(@!f:internal_font_number;@!c:eight_bits):pointer;
482@y
483@p function new_character(@!f:internal_font_number;@!c:ASCII_code):pointer;
484@z
485
486@x [30.582] l.11276 - MLTeX: call |effective_char| in |new_character|
487begin ec:=effective_char(false,f,qi(c));
488@y
489begin
490if is_native_font(f) then
491  begin new_character:=new_native_character(f,c); return;
492  end;
493ec:=effective_char(false,f,qi(c));
494@z
495
496@x [32.619] l.12294 - MLTeX: substitute character in |hlist_out|
497label reswitch, move_past, fin_rule, next_p, continue, found;
498@y
499label reswitch, move_past, fin_rule, next_p, continue, found, check_next, end_node_run;
500@z
501
502@x
503if list_ptr(p)=null then cur_v:=cur_v+height(p)+depth(p)
504@y
505if list_ptr(p)=null then begin
506    if upwards then cur_v:=cur_v-depth(p)-height(p) else cur_v:=cur_v+height(p)+depth(p);
507  end
508@z
509
510@x [32.645] l.12780 - use print_file_name
511  print_nl("Output written on "); print_file_name(0, output_file_name, 0);
512@.Output written on x@>
513  print(" ("); print_int(total_pages);
514  if total_pages<>1 then print(" pages")
515  else print(" page");
516  print(", "); print_int(dvi_offset+dvi_ptr); print(" bytes).");
517  b_close(dvi_file);
518@y
519  k:=dvi_close(dvi_file);
520  if k=0 then begin
521    print_nl("Output written on "); print(output_file_name);
522@.Output written on x@>
523    print(" ("); print_int(total_pages);
524    if total_pages<>1 then print(" pages")
525    else print(" page");
526    if no_pdf_output then begin
527      print(", "); print_int(dvi_offset+dvi_ptr); print(" bytes).");
528    end else print(").");
529  end else begin
530    print_nl("Error "); print_int(k); print(" (");
531    if no_pdf_output then print_c_string(strerror(k))
532    else print("driver return code");
533    print(") generating output;");
534    print_nl("file "); print(output_file_name); print(" may not be valid.");
535    end;
536@z
537
538@x [43.943] l.18348 - bigtrie: Larger hyphenation tries.
539@!trie_used:array[ASCII_code] of trie_opcode;
540@y
541@!trie_used:array[0..biggest_lang] of trie_opcode;
542@z
543
544@x [43.946] l.18416 - bigtrie: And larger tries again.
545for k:=0 to 255 do trie_used[k]:=min_trie_op;
546@y
547for k:=0 to biggest_lang do trie_used[k]:=min_trie_op;
548@z
549
550@xx [43.958] l.18638 - bigtrie: Larger tries.
551  begin for r:=0 to 256 do clear_trie;
552  trie_max:=256;
553@y
554  begin for r:=0 to max_hyph_char do clear_trie;
555  trie_max:=max_hyph_char;
556@z
557
558@x [49.1222] l.22833 - MLTeX: \charsubdef primitive
559else begin n:=cur_chr; get_r_token; p:=cur_cs; define(p,relax,256);
560@y
561else begin n:=cur_chr; get_r_token; p:=cur_cs; define(p,relax,too_big_usv);
562@z
563
564@x [49.1275] l.23441 - Same stuff as for \input, this time for \openin.
565var c:0..1; {1 for \.{\\openin}, 0 for \.{\\closein}}
566@!n:0..15; {stream number}
567@y
568var c:0..1; {1 for \.{\\openin}, 0 for \.{\\closein}}
569@!n:0..15; {stream number}
570@!k:0..file_name_size; {index into |name_of_file16|}
571@z
572
573@x [49.1275] l.23441 - Same stuff as for \input, this time for \openin.
574     and a_open_in(read_file[n], kpse_tex_format) then
575    read_open[n]:=just_open;
576@y
577     and u_open_in(read_file[n], kpse_tex_format, XeTeX_default_input_mode, XeTeX_default_input_encoding) then
578    begin
579    make_utf16_name;
580    name_in_progress:=true;
581    begin_name;
582    stop_at_space:=false;
583    k:=0;
584    while (k<name_length16)and(more_name(name_of_file16[k])) do
585      incr(k);
586    stop_at_space:=true;
587    end_name;
588    name_in_progress:=false;
589    read_open[n]:=just_open;
590    end;
591@z
592
593@x [50.1302] l.23690 - store_fmt_file
594@!format_engine: ^text_char;
595@y
596@!format_engine: ^char;
597@z
598
599@x [50.1303] l.23722 - load_fmt_file
600@!format_engine: ^text_char;
601@!dummy_xord: ASCII_code;
602@!dummy_xchr: text_char;
603@!dummy_xprn: ASCII_code;
604@y
605@!format_engine: ^char;
606@z
607
608@x [50,1307] l.23779 - texarray
609format_engine:=xmalloc_array(text_char,x+4);
610@y
611format_engine:=xmalloc_array(char,x+4);
612@z
613
614@x [50,1307] l.23779 - texarray
615@<Dump |xord|, |xchr|, and |xprn|@>;
616@y
617@z
618
619@x [50.1308] l.23793 - texarray
620format_engine:=xmalloc_array(text_char, x);
621@y
622format_engine:=xmalloc_array(char, x);
623@z
624
625@x [50.1308] l.23793 - texarray
626@<Undump |xord|, |xchr|, and |xprn|@>;
627@y
628@z
629
630@x [50.1309] l.23814 - Make dumping/undumping more efficient.
631dump_things(str_start[0], str_ptr+1);
632@y
633dump_things(str_start_macro(too_big_char), str_ptr+1-too_big_char);
634@z
635
636@x [50.1310] l.23829 - Make dumping/undumping more efficient.
637undump_checked_things(0, pool_ptr, str_start[0], str_ptr+1);@/
638@y
639undump_checked_things(0, pool_ptr, str_start_macro(too_big_char), str_ptr+1-too_big_char);@/
640@z
641
642@x [50.1322] l.24000 - Make dumping/undumping more efficient - tfm
643  print_file_name(font_name[k],font_area[k],"");
644@y
645  if is_native_font(k) or (font_mapping[k]<>0) then
646    begin print_file_name(font_name[k],"","");
647    print_err("Can't \dump a format with native fonts or font-mappings");
648    help3("You really, really don't want to do this.")
649    ("It won't work, and only confuses me.")
650    ("(Load them at runtime, not as part of the format file.)");
651    error;
652    end
653  else print_file_name(font_name[k],font_area[k],"");
654@z
655
656@x [50.1322] l.24031 - Make dumping/undumping more efficient - tfm
657begin {Allocate the font arrays}
658@y
659begin {Allocate the font arrays}
660font_mapping:=xmalloc_array(void_pointer, font_max);
661font_layout_engine:=xmalloc_array(void_pointer, font_max);
662font_flags:=xmalloc_array(char, font_max);
663font_letter_space:=xmalloc_array(scaled, font_max);
664@z
665
666@x [50.1322] l.24031 - Make dumping/undumping more efficient - tfm
667font_bc:=xmalloc_array(eight_bits, font_max);
668font_ec:=xmalloc_array(eight_bits, font_max);
669@y
670font_bc:=xmalloc_array(UTF16_code, font_max);
671font_ec:=xmalloc_array(UTF16_code, font_max);
672@z
673
674@x [50.1322] l.24031 - Make dumping/undumping more efficient - tfm
675undump_things(font_check[null_font], font_ptr+1-null_font);
676@y
677for k:=null_font to font_ptr do font_mapping[k]:=0;
678undump_things(font_check[null_font], font_ptr+1-null_font);
679@z
680
681@x [51.1332] l.24203 - make the main program a procedure, for eqtb hack.
682  setup_bound_var (15000)('max_strings')(max_strings);
683@y
684  setup_bound_var (15000)('max_strings')(max_strings);
685  max_strings:=max_strings+too_big_char; {the |max_strings| value doesn't include the 64K synthetic strings}
686@z
687
688@x [51.1332] l.24203 - make the main program a procedure, for eqtb hack.
689  buffer:=xmalloc_array (ASCII_code, buf_size);
690@y
691  buffer:=xmalloc_array (UnicodeScalar, buf_size);
692@z
693
694@x [51.1332] l.24203 - make the main program a procedure, for eqtb hack.
695  input_file:=xmalloc_array (alpha_file, max_in_open);
696@y
697  input_file:=xmalloc_array (unicode_file, max_in_open);
698@z
699
700@x [51.1332] l.24203 (ca.) texarray
701  line_stack:=xmalloc_array (integer, max_in_open);
702@y
703  line_stack:=xmalloc_array (integer, max_in_open);
704  eof_seen:=xmalloc_array (boolean, max_in_open);
705  grp_stack:=xmalloc_array (save_pointer, max_in_open);
706  if_stack:=xmalloc_array (pointer, max_in_open);
707@z
708
709@x [51.1333] l.24254 - Print new line before termination; switch to editor if necessary.
710    print_file_name(0, log_name, 0); print_char(".");
711@y
712    print(log_name); print_char(".");
713@z
714
715@x [51.1337] l.24371 (ca.) texarray
716  trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
717@y
718  trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
719  hyph_root:=0; hyph_start:=0;
720@z
721
722@x [51.1337] l.24371 - Allocate hyphenation tries, do char translation, MLTeX
723  {Allocate and initialize font arrays}
724@y
725  {Allocate and initialize font arrays}
726  font_mapping:=xmalloc_array(void_pointer, font_max);
727  font_layout_engine:=xmalloc_array(void_pointer, font_max);
728  font_flags:=xmalloc_array(char, font_max);
729  font_letter_space:=xmalloc_array(scaled, font_max);
730@z
731
732@x [51.1337] l.24371 - Allocate hyphenation tries, do char translation, MLTeX
733  font_bc:=xmalloc_array(eight_bits, font_max);
734  font_ec:=xmalloc_array(eight_bits, font_max);
735@y
736  font_bc:=xmalloc_array(UTF16_code, font_max);
737  font_ec:=xmalloc_array(UTF16_code, font_max);
738@z
739
740@x [51.1337] l.24371 - Allocate hyphenation tries, do char translation, MLTeX
741  param_base[null_font]:=-1;
742@y
743  font_mapping[null_font]:=0;
744  param_base[null_font]:=-1;
745@z
746
747@x [53.1348] (do_extension) Remove unused variables
748var k:integer; {all-purpose integers}
749@y
750var i,@!j,@!k:integer; {all-purpose integers}
751@z
752
753@x [53.1370] l.24779 - system: (write_out) \write18{foo} => system(foo).
754    print(so(str_pool[str_start[str_ptr]+d])); {N.B.: not |print_char|}
755@y
756    print(so(str_pool[str_start_macro(str_ptr)+d])); {N.B.: not |print_char|}
757@z
758
759@x [53.1370] l.24779 - system: (write_out) \write18{foo} => system(foo).
760        str_pool[str_start[str_ptr]+d]:=xchr[str_pool[str_start[str_ptr]+d]];
761        if (str_pool[str_start[str_ptr]+d]=null_code)
762@y
763      if (str_pool[str_start_macro(str_ptr)+d]=null_code)
764@z
765
766@x [53.1370] l.24779 - convert from UTF-16 to UTF-8 for system(3).
767      runsystem_ret := runsystem(conststringcast(addressof(
768                                              str_pool[str_start[str_ptr]])));
769@y
770      if name_of_file then libc_free(name_of_file);
771      name_of_file := xmalloc(cur_length * 3 + 2);
772      k := 0;
773      for d:=0 to cur_length-1 do
774        append_to_name(str_pool[str_start_macro(str_ptr)+d]);
775      name_of_file[k+1] := 0;
776      runsystem_ret := runsystem(conststringcast(name_of_file+1));
777@z
778
779@x [53.1370] l.24779 - system: (write_out) \write18{foo} => system(foo).
780  pool_ptr:=str_start[str_ptr];  {erase the string}
781@y
782  pool_ptr:=str_start_macro(str_ptr);  {erase the string}
783@z
784
785@x [53a.1379] l.??? -etex command line switch
786@!init if (buffer[loc]="*")and(format_ident=" (INITEX)") then
787@y
788@!init if (etex_p or(buffer[loc]="*"))and(format_ident=" (INITEX)") then
789@z
790
791@x [53a.1379] l.??? -etex command line switch
792  incr(loc); eTeX_mode:=1; {enter extended mode}
793@y
794  if buffer[loc]="*" then incr(loc);
795  eTeX_mode:=1; {enter extended mode}
796@z
797
798@x [53a.1383] l.??? -etex command line switch
799@!eTeX_mode: 0..1; {identifies compatibility and extended mode}
800@y
801@!eTeX_mode: 0..1; {identifies compatibility and extended mode}
802@!etex_p: boolean; {was the -etex option specified}
803@z
804
805@x [53a.1391] l.??? texarray
806@!eof_seen : array[1..max_in_open] of boolean; {has eof been seen?}
807@y
808@!eof_seen : ^boolean; {has eof been seen?}
809@z
810
811@x [53a.1506] l.??? texarray
812@!grp_stack : array[0..max_in_open] of save_pointer; {initial |cur_boundary|}
813@!if_stack : array[0..max_in_open] of pointer; {initial |cond_ptr|}
814@y
815@!grp_stack : ^save_pointer; {initial |cur_boundary|}
816@!if_stack : ^pointer; {initial |cond_ptr|}
817@z
818
819@x [54.1376] l.24903 - print_csnames
820      for c := str_start[text(h)] to str_start[text(h) + 1] - 1
821@y
822      for c := str_start_macro(text(h)) to str_start_macro(text(h) + 1) - 1
823@z
824
825@x [54.1376] l.24903 - Dumping/Undumping
826@ Dumping the |xord|, |xchr|, and |xprn| arrays.  We dump these always
827in the format, so a TCX file loaded during format creation can set a
828default for users of the format.
829
830@<Dump |xord|, |xchr|, and |xprn|@>=
831dump_things(xord[0], 256);
832dump_things(xchr[0], 256);
833dump_things(xprn[0], 256);
834
835@ Undumping the |xord|, |xchr|, and |xprn| arrays.  This code is more
836complicated, because we want to ensure that a TCX file specified on
837the command line will override whatever is in the format.  Since the
838tcx file has already been loaded, that implies throwing away the data
839in the format.  Also, if no |translate_filename| is given, but
840|eight_bit_p| is set we have to make all characters printable.
841
842@<Undump |xord|, |xchr|, and |xprn|@>=
843if translate_filename then begin
844  for k:=0 to 255 do undump_things(dummy_xord, 1);
845  for k:=0 to 255 do undump_things(dummy_xchr, 1);
846  for k:=0 to 255 do undump_things(dummy_xprn, 1);
847  end
848else begin
849  undump_things(xord[0], 256);
850  undump_things(xchr[0], 256);
851  undump_things(xprn[0], 256);
852  if eight_bit_p then
853    for k:=0 to 255 do
854      xprn[k]:=1;
855end;
856
857
858@y
859@z
860
861@x
862  while s>255 do  {first 256 strings depend on implementation!!}
863@y
864  while s>65535 do  {first 64K strings don't really exist in the pool!}
865@z
866
867@x
868@!mltex_enabled_p:boolean;  {enable character substitution}
869@y
870@!mltex_enabled_p:boolean;  {enable character substitution}
871@!native_font_type_flag:integer; {used by XeTeX font loading code to record which font technology was used}
872@!xtx_ligature_present:boolean; {to suppress tfm font mapping of char codes from ligature nodes (already mapped)}
873@z
874
875@x [54/web2c.???] l.??? needed earlier
876replacement, but always existing character |font_bc[f]|.
877@^inner loop@>
878
879@<Declare additional functions for ML\TeX@>=
880function effective_char(@!err_p:boolean;
881@y
882replacement, but always existing character |font_bc[f]|.
883@^inner loop@>
884
885@<Declare \eTeX\ procedures for sc...@>=
886function effective_char(@!err_p:boolean;
887@z
888
889@x
890begin result:=c;  {return |c| unless it does not exist in the font}
891@y
892begin if (not xtx_ligature_present) and (font_mapping[f]<>nil) then
893  c:=apply_tfm_font_mapping(font_mapping[f],c);
894xtx_ligature_present:=false;
895result:=c;  {return |c| unless it does not exist in the font}
896@z
897
898@x
899begin if not mltex_enabled_p then
900@y
901begin if (not xtx_ligature_present) and (font_mapping[f]<>nil) then
902  c:=apply_tfm_font_mapping(font_mapping[f],c);
903xtx_ligature_present:=false;
904if not mltex_enabled_p then
905@z
906
907@x
908effective_char_info:=null_character;
909exit:end;
910@y
911effective_char_info:=null_character;
912exit:end;
913@#
914@<Declare subroutines for |new_character|@>@;
915@z
916