| 1 |
% |
| 2 |
% This file is part of the Omega project, which |
| 3 |
% is based in the web2c distribution of TeX. |
| 4 |
% |
| 5 |
% Copyright (c) 1994--1998 John Plaice and Yannis Haralambous |
| 6 |
% applies only to the changes to the original pltotf.ch. |
| 7 |
% |
| 8 |
% pltotf.ch for C compilation with web2c. |
| 9 |
% |
| 10 |
% 04/04/83 (PC) Original version, made to work with version 1.2 of PLtoTF. |
| 11 |
% 04/16/83 (PC) Brought up to version 1.3 of PLtoTF. |
| 12 |
% 06/30/83 (HWT) Revised changefile format for version 1.7 Tangle |
| 13 |
% 07/28/83 (HWT) Brought up to version 2 |
| 14 |
% 12/19/86 (ETM) Brought up to version 2.1 |
| 15 |
% 07/05/87 (ETM) Brought up to version 2.3 |
| 16 |
% 03/22/88 (ETM) Converted for use with WEB to C |
| 17 |
% 11/29/89 (KB) Version 3. |
| 18 |
% 01/16/90 (SR) Version 3.2. |
| 19 |
% (more recent changes in the ChangeLog) |
| 20 |
|
| 21 |
@x [0] WEAVE: print changes only. |
| 22 |
\pageno=\contentspagenumber \advance\pageno by 1 |
| 23 |
@y |
| 24 |
\pageno=\contentspagenumber \advance\pageno by 1 |
| 25 |
%\let\maybe=\iffalse |
| 26 |
%\def\title{OPL2OFM changes for C} |
| 27 |
@z |
| 28 |
|
| 29 |
@x [1] Define my_name |
| 30 |
@d banner=='This is OPL2OFM, Version 1.13' {printed when the program starts} |
| 31 |
@y |
| 32 |
@d my_name=='opl2ofm' |
| 33 |
@d banner=='This is OPL2OFM, Version 1.13' {printed when the program starts} |
| 34 |
@z |
| 35 |
|
| 36 |
@x [2] Print all terminal output on stderr. |
| 37 |
@d print(#)==write(#) |
| 38 |
@d print_ln(#)==write_ln(#) |
| 39 |
@y |
| 40 |
@d print(#)==write(stderr,#) |
| 41 |
@d print_ln(#)==write_ln(stderr,#) |
| 42 |
@d print_real(#)==fprint_real(stderr,#) |
| 43 |
@z |
| 44 |
|
| 45 |
@x [still 2] No banner unless verbose. |
| 46 |
procedure initialize; {this procedure gets things started properly} |
| 47 |
var @<Local variables for initialization@>@/ |
| 48 |
begin print_ln(banner);@/ |
| 49 |
@y |
| 50 |
@<Define |parse_arguments|@> |
| 51 |
procedure initialize; {this procedure gets things started properly} |
| 52 |
var @<Local variables for initialization@>@/ |
| 53 |
begin kpse_set_program_name (argv[0], my_name); |
| 54 |
parse_arguments; |
| 55 |
@z |
| 56 |
|
| 57 |
@x [3] Larger constants. |
| 58 |
@!buf_size=60; {length of lines displayed in error messages} |
| 59 |
@y |
| 60 |
@!buf_size=3000; {length of lines displayed in error messages} |
| 61 |
@z |
| 62 |
|
| 63 |
@x [6] Open PL file. |
| 64 |
reset(pl_file); |
| 65 |
@y |
| 66 |
reset (pl_file, pl_name); |
| 67 |
if verbose then begin |
| 68 |
print (banner); |
| 69 |
print_ln (version_string); |
| 70 |
end; |
| 71 |
@z |
| 72 |
|
| 73 |
@x [16] Open TFM file. |
| 74 |
@ On some systems you may have to do something special to write a |
| 75 |
packed file of bytes. For example, the following code didn't work |
| 76 |
when it was first tried at Stanford, because packed files have to be |
| 77 |
opened with a special switch setting on the \PASCAL\ that was used. |
| 78 |
@^system dependencies@> |
| 79 |
|
| 80 |
@<Set init...@>= |
| 81 |
rewrite(tfm_file); |
| 82 |
@y |
| 83 |
@ On some systems you may have to do something special to write a |
| 84 |
packed file of bytes. It's no problem in C. |
| 85 |
@^system dependencies@> |
| 86 |
|
| 87 |
@<Set init...@>= |
| 88 |
rewritebin (tfm_file, tfm_name); |
| 89 |
@z |
| 90 |
|
| 91 |
@x [17] Avoid name conflict; MinGW defines `byte' in <rpcndr.h>. |
| 92 |
correspond to one-character constants like \.{"A"} in \.{WEB} language. |
| 93 |
@y |
| 94 |
correspond to one-character constants like \.{"A"} in \.{WEB} language. |
| 95 |
|
| 96 |
@d byte == byte_type |
| 97 |
@z |
| 98 |
|
| 99 |
@x [18] Pascal Web's char |
| 100 |
@d first_ord=0 {ordinal number of the smallest element of |char|} |
| 101 |
@y |
| 102 |
@d char == 0..255 |
| 103 |
@d first_ord=0 {ordinal number of the smallest element of |char|} |
| 104 |
@z |
| 105 |
|
| 106 |
@x [25] Non-zero return code in case of problems. |
| 107 |
@!chars_on_line:0..9; {the number of characters printed on the current line} |
| 108 |
@y |
| 109 |
@!chars_on_line:0..9; {the number of characters printed on the current line} |
| 110 |
@!perfect:boolean; {was the file free of errors?} |
| 111 |
@z |
| 112 |
|
| 113 |
@x [26] Non-zero return code in case of problems. |
| 114 |
chars_on_line:=0; |
| 115 |
@y |
| 116 |
chars_on_line:=0; |
| 117 |
perfect:=true; {innocent until proved guilty} |
| 118 |
@z |
| 119 |
|
| 120 |
@x [27] Non-zero return code in case of problems. |
| 121 |
chars_on_line:=0; |
| 122 |
@y |
| 123 |
chars_on_line:=0; |
| 124 |
perfect:=false; |
| 125 |
@z |
| 126 |
|
| 127 |
@x [31] (get_keyword_char) Unnecessary due to previous change. |
| 128 |
begin while (loc=limit)and(not right_ln) do fill_buffer; |
| 129 |
if loc=limit then cur_char:=" " {end-of-line counts as a delimiter} |
| 130 |
else begin cur_char:=xord[buffer[loc+1]]; |
| 131 |
@y |
| 132 |
begin while loc=limit do fill_buffer; |
| 133 |
begin cur_char:=xord[buffer[loc+1]]; |
| 134 |
@z |
| 135 |
|
| 136 |
@x [79] `index' might be a library routine. |
| 137 |
|k|th element of its list. |
| 138 |
@y |
| 139 |
|k|th element of its list. |
| 140 |
@d index == index_var |
| 141 |
@z |
| 142 |
|
| 143 |
@x [116] No output (except errors) unless verbose. |
| 144 |
@<Print |c| in hex notation@>; |
| 145 |
@y |
| 146 |
if verbose then @<Print |c| in hex notation@>; |
| 147 |
@z |
| 148 |
|
| 149 |
@x [119] No output (except errors) unless verbose. |
| 150 |
@<Print |c| in hex notation@>; |
| 151 |
@y |
| 152 |
if verbose then @<Print |c| in hex notation@>; |
| 153 |
@z |
| 154 |
@x |
| 155 |
print('-'); print_hex(c+crange); incr(chars_on_line); |
| 156 |
@y |
| 157 |
if verbose then begin |
| 158 |
print('-'); print_hex(c+crange); incr(chars_on_line); |
| 159 |
end; |
| 160 |
@z |
| 161 |
|
| 162 |
% [27, 28] Change strings to C char pointers. The Pascal strings are |
| 163 |
% indexed starting at 1, so we pad with a blank. |
| 164 |
@x |
| 165 |
@!HEX: packed array [1..16] of char; |
| 166 |
@y |
| 167 |
@!HEX: const_c_string; |
| 168 |
@z |
| 169 |
|
| 170 |
@x |
| 171 |
HEX:='0123456789ABCDEF';@/ |
| 172 |
@y |
| 173 |
HEX:=' 0123456789ABCDEF';@/ |
| 174 |
@z |
| 175 |
|
| 176 |
@x [115] Output of reals. |
| 177 |
@ @d round_message(#)==if delta>0 then print_ln('I had to round some ', |
| 178 |
@.I had to round...@> |
| 179 |
#,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.') |
| 180 |
@y |
| 181 |
@ @d round_message(#)==if delta>0 then begin print('I had to round some ', |
| 182 |
@.I had to round...@> |
| 183 |
#,'s by '); print_real((((delta+1) div 2)/@'4000000),1,7); |
| 184 |
print_ln(' units.'); end |
| 185 |
@z |
| 186 |
|
| 187 |
% [118] Change the name of the variable `class', since AIX 3.1's <math.h> |
| 188 |
% defines a function by that name. |
| 189 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 190 |
@x |
| 191 |
@d pending=4 {$f(x,y)$ is being evaluated} |
| 192 |
@y |
| 193 |
@d pending=4 {$f(x,y)$ is being evaluated} |
| 194 |
@d class == class_var {Avoid problems with AIX \.{<math.h>}} |
| 195 |
@z |
| 196 |
|
| 197 |
% [123] web2c can't handle these mutually recursive procedures. |
| 198 |
% But let's do a fake definition of f here, so that it gets into web2c's |
| 199 |
% symbol table... |
| 200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 201 |
@x |
| 202 |
@p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@> |
| 203 |
{compute $f$ for arguments known to be in |hash[h]|} |
| 204 |
@y |
| 205 |
@p |
| 206 |
ifdef('notdef') |
| 207 |
function f(@!h,@!x,@!y:indx):indx; begin end;@t\2@> |
| 208 |
{compute $f$ for arguments known to be in |hash[h]|} |
| 209 |
endif('notdef') |
| 210 |
@z |
| 211 |
|
| 212 |
% [124] ... and then really define it now. |
| 213 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 214 |
@x |
| 215 |
@p function f; |
| 216 |
@y |
| 217 |
@p function f(@!h,@!x,@!y:indx):indx; |
| 218 |
@z |
| 219 |
|
| 220 |
@x [127] Fix up output of bytes. |
| 221 |
@d out(#)==write(tfm_file,#) |
| 222 |
@y |
| 223 |
@d out(#)==putbyte(#,tfm_file) |
| 224 |
@z |
| 225 |
|
| 226 |
@x [136] Fix output of reals. |
| 227 |
@p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|} |
| 228 |
var @!n:byte; {the first byte after the sign} |
| 229 |
@!m:0..65535; {the two least significant bytes} |
| 230 |
begin if abs(x/design_units)>=16.0 then |
| 231 |
begin print_ln('The relative dimension ',x/@'4000000:1:3, |
| 232 |
' is too large.'); |
| 233 |
@.The relative dimension...@> |
| 234 |
print(' (Must be less than 16*designsize'); |
| 235 |
if design_units<>unity then print(' =',design_units/@'200000:1:3, |
| 236 |
' designunits'); |
| 237 |
@y |
| 238 |
@p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|} |
| 239 |
var @!n:byte; {the first byte after the sign} |
| 240 |
@!m:0..65535; {the two least significant bytes} |
| 241 |
begin if fabs(x/design_units)>=16.0 then |
| 242 |
begin print('The relative dimension '); |
| 243 |
print_real(x/@'4000000,1,3); |
| 244 |
print_ln(' is too large.'); |
| 245 |
@.The relative dimension...@> |
| 246 |
print(' (Must be less than 16*designsize'); |
| 247 |
if design_units<>unity then begin print(' ='); |
| 248 |
print_real(design_units/@'200000,1,3); |
| 249 |
print(' designunits'); |
| 250 |
end; |
| 251 |
@z |
| 252 |
|
| 253 |
@x [170] Eliminate unused variables. |
| 254 |
var @!krn_ptr:0..max_kerns; {an index into |kern|} |
| 255 |
@!c:integer; {runs through all character codes} |
| 256 |
@y |
| 257 |
@z |
| 258 |
|
| 259 |
@x [172] Be quiet unless verbose. |
| 260 |
read_input; print('.');@/ |
| 261 |
@y |
| 262 |
read_input; |
| 263 |
if verbose then print_ln('.'); |
| 264 |
@z |
| 265 |
|
| 266 |
@x [172] Non-zero return code in case of problems, |
| 267 |
end. |
| 268 |
@y |
| 269 |
if not perfect then uexit(1); |
| 270 |
end. |
| 271 |
@z |
| 272 |
|
| 273 |
@x [253] System-dependent changes. |
| 274 |
This section should be replaced, if necessary, by changes to the program |
| 275 |
that are necessary to make \.{PLtoTF} work at a particular installation. |
| 276 |
It is usually best to design your change file so that all changes to |
| 277 |
previous sections preserve the section numbering; then everybody's version |
| 278 |
will be consistent with the printed program. More extensive changes, |
| 279 |
which introduce new sections, can be inserted here; then only the index |
| 280 |
itself will get a new section number. |
| 281 |
@^system dependencies@> |
| 282 |
@y |
| 283 |
Parse a Unix-style command line. |
| 284 |
|
| 285 |
@d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0) |
| 286 |
|
| 287 |
@<Define |parse_arguments|@> = |
| 288 |
procedure parse_arguments; |
| 289 |
const n_options = 3; {Pascal won't count array lengths for us.} |
| 290 |
var @!long_options: array[0..n_options] of getopt_struct; |
| 291 |
@!getopt_return_val: integer; |
| 292 |
@!option_index: c_int_type; |
| 293 |
@!current_option: 0..n_options; |
| 294 |
begin |
| 295 |
@<Initialize the option variables@>; |
| 296 |
@<Define the option table@>; |
| 297 |
repeat |
| 298 |
getopt_return_val := getopt_long_only (argc, argv, '', long_options, |
| 299 |
address_of (option_index)); |
| 300 |
if getopt_return_val = -1 then begin |
| 301 |
{End of arguments; we exit the loop below.} ; |
| 302 |
|
| 303 |
end else if getopt_return_val = "?" then begin |
| 304 |
usage (my_name); |
| 305 |
|
| 306 |
end else if argument_is ('help') then begin |
| 307 |
usage_help (OPL2OFM_HELP, nil); |
| 308 |
|
| 309 |
end else if argument_is ('version') then begin |
| 310 |
print_version_and_exit |
| 311 |
(banner, nil, 'J. Plaice, Y. Haralambous, D.E. Knuth', nil); |
| 312 |
|
| 313 |
end; {Else it was a flag; |getopt| has already done the assignment.} |
| 314 |
until getopt_return_val = -1; |
| 315 |
|
| 316 |
{Now |optind| is the index of first non-option on the command line. |
| 317 |
We must have one or two remaining arguments.} |
| 318 |
if (optind + 1 <> argc) and (optind + 2 <> argc) then begin |
| 319 |
write_ln (stderr, my_name, ': Need one or two file arguments.'); |
| 320 |
usage (my_name); |
| 321 |
end; |
| 322 |
|
| 323 |
pl_name := extend_filename (cmdline (optind), 'opl'); |
| 324 |
|
| 325 |
{If an explicit output filename isn't given, construct it from |pl_name|.} |
| 326 |
if optind + 2 = argc then begin |
| 327 |
tfm_name := extend_filename (cmdline (optind + 1), 'ofm'); |
| 328 |
end else begin |
| 329 |
tfm_name := basename_change_suffix (pl_name, '.opl', '.ofm'); |
| 330 |
end; |
| 331 |
end; |
| 332 |
|
| 333 |
@ Here are the options we allow. The first is one of the standard GNU options. |
| 334 |
@.-help@> |
| 335 |
|
| 336 |
@<Define the option...@> = |
| 337 |
current_option := 0; |
| 338 |
long_options[current_option].name := 'help'; |
| 339 |
long_options[current_option].has_arg := 0; |
| 340 |
long_options[current_option].flag := 0; |
| 341 |
long_options[current_option].val := 0; |
| 342 |
incr (current_option); |
| 343 |
|
| 344 |
@ Another of the standard options. |
| 345 |
@.-version@> |
| 346 |
|
| 347 |
@<Define the option...@> = |
| 348 |
long_options[current_option].name := 'version'; |
| 349 |
long_options[current_option].has_arg := 0; |
| 350 |
long_options[current_option].flag := 0; |
| 351 |
long_options[current_option].val := 0; |
| 352 |
incr (current_option); |
| 353 |
|
| 354 |
@ Print progress information? |
| 355 |
|
| 356 |
@<Define the option...@> = |
| 357 |
long_options[current_option].name := 'verbose'; |
| 358 |
long_options[current_option].has_arg := 0; |
| 359 |
long_options[current_option].flag := address_of (verbose); |
| 360 |
long_options[current_option].val := 1; |
| 361 |
incr (current_option); |
| 362 |
|
| 363 |
@ |
| 364 |
@<Glob...@> = |
| 365 |
@!verbose: c_int_type; |
| 366 |
|
| 367 |
@ |
| 368 |
@<Initialize the option...@> = |
| 369 |
verbose := false; |
| 370 |
|
| 371 |
@ An element with all zeros always ends the list. |
| 372 |
|
| 373 |
@<Define the option...@> = |
| 374 |
long_options[current_option].name := 0; |
| 375 |
long_options[current_option].has_arg := 0; |
| 376 |
long_options[current_option].flag := 0; |
| 377 |
long_options[current_option].val := 0; |
| 378 |
|
| 379 |
@ Global filenames. |
| 380 |
|
| 381 |
@<Global...@> = |
| 382 |
@!tfm_name,@!pl_name:const_c_string; |
| 383 |
@z |