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