| 1 |
% mf.ch for C compilation with web2c, derived from various other change |
| 2 |
% files: INITEX.CH for Berkeley Unix TeX 1.1 (by Howard Trickey and |
| 3 |
% Pavel Curtis), by Paul Richards. web2c modifications by Tim Morgan, et al. |
| 4 |
% |
| 5 |
% (more recent changes in ChangeLog) |
| 6 |
% Revision 2.0 90/3/27 20:20:00 ken To version 2.0. |
| 7 |
% Revision 1.9 90/1/20 09:05:32 karl To version 1.9. |
| 8 |
% Revision 1.8 89/11/30 09:08:16 karl To version 1.8. |
| 9 |
% Revision 1.7 88/12/27 15:02:24 mackay Cosmetic upgrade for version 1.7 |
| 10 |
% Revision 1.6 88/12/11 15:59:15 morgan Brought up to MF version 1.6 |
| 11 |
% Revision 1.5 88/03/02 13:25:44 morgan More C changes |
| 12 |
% Revision 1.4 87/12/09 12:50:00 hesse Changes for C version |
| 13 |
% Revision 1.3 87/03/07 21:15:21 mackay |
| 14 |
% Minor changes found on archive version on SCORE |
| 15 |
% Revision 1.2 86/09/29 21:46:43 mackay |
| 16 |
% Made no-debug the default, and changed version number |
| 17 |
% to correspond with improved mf.web file |
| 18 |
% (Got rid of debug code to avoid bug in range check |
| 19 |
% code of VAX4.3 BSD and SUN3 version 3.1 Os pc interpreter) |
| 20 |
% Revision 1.0 86/01/31 15:46:08 richards |
| 21 |
% Incorporates: New binary I/O library, separate optimized |
| 22 |
% arithmetic for takefraction/makefraction, new graphics interface. |
| 23 |
% |
| 24 |
% The part, module, and line numbers in this change file refer to |
| 25 |
% MF.WEB 2.71828182 as of January, 2021 (published as Donald E. Knuth, |
| 26 |
% Metafont: The Program, Volume D of Computers & Typesetting Jubilee Editions). |
| 27 |
|
| 28 |
@x [0.0] l.70 |
| 29 |
\def\title{{\eightlogo METAFONT}} |
| 30 |
@y |
| 31 |
\def\title{{\eightlogo METAFONT} changes for C} |
| 32 |
@z |
| 33 |
|
| 34 |
@x [0.0] l.75 - WEAVE: print changes only. |
| 35 |
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in} |
| 36 |
@y |
| 37 |
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in} |
| 38 |
\let\maybe=\iffalse |
| 39 |
\def\glob{13}\def\gglob{20, 25} % these are defined in module 1 |
| 40 |
@z |
| 41 |
|
| 42 |
@x [1.6] l.246 - Purge non-local 'goto' label. |
| 43 |
@d end_of_MF=9998 {go here to close files and terminate gracefully} |
| 44 |
@y |
| 45 |
@z |
| 46 |
@x [1.6] l.250 |
| 47 |
start_of_MF@t\hskip-2pt@>, end_of_MF@t\hskip-2pt@>,@,final_end; |
| 48 |
@y |
| 49 |
start_of_MF@t\hskip-2pt@>,@,final_end; |
| 50 |
@z |
| 51 |
|
| 52 |
@x [1.7] l.267 - Convert `debug..gubed' and `stat..tats' into #ifdefs. |
| 53 |
@d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging} |
| 54 |
@d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging} |
| 55 |
@y |
| 56 |
@d debug==ifdef('TEXMF_DEBUG') |
| 57 |
@d gubed==endif('TEXMF_DEBUG') |
| 58 |
@z |
| 59 |
|
| 60 |
@x [1.7] l.272 |
| 61 |
@d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering |
| 62 |
usage statistics} |
| 63 |
@d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering |
| 64 |
usage statistics} |
| 65 |
@y |
| 66 |
@d stat==ifdef('STAT') |
| 67 |
@d tats==endif('STAT') |
| 68 |
@z |
| 69 |
|
| 70 |
@x [1.8] l.287 - Same, for `init..tini'. |
| 71 |
@d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version} |
| 72 |
@d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version} |
| 73 |
@y |
| 74 |
@d init==ifdef('INIMF') |
| 75 |
@d tini==endif('INIMF') |
| 76 |
@z |
| 77 |
|
| 78 |
% [1.11] Compile-time constants. Although we only change a few of |
| 79 |
% these, listing them all makes the patch file for a big Metafont simpler. |
| 80 |
% 16K for BSD I/O; file_name_size is set from the system constant. |
| 81 |
@x [1.11] l.348 |
| 82 |
@<Constants...@>= |
| 83 |
@!mem_max=30000; {greatest index in \MF's internal |mem| array; |
| 84 |
must be strictly less than |max_halfword|; |
| 85 |
must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|} |
| 86 |
@!max_internal=100; {maximum number of internal quantities} |
| 87 |
@!buf_size=500; {maximum number of characters simultaneously present in |
| 88 |
current lines of open files; must not exceed |max_halfword|} |
| 89 |
@!error_line=72; {width of context lines on terminal error messages} |
| 90 |
@!half_error_line=42; {width of first lines of contexts in terminal |
| 91 |
error messages; should be between 30 and |error_line-15|} |
| 92 |
@!max_print_line=79; {width of longest text lines output; should be at least 60} |
| 93 |
@!screen_width=768; {number of pixels in each row of screen display} |
| 94 |
@!screen_depth=1024; {number of pixels in each column of screen display} |
| 95 |
@!stack_size=30; {maximum number of simultaneous input sources} |
| 96 |
@!max_strings=2000; {maximum number of strings; must not exceed |max_halfword|} |
| 97 |
@!string_vacancies=8000; {the minimum number of characters that should be |
| 98 |
available for the user's identifier names and strings, |
| 99 |
after \MF's own error messages are stored} |
| 100 |
@!pool_size=32000; {maximum number of characters in strings, including all |
| 101 |
error messages and help texts, and the names of all identifiers; |
| 102 |
must exceed |string_vacancies| by the total |
| 103 |
length of \MF's own strings, which is currently about 22000} |
| 104 |
@!move_size=5000; {space for storing moves in a single octant} |
| 105 |
@!max_wiggle=300; {number of autorounded points per cycle} |
| 106 |
@!gf_buf_size=800; {size of the output buffer, must be a multiple of 8} |
| 107 |
@!file_name_size=40; {file names shouldn't be longer than this} |
| 108 |
@!pool_name='MFbases:MF.POOL '; |
| 109 |
{string of length |file_name_size|; tells where the string pool appears} |
| 110 |
@.MFbases@> |
| 111 |
@!path_size=300; {maximum number of knots between breakpoints of a path} |
| 112 |
@!bistack_size=785; {size of stack for bisection algorithms; |
| 113 |
should probably be left at this value} |
| 114 |
@!header_size=100; {maximum number of \.{TFM} header words, times~4} |
| 115 |
@!lig_table_size=5000; {maximum number of ligature/kern steps, must be |
| 116 |
at least 255 and at most 32510} |
| 117 |
@!max_kerns=500; {maximum number of distinct kern amounts} |
| 118 |
@!max_font_dimen=50; {maximum number of \&{fontdimen} parameters} |
| 119 |
@y |
| 120 |
@d file_name_size == maxint |
| 121 |
@d ssup_error_line = 255 |
| 122 |
@d ssup_screen_width = 32767 |
| 123 |
@d ssup_screen_depth = 32767 |
| 124 |
|
| 125 |
@<Constants...@>= |
| 126 |
@!max_internal=300; {maximum number of internal quantities} |
| 127 |
@!stack_size=300; {maximum number of simultaneous input sources} |
| 128 |
@!max_strings=7500; {maximum number of strings; must not exceed |max_halfword|} |
| 129 |
@!string_vacancies=74000; {the minimum number of characters that should be |
| 130 |
available for the user's identifier names and strings, |
| 131 |
after \MF's own error messages are stored} |
| 132 |
@!pool_size=100000; {maximum number of characters in strings, including all |
| 133 |
error messages and help texts, and the names of all identifiers; |
| 134 |
must exceed |string_vacancies| by the total |
| 135 |
length of \MF's own strings, which is currently about 22000} |
| 136 |
@!move_size=20000; {space for storing moves in a single octant} |
| 137 |
@!max_wiggle=1000; {number of autorounded points per cycle} |
| 138 |
@!pool_name=TEXMF_POOL_NAME; |
| 139 |
{string that tells where the string pool appears} |
| 140 |
@!engine_name=TEXMF_ENGINE_NAME; {the name of this engine} |
| 141 |
@!path_size=1000; {maximum number of knots between breakpoints of a path} |
| 142 |
@!bistack_size=1500; {size of stack for bisection algorithms; |
| 143 |
should probably be left at this value} |
| 144 |
@!header_size=100; {maximum number of \.{TFM} header words, times~4} |
| 145 |
@!lig_table_size=15000; {maximum number of ligature/kern steps, must be |
| 146 |
at least 255 and at most 32510} |
| 147 |
@!max_kerns=2500; {maximum number of distinct kern amounts} |
| 148 |
@!max_font_dimen=60; {maximum number of \&{fontdimen} parameters} |
| 149 |
@# |
| 150 |
@!inf_main_memory = 3000; |
| 151 |
@!sup_main_memory = 8000000; |
| 152 |
|
| 153 |
@!inf_buf_size = 500; |
| 154 |
@!sup_buf_size = 30000000; |
| 155 |
@z |
| 156 |
|
| 157 |
@x [1.12] l.397 - Constants defined as WEB macros. |
| 158 |
@d mem_min=0 {smallest index in the |mem| array, must not be less |
| 159 |
than |min_halfword|} |
| 160 |
@d mem_top==30000 {largest index in the |mem| array dumped by \.{INIMF}; |
| 161 |
must be substantially larger than |mem_min| |
| 162 |
and not greater than |mem_max|} |
| 163 |
@d hash_size=2100 {maximum number of symbolic tokens, |
| 164 |
must be less than |max_halfword-3*param_size|} |
| 165 |
@d hash_prime=1777 {a prime number equal to about 85\pct! of |hash_size|} |
| 166 |
@d max_in_open=6 {maximum number of input files and error insertions that |
| 167 |
can be going on simultaneously} |
| 168 |
@d param_size=150 {maximum number of simultaneous macro parameters} |
| 169 |
@y |
| 170 |
@d mem_min=0 {smallest index in the |mem| array, must not be less |
| 171 |
than |min_halfword|} |
| 172 |
@d hash_size=9500 {maximum number of symbolic tokens, |
| 173 |
must be less than |max_halfword-3*param_size|} |
| 174 |
@d hash_prime=7919 {a prime number equal to about 85\pct! of |hash_size|} |
| 175 |
@d max_in_open=15 {maximum number of input files and error insertions that |
| 176 |
can be going on simultaneously} |
| 177 |
@d param_size=150 {maximum number of simultaneous macro parameters} |
| 178 |
@z |
| 179 |
|
| 180 |
@x [1.13] l.416 - Global parameters that can be changed in texmf.cnf. |
| 181 |
@<Glob...@>= |
| 182 |
@!bad:integer; {is some ``constant'' wrong?} |
| 183 |
@y |
| 184 |
@<Glob...@>= |
| 185 |
@!bad:integer; {is some ``constant'' wrong?} |
| 186 |
@# |
| 187 |
@!init |
| 188 |
@!ini_version:boolean; {are we \.{INIMF}? Set in \.{lib/texmfmp.c}} |
| 189 |
@!dump_option:boolean; {was the dump name option used?} |
| 190 |
@!dump_line:boolean; {was a \.{\%\AM base} line seen?} |
| 191 |
tini@/ |
| 192 |
@# |
| 193 |
@!dump_name:const_cstring; {base name for terminal display} |
| 194 |
@# |
| 195 |
@!bound_default:integer; {temporary for setup} |
| 196 |
@!bound_name:const_cstring; {temporary for setup} |
| 197 |
@# |
| 198 |
@!main_memory:integer; {total memory words allocated in initex} |
| 199 |
@!mem_top:integer; {largest index in the |mem| array dumped by \.{INIMF}; |
| 200 |
must be substantially larger than |mem_bot|, |
| 201 |
equal to |mem_max| in \.{INIMF}, else not greater than |mem_max|} |
| 202 |
@!mem_max:integer; {greatest index in \MF's internal |mem| array; |
| 203 |
must be strictly less than |max_halfword|; |
| 204 |
must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|} |
| 205 |
@!buf_size:integer; {maximum number of characters simultaneously present in |
| 206 |
current lines of open files; must not exceed |max_halfword|} |
| 207 |
@!error_line:integer; {width of context lines on terminal error messages} |
| 208 |
@!half_error_line:integer; {width of first lines of contexts in terminal |
| 209 |
error messages; should be between 30 and |error_line-15|} |
| 210 |
@!max_print_line:integer; {width of longest text lines output; |
| 211 |
should be at least 60} |
| 212 |
@!screen_width:integer; {number of pixels in each row of screen display} |
| 213 |
@!screen_depth:integer; {number of pixels in each column of screen display} |
| 214 |
@!gf_buf_size:integer; {size of the output buffer, must be a multiple of 8} |
| 215 |
@!parse_first_line_p:c_int_type; {parse the first line for options} |
| 216 |
@!file_line_error_style_p:c_int_type; {output file:line:error style errors.} |
| 217 |
@!eight_bit_p:c_int_type; {make all characters printable by default} |
| 218 |
@!halt_on_error_p:c_int_type; {stop at first error} |
| 219 |
@!halting_on_error_p:boolean; {already trying to halt?} |
| 220 |
@!quoted_filename:boolean; {current filename is quoted} |
| 221 |
@z |
| 222 |
|
| 223 |
@x [1.16] l.468 - Use C macros for `incr' and `decr'. |
| 224 |
@d incr(#) == #:=#+1 {increase a variable by unity} |
| 225 |
@d decr(#) == #:=#-1 {decrease a variable by unity} |
| 226 |
@y |
| 227 |
@z |
| 228 |
|
| 229 |
% [2.19] The text_char type is used as an array index into xord. The |
| 230 |
% default type `char' produces signed integers, which are bad array |
| 231 |
% indices in C. |
| 232 |
@x [2.19] l.524 |
| 233 |
@d text_char == char {the data type of characters in text files} |
| 234 |
@y |
| 235 |
@d text_char == ASCII_code {the data type of characters in text files} |
| 236 |
@z |
| 237 |
|
| 238 |
@x [2.22] l.665 - Allow any character as input. |
| 239 |
@^character set dependencies@> |
| 240 |
@^system dependencies@> |
| 241 |
|
| 242 |
@<Set init...@>= |
| 243 |
for i:=0 to @'37 do xchr[i]:=' '; |
| 244 |
for i:=@'177 to @'377 do xchr[i]:=' '; |
| 245 |
@y |
| 246 |
@^character set dependencies@> |
| 247 |
@^system dependencies@> |
| 248 |
|
| 249 |
@d tab = @'11 { ASCII horizontal tab } |
| 250 |
@d form_feed = @'14 { ASCII form feed } |
| 251 |
|
| 252 |
@<Set init...@>= |
| 253 |
{Initialize |xchr| to the identity mapping.} |
| 254 |
for i:=0 to @'37 do xchr[i]:=i; |
| 255 |
for i:=@'177 to @'377 do xchr[i]:=i; |
| 256 |
@z |
| 257 |
|
| 258 |
@x [2.23] l.681 |
| 259 |
for i:=0 to @'176 do xord[xchr[i]]:=i; |
| 260 |
@y |
| 261 |
for i:=0 to @'176 do xord[xchr[i]]:=i; |
| 262 |
{Set |xprn| for printable ASCII, unless |eight_bit_p| is set.} |
| 263 |
for i:=0 to 255 do xprn[i]:=(eight_bit_p or ((i>=" ")and(i<="~"))); |
| 264 |
|
| 265 |
{The idea for this dynamic translation comes from the patch by |
| 266 |
Libor Skarvada \.{<libor@@informatics.muni.cz>} |
| 267 |
and Petr Sojka \.{<sojka@@informatics.muni.cz>}. I didn't use any of the |
| 268 |
actual code, though, preferring a more general approach.} |
| 269 |
|
| 270 |
{This updates the |xchr|, |xord|, and |xprn| arrays from the provided |
| 271 |
|translate_filename|. See the function definition in \.{texmfmp.c} for |
| 272 |
more comments.} |
| 273 |
if translate_filename then read_tcx_file; |
| 274 |
@z |
| 275 |
|
| 276 |
% [3.25] Declare name_of_file as a C string. See comments in tex.ch for |
| 277 |
% why we change the element type to text_char. |
| 278 |
@x [3.25] l.737 |
| 279 |
@!name_of_file:packed array[1..file_name_size] of char;@;@/ |
| 280 |
{on some systems this may be a \&{record} variable} |
| 281 |
@y |
| 282 |
@!name_of_file:^text_char; |
| 283 |
@z |
| 284 |
|
| 285 |
@x [3.26] l.742 - Do file opening in C. |
| 286 |
@ The \ph\ compiler with which the present version of \MF\ was prepared has |
| 287 |
extended the rules of \PASCAL\ in a very convenient way. To open file~|f|, |
| 288 |
we can write |
| 289 |
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr |
| 290 |
|reset(f,@t\\{name}@>,'/O')|&for input;\cr |
| 291 |
|rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$ |
| 292 |
The `\\{name}' parameter, which is of type `\ignorespaces|packed |
| 293 |
array[@t\<\\{any}>@>] of text_char|', stands for the name of |
| 294 |
the external file that is being opened for input or output. |
| 295 |
Blank spaces that might appear in \\{name} are ignored. |
| 296 |
|
| 297 |
The `\.{/O}' parameter tells the operating system not to issue its own |
| 298 |
error messages if something goes wrong. If a file of the specified name |
| 299 |
cannot be found, or if such a file cannot be opened for some other reason |
| 300 |
(e.g., someone may already be trying to write the same file), we will have |
| 301 |
|@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|. This allows |
| 302 |
\MF\ to undertake appropriate corrective action. |
| 303 |
@:PASCAL H}{\ph@> |
| 304 |
@^system dependencies@> |
| 305 |
|
| 306 |
\MF's file-opening procedures return |false| if no file identified by |
| 307 |
|name_of_file| could be opened. |
| 308 |
|
| 309 |
@d reset_OK(#)==erstat(#)=0 |
| 310 |
@d rewrite_OK(#)==erstat(#)=0 |
| 311 |
|
| 312 |
@p function a_open_in(var @!f:alpha_file):boolean; |
| 313 |
{open a text file for input} |
| 314 |
begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f); |
| 315 |
end; |
| 316 |
@# |
| 317 |
function a_open_out(var @!f:alpha_file):boolean; |
| 318 |
{open a text file for output} |
| 319 |
begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f); |
| 320 |
end; |
| 321 |
@# |
| 322 |
function b_open_out(var @!f:byte_file):boolean; |
| 323 |
{open a binary file for output} |
| 324 |
begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f); |
| 325 |
end; |
| 326 |
@# |
| 327 |
function w_open_in(var @!f:word_file):boolean; |
| 328 |
{open a word file for input} |
| 329 |
begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f); |
| 330 |
end; |
| 331 |
@# |
| 332 |
function w_open_out(var @!f:word_file):boolean; |
| 333 |
{open a word file for output} |
| 334 |
begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f); |
| 335 |
end; |
| 336 |
@y |
| 337 |
@ All of the file opening functions are defined in C. |
| 338 |
@z |
| 339 |
|
| 340 |
@x [3.27] l.793 - Do file closing in C. |
| 341 |
@ Files can be closed with the \ph\ routine `|close(f)|', which |
| 342 |
@:PASCAL H}{\ph@> |
| 343 |
@^system dependencies@> |
| 344 |
should be used when all input or output with respect to |f| has been completed. |
| 345 |
This makes |f| available to be opened again, if desired; and if |f| was used for |
| 346 |
output, the |close| operation makes the corresponding external file appear |
| 347 |
on the user's area, ready to be read. |
| 348 |
|
| 349 |
@p procedure a_close(var @!f:alpha_file); {close a text file} |
| 350 |
begin close(f); |
| 351 |
end; |
| 352 |
@# |
| 353 |
procedure b_close(var @!f:byte_file); {close a binary file} |
| 354 |
begin close(f); |
| 355 |
end; |
| 356 |
@# |
| 357 |
procedure w_close(var @!f:word_file); {close a word file} |
| 358 |
begin close(f); |
| 359 |
end; |
| 360 |
@y |
| 361 |
@ And all the file closing routines as well. |
| 362 |
@z |
| 363 |
|
| 364 |
@x [3.29] l.829 - Array size of input buffer is determined at runtime. |
| 365 |
@!buffer:array[0..buf_size] of ASCII_code; {lines of characters being read} |
| 366 |
@y |
| 367 |
@!buffer:^ASCII_code; {lines of characters being read} |
| 368 |
@z |
| 369 |
|
| 370 |
@x [3.30] l.862 - Do `input_ln' in C. |
| 371 |
Standard \PASCAL\ says that a file should have |eoln| immediately |
| 372 |
before |eof|, but \MF\ needs only a weaker restriction: If |eof| |
| 373 |
occurs in the middle of a line, the system function |eoln| should return |
| 374 |
a |true| result (even though |f^| will be undefined). |
| 375 |
|
| 376 |
@p function input_ln(var @!f:alpha_file;@!bypass_eoln:boolean):boolean; |
| 377 |
{inputs the next line or returns |false|} |
| 378 |
var @!last_nonblank:0..buf_size; {|last| with trailing blanks removed} |
| 379 |
begin if bypass_eoln then if not eof(f) then get(f); |
| 380 |
{input the first character of the line into |f^|} |
| 381 |
last:=first; {cf.\ Matthew 19\thinspace:\thinspace30} |
| 382 |
if eof(f) then input_ln:=false |
| 383 |
else begin last_nonblank:=first; |
| 384 |
while not eoln(f) do |
| 385 |
begin if last>=max_buf_stack then |
| 386 |
begin max_buf_stack:=last+1; |
| 387 |
if max_buf_stack=buf_size then |
| 388 |
@<Report overflow of the input buffer, and abort@>; |
| 389 |
end; |
| 390 |
buffer[last]:=xord[f^]; get(f); incr(last); |
| 391 |
if buffer[last-1]<>" " then last_nonblank:=last; |
| 392 |
end; |
| 393 |
last:=last_nonblank; input_ln:=true; |
| 394 |
end; |
| 395 |
end; |
| 396 |
@y |
| 397 |
We define |input_ln| in C, for efficiency. Nevertheless we quote the module |
| 398 |
`Report overflow of the input buffer, and abort' here in order to make |
| 399 |
\.{WEAVE} happy. |
| 400 |
|
| 401 |
@p @{ @<Report overflow of the input buffer, and abort@> @} |
| 402 |
@z |
| 403 |
|
| 404 |
@x [3.31] l.894 - `term_in' and `term_out' are standard input and output. |
| 405 |
@<Glob...@>= |
| 406 |
@!term_in:alpha_file; {the terminal as an input file} |
| 407 |
@!term_out:alpha_file; {the terminal as an output file} |
| 408 |
@y |
| 409 |
@d term_in==stdin {the terminal as an input file} |
| 410 |
@d term_out==stdout {the terminal as an output file} |
| 411 |
@z |
| 412 |
|
| 413 |
@x [3.32] l.898 - We don't need to open the terminal files. |
| 414 |
@ Here is how to open the terminal files |
| 415 |
in \ph. The `\.{/I}' switch suppresses the first |get|. |
| 416 |
@:PASCAL H}{\ph@> |
| 417 |
@^system dependencies@> |
| 418 |
|
| 419 |
@d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input} |
| 420 |
@d t_open_out==rewrite(term_out,'TTY:','/O') |
| 421 |
{open the terminal for text output} |
| 422 |
@y |
| 423 |
@ Here is how to open the terminal files. |t_open_out| does nothing. |
| 424 |
|t_open_in|, on the other hand, does the work of ``rescanning,'' or getting |
| 425 |
any command line arguments the user has provided. It's defined in C. |
| 426 |
|
| 427 |
@d t_open_out == {output already open for text output} |
| 428 |
@z |
| 429 |
|
| 430 |
@x [3.33] l.918 - Flushing output. |
| 431 |
these operations can be specified in \ph: |
| 432 |
@:PASCAL H}{\ph@> |
| 433 |
@^system dependencies@> |
| 434 |
|
| 435 |
@d update_terminal == break(term_out) {empty the terminal output buffer} |
| 436 |
@d clear_terminal == break_in(term_in,true) {clear the terminal input buffer} |
| 437 |
@y |
| 438 |
these operations can be specified with {\mc UNIX}. |update_terminal| |
| 439 |
does an |fflush|. |clear_terminal| is redefined |
| 440 |
to do nothing, since the user should control the terminal. |
| 441 |
@^system dependencies@> |
| 442 |
|
| 443 |
@d update_terminal == fflush(term_out) |
| 444 |
@d clear_terminal == do_nothing |
| 445 |
@z |
| 446 |
|
| 447 |
@x [3.36] l.991 - Reading the command line. |
| 448 |
@ The following program does the required initialization |
| 449 |
without retrieving a possible command line. |
| 450 |
It should be clear how to modify this routine to deal with command lines, |
| 451 |
if the system permits them. |
| 452 |
@^system dependencies@> |
| 453 |
|
| 454 |
@p function init_terminal:boolean; {gets the terminal input started} |
| 455 |
label exit; |
| 456 |
begin t_open_in; |
| 457 |
loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal; |
| 458 |
@.**@> |
| 459 |
if not input_ln(term_in,true) then {this shouldn't happen} |
| 460 |
begin write_ln(term_out); |
| 461 |
write(term_out,'! End of file on the terminal... why?'); |
| 462 |
@.End of file on the terminal@> |
| 463 |
init_terminal:=false; return; |
| 464 |
end; |
| 465 |
loc:=first; |
| 466 |
while (loc<last)and(buffer[loc]=" ") do incr(loc); |
| 467 |
if loc<last then |
| 468 |
begin init_terminal:=true; |
| 469 |
return; {return unless the line was all blank} |
| 470 |
end; |
| 471 |
write_ln(term_out,'Please type the name of your input file.'); |
| 472 |
end; |
| 473 |
exit:end; |
| 474 |
@y |
| 475 |
@ The following program does the required initialization. |
| 476 |
Iff anything has been specified on the command line, then |t_open_in| |
| 477 |
will return with |last > first|. |
| 478 |
@^system dependencies@> |
| 479 |
|
| 480 |
@p |
| 481 |
function init_terminal:boolean; {gets the terminal input started} |
| 482 |
label exit; |
| 483 |
begin |
| 484 |
t_open_in; |
| 485 |
if last > first then begin |
| 486 |
loc := first; |
| 487 |
while (loc < last) and (buffer[loc]=' ') do |
| 488 |
incr(loc); |
| 489 |
if loc < last then begin |
| 490 |
init_terminal := true; |
| 491 |
goto exit; |
| 492 |
end; |
| 493 |
end; |
| 494 |
loop@+begin |
| 495 |
wake_up_terminal; write(term_out, '**'); update_terminal; |
| 496 |
@.**@> |
| 497 |
if not input_ln(term_in,true) then begin {this shouldn't happen} |
| 498 |
write_ln(term_out); |
| 499 |
write_ln(term_out, '! End of file on the terminal... why?'); |
| 500 |
@.End of file on the terminal@> |
| 501 |
init_terminal:=false; |
| 502 |
return; |
| 503 |
end; |
| 504 |
|
| 505 |
loc:=first; |
| 506 |
while (loc<last)and(buffer[loc]=" ") do |
| 507 |
incr(loc); |
| 508 |
|
| 509 |
if loc<last then begin |
| 510 |
init_terminal:=true; |
| 511 |
return; {return unless the line was all blank} |
| 512 |
end; |
| 513 |
write_ln(term_out, 'Please type the name of your input file.'); |
| 514 |
end; |
| 515 |
exit: |
| 516 |
end; |
| 517 |
@z |
| 518 |
|
| 519 |
@x [4.49] l.1253 - change documentation (probably needed in more places) |
| 520 |
would like string @'32 to be the single character @'32 instead of the |
| 521 |
@y |
| 522 |
would like string @'32 to be printed as the single character @'32 instead |
| 523 |
of the |
| 524 |
@z |
| 525 |
|
| 526 |
% [4.51] Open the pool file using a path, and can't do string |
| 527 |
% assignments directly. (`strcpy' and `strlen' work here because |
| 528 |
% `pool_name' is a constant string, and thus ends in a null and doesn't |
| 529 |
% start with a space.) |
| 530 |
@x [4.51] l.1292 |
| 531 |
name_of_file:=pool_name; {we needn't set |name_length|} |
| 532 |
if a_open_in(pool_file) then |
| 533 |
@y |
| 534 |
name_length := strlen (pool_name); |
| 535 |
name_of_file := xmalloc_array (ASCII_code, 1 + name_length); |
| 536 |
strcpy (stringcast(name_of_file+1), pool_name); {copy the string} |
| 537 |
if a_open_in (pool_file, kpse_mfpool_format) then |
| 538 |
@z |
| 539 |
|
| 540 |
@x [4.51] l.1300 - Make `MF.POOL' lowercase, and change how it's read. |
| 541 |
else bad_pool('! I can''t read MF.POOL.') |
| 542 |
@y |
| 543 |
else bad_pool('! I can''t read ', pool_name, '; bad path?') |
| 544 |
@z |
| 545 |
@x [4.52] l.1304 |
| 546 |
begin if eof(pool_file) then bad_pool('! MF.POOL has no check sum.'); |
| 547 |
@.MF.POOL has no check sum@> |
| 548 |
read(pool_file,m,n); {read two digits of string length} |
| 549 |
@y |
| 550 |
begin if eof(pool_file) then bad_pool('! ', pool_name, ' has no check sum.'); |
| 551 |
@.MF.POOL has no check sum@> |
| 552 |
read(pool_file,m); read(pool_file,n); {read two digits of string length} |
| 553 |
@z |
| 554 |
@x [4.52] l.1310 |
| 555 |
bad_pool('! MF.POOL line doesn''t begin with two digits.'); |
| 556 |
@y |
| 557 |
bad_pool('! ', pool_name, ' line doesn''t begin with two digits.'); |
| 558 |
@z |
| 559 |
@x [4.53] l.1332 |
| 560 |
bad_pool('! MF.POOL check sum doesn''t have nine digits.'); |
| 561 |
@y |
| 562 |
bad_pool('! ', pool_name, ' check sum doesn''t have nine digits.'); |
| 563 |
@z |
| 564 |
@x [4.53] l.1338 |
| 565 |
done: if a<>@$ then bad_pool('! MF.POOL doesn''t match; TANGLE me again.'); |
| 566 |
@y |
| 567 |
done: if a<>@$ then |
| 568 |
bad_pool('! ', pool_name, ' doesn''t match; tangle me again (or fix the path).'); |
| 569 |
@z |
| 570 |
|
| 571 |
@x [5.54] l.1398 - error_line is a variable, so can't be a subrange array bound |
| 572 |
@!trick_buf:array[0..error_line] of ASCII_code; {circular buffer for |
| 573 |
@y |
| 574 |
@!trick_buf:array[0..ssup_error_line] of ASCII_code; {circular buffer for |
| 575 |
@z |
| 576 |
|
| 577 |
@x [5.59] l.1478 - Do not expand printable characters. |
| 578 |
if (s<256)and(selector>pseudo) then print_char(s) |
| 579 |
@y |
| 580 |
if (s<256)and((selector>pseudo)or xprn[s]) then print_char(s) |
| 581 |
@z |
| 582 |
|
| 583 |
@x [5.60] l.1494 - Do not expand printable characters. |
| 584 |
if (s<256)and(selector>pseudo) then print_char(s) |
| 585 |
@y |
| 586 |
if (s<256)and((selector>pseudo) or xprn[s])then print_char(s) |
| 587 |
@z |
| 588 |
|
| 589 |
@x [5.61] l.1509 - Print rest of banner. |
| 590 |
wterm(banner); |
| 591 |
if base_ident=0 then wterm_ln(' (no base preloaded)') |
| 592 |
else begin slow_print(base_ident); print_ln; |
| 593 |
end; |
| 594 |
@y |
| 595 |
wterm (banner); |
| 596 |
wterm (version_string); |
| 597 |
if base_ident=0 then wterm_ln(' (preloaded base=',dump_name,')') |
| 598 |
else begin slow_print(base_ident); print_ln; |
| 599 |
end; |
| 600 |
if translate_filename then begin |
| 601 |
wterm('('); |
| 602 |
fputs(translate_filename, stdout); |
| 603 |
wterm_ln(')'); |
| 604 |
end; |
| 605 |
@z |
| 606 |
|
| 607 |
@x [6.68] l.1618 - Add unspecified_mode. |
| 608 |
@d error_stop_mode=3 {stops at every opportunity to interact} |
| 609 |
@y |
| 610 |
@d error_stop_mode=3 {stops at every opportunity to interact} |
| 611 |
@d unspecified_mode=4 {extra value for command-line switch} |
| 612 |
@z |
| 613 |
|
| 614 |
@x [6.68] l.1620 - file:line:error style messages. |
| 615 |
print_nl("! "); print(#); |
| 616 |
@y |
| 617 |
if (file_line_error_style_p and not terminal_input) then |
| 618 |
begin |
| 619 |
print_nl (""); |
| 620 |
print (full_source_filename_stack[in_open]); |
| 621 |
print (":"); print_int (line); print (": "); |
| 622 |
print (#); |
| 623 |
end |
| 624 |
else begin print_nl("! "); print(#) end; |
| 625 |
@z |
| 626 |
|
| 627 |
@x [6.68] l.1625 - Add interaction_option. |
| 628 |
@!interaction:batch_mode..error_stop_mode; {current level of interaction} |
| 629 |
@y |
| 630 |
@!interaction:batch_mode..error_stop_mode; {current level of interaction} |
| 631 |
@!interaction_option:batch_mode..unspecified_mode; {set from command line} |
| 632 |
@z |
| 633 |
|
| 634 |
@x [6.69] l.1627 - Allow override by command line switch. |
| 635 |
@ @<Set init...@>=interaction:=error_stop_mode; |
| 636 |
@y |
| 637 |
@ @<Set init...@>=if interaction_option=unspecified_mode then |
| 638 |
interaction:=error_stop_mode |
| 639 |
else |
| 640 |
interaction:=interaction_option; |
| 641 |
@z |
| 642 |
|
| 643 |
@x [6.76] l.1727 - Eliminate non-local goto. |
| 644 |
@ The |jump_out| procedure just cuts across all active procedure levels and |
| 645 |
goes to |end_of_MF|. This is the only nontrivial |@!goto| statement in the |
| 646 |
whole program. It is used when there is no recovery from a particular error. |
| 647 |
|
| 648 |
Some \PASCAL\ compilers do not implement non-local |goto| statements. |
| 649 |
@^system dependencies@> |
| 650 |
In such cases the body of |jump_out| should simply be |
| 651 |
`|close_files_and_terminate|;\thinspace' followed by a call on some system |
| 652 |
procedure that quietly terminates the program. |
| 653 |
|
| 654 |
@<Error hand...@>= |
| 655 |
procedure jump_out; |
| 656 |
begin goto end_of_MF; |
| 657 |
end; |
| 658 |
@y |
| 659 |
@ The |jump_out| procedure just cuts across all active procedure levels. |
| 660 |
The body of |jump_out| simply calls |
| 661 |
`|close_files_and_terminate|;\thinspace' followed by a call on some system |
| 662 |
procedure that quietly terminates the program. |
| 663 |
@^system dependencies@> |
| 664 |
|
| 665 |
@f noreturn==procedure |
| 666 |
|
| 667 |
@d do_final_end==begin |
| 668 |
update_terminal; |
| 669 |
ready_already:=0; |
| 670 |
if (history <> spotless) and (history <> warning_issued) then |
| 671 |
uexit(1) |
| 672 |
else |
| 673 |
uexit(0); |
| 674 |
end |
| 675 |
@<Error hand...@>= |
| 676 |
noreturn procedure jump_out; |
| 677 |
begin |
| 678 |
close_files_and_terminate; |
| 679 |
do_final_end; |
| 680 |
end; |
| 681 |
@z |
| 682 |
|
| 683 |
@x [6.77] l.1751 - halt on error? |
| 684 |
print_char("."); show_context; |
| 685 |
@y |
| 686 |
print_char("."); show_context; |
| 687 |
if (halt_on_error_p) then begin |
| 688 |
{If |close_files_and_terminate| generates an error, we'll end up back |
| 689 |
here; just give up in that case. If files are truncated, too bad.} |
| 690 |
if (halting_on_error_p) then do_final_end; {quit immediately} |
| 691 |
halting_on_error_p:=true; |
| 692 |
history:=fatal_error_stop; |
| 693 |
jump_out; |
| 694 |
end; |
| 695 |
@z |
| 696 |
|
| 697 |
@x [6.79] l.1774 - Handle the switch-to-editor option. |
| 698 |
line ready to be edited. But such an extension requires some system |
| 699 |
wizardry, so the present implementation simply types out the name of the |
| 700 |
file that should be |
| 701 |
edited and the relevant line number. |
| 702 |
@^system dependencies@> |
| 703 |
|
| 704 |
There is a secret `\.D' option available when the debugging routines haven't |
| 705 |
been commented~out. |
| 706 |
@^debugging@> |
| 707 |
@y |
| 708 |
line ready to be edited. |
| 709 |
We do this by calling the external procedure |call_edit| with a pointer to |
| 710 |
the filename, its length, and the line number. |
| 711 |
However, here we just set up the variables that will be used as arguments, |
| 712 |
since we don't want to do the switch-to-editor until after \MF\ has closed |
| 713 |
its files. |
| 714 |
@^system dependencies@> |
| 715 |
|
| 716 |
There is a secret `\.D' option available when the debugging routines have |
| 717 |
not been commented out. |
| 718 |
@^debugging@> |
| 719 |
@d edit_file==input_stack[file_ptr] |
| 720 |
@z |
| 721 |
@x [6.79] l.1789 |
| 722 |
"E": if file_ptr>0 then if input_stack[file_ptr].name_field>=256 then |
| 723 |
begin print_nl("You want to edit file "); |
| 724 |
@.You want to edit file x@> |
| 725 |
slow_print(input_stack[file_ptr].name_field); |
| 726 |
print(" at line "); print_int(line);@/ |
| 727 |
interaction:=scroll_mode; jump_out; |
| 728 |
@y |
| 729 |
"E": if file_ptr>0 then if input_stack[file_ptr].name_field>=256 then |
| 730 |
begin |
| 731 |
edit_name_start:=str_start[edit_file.name_field]; |
| 732 |
edit_name_length:=str_start[edit_file.name_field+1] - |
| 733 |
str_start[edit_file.name_field]; |
| 734 |
edit_line:=line; |
| 735 |
jump_out; |
| 736 |
@z |
| 737 |
|
| 738 |
@x [6.88] l.1931 - Declare fatal_error as noreturn. |
| 739 |
procedure fatal_error(@!s:str_number); {prints |s|, and that's it} |
| 740 |
@y |
| 741 |
noreturn procedure fatal_error(@!s:str_number); {prints |s|, and that's it} |
| 742 |
@z |
| 743 |
|
| 744 |
@x [6.89] l.1940 - Declare overflow as noreturn. |
| 745 |
procedure overflow(@!s:str_number;@!n:integer); {stop due to finiteness} |
| 746 |
@y |
| 747 |
noreturn procedure overflow(@!s:str_number;@!n:integer); {stop due to finiteness} |
| 748 |
@z |
| 749 |
|
| 750 |
@x [6.90] l.1959 - Declare confusion as noreturn. |
| 751 |
procedure confusion(@!s:str_number); |
| 752 |
@y |
| 753 |
noreturn procedure confusion(@!s:str_number); |
| 754 |
@z |
| 755 |
|
| 756 |
@x [7.96] l.2054 - Do half in cpascal.h. And add halfp as in MetaPost for speed. |
| 757 |
@d half(#)==(#) div 2 |
| 758 |
@y |
| 759 |
@z |
| 760 |
|
| 761 |
@x [7.102] l.2123 - Use halfp. |
| 762 |
round_decimals:=half(a+1); |
| 763 |
@y |
| 764 |
round_decimals:=halfp(a+1); |
| 765 |
@z |
| 766 |
|
| 767 |
@x [7.107] l.2231 - Optionally replace make_fraction etc. with external routines |
| 768 |
@p function make_fraction(@!p,@!q:integer):fraction; |
| 769 |
@y |
| 770 |
In the C version, there are external routines that use double precision |
| 771 |
floating point to simulate functions such as |make_fraction|. This is |
| 772 |
carefully done to be virtually machine-independent and it gives up to 12 |
| 773 |
times speed-up on machines with hardware floating point. Since some |
| 774 |
machines do not have fast double-precision floating point, we provide a |
| 775 |
C preprocessor switch that allows selecting the standard versions given |
| 776 |
below. (There's no configure option to select FIXPT, however, since I |
| 777 |
don't expect anyone will actually notice.) |
| 778 |
|
| 779 |
@p ifdef('FIXPT')@/ |
| 780 |
function make_fraction(@!p,@!q:integer):fraction; |
| 781 |
@z |
| 782 |
@x [7.107] l.2251 |
| 783 |
if negative then make_fraction:=-(f+n)@+else make_fraction:=f+n; |
| 784 |
end; |
| 785 |
end; |
| 786 |
@y |
| 787 |
if negative then make_fraction:=-(f+n)@+else make_fraction:=f+n; |
| 788 |
end; |
| 789 |
end;@/ |
| 790 |
endif('FIXPT') |
| 791 |
@z |
| 792 |
@x [7.109] l.2289 |
| 793 |
@p function take_fraction(@!q:integer;@!f:fraction):integer; |
| 794 |
@y |
| 795 |
@p ifdef('FIXPT')@/ |
| 796 |
function take_fraction(@!q:integer;@!f:fraction):integer; |
| 797 |
@z |
| 798 |
@x [7.109] l.2308 |
| 799 |
else take_fraction:=n+p; |
| 800 |
end; |
| 801 |
@y |
| 802 |
else take_fraction:=n+p; |
| 803 |
end;@/ |
| 804 |
endif('FIXPT') |
| 805 |
@z |
| 806 |
|
| 807 |
@x [7.111] l.2327 - Use halfp. |
| 808 |
repeat if odd(f) then p:=half(p+q)@+else p:=half(p); |
| 809 |
f:=half(f); |
| 810 |
until f=1 |
| 811 |
else repeat if odd(f) then p:=p+half(q-p)@+else p:=half(p); |
| 812 |
f:=half(f); |
| 813 |
@y |
| 814 |
repeat if odd(f) then p:=halfp(p+q)@+else p:=halfp(p); |
| 815 |
f:=halfp(f); |
| 816 |
until f=1 |
| 817 |
else repeat if odd(f) then p:=p+halfp(q-p)@+else p:=halfp(p); |
| 818 |
f:=halfp(f); |
| 819 |
@z |
| 820 |
|
| 821 |
@x [7.112] l.2345 |
| 822 |
@p function take_scaled(@!q:integer;@!f:scaled):integer; |
| 823 |
@y |
| 824 |
@p ifdef('FIXPT')@/ |
| 825 |
function take_scaled(@!q:integer;@!f:scaled):integer; |
| 826 |
@z |
| 827 |
@x [7.112] l.2364 |
| 828 |
else take_scaled:=n+p; |
| 829 |
end; |
| 830 |
@y |
| 831 |
else take_scaled:=n+p; |
| 832 |
end;@/ |
| 833 |
endif('FIXPT') |
| 834 |
@z |
| 835 |
|
| 836 |
@x [7.113] l.2371 - Use halfp. |
| 837 |
repeat if odd(f) then p:=half(p+q)@+else p:=half(p); |
| 838 |
f:=half(f); |
| 839 |
until f=1 |
| 840 |
else repeat if odd(f) then p:=p+half(q-p)@+else p:=half(p); |
| 841 |
f:=half(f); |
| 842 |
@y |
| 843 |
repeat if odd(f) then p:=halfp(p+q)@+else p:=halfp(p); |
| 844 |
f:=halfp(f); |
| 845 |
until f=1 |
| 846 |
else repeat if odd(f) then p:=p+halfp(q-p)@+else p:=halfp(p); |
| 847 |
f:=halfp(f); |
| 848 |
@z |
| 849 |
|
| 850 |
@x [7.114] l.2381 |
| 851 |
operands are positive. \ (This procedure is not used especially often, |
| 852 |
so it is not part of \MF's inner loop.) |
| 853 |
|
| 854 |
@p function make_scaled(@!p,@!q:integer):scaled; |
| 855 |
@y |
| 856 |
operands are positive. \ (This procedure is not used especially often, |
| 857 |
so it is not part of \MF's inner loop, but we might as well allow for |
| 858 |
an external C routine.) |
| 859 |
|
| 860 |
@p ifdef('FIXPT')@/ |
| 861 |
function make_scaled(@!p,@!q:integer):scaled; |
| 862 |
@z |
| 863 |
@x [7.114] l.2404 |
| 864 |
if negative then make_scaled:=-(f+n)@+else make_scaled:=f+n; |
| 865 |
end; |
| 866 |
end; |
| 867 |
@y |
| 868 |
if negative then make_scaled:=-(f+n)@+else make_scaled:=f+n; |
| 869 |
end; |
| 870 |
end;@/ |
| 871 |
endif('FIXPT') |
| 872 |
@z |
| 873 |
|
| 874 |
@x [7.119] l.2504 - Do floor_scaled, floor_unscaled, round_unscaled, round_fraction in C. |
| 875 |
@p function floor_scaled(@!x:scaled):scaled; |
| 876 |
{$2^{16}\lfloor x/2^{16}\rfloor$} |
| 877 |
var @!be_careful:integer; {temporary register} |
| 878 |
begin if x>=0 then floor_scaled:=x-(x mod unity) |
| 879 |
else begin be_careful:=x+1; |
| 880 |
floor_scaled:=x+((-be_careful) mod unity)+1-unity; |
| 881 |
end; |
| 882 |
end; |
| 883 |
@# |
| 884 |
function floor_unscaled(@!x:scaled):integer; |
| 885 |
{$\lfloor x/2^{16}\rfloor$} |
| 886 |
var @!be_careful:integer; {temporary register} |
| 887 |
begin if x>=0 then floor_unscaled:=x div unity |
| 888 |
else begin be_careful:=x+1; floor_unscaled:=-(1+((-be_careful) div unity)); |
| 889 |
end; |
| 890 |
end; |
| 891 |
@# |
| 892 |
function round_unscaled(@!x:scaled):integer; |
| 893 |
{$\lfloor x/2^{16}+.5\rfloor$} |
| 894 |
var @!be_careful:integer; {temporary register} |
| 895 |
begin if x>=half_unit then round_unscaled:=1+((x-half_unit) div unity) |
| 896 |
else if x>=-half_unit then round_unscaled:=0 |
| 897 |
else begin be_careful:=x+1; |
| 898 |
round_unscaled:=-(1+((-be_careful-half_unit) div unity)); |
| 899 |
end; |
| 900 |
end; |
| 901 |
@# |
| 902 |
function round_fraction(@!x:fraction):scaled; |
| 903 |
{$\lfloor x/2^{12}+.5\rfloor$} |
| 904 |
var @!be_careful:integer; {temporary register} |
| 905 |
begin if x>=2048 then round_fraction:=1+((x-2048) div 4096) |
| 906 |
else if x>=-2048 then round_fraction:=0 |
| 907 |
else begin be_careful:=x+1; |
| 908 |
round_fraction:=-(1+((-be_careful-2048) div 4096)); |
| 909 |
end; |
| 910 |
end; |
| 911 |
@y |
| 912 |
@z |
| 913 |
|
| 914 |
@x [8.121] l.2567 - Use halfp. |
| 915 |
square_rt:=half(q); |
| 916 |
@y |
| 917 |
square_rt:=halfp(q); |
| 918 |
@z |
| 919 |
|
| 920 |
@x [8.126] l.2651 - Use halfp. |
| 921 |
else begin a:=half(a); b:=half(b); big:=true; |
| 922 |
@y |
| 923 |
else begin a:=halfp(a); b:=halfp(b); big:=true; |
| 924 |
@z |
| 925 |
|
| 926 |
@x [8.133] l.2748 - Use halfp. |
| 927 |
begin z:=half(z+1); k:=k+1; |
| 928 |
@y |
| 929 |
begin z:=halfp(z+1); k:=k+1; |
| 930 |
@z |
| 931 |
|
| 932 |
@x [8.142] l.2910 - Use halfp. |
| 933 |
begin x:=half(x); y:=half(y); |
| 934 |
@y |
| 935 |
begin x:=halfp(x); y:=halfp(y); |
| 936 |
@z |
| 937 |
|
| 938 |
@x [8.150] l.3059 - Use halfp. |
| 939 |
while j>=fraction_one do j:=half(j); |
| 940 |
@y |
| 941 |
while j>=fraction_one do j:=halfp(j); |
| 942 |
@z |
| 943 |
|
| 944 |
@x [9.153] l.3148 - Increase memory size. |
| 945 |
@d min_quarterword=0 {smallest allowable value in a |quarterword|} |
| 946 |
@d max_quarterword=255 {largest allowable value in a |quarterword|} |
| 947 |
@d min_halfword==0 {smallest allowable value in a |halfword|} |
| 948 |
@d max_halfword==65535 {largest allowable value in a |halfword|} |
| 949 |
@y |
| 950 |
@d min_quarterword=0 {smallest allowable value in a |quarterword|} |
| 951 |
@d max_quarterword=255 {largest allowable value in a |quarterword|} |
| 952 |
@d min_halfword==0 {smallest allowable value in a |halfword|} |
| 953 |
@d max_halfword==@"FFFFFFF {largest allowable value in a |halfword|} |
| 954 |
@z |
| 955 |
|
| 956 |
@x [9.155] l.3177 - Don't bother to subtract zero. |
| 957 |
@d ho(#)==#-min_halfword |
| 958 |
{to take a sixteen-bit item from a halfword} |
| 959 |
@d qo(#)==#-min_quarterword {to read eight bits from a quarterword} |
| 960 |
@d qi(#)==#+min_quarterword {to store eight bits in a quarterword} |
| 961 |
@y |
| 962 |
@d ho(#)==# |
| 963 |
@d qo(#)==# |
| 964 |
@d qi(#)==# |
| 965 |
@z |
| 966 |
|
| 967 |
@x [9.156] l.3192 - memory_word is defined externally. |
| 968 |
@!two_halves = packed record@;@/ |
| 969 |
@!rh:halfword; |
| 970 |
case two_choices of |
| 971 |
1: (@!lh:halfword); |
| 972 |
2: (@!b0:quarterword; @!b1:quarterword); |
| 973 |
end; |
| 974 |
@!four_quarters = packed record@;@/ |
| 975 |
@!b0:quarterword; |
| 976 |
@!b1:quarterword; |
| 977 |
@!b2:quarterword; |
| 978 |
@!b3:quarterword; |
| 979 |
end; |
| 980 |
@!memory_word = record@;@/ |
| 981 |
case three_choices of |
| 982 |
1: (@!int:integer); |
| 983 |
2: (@!hh:two_halves); |
| 984 |
3: (@!qqqq:four_quarters); |
| 985 |
end; |
| 986 |
@y |
| 987 |
@=#include "texmfmem.h";@> |
| 988 |
@z |
| 989 |
|
| 990 |
@x [10.159] l.3267 - mem is dynamically allocated. |
| 991 |
@!mem : array[mem_min..mem_max] of memory_word; {the big dynamic storage area} |
| 992 |
@y |
| 993 |
@!mem : ^memory_word; {the big dynamic storage area} |
| 994 |
@z |
| 995 |
|
| 996 |
% [11.178] Change the word `free' so that it doesn't conflict with the |
| 997 |
% standard C library routine of the same name. Also change arrays that |
| 998 |
% use mem_max, since that's a variable now, effectively disabling the feature. |
| 999 |
@x [11.178] l.3582 |
| 1000 |
are debugging.) |
| 1001 |
|
| 1002 |
@<Glob...@>= |
| 1003 |
@!debug @!free: packed array [mem_min..mem_max] of boolean; {free cells} |
| 1004 |
@t\hskip1em@>@!was_free: packed array [mem_min..mem_max] of boolean; |
| 1005 |
@y |
| 1006 |
are debugging.) |
| 1007 |
|
| 1008 |
@d free==free_arr |
| 1009 |
@<Glob...@>= |
| 1010 |
@!debug @!free: packed array [0..1] of boolean; {free cells; this loses} |
| 1011 |
@t\hskip1em@>@!was_free: packed array [0..1] of boolean; {this loses too} |
| 1012 |
@z |
| 1013 |
|
| 1014 |
@x [11.182] l.3638 - Eliminate unsigned comparisons to zero. |
| 1015 |
repeat if (p>=lo_mem_max)or(p<mem_min) then clobbered:=true |
| 1016 |
else if (rlink(p)>=lo_mem_max)or(rlink(p)<mem_min) then clobbered:=true |
| 1017 |
@y |
| 1018 |
repeat if (p>=lo_mem_max) then clobbered:=true |
| 1019 |
else if (rlink(p)>=lo_mem_max) then clobbered:=true |
| 1020 |
@z |
| 1021 |
|
| 1022 |
@x [12.194] l.4268 - Do `fix_date_and_time' in C. |
| 1023 |
@ The following procedure, which is called just before \MF\ initializes its |
| 1024 |
input and output, establishes the initial values of the date and time. |
| 1025 |
@^system dependencies@> |
| 1026 |
Since standard \PASCAL\ cannot provide such information, something special |
| 1027 |
is needed. The program here simply assumes that suitable values appear in |
| 1028 |
the global variables \\{sys\_time}, \\{sys\_day}, \\{sys\_month}, and |
| 1029 |
\\{sys\_year} (which are initialized to noon on 4 July 1776, |
| 1030 |
in case the implementor is careless). |
| 1031 |
|
| 1032 |
Note that the values are |scaled| integers. Hence \MF\ can no longer |
| 1033 |
be used after the year 32767. |
| 1034 |
|
| 1035 |
@p procedure fix_date_and_time; |
| 1036 |
begin sys_time:=12*60; |
| 1037 |
sys_day:=4; sys_month:=7; sys_year:=1776; {self-evident truths} |
| 1038 |
@y |
| 1039 |
@ The following procedure, which is called just before \MF\ initializes its |
| 1040 |
input and output, establishes the initial values of the date and time. |
| 1041 |
It calls an externally defined |date_and_time|, which also sets up |
| 1042 |
interrupt catching. See more comments in \.{tex.ch}. |
| 1043 |
@^system dependencies@> |
| 1044 |
|
| 1045 |
Note that the values are |scaled| integers. Hence \MF\ can no longer |
| 1046 |
be used after the year 32767. |
| 1047 |
|
| 1048 |
@p procedure fix_date_and_time; |
| 1049 |
begin date_and_time(sys_time,sys_day,sys_month,sys_year); |
| 1050 |
@z |
| 1051 |
|
| 1052 |
@x [12.198] l.4347 - Change class to c_class to avoid C++ keyword. |
| 1053 |
@d max_class=20 {the largest class number} |
| 1054 |
@y |
| 1055 |
@d max_class=20 {the largest class number} |
| 1056 |
@d class==c_class |
| 1057 |
@z |
| 1058 |
|
| 1059 |
@x [12.199] l.4395 - Allow tab and form feed as input. |
| 1060 |
for k:=127 to 255 do char_class[k]:=invalid_class; |
| 1061 |
@y |
| 1062 |
for k:=127 to 255 do char_class[k]:=invalid_class; |
| 1063 |
char_class[tab]:=space_class; |
| 1064 |
char_class[form_feed]:=space_class; |
| 1065 |
@z |
| 1066 |
|
| 1067 |
@x [15.232] l.5187 - Use halfp. |
| 1068 |
name_type(q+s):=half(s)+x_part_sector; link(q+s):=null; |
| 1069 |
@y |
| 1070 |
name_type(q+s):=halfp(s)+x_part_sector; link(q+s):=null; |
| 1071 |
@z |
| 1072 |
|
| 1073 |
[20.329] |valid_range| uses |abs|, which we have defined as a C |
| 1074 |
% macro. Some C preprocessors cannot expand the giant argument here. |
| 1075 |
% So we add a temporary. |
| 1076 |
@x [20.329] l.7270 |
| 1077 |
@p procedure edge_prep(@!ml,@!mr,@!nl,@!nr:integer); |
| 1078 |
var @!delta:halfword; {amount of change} |
| 1079 |
@y |
| 1080 |
@p procedure edge_prep(@!ml,@!mr,@!nl,@!nr:integer); |
| 1081 |
var @!delta:halfword; {amount of change} |
| 1082 |
temp:integer; |
| 1083 |
@z |
| 1084 |
@x [20.329] l.7277 |
| 1085 |
if not valid_range(m_min(cur_edges)+m_offset(cur_edges)-zero_field) or@| |
| 1086 |
not valid_range(m_max(cur_edges)+m_offset(cur_edges)-zero_field) then |
| 1087 |
@y |
| 1088 |
temp := m_offset (cur_edges) - zero_field; |
| 1089 |
if not valid_range (m_min (cur_edges) + temp) |
| 1090 |
or not valid_range (m_max (cur_edges) + temp) |
| 1091 |
then |
| 1092 |
@z |
| 1093 |
|
| 1094 |
@x [21.442] l.9489 - Use halfp. |
| 1095 |
if odd(right_type(q)) then a:=good_val(b,pen_edge+half(cur_gran)) |
| 1096 |
else a:=good_val(b-1,pen_edge+half(cur_gran)); |
| 1097 |
@y |
| 1098 |
if odd(right_type(q)) then a:=good_val(b,pen_edge+halfp(cur_gran)) |
| 1099 |
else a:=good_val(b-1,pen_edge+halfp(cur_gran)); |
| 1100 |
@z |
| 1101 |
|
| 1102 |
@x [24.509] l.10808 - i18n fix |
| 1103 |
print(" ("); print_int(info(h)); print(" offset"); |
| 1104 |
if info(h)<>1 then print_char("s"); |
| 1105 |
@y |
| 1106 |
print(" ("); print_int(info(h)); |
| 1107 |
if info(h)<>1 then print(" offsets") |
| 1108 |
else print(" offset"); |
| 1109 |
@z |
| 1110 |
|
| 1111 |
% This change was erroneous; it omitted the second term of the |
| 1112 |
% difference. This affects a few pen polygons in a small way, |
| 1113 |
% but don't know if any extant fonts are impacted. |
| 1114 |
% |
| 1115 |
% Hopefully by now, many years later, there's no problem |
| 1116 |
% with the long arguments, but leaving the code here just in case. |
| 1117 |
% Report from Tim Stadelman, |
| 1118 |
% https://tug.org/pipermail/tex-k/2021-August/003648.html. |
| 1119 |
% Applied 13 November 2024. |
| 1120 |
% |
| 1121 |
%% |make_fraction| and |take_fraction| arguments are too long for |
| 1122 |
%% some preprocessors, when they were defined as macros, just as in the |
| 1123 |
%% previous change. |
| 1124 |
%@x [25.530] l.11334 |
| 1125 |
% alpha:=take_fraction(take_fraction(major_axis, |
| 1126 |
% make_fraction(gamma,beta)),n_cos)@| |
| 1127 |
% -take_fraction(take_fraction(minor_axis, |
| 1128 |
% make_fraction(delta,beta)),n_sin); |
| 1129 |
% alpha:=(alpha+half_unit) div unity; |
| 1130 |
% gamma:=pyth_add(take_fraction(major_axis,n_cos), |
| 1131 |
% take_fraction(minor_axis,n_sin)); |
| 1132 |
%@y |
| 1133 |
% alpha := make_fraction (gamma, beta); |
| 1134 |
% alpha := take_fraction (major_axis, alpha); |
| 1135 |
% alpha := take_fraction (alpha, n_cos); |
| 1136 |
% alpha := (alpha+half_unit) div unity; |
| 1137 |
% gamma := take_fraction (minor_axis, n_sin); |
| 1138 |
% gamma := pyth_add (take_fraction (major_axis, n_cos), gamma); |
| 1139 |
%@z |
| 1140 |
|
| 1141 |
@x [26.556] l.11902 - Use halfp. |
| 1142 |
begin cur_t:=half(cur_t+1); cur_tt:=half(cur_tt+1); return; |
| 1143 |
@y |
| 1144 |
begin cur_t:=halfp(cur_t+1); cur_tt:=halfp(cur_tt+1); return; |
| 1145 |
@z |
| 1146 |
|
| 1147 |
@x [26.561] l.11999 - Use halfp. |
| 1148 |
begin cur_t:=half(cur_t); cur_tt:=half(cur_tt); |
| 1149 |
@y |
| 1150 |
begin cur_t:=halfp(cur_t); cur_tt:=halfp(cur_tt); |
| 1151 |
@z |
| 1152 |
|
| 1153 |
@x [27.564] l.12089 - The window functions are defined externally, in C. |
| 1154 |
@p function init_screen:boolean; |
| 1155 |
begin init_screen:=false; |
| 1156 |
end; |
| 1157 |
@# |
| 1158 |
procedure update_screen; {will be called only if |init_screen| returns |true|} |
| 1159 |
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only} |
| 1160 |
end; |
| 1161 |
@y |
| 1162 |
{These functions/procedures are defined externally in C.} |
| 1163 |
@z |
| 1164 |
|
| 1165 |
@x [27.565] l.12114 - screen_row, screen_col are variables, so can't be subrange array bounds. |
| 1166 |
@!screen_row=0..screen_depth; {a row number on the screen} |
| 1167 |
@!screen_col=0..screen_width; {a column number on the screen} |
| 1168 |
@!trans_spec=array[screen_col] of screen_col; {a transition spec, see below} |
| 1169 |
@y |
| 1170 |
@!screen_row=0..ssup_screen_depth; {a row number on the screen} |
| 1171 |
@!screen_col=0..ssup_screen_width; {a column number on the screen} |
| 1172 |
@!trans_spec=^screen_col; {a transition spec, see below} |
| 1173 |
@z |
| 1174 |
|
| 1175 |
@x [27.567] l.12138 |
| 1176 |
@p procedure blank_rectangle(@!left_col,@!right_col:screen_col; |
| 1177 |
@!top_row,@!bot_row:screen_row); |
| 1178 |
var @!r:screen_row; |
| 1179 |
@!c:screen_col; |
| 1180 |
begin @{@+for r:=top_row to bot_row-1 do |
| 1181 |
for c:=left_col to right_col-1 do |
| 1182 |
screen_pixel[r,c]:=white;@+@}@/ |
| 1183 |
@!init wlog_cr; {this will be done only after |init_screen=true|} |
| 1184 |
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',', |
| 1185 |
right_col:1,',',top_row:1,',',bot_row:1,')');@+tini |
| 1186 |
end; |
| 1187 |
@y |
| 1188 |
{Same thing.} |
| 1189 |
@z |
| 1190 |
|
| 1191 |
@x [27.568] l.12165 |
| 1192 |
@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec; |
| 1193 |
@!n:screen_col); |
| 1194 |
var @!k:screen_col; {an index into |a|} |
| 1195 |
@!c:screen_col; {an index into |screen_pixel|} |
| 1196 |
begin @{@+k:=0; c:=a[0]; |
| 1197 |
repeat incr(k); |
| 1198 |
repeat screen_pixel[r,c]:=b; incr(c); |
| 1199 |
until c=a[k]; |
| 1200 |
b:=black-b; {$|black|\swap|white|$} |
| 1201 |
until k=n;@+@}@/ |
| 1202 |
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';'); |
| 1203 |
{this is done only after |init_screen=true|} |
| 1204 |
for k:=0 to n do |
| 1205 |
begin wlog(a[k]:1); if k<>n then wlog(','); |
| 1206 |
end; |
| 1207 |
wlog_ln(')');@+tini |
| 1208 |
end; |
| 1209 |
@y |
| 1210 |
{Same thing} |
| 1211 |
@z |
| 1212 |
|
| 1213 |
@x [28.596] l.12687 - Use halfp. |
| 1214 |
if abs(v)>half(threshold) then |
| 1215 |
@y |
| 1216 |
if abs(v)>halfp(threshold) then |
| 1217 |
@z |
| 1218 |
|
| 1219 |
@x [31.631] l.13377 - Add datastructures for file:line:error. |
| 1220 |
@!line_stack : array[1..max_in_open] of integer; |
| 1221 |
@y |
| 1222 |
@!line_stack : array[1..max_in_open] of integer; |
| 1223 |
@!source_filename_stack : ^str_number; |
| 1224 |
@!full_source_filename_stack : ^str_number; |
| 1225 |
@z |
| 1226 |
|
| 1227 |
@x [38.768] l.15564 - Area and extension rules. |
| 1228 |
@ The file names we shall deal with for illustrative purposes have the |
| 1229 |
following structure: If the name contains `\.>' or `\.:', the file area |
| 1230 |
consists of all characters up to and including the final such character; |
| 1231 |
otherwise the file area is null. If the remaining file name contains |
| 1232 |
`\..', the file extension consists of all such characters from the first |
| 1233 |
remaining `\..' to the end, otherwise the file extension is null. |
| 1234 |
@^system dependencies@> |
| 1235 |
|
| 1236 |
We can scan such file names easily by using two global variables that keep track |
| 1237 |
of the occurrences of area and extension delimiters: |
| 1238 |
|
| 1239 |
@<Glob...@>= |
| 1240 |
@!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any} |
| 1241 |
@!ext_delimiter:pool_pointer; {the relevant `\..', if any} |
| 1242 |
@y |
| 1243 |
@ The file names we shall deal with for illustrative purposes have the |
| 1244 |
following structure: If the name contains `\./', the file area |
| 1245 |
consists of all characters up to and including the final such character; |
| 1246 |
otherwise the file area is null. If the remaining file name contains |
| 1247 |
`\..', the file extension consists of all such characters from the first |
| 1248 |
remaining `\..' to the end, otherwise the file extension is null. |
| 1249 |
@^system dependencies@> |
| 1250 |
|
| 1251 |
We can scan such file names easily by using two global variables that keep |
| 1252 |
track of the occurrences of area and extension delimiters: |
| 1253 |
|
| 1254 |
@<Glob...@>= |
| 1255 |
@!area_delimiter:pool_pointer; {the most recent `\./', if any} |
| 1256 |
@!ext_delimiter:pool_pointer; {the most recent `\..', if any} |
| 1257 |
@z |
| 1258 |
|
| 1259 |
@x [38.769] l.15584 - MF area directories. |
| 1260 |
@d MF_area=="MFinputs:" |
| 1261 |
@.MFinputs@> |
| 1262 |
@y |
| 1263 |
In C, the default paths are specified separately. |
| 1264 |
@z |
| 1265 |
|
| 1266 |
@x [38.770] l.15591 - filenames: quoted |
| 1267 |
begin area_delimiter:=0; ext_delimiter:=0; |
| 1268 |
@y |
| 1269 |
begin area_delimiter:=0; ext_delimiter:=0; quoted_filename:=false; |
| 1270 |
@z |
| 1271 |
|
| 1272 |
@x [38.771] l.15598 - more_name |
| 1273 |
begin if c=" " then more_name:=false |
| 1274 |
else begin if (c=">")or(c=":") then |
| 1275 |
@y |
| 1276 |
begin |
| 1277 |
if c="""" then begin |
| 1278 |
quoted_filename:=not quoted_filename; |
| 1279 |
more_name:=true; |
| 1280 |
end |
| 1281 |
else if ((c=" ")or(c=tab)) and stop_at_space and (not quoted_filename) then |
| 1282 |
more_name:=false |
| 1283 |
else begin |
| 1284 |
if IS_DIR_SEP (c) then |
| 1285 |
@z |
| 1286 |
|
| 1287 |
@x [38.771] l.15602 - more_name |
| 1288 |
else if (c=".")and(ext_delimiter=0) then ext_delimiter:=pool_ptr; |
| 1289 |
@y |
| 1290 |
else if c="." then ext_delimiter:=pool_ptr; |
| 1291 |
@z |
| 1292 |
|
| 1293 |
@x [38.772] l.15611 - end_name: quote if spaces in names. |
| 1294 |
@p procedure end_name; |
| 1295 |
@y |
| 1296 |
@d pool_seq_check(#) == {set |s:=str_start[str_ptr]| and |t:=#|, |
| 1297 |
then check if sequence of pool bytes |s<=j<t| needs quoting} |
| 1298 |
must_quote:=false; |
| 1299 |
s:=str_start[str_ptr]; |
| 1300 |
t:=#; |
| 1301 |
j:=s; |
| 1302 |
while (not must_quote) and (j<t) do begin |
| 1303 |
must_quote:=str_pool[j]=" "; incr(j); |
| 1304 |
end |
| 1305 |
@d pool_seq_quote_move == {quote sequence of pool bytes |s<=j<t|, |
| 1306 |
first moving up pool bytes |t<=j<pool_ptr|} |
| 1307 |
for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j]; |
| 1308 |
pool_seq_quote |
| 1309 |
@d pool_seq_quote == {quote sequence of pool bytes |s<=j<t|} |
| 1310 |
str_pool[t+1]:=""""; |
| 1311 |
for j:=t-1 downto s do str_pool[j+1]:=str_pool[j]; |
| 1312 |
str_pool[s]:=""""; |
| 1313 |
pool_ptr:=pool_ptr+2 |
| 1314 |
|
| 1315 |
@p procedure end_name; |
| 1316 |
var must_quote:boolean; {whether we need to quote a string} |
| 1317 |
@!j,@!s,@!t: pool_pointer; {running indices} |
| 1318 |
@z |
| 1319 |
|
| 1320 |
@x [38.772] l.15618 - end_name: quote if spaces in names. |
| 1321 |
if area_delimiter=0 then cur_area:="" |
| 1322 |
else begin cur_area:=str_ptr; incr(str_ptr); |
| 1323 |
str_start[str_ptr]:=area_delimiter+1; |
| 1324 |
end; |
| 1325 |
if ext_delimiter=0 then |
| 1326 |
begin cur_ext:=""; cur_name:=make_string; |
| 1327 |
end |
| 1328 |
else begin cur_name:=str_ptr; incr(str_ptr); |
| 1329 |
str_start[str_ptr]:=ext_delimiter; cur_ext:=make_string; |
| 1330 |
end; |
| 1331 |
@y |
| 1332 |
str_room(6); {room for quotes, if they are needed} |
| 1333 |
if area_delimiter=0 then cur_area:="" |
| 1334 |
else begin {maybe quote |cur_area|} |
| 1335 |
pool_seq_check(area_delimiter+1); |
| 1336 |
if must_quote then begin |
| 1337 |
pool_seq_quote_move; |
| 1338 |
area_delimiter:=area_delimiter+2; |
| 1339 |
if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2; |
| 1340 |
end; |
| 1341 |
cur_area:=str_ptr; incr(str_ptr); |
| 1342 |
str_start[str_ptr]:=area_delimiter+1; |
| 1343 |
end; |
| 1344 |
if ext_delimiter=0 then cur_ext:="" |
| 1345 |
else begin {maybe quote |cur_name| followed by |cur_ext|} |
| 1346 |
pool_seq_check(ext_delimiter); |
| 1347 |
if must_quote then begin |
| 1348 |
pool_seq_quote_move; |
| 1349 |
ext_delimiter:=ext_delimiter+2; |
| 1350 |
end; |
| 1351 |
cur_name:=str_ptr; incr(str_ptr); |
| 1352 |
str_start[str_ptr]:=ext_delimiter; |
| 1353 |
end; |
| 1354 |
{maybe quote |cur_ext| if present or |cur_name| otherwise} |
| 1355 |
pool_seq_check(pool_ptr); |
| 1356 |
if must_quote then begin |
| 1357 |
pool_seq_quote; |
| 1358 |
end; |
| 1359 |
if ext_delimiter=0 then cur_name:=make_string |
| 1360 |
else cur_ext:=make_string; |
| 1361 |
@z |
| 1362 |
|
| 1363 |
@x [38.773] l.15635 - print_file_name: quote if spaces in names. |
| 1364 |
@<Basic printing...@>= |
| 1365 |
procedure print_file_name(@!n,@!a,@!e:integer); |
| 1366 |
begin slow_print(a); slow_print(n); slow_print(e); |
| 1367 |
@y |
| 1368 |
@d string_check(#) == {check if string |#| needs quoting} |
| 1369 |
if #<>0 then begin |
| 1370 |
j:=str_start[#]; |
| 1371 |
while (not must_quote) and (j<str_start[#+1]) do begin |
| 1372 |
must_quote:=str_pool[j]=" "; incr(j); |
| 1373 |
end; |
| 1374 |
end |
| 1375 |
@d print_quoted(#) == {print string |#|, omitting quotes} |
| 1376 |
if #<>0 then |
| 1377 |
for j:=str_start[#] to str_start[#+1]-1 do |
| 1378 |
if so(str_pool[j])<>"""" then |
| 1379 |
print(so(str_pool[j])) |
| 1380 |
|
| 1381 |
@<Basic printing...@>= |
| 1382 |
procedure print_file_name(@!n,@!a,@!e:integer); |
| 1383 |
var must_quote: boolean; {whether to quote the filename} |
| 1384 |
@!j:pool_pointer; {index into |str_pool|} |
| 1385 |
begin |
| 1386 |
must_quote:=false; |
| 1387 |
string_check(a); string_check(n); string_check(e); |
| 1388 |
if must_quote then slow_print(""""); |
| 1389 |
print_quoted(a); print_quoted(n); print_quoted(e); |
| 1390 |
if must_quote then slow_print(""""); |
| 1391 |
@z |
| 1392 |
|
| 1393 |
@x [38.774] l.15646 - have append_to_name skip quotes. |
| 1394 |
@d append_to_name(#)==begin c:=#; incr(k); |
| 1395 |
if k<=file_name_size then name_of_file[k]:=xchr[c]; |
| 1396 |
end |
| 1397 |
@y |
| 1398 |
@d append_to_name(#)==begin c:=#; if not (c="""") then begin incr(k); |
| 1399 |
if k<=file_name_size then name_of_file[k]:=xchr[c]; |
| 1400 |
end end |
| 1401 |
@z |
| 1402 |
|
| 1403 |
@x [38.774] l.15655 - (pack_file_name) malloc and null terminate name_of_file. |
| 1404 |
for j:=str_start[a] to str_start[a+1]-1 do append_to_name(so(str_pool[j])); |
| 1405 |
@y |
| 1406 |
if name_of_file then libc_free (name_of_file); |
| 1407 |
name_of_file := xmalloc_array (ASCII_code, length(a)+length(n)+length(e)+1); |
| 1408 |
for j:=str_start[a] to str_start[a+1]-1 do append_to_name(so(str_pool[j])); |
| 1409 |
@z |
| 1410 |
@x [38.774] l.15659 |
| 1411 |
for k:=name_length+1 to file_name_size do name_of_file[k]:=' '; |
| 1412 |
@y |
| 1413 |
name_of_file[name_length + 1] := 0; |
| 1414 |
@z |
| 1415 |
|
| 1416 |
@x [38.775] l.15668 - The default base. |
| 1417 |
@d base_default_length=18 {length of the |MF_base_default| string} |
| 1418 |
@d base_area_length=8 {length of its area part} |
| 1419 |
@y |
| 1420 |
@d base_area_length=0 {no fixed area in C} |
| 1421 |
@z |
| 1422 |
|
| 1423 |
@x [38.775] l.15674 - Where `plain.base' is. |
| 1424 |
@!MF_base_default:packed array[1..base_default_length] of char; |
| 1425 |
|
| 1426 |
@ @<Set init...@>= |
| 1427 |
MF_base_default:='MFbases:plain.base'; |
| 1428 |
@y |
| 1429 |
@!base_default_length: integer; |
| 1430 |
@!MF_base_default: cstring; |
| 1431 |
|
| 1432 |
@ We set the name of the default format file and the length of that name |
| 1433 |
in \.{texmfmp.c}, since we want them to depend on the name of the |
| 1434 |
program. |
| 1435 |
@z |
| 1436 |
|
| 1437 |
@x [38.778] l.15703 - Change to pack_buffered_name as with pack_file_name. |
| 1438 |
for j:=1 to n do append_to_name(xord[MF_base_default[j]]); |
| 1439 |
for j:=a to b do append_to_name(buffer[j]); |
| 1440 |
for j:=base_default_length-base_ext_length+1 to base_default_length do |
| 1441 |
append_to_name(xord[MF_base_default[j]]); |
| 1442 |
if k<=file_name_size then name_length:=k@+else name_length:=file_name_size; |
| 1443 |
for k:=name_length+1 to file_name_size do name_of_file[k]:=' '; |
| 1444 |
@y |
| 1445 |
if name_of_file then libc_free (name_of_file); |
| 1446 |
name_of_file := xmalloc_array (ASCII_code, n + (b-a+1) + base_ext_length + 1); |
| 1447 |
for j:=1 to n do append_to_name(xord[ucharcast(MF_base_default[j])]); |
| 1448 |
for j:=a to b do append_to_name(buffer[j]); |
| 1449 |
for j:=base_default_length-base_ext_length+1 to base_default_length do |
| 1450 |
append_to_name(xord[ucharcast(MF_base_default[j])]); |
| 1451 |
if k<=file_name_size then name_length:=k@+else name_length:=file_name_size; |
| 1452 |
name_of_file[name_length + 1] := 0; |
| 1453 |
@z |
| 1454 |
|
| 1455 |
@x [38.779] l.15726 - Base file opening: do path searching for the default, not plain. |
| 1456 |
pack_buffered_name(0,loc,j-1); {try first without the system file area} |
| 1457 |
if w_open_in(base_file) then goto found; |
| 1458 |
pack_buffered_name(base_area_length,loc,j-1); |
| 1459 |
{now try the system base file area} |
| 1460 |
if w_open_in(base_file) then goto found; |
| 1461 |
@y |
| 1462 |
pack_buffered_name(0,loc,j-1); |
| 1463 |
if w_open_in(base_file) then goto found; |
| 1464 |
@z |
| 1465 |
@x [38.779] l.15732 |
| 1466 |
wterm_ln('Sorry, I can''t find that base;',' will try PLAIN.'); |
| 1467 |
@y |
| 1468 |
wterm ('Sorry, I can''t find the base `'); |
| 1469 |
fputs (stringcast(name_of_file + 1), stdout); |
| 1470 |
wterm ('''; will try `'); |
| 1471 |
fputs (MF_base_default + 1, stdout); |
| 1472 |
wterm_ln ('''.'); |
| 1473 |
@z |
| 1474 |
@x [38.779] l.15740 |
| 1475 |
wterm_ln('I can''t find the PLAIN base file!'); |
| 1476 |
@.I can't find PLAIN...@> |
| 1477 |
@y |
| 1478 |
wterm ('I can''t find the base file `'); |
| 1479 |
fputs (MF_base_default + 1, stdout); |
| 1480 |
wterm_ln ('''!'); |
| 1481 |
@.I can't find the base...@> |
| 1482 |
@z |
| 1483 |
|
| 1484 |
@x [38.780] l.15763 - make_name_string |
| 1485 |
make_name_string:=make_string; |
| 1486 |
end; |
| 1487 |
@y |
| 1488 |
make_name_string:=make_string; |
| 1489 |
end; |
| 1490 |
{At this point we also set |cur_name|, |cur_ext|, and |cur_area| to |
| 1491 |
match the contents of |name_of_file|.} |
| 1492 |
k:=1; |
| 1493 |
begin_name; |
| 1494 |
stop_at_space:=false; |
| 1495 |
while (k<=name_length)and(more_name(name_of_file[k])) do |
| 1496 |
incr(k); |
| 1497 |
stop_at_space:=true; |
| 1498 |
end_name; |
| 1499 |
@z |
| 1500 |
|
| 1501 |
@x [38.781] l.15795 - Make scan_file_name ignore leading tabs as well as spaces. |
| 1502 |
while buffer[loc]=" " do incr(loc); |
| 1503 |
@y |
| 1504 |
while (buffer[loc]=" ")or(buffer[loc]=tab) do incr(loc); |
| 1505 |
@z |
| 1506 |
|
| 1507 |
@x [38.782] l.15805 - `logname' is declared in <unistd.h> on some systems. |
| 1508 |
`\.{.base}' and `\.{.tfm}' in the names of \MF's output files. |
| 1509 |
@y |
| 1510 |
`\.{.base}' and `\.{.tfm}' in the names of \MF's output files. |
| 1511 |
@d log_name == texmf_log_name |
| 1512 |
@z |
| 1513 |
|
| 1514 |
@x [38.786] l.15847 - prompt_file_name: avoid empty filenames. |
| 1515 |
var @!k:0..buf_size; {index into |buffer|} |
| 1516 |
@y |
| 1517 |
var @!k:0..buf_size; {index into |buffer|} |
| 1518 |
@!saved_cur_name:str_number; {to catch empty terminal input} |
| 1519 |
@z |
| 1520 |
|
| 1521 |
@x [38.786] l.15860 - prompt_file_name: avoid empty filenames. |
| 1522 |
clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>; |
| 1523 |
if cur_ext="" then cur_ext:=e; |
| 1524 |
@y |
| 1525 |
saved_cur_name:=cur_name; |
| 1526 |
clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>; |
| 1527 |
if cur_ext="" then cur_ext:=e; |
| 1528 |
if length(cur_name)=0 then cur_name:=saved_cur_name; |
| 1529 |
@z |
| 1530 |
|
| 1531 |
@x [38.787] l.15867 - <Scan file name...> needs similar leading tab treatment. |
| 1532 |
while (buffer[k]=" ")and(k<last) do incr(k); |
| 1533 |
@y |
| 1534 |
while ((buffer[k]=" ")or(buffer[k]=tab))and(k<last) do incr(k); |
| 1535 |
@z |
| 1536 |
|
| 1537 |
@x [38.788] l.15883 - Adjust for C string conventions. |
| 1538 |
@!months:packed array [1..36] of char; {abbreviations of month names} |
| 1539 |
@y |
| 1540 |
@!months:const_cstring; |
| 1541 |
@z |
| 1542 |
|
| 1543 |
@x [38.788] l.15885 - Set correct filename for recorder. |
| 1544 |
if job_name=0 then job_name:="mfput"; |
| 1545 |
@.mfput@> |
| 1546 |
pack_job_name(".log"); |
| 1547 |
@y |
| 1548 |
if job_name=0 then job_name:=get_job_name("mfput"); |
| 1549 |
@.mfput@> |
| 1550 |
pack_job_name(".fls"); |
| 1551 |
recorder_change_filename(stringcast(name_of_file+1)); |
| 1552 |
pack_job_name(".log"); |
| 1553 |
@z |
| 1554 |
|
| 1555 |
@x [38.790] l.15924 - leading character for C string |
| 1556 |
months:='JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'; |
| 1557 |
@y |
| 1558 |
months := ' JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'; |
| 1559 |
@z |
| 1560 |
|
| 1561 |
@x [38.790] l.15928 - Print TCX name, if given. |
| 1562 |
end |
| 1563 |
@y |
| 1564 |
if translate_filename then begin |
| 1565 |
wlog_cr; |
| 1566 |
wlog('('); |
| 1567 |
fputs(translate_filename, log_file); |
| 1568 |
wlog(')'); |
| 1569 |
end; |
| 1570 |
end |
| 1571 |
@z |
| 1572 |
|
| 1573 |
@x [38.793] l.15956 - (start_input) a_open_in of input file needs path specifier. |
| 1574 |
begin @<Put the desired file name in |(cur_name,cur_ext,cur_area)|@>; |
| 1575 |
if cur_ext="" then cur_ext:=".mf"; |
| 1576 |
pack_cur_name; |
| 1577 |
loop@+ begin begin_file_reading; {set up |cur_file| and new level of input} |
| 1578 |
if a_open_in(cur_file) then goto done; |
| 1579 |
if cur_area="" then |
| 1580 |
begin pack_file_name(cur_name,MF_area,cur_ext); |
| 1581 |
if a_open_in(cur_file) then goto done; |
| 1582 |
end; |
| 1583 |
@y Don't assume a single . in filenames. |
| 1584 |
begin @<Put the desired file name in |(cur_name,cur_ext,cur_area)|@>; |
| 1585 |
pack_cur_name; |
| 1586 |
loop@+begin |
| 1587 |
begin_file_reading; {set up |cur_file| and new level of input} |
| 1588 |
if cur_ext = ".mf" then begin |
| 1589 |
cur_ext := ""; |
| 1590 |
pack_cur_name; |
| 1591 |
end; |
| 1592 |
{Kpathsea tries all the various ways to get the file.} |
| 1593 |
if kpse_in_name_ok(stringcast(name_of_file+1)) |
| 1594 |
and a_open_in(cur_file, kpse_mf_format) then |
| 1595 |
goto done; |
| 1596 |
@z |
| 1597 |
|
| 1598 |
@x [38.793] l.15970 - The job name may have been given on the command line. |
| 1599 |
begin job_name:=cur_name; open_log_file; |
| 1600 |
@y |
| 1601 |
begin job_name:=get_job_name(cur_name); open_log_file; |
| 1602 |
@z |
| 1603 |
|
| 1604 |
@x [38.793] l.15976 - Can't return name to string pool because of editor option? |
| 1605 |
if name=str_ptr-1 then {conserve string pool space (but see note above)} |
| 1606 |
begin flush_string(name); name:=cur_name; |
| 1607 |
end; |
| 1608 |
@y |
| 1609 |
@z |
| 1610 |
|
| 1611 |
@x [41.866] l.17320 - Use halfp. |
| 1612 |
major_axis:=half(a_minus_b+a_plus_b); minor_axis:=half(abs(a_plus_b-a_minus_b)); |
| 1613 |
if major_axis=minor_axis then theta:=0 {circle} |
| 1614 |
else theta:=half(n_arg(txx-tyy,tyx+txy)+n_arg(txx+tyy,tyx-txy)); |
| 1615 |
@y |
| 1616 |
major_axis:=halfp(a_minus_b+a_plus_b); minor_axis:=halfp(abs(a_plus_b-a_minus_b)); |
| 1617 |
if major_axis=minor_axis then theta:=0 {circle} |
| 1618 |
else theta:=half(n_arg(txx-tyy,tyx+txy)+n_arg(txx+tyy,tyx-txy)); |
| 1619 |
@z |
| 1620 |
|
| 1621 |
@x [44.1023] l.19871 - if batchmode, MakeTeX... scripts should be silent. |
| 1622 |
mode_command: begin print_ln; interaction:=cur_mod; |
| 1623 |
@y |
| 1624 |
mode_command: begin print_ln; interaction:=cur_mod; |
| 1625 |
if interaction = batch_mode |
| 1626 |
then kpse_make_tex_discard_errors := 1 |
| 1627 |
else kpse_make_tex_discard_errors := 0; |
| 1628 |
@z |
| 1629 |
|
| 1630 |
% [45.1120] `threshold' is both a function and a variable. Since the |
| 1631 |
% function is used much less often than the variable, we'll change that |
| 1632 |
@x [45.1120] l.21405 |
| 1633 |
@p function threshold(@!m:integer):scaled; |
| 1634 |
var @!d:scaled; {lower bound on the smallest interval size} |
| 1635 |
begin excess:=min_cover(0)-m; |
| 1636 |
if excess<=0 then threshold:=0 |
| 1637 |
else begin repeat d:=perturbation; |
| 1638 |
until min_cover(d+d)<=m; |
| 1639 |
while min_cover(d)>m do d:=perturbation; |
| 1640 |
threshold:=d; |
| 1641 |
@y |
| 1642 |
@p function threshold_fn(@!m:integer):scaled; |
| 1643 |
var @!d:scaled; {lower bound on the smallest interval size} |
| 1644 |
begin excess:=min_cover(0)-m; |
| 1645 |
if excess<=0 then threshold_fn:=0 |
| 1646 |
else begin repeat d:=perturbation; |
| 1647 |
until min_cover(d+d)<=m; |
| 1648 |
while min_cover(d)>m do d:=perturbation; |
| 1649 |
threshold_fn:=d; |
| 1650 |
@z |
| 1651 |
|
| 1652 |
@x [45.1121] l.21428 - Change the call to the threshold function. |
| 1653 |
begin d:=threshold(m); perturbation:=0; |
| 1654 |
@y |
| 1655 |
begin d:=threshold_fn(m); perturbation:=0; |
| 1656 |
@z |
| 1657 |
|
| 1658 |
@x [45.1122] l.21443 - Use halfp. |
| 1659 |
v:=l+half(value(p)-l); |
| 1660 |
@y |
| 1661 |
v:=l+halfp(value(p)-l); |
| 1662 |
@z |
| 1663 |
|
| 1664 |
@x [45.1133] l.21592 - Use C macros to do the TFM writing, to avoid casting(?) problems. |
| 1665 |
@d tfm_out(#)==write(tfm_file,#) {output one byte to |tfm_file|} |
| 1666 |
|
| 1667 |
@p procedure tfm_two(@!x:integer); {output two bytes to |tfm_file|} |
| 1668 |
begin tfm_out(x div 256); tfm_out(x mod 256); |
| 1669 |
end; |
| 1670 |
@# |
| 1671 |
procedure tfm_four(@!x:integer); {output four bytes to |tfm_file|} |
| 1672 |
begin if x>=0 then tfm_out(x div three_bytes) |
| 1673 |
else begin x:=x+@'10000000000; {use two's complement for negative values} |
| 1674 |
x:=x+@'10000000000; |
| 1675 |
tfm_out((x div three_bytes) + 128); |
| 1676 |
end; |
| 1677 |
x:=x mod three_bytes; tfm_out(x div unity); |
| 1678 |
x:=x mod unity; tfm_out(x div @'400); |
| 1679 |
tfm_out(x mod @'400); |
| 1680 |
end; |
| 1681 |
@# |
| 1682 |
procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|} |
| 1683 |
@y |
| 1684 |
The default definitions for |tfm_two| and |tfm_four| don't work. |
| 1685 |
I don't know why not. Some casting problem? |
| 1686 |
|
| 1687 |
@d tfm_out(#) == put_byte (#, tfm_file) |
| 1688 |
@d tfm_two(#) == put_2_bytes (tfm_file, #) |
| 1689 |
@d tfm_four(#) == put_4_bytes (tfm_file, #) |
| 1690 |
|
| 1691 |
@p procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|} |
| 1692 |
@z |
| 1693 |
|
| 1694 |
@x [45.1134] l.21627 - print_file_name |
| 1695 |
print_nl("Font metrics written on "); slow_print(metric_file_name); |
| 1696 |
@y |
| 1697 |
print_nl("Font metrics written on "); print_file_name(0,metric_file_name,0); |
| 1698 |
@z |
| 1699 |
|
| 1700 |
@x [47.1152] l.22122 - declare gf_buf as a pointer, for dynamic allocated |
| 1701 |
@!gf_buf:array[gf_index] of eight_bits; {buffer for \.{GF} output} |
| 1702 |
@y |
| 1703 |
@!gf_buf:^eight_bits; {dynamically-allocated buffer for \.{GF} output} |
| 1704 |
@z |
| 1705 |
|
| 1706 |
@x [47.1154] l.22143 - omit write_gf |
| 1707 |
@<Declare generic font output procedures@>= |
| 1708 |
procedure write_gf(@!a,@!b:gf_index); |
| 1709 |
var k:gf_index; |
| 1710 |
begin for k:=a to b do write(gf_file,gf_buf[k]); |
| 1711 |
end; |
| 1712 |
@y |
| 1713 |
In C, we use a macro to call |fwrite| or |write| directly, writing all |
| 1714 |
the bytes to be written in one shot. Much better than writing four |
| 1715 |
bytes at a time. |
| 1716 |
@z |
| 1717 |
|
| 1718 |
@x [47.1155] l.22150 - check gf file size |
| 1719 |
each time, we use the macro |gf_out|. |
| 1720 |
@y |
| 1721 |
each time, we use the macro |gf_out|. |
| 1722 |
|
| 1723 |
The length of |gf_file| should not exceed |@"7FFFFFFF|; we set |
| 1724 |
|gf_prev_ptr:=0| to prevent further \.{GF} output causing infinite |
| 1725 |
recursion. |
| 1726 |
@z |
| 1727 |
|
| 1728 |
@x [47.1155] l.22158 - gf_swap: check gf file size |
| 1729 |
begin if gf_limit=gf_buf_size then |
| 1730 |
@y |
| 1731 |
begin if gf_ptr>(@"7FFFFFFF-gf_offset) then |
| 1732 |
begin gf_prev_ptr:=0; |
| 1733 |
fatal_error("gf length exceeds ""7FFFFFFF"); |
| 1734 |
@.gf length exceeds...@> |
| 1735 |
end; |
| 1736 |
if gf_limit=gf_buf_size then |
| 1737 |
@z |
| 1738 |
|
| 1739 |
@x [47.1156] l.22171 - empty the last bytes: check gf file size |
| 1740 |
if gf_ptr>0 then write_gf(0,gf_ptr-1) |
| 1741 |
@y |
| 1742 |
if gf_ptr>(@"7FFFFFFF-gf_offset) then |
| 1743 |
begin gf_prev_ptr:=0; |
| 1744 |
fatal_error("gf length exceeds ""7FFFFFFF"); |
| 1745 |
@.gf length exceeds...@> |
| 1746 |
end; |
| 1747 |
if gf_ptr>0 then write_gf(0,gf_ptr-1) |
| 1748 |
@z |
| 1749 |
|
| 1750 |
@x [47.1163] l.22263 - C needs k to be 0..256 instead of 0..255. |
| 1751 |
procedure init_gf; |
| 1752 |
var @!k:eight_bits; {runs through all possible character codes} |
| 1753 |
@y |
| 1754 |
procedure init_gf; |
| 1755 |
var @!k:0..256; {runs through all possible character codes} |
| 1756 |
@z |
| 1757 |
|
| 1758 |
@x [47.1182] l.22501 - print_file_name |
| 1759 |
print_nl("Output written on "); slow_print(output_file_name); |
| 1760 |
@y |
| 1761 |
print_nl("Output written on "); print_file_name(0,output_file_name,0); |
| 1762 |
@z |
| 1763 |
|
| 1764 |
@x [47.1182] l.22503 - i18n fix |
| 1765 |
print(" ("); print_int(total_chars); print(" character"); |
| 1766 |
if total_chars<>1 then print_char("s"); |
| 1767 |
@y |
| 1768 |
print(" ("); print_int(total_chars); |
| 1769 |
if total_chars<>1 then print(" characters") |
| 1770 |
else print(" character"); |
| 1771 |
@z |
| 1772 |
|
| 1773 |
@x [48.1185] l.22533 - INI = VIR. |
| 1774 |
base_ident:=" (INIMF)"; |
| 1775 |
@y |
| 1776 |
if ini_version then base_ident:=" (INIMF)"; |
| 1777 |
@z |
| 1778 |
|
| 1779 |
@x [48.1186] l.22540 - Add base_engine. |
| 1780 |
@!w: four_quarters; {four ASCII codes} |
| 1781 |
@y |
| 1782 |
@!w: four_quarters; {four ASCII codes} |
| 1783 |
@!base_engine: ^text_char; |
| 1784 |
@z |
| 1785 |
|
| 1786 |
@x [48.1187] l.22569 - Add base_engine. |
| 1787 |
@!w: four_quarters; {four ASCII codes} |
| 1788 |
@y |
| 1789 |
@!w: four_quarters; {four ASCII codes} |
| 1790 |
@!base_engine: ^text_char; |
| 1791 |
@!dummy_xord: ASCII_code; |
| 1792 |
@!dummy_xchr: text_char; |
| 1793 |
@!dummy_xprn: ASCII_code; |
| 1794 |
@z |
| 1795 |
|
| 1796 |
@x [48.1188] l.22585 - Reading and writing of `base_file' is done in C. |
| 1797 |
@d dump_wd(#)==begin base_file^:=#; put(base_file);@+end |
| 1798 |
@d dump_int(#)==begin base_file^.int:=#; put(base_file);@+end |
| 1799 |
@d dump_hh(#)==begin base_file^.hh:=#; put(base_file);@+end |
| 1800 |
@d dump_qqqq(#)==begin base_file^.qqqq:=#; put(base_file);@+end |
| 1801 |
@y |
| 1802 |
@z |
| 1803 |
|
| 1804 |
@x [48.1189] l.22599 |
| 1805 |
@d undump_wd(#)==begin get(base_file); #:=base_file^;@+end |
| 1806 |
@d undump_int(#)==begin get(base_file); #:=base_file^.int;@+end |
| 1807 |
@d undump_hh(#)==begin get(base_file); #:=base_file^.hh;@+end |
| 1808 |
@d undump_qqqq(#)==begin get(base_file); #:=base_file^.qqqq;@+end |
| 1809 |
@y |
| 1810 |
@z |
| 1811 |
|
| 1812 |
@x [48.1190] l.22615 - Dump engine name. |
| 1813 |
dump_int(@$);@/ |
| 1814 |
@y |
| 1815 |
dump_int(@"57324D46); {Web2C \MF's magic constant: "W2MF"} |
| 1816 |
{Align engine to 4 bytes with one or more trailing NUL} |
| 1817 |
x:=strlen(engine_name); |
| 1818 |
base_engine:=xmalloc_array(text_char,x+4); |
| 1819 |
strcpy(stringcast(base_engine), engine_name); |
| 1820 |
for k:=x to x+3 do base_engine[k]:=0; |
| 1821 |
x:=x+4-(x mod 4); |
| 1822 |
dump_int(x);dump_things(base_engine[0], x); |
| 1823 |
libc_free(base_engine);@/ |
| 1824 |
dump_int(@$);@/ |
| 1825 |
@<Dump |xord|, |xchr|, and |xprn|@>; |
| 1826 |
@z |
| 1827 |
|
| 1828 |
@x [48.1191] l.22629 - Avoid Pascal file convention. |
| 1829 |
x:=base_file^.int; |
| 1830 |
if x<>@$ then goto off_base; {check that strings are the same} |
| 1831 |
undump_int(x); |
| 1832 |
if x<>mem_min then goto off_base; |
| 1833 |
undump_int(x); |
| 1834 |
if x<>mem_top then goto off_base; |
| 1835 |
@y |
| 1836 |
undump_int(x); |
| 1837 |
if x<>@"57324D46 then goto off_base; {not a base file} |
| 1838 |
undump_int(x); |
| 1839 |
if (x<0) or (x>256) then goto off_base; {corrupted base file} |
| 1840 |
base_engine:=xmalloc_array(text_char, x); |
| 1841 |
undump_things(base_engine[0], x); |
| 1842 |
base_engine[x-1]:=0; {force string termination, just in case} |
| 1843 |
if strcmp(engine_name, stringcast(base_engine)) then |
| 1844 |
begin wake_up_terminal; |
| 1845 |
wterm_ln('---! ', stringcast(name_of_file+1), ' was written by ', stringcast(base_engine)); |
| 1846 |
libc_free(base_engine); |
| 1847 |
goto off_base; |
| 1848 |
end; |
| 1849 |
libc_free(base_engine); |
| 1850 |
undump_int(x); |
| 1851 |
if x<>@$ then begin {check that strings are the same} |
| 1852 |
wake_up_terminal; |
| 1853 |
wterm_ln('---! ', stringcast(name_of_file+1), |
| 1854 |
' made by different executable version'); |
| 1855 |
goto off_base; |
| 1856 |
end; |
| 1857 |
@<Undump |xord|, |xchr|, and |xprn|@>; |
| 1858 |
undump_int(x); |
| 1859 |
if x<>mem_min then goto off_base; |
| 1860 |
{Now we deal with dynamically allocating the memory. We don't provide |
| 1861 |
all the fancy features \.{tex.ch} does---all that matters is enough to |
| 1862 |
run the trap test with a memory size of 3000.} |
| 1863 |
@+init |
| 1864 |
if ini_version then begin |
| 1865 |
{We allocated this at start-up, but now we need to reallocate.} |
| 1866 |
libc_free (mem); |
| 1867 |
end; |
| 1868 |
@+tini |
| 1869 |
undump_int (mem_top); {Overwrite whatever we had.} |
| 1870 |
if mem_max < mem_top then mem_max:=mem_top; {Use at least what we dumped.} |
| 1871 |
if mem_min+1100>mem_top then goto off_base; |
| 1872 |
mem:=xmalloc_array (memory_word, mem_max - mem_min + 1); |
| 1873 |
@z |
| 1874 |
|
| 1875 |
@x [48.1195] l.22713 - Check that p did not become corrupt. |
| 1876 |
p:=q+node_size(q); |
| 1877 |
if (p>lo_mem_max)or((q>=rlink(q))and(rlink(q)<>rover)) then goto off_base; |
| 1878 |
@y |
| 1879 |
{If the base file is messed up, that addition to |p| might cause it to |
| 1880 |
become garbage. Report from Gregory James DUCK to Karl, 14 Sep 2023. |
| 1881 |
Also changed in \MF. Fix from DRF, who explains: we test before doing the |
| 1882 |
addition to avoid assuming silent wrap-around overflow, and also to to |
| 1883 |
catch cases where |node_size| was, say, bogusly the equivalent of $-1$ |
| 1884 |
and thus |p+node_size| would still look valid.} |
| 1885 |
if (node_size(q)>lo_mem_max-q) or (rlink(q)>lo_mem_max) |
| 1886 |
or ((q>=rlink(q))and(rlink(q)<>rover)) |
| 1887 |
then goto off_base; |
| 1888 |
p:=q+node_size(q); |
| 1889 |
@z |
| 1890 |
|
| 1891 |
@x [48.1199] l.22767 - Allow command line to override dumped value. |
| 1892 |
undump(batch_mode)(error_stop_mode)(interaction); |
| 1893 |
@y |
| 1894 |
undump(batch_mode)(error_stop_mode)(interaction); |
| 1895 |
if interaction_option<>unspecified_mode then interaction:=interaction_option; |
| 1896 |
@z |
| 1897 |
|
| 1898 |
@x [48.1199] l.22772 - Test for end-of-file already done by undump. |
| 1899 |
undump_int(x);@+if (x<>69069)or eof(base_file) then goto off_base |
| 1900 |
@y |
| 1901 |
undump_int(x);@+if x<>69069 then goto off_base |
| 1902 |
@z |
| 1903 |
|
| 1904 |
@x [49.1204] l.22858 - Dynamic allocation. |
| 1905 |
@p begin @!{|start_here|} |
| 1906 |
@y |
| 1907 |
@d const_chk(#) == begin if # < inf@&# then # := inf@&# else |
| 1908 |
if # > sup@&# then # := sup@&# end |
| 1909 |
{|setup_bound_var| stuff duplicated in \.{tex.ch}.} |
| 1910 |
@d setup_bound_var(#) == bound_default := #; setup_bound_var_end |
| 1911 |
@d setup_bound_var_end(#) == bound_name := #; setup_bound_var_end_end |
| 1912 |
@d setup_bound_var_end_end(#) == |
| 1913 |
setup_bound_variable (address_of (#), bound_name, bound_default) |
| 1914 |
|
| 1915 |
@p begin @!{|start_here|} |
| 1916 |
{See comments in \.{tex.ch} for why the name has to be duplicated.} |
| 1917 |
setup_bound_var (250000)('main_memory')(main_memory); |
| 1918 |
{|memory_word|s for |mem| in \.{INIMF}} |
| 1919 |
setup_bound_var (3000)('buf_size')(buf_size); |
| 1920 |
setup_bound_var (79)('error_line')(error_line); |
| 1921 |
setup_bound_var (50)('half_error_line')(half_error_line); |
| 1922 |
setup_bound_var (79)('max_print_line')(max_print_line); |
| 1923 |
setup_bound_var (768)('screen_width')(screen_width); |
| 1924 |
setup_bound_var (1024)('screen_depth')(screen_depth); |
| 1925 |
setup_bound_var (16384)('gf_buf_size')(gf_buf_size); |
| 1926 |
if error_line > ssup_error_line then error_line := ssup_error_line; |
| 1927 |
if screen_width > ssup_screen_width then screen_width := ssup_screen_width; |
| 1928 |
if screen_depth > ssup_screen_depth then screen_depth := ssup_screen_depth; |
| 1929 |
|
| 1930 |
const_chk (main_memory); |
| 1931 |
{|mem_top| is an index, |main_memory| is a size} |
| 1932 |
mem_top := mem_min + main_memory - 1; |
| 1933 |
mem_max := mem_top; |
| 1934 |
const_chk (buf_size); |
| 1935 |
|
| 1936 |
buffer:=xmalloc_array (ASCII_code, buf_size); |
| 1937 |
row_transition:=xmalloc_array (screen_col, screen_width); |
| 1938 |
gf_buf:=xmalloc_array (eight_bits, gf_buf_size); |
| 1939 |
source_filename_stack:=xmalloc_array (str_number, max_in_open); |
| 1940 |
full_source_filename_stack:=xmalloc_array (str_number, max_in_open); |
| 1941 |
|
| 1942 |
@+init |
| 1943 |
if ini_version then begin |
| 1944 |
mem:=xmalloc_array (memory_word, mem_top - mem_min + 1); |
| 1945 |
end; |
| 1946 |
@+tini |
| 1947 |
@z |
| 1948 |
|
| 1949 |
@x [49.1204] l.22870 - Only do get_strings_started if ini. |
| 1950 |
@!init if not get_strings_started then goto final_end; |
| 1951 |
init_tab; {initialize the tables} |
| 1952 |
init_prim; {call |primitive| for each primitive} |
| 1953 |
init_str_ptr:=str_ptr; init_pool_ptr:=pool_ptr;@/ |
| 1954 |
max_str_ptr:=str_ptr; max_pool_ptr:=pool_ptr; fix_date_and_time; |
| 1955 |
tini@/ |
| 1956 |
@y 22833 |
| 1957 |
@!init |
| 1958 |
if ini_version then begin |
| 1959 |
if not get_strings_started then goto final_end; |
| 1960 |
init_tab; {initialize the tables} |
| 1961 |
init_prim; {call |primitive| for each primitive} |
| 1962 |
init_str_ptr:=str_ptr; init_pool_ptr:=pool_ptr;@/ |
| 1963 |
max_str_ptr:=str_ptr; max_pool_ptr:=pool_ptr; fix_date_and_time; |
| 1964 |
end; |
| 1965 |
tini@/ |
| 1966 |
@z |
| 1967 |
|
| 1968 |
@x [49.1204] l.22885 |
| 1969 |
end_of_MF: close_files_and_terminate; |
| 1970 |
final_end: ready_already:=0; |
| 1971 |
@y |
| 1972 |
close_files_and_terminate; |
| 1973 |
final_end: do_final_end; |
| 1974 |
@z |
| 1975 |
|
| 1976 |
% [49.1205] close_files_and_terminate: Print new line before |
| 1977 |
% termination; switch to editor if necessary. |
| 1978 |
@x [49.1205] l.22917 |
| 1979 |
slow_print(log_name); print_char("."); |
| 1980 |
end; |
| 1981 |
end; |
| 1982 |
@y |
| 1983 |
print_file_name(0,log_name,0); print_char("."); |
| 1984 |
end; |
| 1985 |
end; |
| 1986 |
print_ln; |
| 1987 |
if (edit_name_start<>0) and (interaction>batch_mode) then |
| 1988 |
call_edit(str_pool,edit_name_start,edit_name_length,edit_line); |
| 1989 |
@z |
| 1990 |
|
| 1991 |
@x [49.1209] l.23018 - Only do dump if ini. |
| 1992 |
begin @!init store_base_file; return;@+tini@/ |
| 1993 |
@y |
| 1994 |
begin |
| 1995 |
@!init if ini_version then begin store_base_file; return;end;@+tini@/ |
| 1996 |
@z |
| 1997 |
|
| 1998 |
%@x [49.1211] l.23002 - Handle %&base line. |
| 1999 |
%if (base_ident=0)or(buffer[loc]="&") then |
| 2000 |
%@y |
| 2001 |
%if (base_ident=0)or(buffer[loc]="&")or dump_line then |
| 2002 |
%@z |
| 2003 |
|
| 2004 |
@x [51.1214] l.23126 - Add editor-switch variable to globals. |
| 2005 |
This section should be replaced, if necessary, by any special |
| 2006 |
modifications of the program |
| 2007 |
that are necessary to make \MF\ work at a particular installation. |
| 2008 |
It is usually best to design your change file so that all changes to |
| 2009 |
previous sections preserve the section numbering; then everybody's version |
| 2010 |
will be consistent with the published program. More extensive changes, |
| 2011 |
which introduce new sections, can be inserted here; then only the index |
| 2012 |
itself will get a new section number. |
| 2013 |
@^system dependencies@> |
| 2014 |
@y |
| 2015 |
Here are the variables used to hold ``switch-to-editor'' information. |
| 2016 |
@^system dependencies@> |
| 2017 |
|
| 2018 |
@<Global...@>= |
| 2019 |
@!edit_name_start: pool_pointer; |
| 2020 |
@!edit_name_length,@!edit_line: integer; |
| 2021 |
@!xprn: array[ASCII_code] of ASCII_code; {use \.{\^\^} notation?} |
| 2022 |
@!stop_at_space: boolean; {whether |more_name| returns false for space} |
| 2023 |
|
| 2024 |
@ The |edit_name_start| will be set to point into |str_pool| somewhere after |
| 2025 |
its beginning if \MF\ is supposed to switch to an editor on exit. |
| 2026 |
|
| 2027 |
Initialize the |stop_at_space| variable for filename parsing. |
| 2028 |
|
| 2029 |
Initialize the |halting_on_error_p| variable to avoid infloop with |
| 2030 |
\.{--halt-on-error}. |
| 2031 |
|
| 2032 |
@<Set init...@>= |
| 2033 |
edit_name_start:=0; |
| 2034 |
stop_at_space:=true; |
| 2035 |
halting_on_error_p:=false; |
| 2036 |
|
| 2037 |
@ Dumping the |xord|, |xchr|, and |xprn| arrays. We dump these always |
| 2038 |
in the format, so a TCX file loaded during format creation can set a |
| 2039 |
default for users of the format. |
| 2040 |
|
| 2041 |
@<Dump |xord|, |xchr|, and |xprn|@>= |
| 2042 |
dump_things(xord[0], 256); |
| 2043 |
dump_things(xchr[0], 256); |
| 2044 |
dump_things(xprn[0], 256); |
| 2045 |
|
| 2046 |
@ Undumping the |xord|, |xchr|, and |xprn| arrays. This code is more |
| 2047 |
complicated, because we want to ensure that a TCX file specified on |
| 2048 |
the command line will override whatever is in the format. Since the |
| 2049 |
tcx file has already been loaded, that implies throwing away the data |
| 2050 |
in the format. Also, if no |translate_filename| is given, but |
| 2051 |
|eight_bit_p| is set we have to make all characters printable. |
| 2052 |
|
| 2053 |
@<Undump |xord|, |xchr|, and |xprn|@>= |
| 2054 |
if translate_filename then begin |
| 2055 |
for k:=0 to 255 do undump_things(dummy_xord, 1); |
| 2056 |
for k:=0 to 255 do undump_things(dummy_xchr, 1); |
| 2057 |
for k:=0 to 255 do undump_things(dummy_xprn, 1); |
| 2058 |
end |
| 2059 |
else begin |
| 2060 |
undump_things(xord[0], 256); |
| 2061 |
undump_things(xchr[0], 256); |
| 2062 |
undump_things(xprn[0], 256); |
| 2063 |
if eight_bit_p then |
| 2064 |
for k:=0 to 255 do |
| 2065 |
xprn[k]:=1; |
| 2066 |
end; |
| 2067 |
@z |