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