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