home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / todo / dynamic / tex / ctex.ch next >
Text File  |  1996-09-28  |  67KB  |  1,825 lines

  1. % Change file for TeX in C, derived from various other change files.
  2. % By Tim Morgan, UC Irvine ICS Department, and many others.
  3. %
  4. %
  5. % Modification history:
  6. %
  7. % (05/28/86) ETM Started with TeX 2.0
  8. % (06/03/87) ETM Brought up to TeX 2.2
  9. % (09/26/87) ETM Brought up to TeX 2.3
  10. % (10/01/87) ETM Brought up to TeX 2.5
  11. % (12/21/87) ETM Brought up to TeX 2.7
  12. % (01/14/88) ETM Brought up to TeX 2.9
  13. % (02/20/88) PAM Revised format and module numbers
  14. % (03/01/88) ETM Eliminated some unused variables and unnecesary tests
  15. % (05/09/88) ETM Added yet another casting bug fix
  16. % (06/21/88) ETM Brought up to TeX version 2.93
  17. % (12/11/88) ETM Brought up to TeX version 2.94
  18. % (01/12/89) PAM Brought up to TeX version 2.95
  19. % (02/14/89) ETM Brought up to TeX version 2.96
  20. % (03/10/89) ETM Brought up to TeX version 2.98
  21. % (07/06/89) ETM Brought up to TeX version 2.991
  22. % (11/30/89) KB  To version 2.992 (8-bit).
  23. % (01/10/90) SR  To version 2.993.
  24. % (03/27/90) KY  To version 3.0.
  25. % (12/05/90) KY  Version 3.1, run time array allocation
  26. % NOTE: the module numbers in this change file refer to the published
  27. %    text in TeX: The Program, Volume B of Computers&Typesetting, 1986.
  28.  
  29.  
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. % [0] WEAVE: print changes only.
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. @x
  34.   \def\?##1]{\hbox to 1in{\hfil##1.\ }}
  35.   }
  36. @y
  37.   \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
  38.   }
  39. \let\maybe=\iffalse
  40. @z
  41.  
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. % [1.2] banner
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  45. @x
  46. @d banner=='This is TeX, Version 3.1' {printed when \TeX\ starts}
  47. @y
  48. @d banner=='This is TeX, C Version 3.1 (with run time sizing)' {printed when \TeX\ starts}
  49. @z
  50.  
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. % [1.4] program header
  53. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54. @x
  55. Actually the heading shown here is not quite normal: The |program| line
  56. does not mention any |output| file, because \ph\ would ask the \TeX\ user
  57. to specify a file name if |output| were specified here.
  58. @^system dependencies@>
  59.  
  60. @d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
  61. @f mtype==type {`\&{mtype}' will be equivalent to `\&{type}'}
  62. @f type==true {but `|type|' will not be treated as a reserved word}
  63.  
  64. @p @t\4@>@<Compiler directives@>@/
  65. program TEX; {all file names are defined dynamically}
  66. label @<Labels in the outer block@>@/
  67. @y
  68.  
  69. @d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
  70. @f mtype==type {`\&{mtype}' will be equivalent to `\&{type}'}
  71. @f type==true {but `|type|' will not be treated as a reserved word}
  72.  
  73. @p @t\4@>@<Compiler directives@>@/
  74. program TEX; {all file names are defined dynamically}
  75. @z
  76.  
  77. @x
  78. @<Labels in the out...@>=
  79. start_of_TEX@t\hskip-2pt@>, end_of_TEX@t\hskip-2pt@>,@,final_end;
  80.   {key control points}
  81. @y
  82. @<Labels in the outer block@>=
  83. start_of_TEX@t\hskip-2pt@>, end_of_TEX@t\hskip-2pt@>,@,final_end;
  84.   {key control points}
  85. @z
  86.  
  87. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  88. % [1.7] debug..gubed, stat..tats
  89. % Here we change these WEB symbols, which are used much as #ifdef's
  90. % are in C, into something which will get translated into actual #ifdef's.
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92. @x
  93. @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging}
  94. @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging}
  95. @y
  96. @d debug==ifdef('DEBUG')
  97. @d gubed==endif('DEBUG')
  98. @z
  99. @x
  100. @d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering
  101.   usage statistics}
  102. @d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering
  103.   usage statistics}
  104. @y
  105. @d stat==ifdef('STAT')
  106. @d tats==endif('STAT')
  107. @z
  108.  
  109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110. % [1.8] Same, for `init..tini'.
  111. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  112. @x
  113. @d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version}
  114. @d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version}
  115. @y
  116. @d init==ifdef('INITEX')
  117. @d tini==endif('INITEX')
  118. @z
  119.  
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. % [1.9] Turn off all compiler directives.
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. @x
  124. @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
  125. @!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging}
  126. @y
  127. @z
  128.  
  129. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  130. % [1.11] Compile-time constants: some enlarged, dvi_buf_size 16K for
  131. % BSD I/O, file_name_size becomes FILENAMESIZE.
  132. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  133. @x
  134. @<Constants...@>=
  135. @!mem_max=30000; {greatest index in \TeX's internal |mem| array;
  136.   must be strictly less than |max_halfword|;
  137.   must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
  138. @!mem_min=0; {smallest index in \TeX's internal |mem| array;
  139.   must be |min_halfword| or more;
  140.   must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
  141. @!buf_size=500; {maximum number of characters simultaneously present in
  142.   current lines of open files and in control sequences between
  143.   \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
  144. @!error_line=72; {width of context lines on terminal error messages}
  145. @!half_error_line=42; {width of first lines of contexts in terminal
  146.   error messages; should be between 30 and |error_line-15|}
  147. @!max_print_line=79; {width of longest text lines output; should be at least 60}
  148. @!stack_size=200; {maximum number of simultaneous input sources}
  149. @!max_in_open=6; {maximum number of input files and error insertions that
  150.   can be going on simultaneously}
  151. @!font_max=75; {maximum internal font number; must not exceed |max_quarterword|
  152.   and must be at most |font_base+256|}
  153. @!font_mem_size=20000; {number of words of |font_info| for all fonts}
  154. @!param_size=60; {maximum number of simultaneous macro parameters}
  155. @!nest_size=40; {maximum number of semantic levels simultaneously active}
  156. @!max_strings=3000; {maximum number of strings; must not exceed |max_halfword|}
  157. @!string_vacancies=8000; {the minimum number of characters that should be
  158.   available for the user's control sequences and font names,
  159.   after \TeX's own error messages are stored}
  160. @!pool_size=32000; {maximum number of characters in strings, including all
  161.   error messages and help texts, and the names of all fonts and
  162.   control sequences; must exceed |string_vacancies| by the total
  163.   length of \TeX's own strings, which is currently about 23000}
  164. @!save_size=600; {space for saving values outside of current group; must be
  165.   at most |max_halfword|}
  166. @!trie_size=8000; {space for hyphenation patterns; should be larger for
  167.   \.{INITEX} than it is in production versions of \TeX}
  168. @!trie_op_size=500; {space for ``opcodes'' in the hyphenation patterns}
  169. @!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8}
  170. @!file_name_size=40; {file names shouldn't be longer than this}
  171. @!pool_name='TeXformats:TEX.POOL                     ';
  172.   {string of length |file_name_size|; tells where the string pool appears}
  173. @y
  174. @d file_name_size == FILENAMESIZE {Get value from \.{site.h}.}
  175. @<Constants...@>=
  176. @!mem_min=0; {smallest index in \TeX's internal |mem| array;
  177.   must be |min_halfword| or more;
  178.   must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
  179. @!buf_size=2000; {maximum number of characters simultaneously present in
  180.   current lines of open files and in control sequences between
  181.   \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
  182. @!error_line=79; {width of context lines on terminal error messages}
  183. @!half_error_line=50; {width of first lines of contexts in terminal
  184.   error messages; should be between 30 and |error_line-15|}
  185. @!max_print_line=79; {width of longest text lines output; should be at least 60}
  186. @!font_max=255; {maximum internal font number; must not exceed |max_quarterword|
  187.   and must be at most |font_base+256|}
  188. @!param_size=60; {maximum number of simultaneous macro parameters}
  189. @!nest_size=40; {maximum number of semantic levels simultaneously active}
  190. @!string_vacancies=15000; {the minimum number of characters that should be
  191.   available for the user's control sequences and font names,
  192.   after \TeX's own error messages are stored}
  193. @!trie_size=8000; {space for hyphenation patterns; should be larger for
  194.   \.{INITEX} than it is in production versions of \TeX}
  195. @!trie_op_size=500; {space for ``opcodes'' in the hyphenation patterns}
  196. @!neg_trie_op_size=-500; {for lower trie_op_hash array bound}
  197. @!dvi_buf_size=16384; {size of the output buffer; must be a multiple of 8}
  198. @!pool_name='tex.pool';
  199.   {string of length |file_name_size|; tells where the string pool appears}
  200. @z
  201.  
  202. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  203. % [1.12] Sensitive compile-time constants.  For C we change mem_base and
  204. % hi_mem_base to reflect our use of 0-origin vs pc's use of
  205. % negative-origin.  Despite the fact that it is a ``sensitive''
  206. % constants, we're going to make mem_top a #define in the C code for
  207. % readability and ease of modification (it's up above), since to needs
  208. % to be changed for the trip test.
  209. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  210. @x
  211. @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX};
  212.   must not be less than |mem_min|}
  213. @d mem_top==30000 {largest index in the |mem| array dumped by \.{INITEX};
  214.   must be substantially larger than |mem_bot|
  215.   and not greater than |mem_max|}
  216. @d font_base=0 {smallest internal font number; must not be less
  217.   than |min_quarterword|}
  218. @d hash_size=2100 {maximum number of control sequences; it should be at most
  219.   about |(mem_max-mem_min)/10|}
  220. @d hash_prime=1777 {a prime number equal to about 85\pct! of |hash_size|}
  221. @y
  222. @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX};
  223.   must not be less than |mem_min|}
  224. @d font_base=0 {smallest internal font number; must not be less
  225.   than |min_quarterword|}
  226. @d hash_size=3000 {maximum number of control sequences; it should be at most
  227.   about |(mem_max-mem_min)/10|}
  228. @d hash_prime=2551 {a prime number equal to about 85\pct! of |hash_size|}
  229. @z
  230.  
  231. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  232. % [1.16] Use C macros for `incr' and `decr'.
  233. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  234. @x
  235. @d incr(#) == #:=#+1 {increase a variable by unity}
  236. @d decr(#) == #:=#-1 {decrease a variable by unity}
  237. @y
  238. @z
  239.  
  240. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  241. % [??] The text_char type is used as an array index into xord.  The
  242. % default type `char' produces signed integers, which are bad array
  243. % indices in C.
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  245. @x
  246. @d text_char == char {the data type of characters in text files}
  247. @y
  248. @d text_char == ASCII_code {the data type of characters in text files}
  249. @z
  250.  
  251. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  252. % [2.23] Allow any character as input.
  253. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  254. @x
  255. for i:=0 to @'37 do xchr[i]:=' ';
  256. for i:=@'177 to @'377 do xchr[i]:=' ';
  257. @y
  258. for i:=0 to @'37 do xchr[i]:=chr(i);
  259. for i:=@'177 to @'377 do xchr[i]:=chr(i);
  260. @z
  261.  
  262. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  263. % [3.25] Remove file types we don't need.
  264. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  265. @x
  266. The program actually makes use also of a third kind of file, called a
  267. |word_file|, when dumping and reloading base information for its own
  268. initialization.  We shall define a word file later; but it will be possible
  269. for us to specify simple operations on word files before they are defined.
  270.  
  271. @y
  272. I/O in C is done using standard I/O.  We will define the path numbers
  273. in an include file for C which are used in searching for files to be
  274. read.  We'll define all the file types in C also.
  275. @z
  276.  
  277. @x
  278. @!alpha_file=packed file of text_char; {files that contain textual data}
  279. @!byte_file=packed file of eight_bits; {files that contain binary data}
  280. @y
  281. @z
  282.  
  283. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  284. % [3.27] Do file opening in C.
  285. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  286. @x
  287. @ The \ph\ compiler with which the present version of \TeX\ was prepared has
  288. extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
  289. we can write
  290. $$\vbox{\halign{#\hfil\qquad&#\hfil\cr
  291. |reset(f,@t\\{name}@>,'/O')|&for input;\cr
  292. |rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
  293. The `\\{name}' parameter, which is of type `{\bf packed array
  294. $[\langle\\{any}\rangle]$ of \\{char}}', stands for the name of
  295. the external file that is being opened for input or output.
  296. Blank spaces that might appear in \\{name} are ignored.
  297.  
  298. The `\.{/O}' parameter tells the operating system not to issue its own
  299. error messages if something goes wrong. If a file of the specified name
  300. cannot be found, or if such a file cannot be opened for some other reason
  301. (e.g., someone may already be trying to write the same file), we will have
  302. |@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|.  This allows
  303. \TeX\ to undertake appropriate corrective action.
  304. @:PASCAL H}{\ph@>
  305. @^system dependencies@>
  306.  
  307. \TeX's file-opening procedures return |false| if no file identified by
  308. |name_of_file| could be opened.
  309.  
  310. @d reset_OK(#)==erstat(#)=0
  311. @d rewrite_OK(#)==erstat(#)=0
  312.  
  313. @p function a_open_in(var f:alpha_file):boolean;
  314.   {open a text file for input}
  315. begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
  316. end;
  317. @#
  318. function a_open_out(var f:alpha_file):boolean;
  319.   {open a text file for output}
  320. begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
  321. end;
  322. @#
  323. function b_open_in(var f:byte_file):boolean;
  324.   {open a binary file for input}
  325. begin reset(f,name_of_file,'/O'); b_open_in:=reset_OK(f);
  326. end;
  327. @#
  328. function b_open_out(var f:byte_file):boolean;
  329.   {open a binary file for output}
  330. begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f);
  331. end;
  332. @#
  333. function w_open_in(var f:word_file):boolean;
  334.   {open a word file for input}
  335. begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f);
  336. end;
  337. @#
  338. function w_open_out(var f:word_file):boolean;
  339.   {open a word file for output}
  340. begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f);
  341. end;
  342. @y
  343. @ All of the file opening functions are defined in C.
  344. @z
  345.  
  346. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  347. % [3.28] Do file closing in C.
  348. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  349. @x
  350. @ Files can be closed with the \ph\ routine `|close(f)|', which
  351. @^system dependencies@>
  352. should be used when all input or output with respect to |f| has been completed.
  353. This makes |f| available to be opened again, if desired; and if |f| was used for
  354. output, the |close| operation makes the corresponding external file appear
  355. on the user's area, ready to be read.
  356.  
  357. These procedures should not generate error messages if a file is
  358. being closed before it has been successfully opened.
  359.  
  360. @p procedure a_close(var f:alpha_file); {close a text file}
  361. begin close(f);
  362. end;
  363. @#
  364. procedure b_close(var f:byte_file); {close a binary file}
  365. begin close(f);
  366. end;
  367. @#
  368. procedure w_close(var f:word_file); {close a word file}
  369. begin close(f);
  370. end;
  371. @y
  372. @ And all the file closing routines as well.
  373. @z
  374.  
  375. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  376. % [3.31] Do `input_ln' in C.
  377. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  378. @x
  379. @p function input_ln(var f:alpha_file;@!bypass_eoln:boolean):boolean;
  380.   {inputs the next line or returns |false|}
  381. var last_nonblank:0..buf_size; {|last| with trailing blanks removed}
  382. begin if bypass_eoln then if not eof(f) then get(f);
  383.   {input the first character of the line into |f^|}
  384. last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
  385. if eof(f) then input_ln:=false
  386. else  begin last_nonblank:=first;
  387.   while not eoln(f) do
  388.     begin if last>=max_buf_stack then
  389.       begin max_buf_stack:=last+1;
  390.       if max_buf_stack=buf_size then
  391.         @<Report overflow of the input buffer, and abort@>;
  392.       end;
  393.     buffer[last]:=xord[f^]; get(f); incr(last);
  394.     if buffer[last-1]<>" " then last_nonblank:=last;
  395.     end;
  396.   last:=last_nonblank; input_ln:=true;
  397.   end;
  398. end;
  399. @y
  400. We define |input_ln| in C, for efficiency.
  401. @z
  402.  
  403. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  404. % [3.32] `term_in' and `term_out' are standard input and output.
  405. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  406. @x
  407. @<Glob...@>=
  408. @!term_in:alpha_file; {the terminal as an input file}
  409. @!term_out:alpha_file; {the terminal as an output file}
  410. @y
  411. @d term_in==stdin {the terminal as an input file}
  412. @d term_out==stdout {the terminal as an output file}
  413. @z
  414.  
  415. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  416. % [3.33] We don't need to open terminal files.
  417. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  418. @x
  419. @ Here is how to open the terminal files
  420. in \ph. The `\.{/I}' switch suppresses the first |get|.
  421. @^system dependencies@>
  422.  
  423. @d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input}
  424. @d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output}
  425. @y
  426. @ Here is how to open the terminal files.  |t_open_out| does nothing.
  427. |t_open_in|, on the other hand, does the work of ``rescanning,'' or getting
  428. any command line arguments the user has provided.  It's defined in C.
  429.  
  430. @d t_open_out == {output already open for text output}
  431. @z
  432.  
  433. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  434. % [3.34] Flushing output.
  435. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  436. @x
  437. these operations can be specified in \ph:
  438. @^system dependencies@>
  439.  
  440. @d update_terminal == break(term_out) {empty the terminal output buffer}
  441. @d clear_terminal == break_in(term_in,true) {clear the terminal input buffer}
  442. @d wake_up_terminal == do_nothing {cancel the user's cancellation of output}
  443. @y
  444. these operations can be specified with {\mc UNIX}.  |update_terminal|
  445. does an |fflush| (via the macro |flush|), since that's easy.
  446. |wake_up_terminal| and |clear_terminal| are defined in C routines, if
  447. desired.
  448. @^system dependencies@>
  449.  
  450. @d update_terminal == flush(term_out)
  451. @z
  452.  
  453. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  454. % [3.37] Reading the command line.
  455. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  456. @x
  457. @ The following program does the required initialization
  458. without retrieving a possible command line.
  459. It should be clear how to modify this routine to deal with command lines,
  460. if the system permits them.
  461. @^system dependencies@>
  462.  
  463. @p function init_terminal:boolean; {gets the terminal input started}
  464. label exit;
  465. begin t_open_in;
  466. loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal;
  467. @.**@>
  468.   if not input_ln(term_in,true) then {this shouldn't happen}
  469.     begin write_ln(term_out);
  470.     write(term_out,'! End of file on the terminal... why?');
  471. @.End of file on the terminal@>
  472.     init_terminal:=false; return;
  473.     end;
  474.   loc:=first;
  475.   while (loc<last)and(buffer[loc]=" ") do incr(loc);
  476.   if loc<last then
  477.     begin init_terminal:=true;
  478.     return; {return unless the line was all blank}
  479.     end;
  480.   write_ln(term_out,'Please type the name of your input file.');
  481.   end;
  482. exit:end;
  483. @y
  484. @ The following program does the required initialization.
  485. Iff anything has been specified on the command line, then |t_open_in|
  486. will return with |last > first|.
  487. @^system dependencies@>
  488.  
  489. @p
  490. function init_terminal:boolean; {gets the terminal input started}
  491. label exit;
  492. begin
  493.     t_open_in;
  494.     if last > first then begin
  495.         loc := first;
  496.         while (loc < last) and (buffer[loc]=' ') do
  497.         incr(loc);
  498.         if loc < last then begin
  499.             init_terminal := true;
  500.             goto exit;
  501.         end;
  502.     end;
  503.     loop@+begin
  504.         wake_up_terminal; write(term_out, '**'); update_terminal;
  505. @.**@>
  506.         if not input_ln(term_in,true) then begin {this shouldn't happen}
  507.             write_ln(term_out);
  508.             write(term_out, '! End of file on the terminal... why?');
  509. @.End of file on the terminal@>
  510.             init_terminal:=false;
  511.         return;
  512.         end;
  513.  
  514.         loc:=first;
  515.         while (loc<last)and(buffer[loc]=" ") do
  516.             incr(loc);
  517.  
  518.         if loc<last then begin
  519.            init_terminal:=true;
  520.            return; {return unless the line was all blank}
  521.         end;
  522.         write_ln(term_out, 'Please type the name of your input file.');
  523.     end;
  524. exit:
  525. end;
  526. @z
  527.  
  528. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  529. % [4.?] str_pool is allocated at run time in C. pool_size is a var.
  530. % Include file that contains linkage to pointer vars in C routines.
  531. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  532. @x
  533. @<Types...@>=
  534. @!pool_pointer = 0..pool_size; {for variables that point into |str_pool|}
  535. @!str_number = 0..max_strings; {for variables that point into |str_start|}
  536. @!packed_ASCII_code = 0..255; {elements of |str_pool| array}
  537.  
  538. @ @<Glob...@>=
  539. @!str_pool:packed array[pool_pointer] of packed_ASCII_code; {the characters}
  540. @!str_start : array[str_number] of pool_pointer; {the starting pointers}
  541. @y
  542. @<Types...@>=
  543. @!pool_pointer = integer; {for variables that point into |str_pool|}
  544. @!str_number = integer; {for variables that point into |str_start|}
  545. @!packed_ASCII_code = 0..255; {elements of |str_pool| array}
  546.  
  547. @ @<Glob...@>=
  548. @!pool_size : integer; {maximum number of characters in strings, including all
  549.   error messages and help texts, and the names of all fonts and
  550.   control sequences; must exceed |string_vacancies| by the total
  551.   length of \TeX's own strings, which is currently about 23000}
  552. @!max_strings : integer; {maximum number of strings; must not exceed |max_halfword|}
  553. @=#include "../common/dynamic.h";@>
  554. @z
  555.  
  556. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  557. % [4.51] Open the pool file using a path, and can't do string
  558. % assignments directly.  (`strcpy' and `strlen' work here because
  559. % `pool_name' is a constant string, and thus ends in a null and doesn't
  560. % start with a space.)
  561. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  562. @x
  563. name_of_file:=pool_name; {we needn't set |name_length|}
  564. if a_open_in(pool_file) then
  565. @y
  566. vstrcpy (name_of_file+1, pool_name); {copy the string}
  567. name_of_file[0] := ' ';
  568. name_of_file[strlen (pool_name)+1] := ' ';
  569. if a_open_in (pool_file, TEX_POOL_PATH) then
  570. @z
  571.  
  572. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  573. % [4.51,52,53] Make `TEX.POOL' lowercase in messages, and change how
  574. % it's read.
  575. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  576. @x
  577. else  bad_pool('! I can''t read TEX.POOL.')
  578. @y
  579. else begin
  580.    {Like |bad_pool|, but must not close file if we never opened it}
  581.    wake_up_terminal; write_ln(term_out, '! I can''t read tex.pool.');
  582.    get_strings_started:= false; return;
  583. end
  584. @z
  585. @x
  586. begin if eof(pool_file) then bad_pool('! TEX.POOL has no check sum.');
  587. @.TEX.POOL has no check sum@>
  588. read(pool_file,m,n); {read two digits of string length}
  589. @y
  590. begin if eof(pool_file) then bad_pool('! tex.pool has no check sum.');
  591. @.TEX.POOL has no check sum@>
  592. read(pool_file,m); read(pool_file,n); {read two digits of string length}
  593. @z
  594. @x
  595.     bad_pool('! TEX.POOL line doesn''t begin with two digits.');
  596. @y
  597.     bad_pool('! tex.pool line doesn''t begin with two digits.');
  598. @z
  599. @x
  600.   bad_pool('! TEX.POOL check sum doesn''t have nine digits.');
  601. @y
  602.   bad_pool('! tex.pool check sum doesn''t have nine digits.');
  603. @z
  604. @x
  605. done: if a<>@$ then bad_pool('! TEX.POOL doesn''t match; TANGLE me again.');
  606. @y
  607. done: if a<>@$ then bad_pool('! tex.pool doesn''t match; tangle me again.');
  608. @z
  609.  
  610. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  611. % [5.61] Eliminate the misleading message ``(no format preloaded)''.
  612. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  613. @x
  614. if format_ident=0 then wterm_ln(' (no format preloaded)')
  615. else  begin print(format_ident); print_ln;
  616.   end;
  617. @y
  618. if format_ident>0 then print(format_ident); 
  619. print_ln;
  620. @z
  621.  
  622. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  623. % [6.81] Eliminate nonlocal goto, since C doesn't have them.
  624. % Plus, it's nicer just to do an exit with the appropriate status code
  625. % under Unix.  We call it `uexit' because there's a WEB symbol called
  626. % `exit' already.  We use a C macro to change `uexit' back to `exit'.
  627. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  628. @x
  629. @<Error hand...@>=
  630. procedure jump_out;
  631. begin goto end_of_TEX;
  632. end;
  633. @y
  634. @d do_final_end==begin
  635.    update_terminal;
  636.    ready_already:=0;
  637.    if (history <> spotless) and (history <> warning_issued) then
  638.        uexit(1)
  639.    else
  640.        uexit(0);
  641.    end
  642. @<Error hand...@>=
  643. procedure jump_out;
  644. begin
  645. close_files_and_terminate;
  646. do_final_end;
  647. end;
  648. @z
  649.  
  650. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  651. % [6.84] Implement the switch-to-editor option.
  652. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  653. @x
  654. line ready to be edited. But such an extension requires some system
  655. wizardry, so the present implementation simply types out the name of the
  656. file that should be
  657. edited and the relevant line number.
  658. @^system dependencies@>
  659.  
  660. There is a secret `\.D' option available when the debugging routines haven't 
  661. been commented~out.
  662. @^debugging@>
  663. @y
  664. line ready to be edited.
  665. We do this by calling the external procedure |call_edit| with a pointer to
  666. the filename, its length, and the line number.
  667. However, here we just set up the variables that will be used as arguments,
  668. since we don't want to do the switch-to-editor until after TeX has closed
  669. its files.
  670. @^system dependencies@>
  671.  
  672. There is a secret `\.D' option available when the debugging routines haven't
  673. been commented~out.
  674. @^debugging@>
  675. @d edit_file==input_stack[base_ptr]
  676. @z
  677. @x
  678. "E": if base_ptr>0 then
  679.   begin print_nl("You want to edit file ");
  680. @.You want to edit file x@>
  681.   print(input_stack[base_ptr].name_field);
  682.   print(" at line "); print_int(line);
  683.   interaction:=scroll_mode; jump_out;
  684. @y
  685. "E": if base_ptr>0 then
  686.     begin
  687.     edit_name_start:=str_start[edit_file.name_field];
  688.     edit_name_length:=str_start[edit_file.name_field+1] -
  689.                   str_start[edit_file.name_field];
  690.     edit_line:=line;
  691.     jump_out;
  692. @z
  693.  
  694. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  695. % [7.109] Define glue_ratio in C.
  696. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  697. @x
  698. @!glue_ratio=real; {one-word representation of a glue expansion factor}
  699. @y
  700. @z
  701.  
  702. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  703. % [8.110] Make it easy to build a bigger TeX.  (Nothing is changed in
  704. % the basic version.)
  705. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  706. @x
  707. @d min_quarterword=0 {smallest allowable value in a |quarterword|}
  708. @d max_quarterword=255 {largest allowable value in a |quarterword|}
  709. @d min_halfword==0 {smallest allowable value in a |halfword|}
  710. @d max_halfword==65535 {largest allowable value in a |halfword|}
  711. @y
  712. @d min_quarterword=0 {smallest allowable value in a |quarterword|}
  713. @d max_quarterword=255 {largest allowable value in a |quarterword|}
  714. @d min_halfword==0 {smallest allowable value in a |halfword|}
  715. @d max_halfword==16777215 {largest allowable value in a |halfword|}
  716. @z
  717.  
  718. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  719. % [8.112] Efficiency.
  720. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  721. @x
  722. The inner loop of \TeX\ will run faster with respect to compilers
  723. that don't optimize expressions like `|x+0|' and `|x-0|', if these
  724. macros are simplified in the obvious way when |min_quarterword=0|.
  725. @^inner loop@>@^system dependencies@>
  726.  
  727. @d qi(#)==#+min_quarterword
  728.   {to put an |eight_bits| item into a quarterword}
  729. @d qo(#)==#-min_quarterword
  730.   {to take an |eight_bits| item out of a quarterword}
  731. @d hi(#)==#+min_halfword
  732.   {to put a sixteen-bit item into a halfword}
  733. @d ho(#)==#-min_halfword
  734.   {to take a sixteen-bit item from a halfword}
  735. @y
  736. The inner loop of \TeX\ will run faster with respect to compilers
  737. that don't optimize expressions like `|x+0|' and `|x-0|', if these
  738. macros are simplified in the obvious way when |min_quarterword=0|.
  739. So they have been simplified here in the obvious way.
  740. @^inner loop@>@^system dependencies@>
  741.  
  742. @d qi(#)==# {to put an |eight_bits| item into a quarterword}
  743. @d qo(#)==# {to take an |eight_bits| item from a quarterword}
  744. @d hi(#)==# {to put a sixteen-bit item into a halfword}
  745. @d ho(#)==# {to take a sixteen-bit item from a halfword}
  746. @z
  747.  
  748. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  749. % [8.113] Put the memory structure into an include file, since it's too
  750. % hard to translate automatically.  Also, remove the `word_file' type.
  751. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  752. @x
  753. @!quarterword = min_quarterword..max_quarterword; {1/4 of a word}
  754. @!halfword=min_halfword..max_halfword; {1/2 of a word}
  755. @!two_choices = 1..2; {used when there are two variants in a record}
  756. @!four_choices = 1..4; {used when there are four variants in a record}
  757. @!two_halves = packed record@;@/
  758.   @!rh:halfword;
  759.   case two_choices of
  760.   1: (@!lh:halfword);
  761.   2: (@!b0:quarterword; @!b1:quarterword);
  762.   end;
  763. @!four_quarters = packed record@;@/
  764.   @!b0:quarterword;
  765.   @!b1:quarterword;
  766.   @!b2:quarterword;
  767.   @!b3:quarterword;
  768.   end;
  769. @!memory_word = record@;@/
  770.   case four_choices of
  771.   1: (@!int:integer);
  772.   2: (@!gr:glue_ratio);
  773.   3: (@!hh:two_halves);
  774.   4: (@!qqqq:four_quarters);
  775.   end;
  776. @!word_file = file of memory_word;
  777. @y
  778. @!quarterword=min_quarterword..max_quarterword;
  779. @!halfword=min_halfword..max_halfword;
  780. @!two_choices = 1..2; {used when there are two variants in a record}
  781. @!four_choices = 1..4; {used when there are four variants in a record}
  782. @=#include "memory.h";@>
  783. @z
  784.  
  785. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  786. % [9.116] mem is allocated at run time in C. mem_max and mem_top are vars.
  787. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  788. @x
  789. @!mem : array[mem_min..mem_max] of memory_word; {the big dynamic storage area}
  790. @y
  791. @!mem_max : integer; {greatest index in \TeX's internal |mem| array;
  792.   must be strictly less than |max_halfword|;
  793.   must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
  794. @!mem_top : integer; {largest index in the |mem| array dumped by \.{INITEX};
  795.   must be substantially larger than |mem_bot|
  796.   and not greater than |mem_max|}
  797. @z
  798.  
  799. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  800. % [9.127] Fix casting problem in C.
  801. % There are several of these.  They come from the rules C uses for
  802. % comparing signed and unsigned quantities.  Just doing the comparison
  803. % can result in incorrect evaluation wrt the way Pascal would do it.
  804. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  805. @x
  806. if r>p+1 then @<Allocate from the top of node |p| and |goto found|@>;
  807. @y
  808. if r>toint(p+1) then @<Allocate from the top of node |p| and |goto found|@>;
  809. @z
  810.  
  811. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  812. % [11.165] Fix the word `free' so that it doesn't conflict with the
  813. % standard C library routine of the same name.
  814. % free and was_free are now allocated at run time in C.
  815. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  816. @x
  817. been included. (You may want to decrease the size of |mem| while you
  818. @^debugging@>
  819. are debugging.)
  820.  
  821. @<Glob...@>=
  822. @!debug @!free: packed array [mem_min..mem_max] of boolean; {free cells}
  823. @t\hskip10pt@>@!was_free: packed array [mem_min..mem_max] of boolean;
  824.   {previously free cells}
  825. @y
  826. been included. (You may want to decrease the size of |mem| while you
  827. @^debugging@>
  828. are debugging.)
  829.  
  830. @d free==free_arr
  831.  
  832. @<Glob...@>=
  833. @!debug
  834. @z
  835.  
  836. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  837. % [12.174,176] Eliminate some unsigned comparisons to zero.
  838. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  839. @x
  840.         begin if (font(p)<font_base)or(font(p)>font_max) then
  841.           print_char("*")
  842. @y
  843.         begin if (font(p)>font_max) then
  844.           print_char("*")
  845. @z
  846.  
  847. @x
  848. @p procedure print_font_and_char(@!p:integer); {prints |char_node| data}
  849. begin if p>mem_end then print_esc("CLOBBERED.")
  850. else  begin if (font(p)<font_base)or(font(p)>font_max) then print_char("*")
  851. @y
  852. @p procedure print_font_and_char(@!p:integer); {prints |char_node| data}
  853. begin if p>mem_end then print_esc("CLOBBERED.")
  854. else  begin if (font(p)>font_max) then print_char("*")
  855. @z
  856.  
  857. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  858. % [12.186] Don't worry about strange floating point values.
  859. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  860. @x
  861.   if glue_sign(p)=shrinking then print("- ");
  862.   if abs(mem[p+glue_offset].int)<@'4000000 then print("?.?")
  863.   else if abs(g)>float_constant(20000) then
  864. @y
  865.   if glue_sign(p)=shrinking then print("- ");
  866.   { The Unix |pc| folks removed this restriction with a remark that
  867.     invalid bit patterns were vanishingly improbable, so we follow
  868.     their example without really understanding it.
  869.   |if abs(mem[p+glue_offset].int)<@'4000000 then print('?.?')|
  870.   |else| }
  871.   if fabs(g)>float_constant(20000) then
  872. @z
  873.  
  874. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  875. % [17.241] Do `fix_date_and_time' in C.
  876. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  877. @x
  878. @ The following procedure, which is called just before \TeX\ initializes its
  879. input and output, establishes the initial values of the date and time.
  880. @^system dependencies@>
  881. Since standard \PASCAL\ cannot provide such information, something special
  882. is needed. The program here simply specifies July 4, 1776, at noon; but
  883. users probably want a better approximation to the truth.
  884.  
  885. @p procedure fix_date_and_time;
  886. begin time:=12*60; {minutes since midnight}
  887. day:=4; {fourth day of the month}
  888. month:=7; {seventh month of the year}
  889. year:=1776; {Anno Domini}
  890. end;
  891. @y
  892. @ The following procedure, which is called just before \TeX\ initializes its
  893. input and output, establishes the initial values of the date and time.
  894. It calls a macro-defined |date_and_time| routine.  |date_and_time|
  895. in turn is a C macro, which calls |get_date_and_time|, passing
  896. it the addresses of the day, month, etc., so they can be set by the
  897. routine.  |get_date_and_time| also sets up interrupt catching if that
  898. is conditionally compiled in the C code.
  899. @^system dependencies@>
  900.  
  901. @d fix_date_and_time==date_and_time(time,day,month,year)
  902. @z
  903.  
  904. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  905. % [17.253] Change eqtb to zeqtb.
  906. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  907. @x
  908. @!eqtb:array[active_base..eqtb_size] of memory_word;
  909. @y
  910. @!zeqtb:array[active_base..eqtb_size] of memory_word;
  911. @z
  912.  
  913. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  914. % [18.262] Remove more unsigned comparisons to zero.
  915. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  916. @x
  917. else if (text(p)<0)or(text(p)>=str_ptr) then print_esc("NONEXISTENT.")
  918. @y
  919. else if (text(p)>=str_ptr) then print_esc("NONEXISTENT.")
  920. @z
  921.  
  922. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  923. % [19.?] save_stack is allocated at run time in C. save_size is a var.
  924. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  925. @x
  926. @ @<Glob...@>=
  927. @!save_stack : array[0..save_size] of memory_word;
  928. @!save_ptr : 0..save_size; {first unused entry on |save_stack|}
  929. @!max_save_stack:0..save_size; {maximum usage of save stack}
  930. @!cur_level: quarterword; {current nesting level for groups}
  931. @!cur_group: group_code; {current group type}
  932. @!cur_boundary: 0..save_size; {where the current level begins}
  933. @y
  934. @ @<Glob...@>=
  935. @!save_size :integer; {space for saving values outside of current group; must be
  936.   at most |max_halfword|}
  937. @!save_ptr : integer; {first unused entry on |save_stack|}
  938. @!max_save_stack:integer; {maximum usage of save stack}
  939. @!cur_level: quarterword; {current nesting level for groups}
  940. @!cur_group: group_code; {current group type}
  941. @!cur_boundary: integer; {where the current level begins}
  942. @z
  943.  
  944. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  945. % [22.?] input_stack is allocated at run time in C.
  946. % stack_size is a var.
  947. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  948. @x
  949. @ @<Glob...@>=
  950. @!input_stack : array[0..stack_size] of in_state_record;
  951. @!input_ptr : 0..stack_size; {first unused location of |input_stack|}
  952. @!max_in_stack: 0..stack_size; {largest value of |input_ptr| when pushing}
  953. @!cur_input : in_state_record;
  954.   {the ``top'' input state, according to convention (1)}
  955. @y
  956. @ @<Glob...@>=
  957. @!stack_size : integer; {maximum number of simultaneous input sources}
  958. @!input_ptr : integer; {first unused location of |input_stack|}
  959. @!max_in_stack: integer; {largest value of |input_ptr| when pushing}
  960. @!cur_input : in_state_record;
  961. @z
  962.  
  963. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  964. % [22.?] input_file and line_stack are allocated at run time in C.
  965. % max_in_open is a var.
  966. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  967. @x
  968. @<Glob...@>=
  969. @!in_open : 0..max_in_open; {the number of lines in the buffer, less one}
  970. @!open_parens : 0..max_in_open; {the number of open text files}
  971. @!input_file : array[1..max_in_open] of alpha_file;
  972. @!line : integer; {current line number in the current source file}
  973. @!line_stack : array[1..max_in_open] of integer;
  974. @y
  975. @<Glob...@>=
  976. @!max_in_open : integer; {maximum number of input files and error insertions that
  977.   can be going on simultaneously}
  978. @!in_open : integer; {the number of lines in the buffer, less one}
  979. @!open_parens : integer; {the number of open text files}
  980. @!line : integer; {current line number in the current source file}
  981. @z
  982.  
  983. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  984. % base_ptr also needs to be integer.
  985. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  986. @x
  987. displayed by this procedure.
  988.  
  989. @<Glob...@>=
  990. @!base_ptr:0..stack_size; {shallowest level shown by |show_context|}
  991. @y
  992. displayed by this procedure.
  993.  
  994. @<Glob...@>=
  995. @!base_ptr:integer; {shallowest level shown by |show_context|}
  996. @z
  997.  
  998. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  999. % [23.331] Use a different for loop index, local to tex_body.
  1000. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1001. %@x
  1002. %first:=buf_size; repeat buffer[first]:=0; decr(first); until first=0;
  1003. %@y
  1004. %bufindx:=buf_size; repeat buffer[bufindx]:=0; decr(bufindx); until bufindx=0;
  1005. %@z
  1006.  
  1007. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1008. % [29.513] Area and extension rules for filenames.
  1009. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1010. @x
  1011. @ The file names we shall deal with for illustrative purposes have the
  1012. following structure:  If the name contains `\.>' or `\.:', the file area
  1013. consists of all characters up to and including the final such character;
  1014. otherwise the file area is null.  If the remaining file name contains
  1015. `\..', the file extension consists of all such characters from the first
  1016. remaining `\..' to the end, otherwise the file extension is null.
  1017. @^system dependencies@>
  1018.  
  1019. We can scan such file names easily by using two global variables that keep track
  1020. of the occurrences of area and extension delimiters:
  1021.  
  1022. @<Glob...@>=
  1023. @!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any}
  1024. @!ext_delimiter:pool_pointer; {the relevant `\..', if any}
  1025. @y
  1026. @ The file names we shall deal with for illustrative purposes have the
  1027. following structure:  If the name contains `\./', the file area
  1028. consists of all characters up to and including the final such character;
  1029. otherwise the file area is null.  If the remaining file name contains
  1030. `\..', the file extension consists of all such characters from the last
  1031. `\..' to the end, otherwise the file extension is null.
  1032. @^system dependencies@>
  1033.  
  1034. We can scan such file names easily by using two global variables that keep
  1035. track of the occurrences of area and extension delimiters:
  1036.  
  1037. @<Glob...@>=
  1038. @!area_delimiter:pool_pointer; {the most recent `\./', if any}
  1039. @!ext_delimiter:pool_pointer; {the most recent `\..', if any}
  1040. @z
  1041.  
  1042. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1043. % [29.514] TeX area directories.
  1044. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1045. @x
  1046. @d TEX_area=="TeXinputs:"
  1047. @.TeXinputs@>
  1048. @d TEX_font_area=="TeXfonts:"
  1049. @.TeXfonts@>
  1050. @y
  1051. In C, the default paths are specified in a separate
  1052. file, \.{site.h}.  The file opening procedures do path searching
  1053. based either on those default paths, or on paths given by the user
  1054. in environment variables.
  1055. @z
  1056.  
  1057. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1058. % [29.516] more_name
  1059. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1060. @x
  1061. else  begin str_room(1); append_char(c); {contribute |c| to the current string}
  1062.   if (c=">")or(c=":") then
  1063.     begin area_delimiter:=cur_length; ext_delimiter:=0;
  1064.     end
  1065.   else if (c=".")and(ext_delimiter=0) then ext_delimiter:=cur_length;
  1066. @y
  1067. else  begin str_room(1); append_char(c); {contribute |c| to the current string}
  1068.   if (c="/") then
  1069.     begin area_delimiter:=cur_length; ext_delimiter:=0;
  1070.     end
  1071.   else if c="." then ext_delimiter:=cur_length;
  1072. @z
  1073.  
  1074. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1075. % [29.520] The default format.
  1076. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1077. @x
  1078. @d format_default_length=20 {length of the |TEX_format_default| string}
  1079. @d format_area_length=11 {length of its area part}
  1080. @d format_ext_length=4 {length of its `\.{.fmt}' part}
  1081. @y
  1082. Under {\mc UNIX} we don't give the area part, instead depending
  1083. on the path searching that will happen during file opening.  Also, the
  1084. length will be set in the main program.
  1085.  
  1086. @d format_area_length=0 {length of its area part}
  1087. @d format_ext_length=4 {length of its `\.{.fmt}' part}
  1088. @z
  1089.  
  1090. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1091. % [29.521] Where `plain.fmt' is.
  1092. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1093. @x
  1094. @!TEX_format_default:packed array[1..format_default_length] of char;
  1095.  
  1096. @ @<Set init...@>=
  1097. TEX_format_default:='TeXformats:plain.fmt';
  1098. @y
  1099. @!format_default_length: integer;
  1100. @!TEX_format_default: c_char_pointer;
  1101.  
  1102. @ We set the name of the default format file and the length of that name
  1103. in C, instead of Pascal, since we want them to depend on the name of the
  1104. program.
  1105. @z
  1106.  
  1107. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1108. % [29.524] Format file opening: only try once, with path searching.
  1109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1110. @x
  1111.   pack_buffered_name(0,loc,j-1); {try first without the system file area}
  1112.   if w_open_in(fmt_file) then goto found;
  1113.   pack_buffered_name(format_area_length,loc,j-1);
  1114.     {now try the system format file area}
  1115.   if w_open_in(fmt_file) then goto found;
  1116. @y
  1117.   pack_buffered_name(0,loc,j-1);
  1118.   if w_open_in(fmt_file) then goto found;
  1119. @z
  1120.  
  1121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1122. % (still [29.524]) replace `PLAIN' in error messages with `default'.
  1123. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1124. @x
  1125.   wterm_ln('Sorry, I can''t find that format;',' will try PLAIN.');
  1126. @y
  1127.   wterm_ln('Sorry, I can''t find that format;',' will try the default.');
  1128. @z
  1129. @x
  1130.   wterm_ln('I can''t find the PLAIN format file!');
  1131. @.I can't find PLAIN...@>
  1132. @y
  1133.   wterm_ln('I can''t find the default format file!');
  1134. @.I can't find default format...@>
  1135. @z
  1136.  
  1137. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1138. % [29.534] Adjust for C string conventions.
  1139. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1140. @x
  1141. @!months:packed array [1..36] of char; {abbreviations of month names}
  1142. @y
  1143. @!months:c_char_pointer;
  1144. @z
  1145.  
  1146. @x
  1147. months:='JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
  1148. @y
  1149. months := ' JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
  1150. @z
  1151.  
  1152. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1153. % [29.537] a_open_in of \input file needs path specifier; also, try to
  1154. % open the file with and without the `.tex'.
  1155. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1156. @x
  1157. if cur_ext="" then cur_ext:=".tex";
  1158. pack_cur_name;
  1159. loop@+  begin begin_file_reading; {set up |cur_file| and new level of input}
  1160.   if a_open_in(cur_file) then goto done;
  1161.   if cur_area="" then
  1162.     begin pack_file_name(cur_name,TEX_area,cur_ext);
  1163.     if a_open_in(cur_file) then goto done;
  1164.     end;
  1165. @y
  1166. if cur_ext="" then pack_file_name(cur_name,cur_area,".tex")
  1167. else pack_cur_name;
  1168. loop@+  begin begin_file_reading; {set up |cur_file| and new level of input}
  1169.   if a_open_in(cur_file, TEX_INPUT_PATH) then goto done;
  1170.   if cur_ext="" then {try to open the file without `\.{.tex}'}
  1171.     begin pack_cur_name;
  1172.     if a_open_in(cur_file, TEX_INPUT_PATH) then goto done;
  1173.     end;
  1174. @z
  1175.  
  1176. % Knuth should fix this bug.
  1177. @x
  1178. if term_offset+length(name)>max_print_line-2 then print_ln
  1179. @y
  1180. if term_offset+length(name)>max_print_line-3 then print_ln
  1181. @z
  1182.  
  1183. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1184. % [29.537] Get rid of return of filename to string pool.
  1185. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1186. @x
  1187. if name=str_ptr-1 then {we can conserve string pool space now}
  1188.   begin flush_string; name:=cur_name;
  1189.   end;
  1190. @y
  1191. @z
  1192.  
  1193. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1194. % [30.?] font_info is allocated at run time in C. font_mem_size is a var.
  1195. % non_address can't be equated anymore to font_mem_size, so use infinity
  1196. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1197. @x
  1198. @<Types...@>=
  1199. @!internal_font_number=font_base..font_max; {|font| in a |char_node|}
  1200. @!font_index=0..font_mem_size; {index into |font_info|}
  1201.  
  1202. @ Here now is the (rather formidable) array of font arrays.
  1203.  
  1204. @d non_char==qi(256) {a |halfword| code that can't match a real character}
  1205. @d non_address==font_mem_size {a spurious |font_index|}
  1206.  
  1207. @<Glob...@>=
  1208. @!font_info:array[font_index] of memory_word;
  1209.   {the big collection of font data}
  1210. @!fmem_ptr:font_index; {first unused word of |font_info|}
  1211. @y
  1212. @<Types...@>=
  1213. @!internal_font_number=font_base..font_max; {|font| in a |char_node|}
  1214. @!font_index=integer; {index into |font_info|}
  1215.  
  1216. @ Here now is the (rather formidable) array of font arrays.
  1217.  
  1218. @d non_char==qi(256) {a |halfword| code that can't match a real character}
  1219. @d non_address==infinity {a spurious |font_index|}
  1220.  
  1221. @<Glob...@>=
  1222. @!font_mem_size : integer; {number of words of |font_info| for all fonts}
  1223. @!fmem_ptr:font_index; {first unused word of |font_info|}
  1224. @z
  1225.  
  1226. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1227. % [30.563] Fix TFM file opening.
  1228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1229. @x
  1230. file_opened:=false;
  1231. if aire="" then pack_file_name(nom,TEX_font_area,".tfm")
  1232. else pack_file_name(nom,aire,".tfm");
  1233. if not b_open_in(tfm_file) then abort;
  1234. file_opened:=true
  1235. @y
  1236. file_opened:=false;
  1237. pack_file_name(nom,aire,".tfm");
  1238. if not b_open_in(tfm_file) then abort;
  1239. file_opened:=true
  1240. @z
  1241.  
  1242. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1243. % [30.564] Reading the tfm file.  As a special case, whenever we open a
  1244. % tfm file, we read its first byte into `tfm_temp' right away.  TeX
  1245. % looks at `fbyte' before calling `fget', so it ends up seeing every
  1246. % byte.  This is Pascal-like I/O.
  1247. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1248. @x
  1249. @d fget==get(tfm_file)
  1250. @d fbyte==tfm_file^
  1251. @y
  1252. @d fget==tfm_temp:=getc(tfm_file)
  1253. @d fbyte==tfm_temp
  1254. @z
  1255.  
  1256. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1257. % [32.597] We only want `eof' on the TFM file to be true if we
  1258. % previously had EOF, not if we're at EOF now.  This is like `feof', and
  1259. % unlike our implementation of `eof' elsewhere.
  1260. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1261. @x
  1262. if eof(tfm_file) then abort;
  1263. @y
  1264. if feof(tfm_file) then abort;
  1265. @z
  1266.  
  1267. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1268. % [32.597] write_dvi
  1269. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1270. @x
  1271. @p procedure write_dvi(@!a,@!b:dvi_index);
  1272. var k:dvi_index;
  1273. begin for k:=a to b do write(dvi_file,dvi_buf[k]);
  1274. end;
  1275. @y
  1276. In C, we use a macro to call |fwrite| or |write| directly, writing all
  1277. the bytes to be written in one shot.  Much better even than writing four
  1278. bytes at a time.
  1279. @z
  1280.  
  1281. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1282. % [38.859] Fix a casting/expression evaluation problem.
  1283. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1284. @x
  1285. if abs(fit_class-fitness(r))>1 then d:=d+adj_demerits;
  1286. @y
  1287. if abs(toint(fit_class)-toint(fitness(r)))>1 then d:=d+adj_demerits;
  1288. @z
  1289.  
  1290. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1291. % [39.875] Another casting problem.
  1292. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1293. @x
  1294. repeat if type(r)<>delta_node then
  1295.   begin line_diff:=line_number(r)-best_line;
  1296. @y
  1297. repeat if type(r)<>delta_node then
  1298.   begin line_diff:=toint(line_number(r))-toint(best_line);
  1299. @z
  1300.  
  1301. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1302. % [43.?] Hack around the negative lower bound here.
  1303. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1304. @x
  1305. The hash table is called |trie_op_hash|, and the number of entries it contains
  1306. is |trie_op_ptr|.
  1307.  
  1308. @<Glob...@>=
  1309. @!init@! trie_op_hash:array[-trie_op_size..trie_op_size] of 0..trie_op_size;
  1310. @y
  1311. The hash table is called |trie_op_hash|, and the number of entries it contains
  1312. is |trie_op_ptr|.
  1313.  
  1314. @<Glob...@>=
  1315. @!init@! trie_op_hash:array[neg_trie_op_size..trie_op_size] of 0..trie_op_size;
  1316. @z
  1317.  
  1318. @x
  1319. var h:-trie_op_size..trie_op_size; {trial hash location}
  1320. @y
  1321. var h:neg_trie_op_size..trie_op_size; {trial hash location}
  1322. @z
  1323.  
  1324. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1325. % [43.944] Another casting problem.
  1326. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1327. @x
  1328. begin h:=abs(n+313*d+361*v+1009*cur_lang) mod (trie_op_size+trie_op_size)
  1329. @y
  1330. begin h:=abs(toint(n)+313*toint(d)+361*toint(v)+1009*toint(cur_lang))
  1331.   mod (trie_op_size+trie_op_size)
  1332. @z
  1333.  
  1334. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1335. % [43.947] And another.
  1336. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1337. @x
  1338. begin h:=abs(trie_c[p]+1009*trie_o[p]+@|
  1339.     2718*trie_l[p]+3142*trie_r[p]) mod trie_size;
  1340. @y
  1341. begin h:=abs(toint(trie_c[p])+1009*toint(trie_o[p])+@|
  1342.     2718*toint(trie_l[p])+3142*toint(trie_r[p])) mod trie_size;
  1343. @z
  1344.  
  1345. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1346. % [49.1275] Use a path for a_open_in of a \read.
  1347. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1348. @x
  1349.   if a_open_in(read_file[n]) then read_open[n]:=just_open;
  1350. @y
  1351.   if a_open_in(read_file[n], TEX_INPUT_PATH) then read_open[n]:=just_open;
  1352. @z
  1353.  
  1354. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1355. % [50.1302] Eliminate now-unused variable `w' in `store_fmt_file'.
  1356. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1357. @x
  1358. @!x: integer; {something to dump}
  1359. @!w: four_quarters; {four ASCII codes}
  1360. @y
  1361. @!x: integer; {something to dump}
  1362. @z
  1363.  
  1364. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1365. % [50.1303] Ditto, for `load_fmt_file'.
  1366. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1367. @x
  1368. @!x: integer; {something undumped}
  1369. @!w: four_quarters; {four ASCII codes}
  1370. @y
  1371. @!x: integer; {something undumped}
  1372. @z
  1373.  
  1374. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1375. % [50.??] Do reading and writing of `fmt_file' in C.
  1376. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1377. @x
  1378. @d dump_wd(#)==begin fmt_file^:=#; put(fmt_file);@+end
  1379. @d dump_int(#)==begin fmt_file^.int:=#; put(fmt_file);@+end
  1380. @d dump_hh(#)==begin fmt_file^.hh:=#; put(fmt_file);@+end
  1381. @d dump_qqqq(#)==begin fmt_file^.qqqq:=#; put(fmt_file);@+end
  1382. @y
  1383. @z
  1384.  
  1385. @x
  1386. @d undump_wd(#)==begin get(fmt_file); #:=fmt_file^;@+end
  1387. @d undump_int(#)==begin get(fmt_file); #:=fmt_file^.int;@+end
  1388. @d undump_hh(#)==begin get(fmt_file); #:=fmt_file^.hh;@+end
  1389. @d undump_qqqq(#)==begin get(fmt_file); #:=fmt_file^.qqqq;@+end
  1390. @y
  1391. @z
  1392.  
  1393. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1394. % [50.??] May relax check on mem_top? Only require current size greater
  1395. % than size stored in fmt file.
  1396. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1397. @x
  1398. @<Undump constants for consistency check@>=
  1399. x:=fmt_file^.int;
  1400. if x<>@$ then goto bad_fmt; {check that strings are the same}
  1401. undump_int(x);
  1402. if x<>mem_bot then goto bad_fmt;
  1403. undump_int(x);
  1404. if x<>mem_top then goto bad_fmt;
  1405. @y
  1406. @<Undump constants for consistency check@>=
  1407. undump_int(x);        {This is reading the first word of the fmt file}
  1408. if x<>@$ then goto bad_fmt; {check that strings are the same}
  1409. undump_int(x);
  1410. if x<>mem_bot then goto bad_fmt;
  1411. undump_int(x);
  1412. if x<>mem_top then goto bad_fmt;
  1413. @z
  1414.  
  1415. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1416. % [50.??] Make dumping/undumping more efficient.
  1417. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1418. @x
  1419. for k:=0 to str_ptr do dump_int(str_start[k]);
  1420. k:=0;
  1421. while k+4<pool_ptr do
  1422.   begin dump_four_ASCII; k:=k+4;
  1423.   end;
  1424. k:=pool_ptr-4; dump_four_ASCII;
  1425. @y
  1426. dump_things(str_start[0], str_ptr+1);
  1427. dump_things(str_pool[0], pool_ptr);
  1428. @z
  1429.  
  1430. @x
  1431. for k:=0 to str_ptr do undump(0)(pool_ptr)(str_start[k]);
  1432. k:=0;
  1433. while k+4<pool_ptr do
  1434.   begin undump_four_ASCII; k:=k+4;
  1435.   end;
  1436. k:=pool_ptr-4; undump_four_ASCII;
  1437. @y
  1438. undump_things(str_start[0], str_ptr+1);
  1439. undump_things(str_pool[0], pool_ptr);
  1440. @z
  1441.  
  1442. @x
  1443. repeat for k:=p to q+1 do dump_wd(mem[k]);
  1444. x:=x+q+2-p; var_used:=var_used+q-p;
  1445. p:=q+node_size(q); q:=rlink(q);
  1446. until q=rover;
  1447. var_used:=var_used+lo_mem_max-p; dyn_used:=mem_end+1-hi_mem_min;@/
  1448. for k:=p to lo_mem_max do dump_wd(mem[k]);
  1449. x:=x+lo_mem_max+1-p;
  1450. dump_int(hi_mem_min); dump_int(avail);
  1451. for k:=hi_mem_min to mem_end do dump_wd(mem[k]);
  1452. @y
  1453. repeat
  1454.  dump_things(mem[p], q+2-p);
  1455. x:=x+q+2-p; var_used:=var_used+q-p;
  1456. p:=q+node_size(q); q:=rlink(q);
  1457. until q=rover;
  1458. var_used:=var_used+lo_mem_max-p; dyn_used:=mem_end+1-hi_mem_min;@/
  1459. dump_things(mem[p], lo_mem_max+1-p);
  1460. x:=x+lo_mem_max+1-p;
  1461. dump_int(hi_mem_min); dump_int(avail);
  1462. dump_things(mem[hi_mem_min], mem_end+1-hi_mem_min);
  1463. @z
  1464.  
  1465. @x
  1466. repeat for k:=p to q+1 do undump_wd(mem[k]);
  1467. p:=q+node_size(q);
  1468. if (p>lo_mem_max)or((q>=rlink(q))and(rlink(q)<>rover)) then goto bad_fmt;
  1469. q:=rlink(q);
  1470. until q=rover;
  1471. for k:=p to lo_mem_max do undump_wd(mem[k]);
  1472. @y
  1473. repeat
  1474.   undump_things(mem[p], q+2-p);
  1475. p:=q+node_size(q);
  1476. if (p>lo_mem_max)or((q>=rlink(q))and(rlink(q)<>rover)) then goto bad_fmt;
  1477. q:=rlink(q);
  1478. until q=rover;
  1479. undump_things(mem[p], lo_mem_max+1-p);
  1480. @z
  1481.  
  1482. @x
  1483. for k:=hi_mem_min to mem_end do undump_wd(mem[k]);
  1484. @y
  1485. undump_things(mem[hi_mem_min], mem_end+1-hi_mem_min);
  1486. @z
  1487.  
  1488. @x
  1489. while k<l do
  1490.   begin dump_wd(eqtb[k]); incr(k);
  1491.   end;
  1492. @y
  1493. dump_things(eqtb[k], l-k);
  1494. @z
  1495.  
  1496. @x
  1497. while k<l do
  1498.   begin dump_wd(eqtb[k]); incr(k);
  1499.   end;
  1500. @y
  1501. dump_things(eqtb[k], l-k);
  1502. @z
  1503.  
  1504. @x
  1505. for j:=k to k+x-1 do undump_wd(eqtb[j]);
  1506. @y
  1507. undump_things(eqtb[k], x);
  1508. @z
  1509.  
  1510. @x
  1511. for p:=hash_used+1 to undefined_control_sequence-1 do dump_hh(hash[p]);
  1512. @y
  1513. dump_things(hash[hash_used+1], undefined_control_sequence-1-hash_used);
  1514. @z
  1515.  
  1516. @x
  1517. for p:=hash_used+1 to undefined_control_sequence-1 do undump_hh(hash[p]);
  1518. @y
  1519. undump_things(hash[hash_used+1], undefined_control_sequence-1-hash_used);
  1520. @z
  1521.  
  1522. @x
  1523. for k:=0 to fmem_ptr-1 do dump_wd(font_info[k]);
  1524. dump_int(font_ptr);
  1525. for k:=null_font to font_ptr do
  1526.   @<Dump the array info for internal font number |k|@>;
  1527. @y
  1528. @<Dump the array info for internal font number |k|@>;
  1529. @z
  1530.  
  1531. @x
  1532. for k:=0 to fmem_ptr-1 do undump_wd(font_info[k]);
  1533. undump_size(font_base)(font_max)('font max')(font_ptr);
  1534. for k:=null_font to font_ptr do
  1535.   @<Undump the array info for internal font number |k|@>
  1536. @y
  1537. @<Undump the array info for internal font number |k|@>;
  1538. @z
  1539.  
  1540. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1541. % [50.1322] Writing font info (almost at end of dump stuff).
  1542. % Knuth's code writes all the information relevant to a single font
  1543. % in the same section of the fmt file.  But it's a lot faster to
  1544. % write the arrays of information out, one whole array at a time.
  1545. % So that's the way we handle dumping and undumping font info.
  1546. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1547. @x
  1548. @ @<Dump the array info for internal font number |k|@>=
  1549. begin dump_qqqq(font_check[k]);
  1550. dump_int(font_size[k]);
  1551. dump_int(font_dsize[k]);
  1552. dump_int(font_params[k]);@/
  1553. dump_int(hyphen_char[k]);
  1554. dump_int(skew_char[k]);@/
  1555. dump_int(font_name[k]);
  1556. dump_int(font_area[k]);@/
  1557. dump_int(font_bc[k]);
  1558. dump_int(font_ec[k]);@/
  1559. dump_int(char_base[k]);
  1560. dump_int(width_base[k]);
  1561. dump_int(height_base[k]);@/
  1562. dump_int(depth_base[k]);
  1563. dump_int(italic_base[k]);
  1564. dump_int(lig_kern_base[k]);@/
  1565. dump_int(kern_base[k]);
  1566. dump_int(exten_base[k]);
  1567. dump_int(param_base[k]);@/
  1568. dump_int(font_glue[k]);@/
  1569. dump_int(bchar_label[k]);
  1570. dump_int(font_bchar[k]);
  1571. dump_int(font_false_bchar[k]);@/
  1572. print_nl("\font"); print_esc(font_id_text(k)); print_char("=");
  1573. print_file_name(font_name[k],font_area[k],"");
  1574. if font_size[k]<>font_dsize[k] then
  1575.   begin print(" at "); print_scaled(font_size[k]); print("pt");
  1576.   end;
  1577. end
  1578. @y
  1579. @ @<Dump the array info for internal font number |k|@>=
  1580. begin dump_things(font_info[0], fmem_ptr);
  1581. dump_int(font_ptr);
  1582. dump_things(font_check[null_font], font_ptr+1-null_font);
  1583. dump_things(font_size[null_font], font_ptr+1-null_font);
  1584. dump_things(font_dsize[null_font], font_ptr+1-null_font);
  1585. dump_things(font_params[null_font], font_ptr+1-null_font);
  1586. dump_things(hyphen_char[null_font], font_ptr+1-null_font);
  1587. dump_things(skew_char[null_font], font_ptr+1-null_font);
  1588. dump_things(font_name[null_font], font_ptr+1-null_font);
  1589. dump_things(font_area[null_font], font_ptr+1-null_font);
  1590. dump_things(font_bc[null_font], font_ptr+1-null_font);
  1591. dump_things(font_ec[null_font], font_ptr+1-null_font);
  1592. dump_things(char_base[null_font], font_ptr+1-null_font);
  1593. dump_things(width_base[null_font], font_ptr+1-null_font);
  1594. dump_things(height_base[null_font], font_ptr+1-null_font);
  1595. dump_things(depth_base[null_font], font_ptr+1-null_font);
  1596. dump_things(italic_base[null_font], font_ptr+1-null_font);
  1597. dump_things(lig_kern_base[null_font], font_ptr+1-null_font);
  1598. dump_things(kern_base[null_font], font_ptr+1-null_font);
  1599. dump_things(exten_base[null_font], font_ptr+1-null_font);
  1600. dump_things(param_base[null_font], font_ptr+1-null_font);
  1601. dump_things(font_glue[null_font], font_ptr+1-null_font);
  1602. dump_things(bchar_label[null_font], font_ptr+1-null_font);
  1603. dump_things(font_bchar[null_font], font_ptr+1-null_font);
  1604. dump_things(font_false_bchar[null_font], font_ptr+1-null_font);
  1605. for k:=null_font to font_ptr do begin
  1606.   print_nl("\font"); print_esc(font_id_text(k)); print_char("=");
  1607.   print_file_name(font_name[k],font_area[k],"");
  1608.   if font_size[k]<>font_dsize[k] then begin
  1609.     print(" at "); print_scaled(font_size[k]); print("pt");
  1610.   end;
  1611. end;
  1612. end
  1613. @z
  1614.  
  1615. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1616. % [50.1322] Reading font info for C (nearly done with undump stuff).
  1617. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1618. @x
  1619. @ @<Undump the array info for internal font number |k|@>=
  1620. begin undump_qqqq(font_check[k]);@/
  1621. undump_int(font_size[k]);
  1622. undump_int(font_dsize[k]);
  1623. undump(min_halfword)(max_halfword)(font_params[k]);@/
  1624. undump_int(hyphen_char[k]);
  1625. undump_int(skew_char[k]);@/
  1626. undump(0)(str_ptr)(font_name[k]);
  1627. undump(0)(str_ptr)(font_area[k]);@/
  1628. undump(0)(255)(font_bc[k]);
  1629. undump(0)(255)(font_ec[k]);@/
  1630. undump_int(char_base[k]);
  1631. undump_int(width_base[k]);
  1632. undump_int(height_base[k]);@/
  1633. undump_int(depth_base[k]);
  1634. undump_int(italic_base[k]);
  1635. undump_int(lig_kern_base[k]);@/
  1636. undump_int(kern_base[k]);
  1637. undump_int(exten_base[k]);
  1638. undump_int(param_base[k]);@/
  1639. undump(min_halfword)(lo_mem_max)(font_glue[k]);@/
  1640. undump(0)(font_mem_size)(bchar_label[k]);
  1641. undump(min_quarterword)(non_char)(font_bchar[k]);
  1642. undump(min_quarterword)(non_char)(font_false_bchar[k]);
  1643. end
  1644. @y
  1645. @  The way this is done in C makes the reference to
  1646. the internal font number meaningless, but putting the code
  1647. here preserves the association with the WEB modules.
  1648.  
  1649. @<Undump the array info for internal font number |k|@>=
  1650. begin undump_things(font_info[0], fmem_ptr);
  1651. undump_size(font_base)(font_max)('font max')(font_ptr);
  1652. undump_things(font_check[null_font], font_ptr+1-null_font);
  1653. undump_things(font_size[null_font], font_ptr+1-null_font);
  1654. undump_things(font_dsize[null_font], font_ptr+1-null_font);
  1655. undump_things(font_params[null_font], font_ptr+1-null_font);
  1656. undump_things(hyphen_char[null_font], font_ptr+1-null_font);
  1657. undump_things(skew_char[null_font], font_ptr+1-null_font);
  1658. undump_things(font_name[null_font], font_ptr+1-null_font);
  1659. undump_things(font_area[null_font], font_ptr+1-null_font);
  1660. undump_things(font_bc[null_font], font_ptr+1-null_font);
  1661. undump_things(font_ec[null_font], font_ptr+1-null_font);
  1662. undump_things(char_base[null_font], font_ptr+1-null_font);
  1663. undump_things(width_base[null_font], font_ptr+1-null_font);
  1664. undump_things(height_base[null_font], font_ptr+1-null_font);
  1665. undump_things(depth_base[null_font], font_ptr+1-null_font);
  1666. undump_things(italic_base[null_font], font_ptr+1-null_font);
  1667. undump_things(lig_kern_base[null_font], font_ptr+1-null_font);
  1668. undump_things(kern_base[null_font], font_ptr+1-null_font);
  1669. undump_things(exten_base[null_font], font_ptr+1-null_font);
  1670. undump_things(param_base[null_font], font_ptr+1-null_font);
  1671. undump_things(font_glue[null_font], font_ptr+1-null_font);
  1672. undump_things(bchar_label[null_font], font_ptr+1-null_font);
  1673. undump_things(font_bchar[null_font], font_ptr+1-null_font);
  1674. undump_things(font_false_bchar[null_font], font_ptr+1-null_font);
  1675. end
  1676. @z
  1677.  
  1678. % The hyphenation patterns.
  1679. @x
  1680. for k:=0 to trie_max do dump_hh(trie[k]);
  1681. dump_int(trie_op_ptr);
  1682. for k:=1 to trie_op_ptr do
  1683.   begin dump_int(hyf_distance[k]);
  1684.   dump_int(hyf_num[k]);
  1685.   dump_int(hyf_next[k]);
  1686.   end;
  1687. @y
  1688. dump_things(trie[0], trie_max+1);
  1689. dump_int(trie_op_ptr);
  1690. dump_things(hyf_distance[1], trie_op_ptr);
  1691. dump_things(hyf_num[1], trie_op_ptr);
  1692. dump_things(hyf_next[1], trie_op_ptr);
  1693. @z
  1694.  
  1695. @x
  1696. for k:=0 to j do undump_hh(trie[k]);
  1697. undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
  1698. for k:=1 to j do
  1699.   begin undump(0)(63)(hyf_distance[k]); {a |small_number|}
  1700.   undump(0)(63)(hyf_num[k]);
  1701.   undump(min_quarterword)(max_quarterword)(hyf_next[k]);
  1702.   end;
  1703. @y
  1704. undump_things(trie[0], j+1);
  1705. undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
  1706. undump_things(hyf_distance[1], j);
  1707. undump_things(hyf_num[1], j);
  1708. undump_things(hyf_next[1], j);
  1709. @z
  1710.  
  1711. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1712. % [50.1327] As with TFM files, `eof' here means `have we previously
  1713. % encountered the end-of-file', not `are we at the end of the file'.
  1714. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1715. @x
  1716. if (x<>69069)or eof(fmt_file) then goto bad_fmt
  1717. @y
  1718. if (x<>69069)or feof(fmt_file) then goto bad_fmt
  1719. @z
  1720.  
  1721. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1722. % [50.1328] Eliminate possibly wrong word `preloaded' from format_idents.
  1723. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1724. @x
  1725. print(" (preloaded format="); print(job_name); print_char(" ");
  1726. @y
  1727. print(" (format="); print(job_name); print_char(" ");
  1728. @z
  1729.  
  1730. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1731. % [51.1332] `uexit' argument depends on `history'; add call to
  1732. % set_paths; make the main program a procedure, so that uses of `eqtb'
  1733. % will work.
  1734. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1735. @x
  1736. @p begin @!{|start_here|}
  1737. @y
  1738. @p procedure tex_body;
  1739. begin @!{|start_here|}
  1740. @z
  1741.  
  1742. @x
  1743. t_open_out; {open the terminal for output}
  1744. @y
  1745. t_open_out; {open the terminal for output}
  1746. {get default file paths from the environment}
  1747. set_paths (TEX_FORMAT_PATH_BIT + TEX_INPUT_PATH_BIT + TEX_POOL_PATH_BIT
  1748.            + TFM_FILE_PATH_BIT);
  1749. @z
  1750.  
  1751. @x
  1752. end_of_TEX: close_files_and_terminate;
  1753. final_end: ready_already:=0;
  1754. end.
  1755. @y
  1756. close_files_and_terminate;
  1757. final_end: do_final_end;
  1758. end {|tex_body|};
  1759. @z
  1760.  
  1761. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1762. % [51.1333] Print new line before termination; switch to editor if
  1763. % necessary.
  1764. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1765. @x
  1766.     print(log_name); print_char(".");
  1767.     end;
  1768.   end;
  1769. @y
  1770.     print(log_name); print_char(".");
  1771.     end;
  1772.   end;
  1773. print_ln;
  1774. if (edit_name_start<>0) and (interaction>batch_mode) then
  1775.     call_edit(str_pool,edit_name_start,edit_name_length,edit_line);
  1776. @z
  1777.  
  1778. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1779. % [52.1338] Core-dump in debugging mode on 0 input.  Under Unix, it's
  1780. % not possible to switch into the debugger while a program is running.
  1781. % The best approximation is to do a core dump, then run the debugger on
  1782. % it later.
  1783. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1784. @x
  1785.     begin goto breakpoint;@\ {go to every label at least once}
  1786.     breakpoint: m:=0; @{'BREAKPOINT'@}@\
  1787.     end
  1788. @y
  1789.     dump_core {Do something to cause a core dump}
  1790. @z
  1791.  
  1792. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1793. % [54.1376] Add editor-switch variables to globals.
  1794. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1795. @x
  1796. This section should be replaced, if necessary, by any special
  1797. modifications of the program
  1798. that are necessary to make \TeX\ work at a particular installation.
  1799. It is usually best to design your change file so that all changes to
  1800. previous sections preserve the section numbering; then everybody's version
  1801. will be consistent with the published program. More extensive changes,
  1802. which introduce new sections, can be inserted here; then only the index
  1803. itself will get a new section number.
  1804. @^system dependencies@>
  1805. @y
  1806. Here is a temporary integer, used as a holder during reading and writing of
  1807. TFM files, and a temporary memory_word, used in reading/writing format
  1808. files.
  1809. Also, the variables used to hold ``switch-to-editor'' information.
  1810. @^<system dependencies@>
  1811.  
  1812. @<Glob...@>=
  1813. @!edit_name_start: pool_pointer;
  1814. @!edit_name_length,@!edit_line,@!tfm_temp: integer;
  1815.  
  1816. @ The |edit_name_start| will be set to point into |str_pool| somewhere after
  1817. its beginning if \TeX\ is supposed to switch to an editor on exit.
  1818.  
  1819. @<Set init...@>=
  1820. edit_name_start:=0;
  1821. @z
  1822.