| 1 |
% vftovp.ch for C compilation with web2c. |
| 2 |
% Written by [email protected]. |
| 3 |
% This file is in the public domain. |
| 4 |
|
| 5 |
@x [0] l.18 |
| 6 |
\def\title{VF\lowercase{to}VP} |
| 7 |
@y |
| 8 |
\def\title{VF$\,$\lowercase{to}$\,$VP changes for C} |
| 9 |
@z |
| 10 |
|
| 11 |
@x [0] WEAVE: print changes only. |
| 12 |
\pageno=\contentspagenumber \advance\pageno by 1 |
| 13 |
@y |
| 14 |
\pageno=\contentspagenumber \advance\pageno by 1 |
| 15 |
\let\maybe=\iffalse |
| 16 |
@z |
| 17 |
|
| 18 |
@x [1] Define my_name |
| 19 |
@d banner=='This is VFtoVP, Version 1.4' {printed when the program starts} |
| 20 |
@y |
| 21 |
@d my_name=='vftovp' |
| 22 |
@d banner=='This is VFtoVP, Version 1.4' {printed when the program starts} |
| 23 |
@z |
| 24 |
|
| 25 |
@x [2] All terminal output goes to stderr, so we can dump the vpl on stdout. |
| 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 |
% [2] We need to tell web2c about one special variable. |
| 35 |
% Perhaps it would be better to allow @define's |
| 36 |
% anywhere in a source file, but that seemed just as painful as this. |
| 37 |
@x [2] |
| 38 |
@p program VFtoVP(@!vf_file,@!tfm_file,@!vpl_file,@!output); |
| 39 |
@y |
| 40 |
@p |
| 41 |
{Tangle doesn't recognize @@ when it's right after the \.=.} |
| 42 |
@\@= @@define var tfm;@>@\ |
| 43 |
|
| 44 |
program VFtoVP(@!vf_file,@!tfm_file,@!vpl_file,@!output); |
| 45 |
@z |
| 46 |
|
| 47 |
@x still [2] Set up for path reading. |
| 48 |
procedure initialize; {this procedure gets things started properly} |
| 49 |
var @!k:integer; {all-purpose index for initialization} |
| 50 |
begin print_ln(banner);@/ |
| 51 |
@y |
| 52 |
@<Define \(p)|parse_arguments|@> |
| 53 |
procedure initialize; {this procedure gets things started properly} |
| 54 |
var @!k:integer; {all-purpose index for initialization} |
| 55 |
begin |
| 56 |
kpse_set_program_name (argv[0], my_name); |
| 57 |
kpse_init_prog ('VFTOVP', 0, nil, nil); |
| 58 |
{We |xrealloc| when we know how big the file is. The 1000 comes |
| 59 |
from the negative lower bound.} |
| 60 |
tfm_file_array := xmalloc_array (byte, 1002); |
| 61 |
parse_arguments; |
| 62 |
@z |
| 63 |
|
| 64 |
% [4] No name_length. |
| 65 |
% Also, AIX defines `class' in <math.h>, so let's take this opportunity to |
| 66 |
% define that away. |
| 67 |
% And increase several constants. |
| 68 |
@x [4] |
| 69 |
@<Constants...@>= |
| 70 |
@!tfm_size=30000; {maximum length of |tfm| data, in bytes} |
| 71 |
@!vf_size=10000; {maximum length of |vf| data, in bytes} |
| 72 |
@!max_fonts=300; {maximum number of local fonts in the |vf| file} |
| 73 |
@!lig_size=5000; {maximum length of |lig_kern| program, in words} |
| 74 |
@!hash_size=5003; {preferably a prime number, a bit larger than the number |
| 75 |
of character pairs in lig/kern steps} |
| 76 |
@!name_length=50; {a file name shouldn't be longer than this} |
| 77 |
@!max_stack=50; {maximum depth of \.{DVI} stack in character packets} |
| 78 |
@y |
| 79 |
@d class == class_var |
| 80 |
@<Constants...@>= |
| 81 |
@!vf_size=100000; {maximum length of |vf| data, in bytes} |
| 82 |
@!max_fonts=300; {maximum number of local fonts in the |vf| file} |
| 83 |
@!lig_size=32510; {maximum length of |lig_kern| program, in words} |
| 84 |
@!hash_size=32579; {preferably a prime number, a bit larger than the number |
| 85 |
of character pairs in lig/kern steps} |
| 86 |
@!max_stack=100; {maximum depth of \.{DVI} stack in character packets} |
| 87 |
@z |
| 88 |
|
| 89 |
@x [11] Open the files. |
| 90 |
@ On some systems you may have to do something special to read a |
| 91 |
packed file of bytes. For example, the following code didn't work |
| 92 |
when it was first tried at Stanford, because packed files have to be |
| 93 |
opened with a special switch setting on the \PASCAL\ that was used. |
| 94 |
@^system dependencies@> |
| 95 |
|
| 96 |
@<Set init...@>= |
| 97 |
reset(tfm_file); reset(vf_file); |
| 98 |
@y |
| 99 |
@ We don't have to do anything special to read a packed file of bytes, |
| 100 |
but we do want to use environment variables to find the input files. |
| 101 |
@^system dependencies@> |
| 102 |
|
| 103 |
@<Set init...@>= |
| 104 |
{See comments at |kpse_find_vf| in \.{kpathsea/tex-file.h} for why we |
| 105 |
don't use it.} |
| 106 |
vf_file := kpse_open_file (vf_name, kpse_vf_format); |
| 107 |
tfm_file := kpse_open_file (tfm_name, kpse_tfm_format); |
| 108 |
|
| 109 |
if verbose then begin |
| 110 |
print (banner); |
| 111 |
print_ln (version_string); |
| 112 |
end; |
| 113 |
@z |
| 114 |
|
| 115 |
@x [21] Open VPL file. |
| 116 |
@ @<Set init...@>= |
| 117 |
rewrite(vpl_file); |
| 118 |
@y |
| 119 |
@ If an explicit filename isn't given, we write to |stdout|. |
| 120 |
|
| 121 |
@<Set init...@>= |
| 122 |
if optind + 3 > argc then begin |
| 123 |
vpl_file := stdout; |
| 124 |
end else begin |
| 125 |
vpl_name := extend_filename (cmdline (optind + 2), 'vpl'); |
| 126 |
rewrite (vpl_file, vpl_name); |
| 127 |
end; |
| 128 |
@z |
| 129 |
|
| 130 |
@x [22] `index' is not a good choice of identifier in C. |
| 131 |
@<Types...@>= |
| 132 |
@!index=0..tfm_size; {address of a byte in |tfm|} |
| 133 |
@y |
| 134 |
@d index == index_type |
| 135 |
|
| 136 |
@<Types...@>= |
| 137 |
@!index=integer; {address of a byte in |tfm|} |
| 138 |
@z |
| 139 |
|
| 140 |
@x [23] Make |tfm| be dynamically allocated. |
| 141 |
@!tfm:array [-1000..tfm_size] of byte; {the \.{TFM} input data all goes here} |
| 142 |
@y |
| 143 |
{Kludge here to define |tfm| as a macro which takes care of the negative |
| 144 |
lower bound. We've defined |tfm| for the benefit of web2c above.} |
| 145 |
@=#define tfm (tfmfilearray + 1001);@>@\ |
| 146 |
@!tfm_file_array: ^byte; {the input data all goes here} |
| 147 |
@z |
| 148 |
|
| 149 |
@x [24] abort() should cause a bad exit code. |
| 150 |
@d abort(#)==begin print_ln(#); |
| 151 |
print_ln('Sorry, but I can''t go on; are you sure this is a TFM?'); |
| 152 |
goto final_end; |
| 153 |
end |
| 154 |
@y |
| 155 |
@d abort(#)==begin print_ln(#); |
| 156 |
print_ln('Sorry, but I can''t go on; are you sure this is a TFM?'); |
| 157 |
uexit(1); |
| 158 |
end |
| 159 |
@z |
| 160 |
|
| 161 |
@x [24] Allow arbitrarily large input files. |
| 162 |
if 4*lf-1>tfm_size then abort('The file is bigger than I can handle!'); |
| 163 |
@.The file is bigger...@> |
| 164 |
@y |
| 165 |
tfm_file_array := xrealloc_array (tfm_file_array, byte, 4 * lf + 1000); |
| 166 |
@z |
| 167 |
|
| 168 |
@x [31] Ditto for vf_abort. |
| 169 |
@d vf_abort(#)== |
| 170 |
begin print_ln(#); |
| 171 |
print_ln('Sorry, but I can''t go on; are you sure this is a VF?'); |
| 172 |
goto final_end; |
| 173 |
end |
| 174 |
@y |
| 175 |
@d vf_abort(#)== |
| 176 |
begin print_ln(#); |
| 177 |
print_ln('Sorry, but I can''t go on; are you sure this is a VF?'); |
| 178 |
uexit(1); |
| 179 |
end |
| 180 |
@z |
| 181 |
|
| 182 |
@x [32] Be quiet if not -verbose. |
| 183 |
for k:=0 to vf_ptr-1 do print(xchr[vf[k]]); |
| 184 |
print_ln(' '); count:=0; |
| 185 |
@y |
| 186 |
if verbose then begin |
| 187 |
for k:=0 to vf_ptr-1 do print(xchr[vf[k]]); |
| 188 |
print_ln(' '); |
| 189 |
end; |
| 190 |
count:=0; |
| 191 |
@z |
| 192 |
|
| 193 |
@x [35] Be quiet if not -verbose. |
| 194 |
@<Print the name of the local font@>; |
| 195 |
@y |
| 196 |
if verbose then begin |
| 197 |
@<Print the name of the local font@>; |
| 198 |
end; |
| 199 |
@z |
| 200 |
|
| 201 |
@x [36] Output of real numbers. |
| 202 |
print_ln(' at ',(((vf[k]*256+vf[k+1])*256+vf[k+2])/@'4000000)*real_dsize:2:2, |
| 203 |
'pt') |
| 204 |
@y |
| 205 |
print(' at '); |
| 206 |
print_real((((vf[k]*256+vf[k+1])*256+vf[k+2])/@'4000000)*real_dsize, 2, 2); |
| 207 |
print_ln('pt') |
| 208 |
@z |
| 209 |
|
| 210 |
@x [37] No arbitrary max on cur_name. |
| 211 |
@!cur_name:packed array[1..name_length] of char; {external name, |
| 212 |
with no lower case letters} |
| 213 |
@y |
| 214 |
@!cur_name:^char; {external tfm name} |
| 215 |
@z |
| 216 |
|
| 217 |
@x [39] Open another TFM file. |
| 218 |
reset(tfm_file,cur_name); |
| 219 |
@^system dependencies@> |
| 220 |
if eof(tfm_file) then |
| 221 |
print_ln('---not loaded, TFM file can''t be opened!') |
| 222 |
@.TFM file can\'t be opened@> |
| 223 |
else begin font_bc:=0; font_ec:=256; {will cause error if not modified soon} |
| 224 |
@y |
| 225 |
tfm_name := kpse_find_tfm (cur_name); |
| 226 |
if not tfm_name then |
| 227 |
print_ln('---not loaded, TFM file ', stringcast(cur_name), |
| 228 |
' can''t be opened!') |
| 229 |
@.TFM file can\'t be opened@> |
| 230 |
else begin |
| 231 |
resetbin (tfm_file, tfm_name); |
| 232 |
font_bc:=0; font_ec:=256; {will cause error if not modified soon} |
| 233 |
@z |
| 234 |
|
| 235 |
@x [39] Better diagnostics. |
| 236 |
if font_ec>255 then print_ln('---not loaded, bad TFM file!') |
| 237 |
@.bad TFM file@> |
| 238 |
@y |
| 239 |
if font_ec>255 then |
| 240 |
print_ln('---not loaded, bad TFM file ', stringcast(tfm_name), '!') |
| 241 |
@.bad TFM file@> |
| 242 |
@z |
| 243 |
|
| 244 |
@x [39] Better diagnostics. |
| 245 |
print_ln('---trouble is brewing, TFM file ended too soon!'); |
| 246 |
@.trouble is brewing...@> |
| 247 |
end; |
| 248 |
@y |
| 249 |
print_ln('---trouble is brewing, TFM file ', stringcast(tfm_name), |
| 250 |
' ended too soon!'); |
| 251 |
@.trouble is brewing...@> |
| 252 |
free(tfm_name); |
| 253 |
end; |
| 254 |
free(cur_name); |
| 255 |
@z |
| 256 |
|
| 257 |
@x [40] Be quiet if not -verbose. |
| 258 |
begin print_ln('Check sum in VF file being replaced by TFM check sum'); |
| 259 |
@y |
| 260 |
begin |
| 261 |
if verbose then |
| 262 |
print_ln('Check sum in VF file being replaced by TFM check sum'); |
| 263 |
@z |
| 264 |
|
| 265 |
@x [43] Remove initialization of now-defunct array. |
| 266 |
@ @<Set init...@>= |
| 267 |
default_directory:=default_directory_name; |
| 268 |
@y |
| 269 |
@ (No initialization to be done. Keep this module to preserve numbering.) |
| 270 |
@z |
| 271 |
|
| 272 |
@x [44] Don't append `.tfm' here, and keep lowercase. |
| 273 |
@ The string |cur_name| is supposed to be set to the external name of the |
| 274 |
\.{TFM} file for the current font. This usually means that we need to |
| 275 |
prepend the name of the default directory, and |
| 276 |
to append the suffix `\.{.TFM}'. Furthermore, we change lower case letters |
| 277 |
to upper case, since |cur_name| is a \PASCAL\ string. |
| 278 |
@^system dependencies@> |
| 279 |
|
| 280 |
@<Move font name into the |cur_name| string@>= |
| 281 |
for k:=1 to name_length do cur_name[k]:=' '; |
| 282 |
if a=0 then |
| 283 |
begin for k:=1 to default_directory_name_length do |
| 284 |
cur_name[k]:=default_directory[k]; |
| 285 |
r:=default_directory_name_length; |
| 286 |
end |
| 287 |
else r:=0; |
| 288 |
for k:=font_start[font_ptr]+14 to vf_ptr-1 do |
| 289 |
begin incr(r); |
| 290 |
if r+4>name_length then vf_abort('Font name too long for me!'); |
| 291 |
@.Font name too long for me@> |
| 292 |
if (vf[k]>="a")and(vf[k]<="z") then |
| 293 |
cur_name[r]:=xchr[vf[k]-@'40] |
| 294 |
else cur_name[r]:=xchr[vf[k]]; |
| 295 |
end; |
| 296 |
cur_name[r+1]:='.'; cur_name[r+2]:='T'; cur_name[r+3]:='F'; cur_name[r+4]:='M' |
| 297 |
@y |
| 298 |
@ The string |cur_name| is supposed to be set to the external name of the |
| 299 |
\.{TFM} file for the current font. We do not impose an arbitrary limit |
| 300 |
on the filename length. |
| 301 |
@^system dependencies@> |
| 302 |
|
| 303 |
@d name_start == (font_start[font_ptr] + 14) |
| 304 |
@d name_end == vf_ptr |
| 305 |
|
| 306 |
@<Move font name into the |cur_name| string@>= |
| 307 |
r := name_end - name_start; |
| 308 |
cur_name := xmalloc_array (char, r); |
| 309 |
{|strncpy| might be faster, but it's probably a good idea to keep the |
| 310 |
|xchr| translation.} |
| 311 |
for k := name_start to name_end do begin |
| 312 |
cur_name[k - name_start] := xchr[vf[k]]; |
| 313 |
end; |
| 314 |
cur_name[r] := 0; {Append null byte since this is C.} |
| 315 |
@z |
| 316 |
|
| 317 |
@x [49] Change strings to C char pointers, so we can initialize them. |
| 318 |
@!ASCII_04,@!ASCII_10,@!ASCII_14: packed array [1..32] of char; |
| 319 |
{strings for output in the user's external character set} |
| 320 |
@!xchr:packed array [0..255] of char; |
| 321 |
@!MBL_string,@!RI_string,@!RCE_string:packed array [1..3] of char; |
| 322 |
{handy string constants for |face| codes} |
| 323 |
@y |
| 324 |
@!ASCII_04,@!ASCII_10,@!ASCII_14: const_c_string; |
| 325 |
{strings for output in the user's external character set} |
| 326 |
@!xchr:packed array [0..255] of char; |
| 327 |
@!MBL_string,@!RI_string,@!RCE_string: const_c_string; |
| 328 |
{handy string constants for |face| codes} |
| 329 |
@z |
| 330 |
|
| 331 |
@x [50] The Pascal strings are indexed starting at 1, so we pad with a blank. |
| 332 |
ASCII_04:=' !"#$%&''()*+,-./0123456789:;<=>?';@/ |
| 333 |
ASCII_10:='@@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';@/ |
| 334 |
ASCII_14:='`abcdefghijklmnopqrstuvwxyz{|}~?';@/ |
| 335 |
@y |
| 336 |
ASCII_04:=' !"#$%&''()*+,-./0123456789:;<=>?';@/ |
| 337 |
ASCII_10:=' @@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';@/ |
| 338 |
ASCII_14:=' `abcdefghijklmnopqrstuvwxyz{|}~?';@/ |
| 339 |
@z |
| 340 |
|
| 341 |
@x [50] |
| 342 |
MBL_string:='MBL'; RI_string:='RI '; RCE_string:='RCE'; |
| 343 |
@y |
| 344 |
MBL_string:=' MBL'; RI_string:=' RI '; RCE_string:=' RCE'; |
| 345 |
@z |
| 346 |
|
| 347 |
@x [60] How we output the character code depends on |charcode_format|. |
| 348 |
begin if font_type>vanilla then |
| 349 |
begin tfm[0]:=c; out_octal(0,1) |
| 350 |
end |
| 351 |
else if ((c>="0")and(c<="9"))or@| |
| 352 |
((c>="A")and(c<="Z"))or@| |
| 353 |
((c>="a")and(c<="z")) then out(' C ',xchr[c]) |
| 354 |
else begin tfm[0]:=c; out_octal(0,1); |
| 355 |
end; |
| 356 |
@y |
| 357 |
begin if (font_type > vanilla) or (charcode_format = charcode_octal) then |
| 358 |
begin tfm[0]:=c; out_octal(0,1) |
| 359 |
end |
| 360 |
else if (charcode_format = charcode_ascii) and (c > " ") and (c <= "~") |
| 361 |
and (c <> "(") and (c <> ")") then |
| 362 |
out(' C ', xchr[c]) |
| 363 |
{default case, use \.C only for letters and digits} |
| 364 |
else if ((c>="0")and(c<="9"))or@| |
| 365 |
((c>="A")and(c<="Z"))or@| |
| 366 |
((c>="a")and(c<="z")) then out(' C ',xchr[c]) |
| 367 |
else begin tfm[0]:=c; out_octal(0,1); |
| 368 |
end; |
| 369 |
@z |
| 370 |
|
| 371 |
@x [61] Don't output the face code as an integer. |
| 372 |
out(MBL_string[1+(b mod 3)]); |
| 373 |
out(RI_string[1+s]); |
| 374 |
out(RCE_string[1+(b div 3)]); |
| 375 |
@y |
| 376 |
put_byte(MBL_string[1+(b mod 3)], vpl_file); |
| 377 |
put_byte(RI_string[1+s], vpl_file); |
| 378 |
put_byte(RCE_string[1+(b div 3)], vpl_file); |
| 379 |
@z |
| 380 |
|
| 381 |
@x [100] No progress reports unless verbose. |
| 382 |
incr(chars_on_line); |
| 383 |
end; |
| 384 |
print_octal(c); {progress report} |
| 385 |
@y |
| 386 |
if verbose then incr(chars_on_line); {keep |chars_on_line = 0|} |
| 387 |
end; |
| 388 |
if verbose then print_octal(c); {progress report} |
| 389 |
@z |
| 390 |
|
| 391 |
@x [112] No nonlocal goto's. |
| 392 |
begin print_ln('Sorry, I haven''t room for so many ligature/kern pairs!'); |
| 393 |
@.Sorry, I haven't room...@> |
| 394 |
goto final_end; |
| 395 |
@y |
| 396 |
begin |
| 397 |
print_ln('Sorry, I haven''t room for so many ligature/kern pairs!'); |
| 398 |
@.Sorry, I haven't room...@> |
| 399 |
uexit(1); |
| 400 |
@z |
| 401 |
|
| 402 |
% still [112] We can't have a function named `f', because of the local |
| 403 |
% variable in do_simple_things. It would be better, but harder, to fix |
| 404 |
% web2c. |
| 405 |
@x [112] |
| 406 |
r:=f(r,(hash[r]-1)div 256,(hash[r]-1)mod 256); |
| 407 |
@y |
| 408 |
r:=lig_f(r,(hash[r]-1)div 256,(hash[r]-1)mod 256); |
| 409 |
@z |
| 410 |
|
| 411 |
@x [112] |
| 412 |
out('(INFINITE LIGATURE LOOP MUST BE BROKEN!)'); goto final_end; |
| 413 |
@y |
| 414 |
out('(INFINITE LIGATURE LOOP MUST BE BROKEN!)'); uexit(1); |
| 415 |
@z |
| 416 |
|
| 417 |
% [116] web2c can't handle these mutually recursive procedures. |
| 418 |
% But let's do a fake definition of f here, so that it gets into web2c's |
| 419 |
% symbol table... |
| 420 |
@x [116] |
| 421 |
@p function f(@!h,@!x,@!y:index):index; forward;@t\2@> |
| 422 |
{compute $f$ for arguments known to be in |hash[h]|} |
| 423 |
@y |
| 424 |
@p |
| 425 |
ifdef('notdef') |
| 426 |
function lig_f(@!h,@!x,@!y:index):index; begin end;@t\2@> |
| 427 |
{compute $f$ for arguments known to be in |hash[h]|} |
| 428 |
endif('notdef') |
| 429 |
@z |
| 430 |
|
| 431 |
@x [116] |
| 432 |
else eval:=f(h,x,y); |
| 433 |
@y |
| 434 |
else eval:=lig_f(h,x,y); |
| 435 |
@z |
| 436 |
|
| 437 |
@x [117] ... and then really define it now. |
| 438 |
@p function f; |
| 439 |
@y |
| 440 |
@p function lig_f(@!h,@!x,@!y:index):index; |
| 441 |
@z |
| 442 |
|
| 443 |
@x [117] |
| 444 |
f:=lig_z[h]; |
| 445 |
@y |
| 446 |
lig_f:=lig_z[h]; |
| 447 |
@z |
| 448 |
|
| 449 |
@x [124] Some cc's can't handle 136 case labels. |
| 450 |
begin o:=vf[vf_ptr]; incr(vf_ptr); |
| 451 |
case o of |
| 452 |
@y |
| 453 |
begin o:=vf[vf_ptr]; incr(vf_ptr); |
| 454 |
if (o<=set1+3)or((o>=put1)and(o<=put1+3)) then |
| 455 |
@<Special cases of \.{DVI} instructions to typeset characters@>@; |
| 456 |
else case o of |
| 457 |
@z |
| 458 |
|
| 459 |
@x [125] `signed' is a reserved word in ANSI C. |
| 460 |
@p function get_bytes(@!k:integer;@!signed:boolean):integer; |
| 461 |
@y |
| 462 |
@d signed == is_signed {|signed| is a reserved word in ANSI C} |
| 463 |
@p function get_bytes(@!k:integer;@!signed:boolean):integer; |
| 464 |
@z |
| 465 |
|
| 466 |
@x [126] No nonlocal goto's. |
| 467 |
begin print_ln('Stack overflow!'); goto final_end; |
| 468 |
@y |
| 469 |
begin print_ln('Stack overflow!'); uexit(1); |
| 470 |
@z |
| 471 |
|
| 472 |
@x [129] This block of code moved outside the case statement. |
| 473 |
@ Before we typeset a character we make sure that it exists. |
| 474 |
|
| 475 |
@<Cases...@>= |
| 476 |
sixty_four_cases(set_char_0),sixty_four_cases(set_char_0+64), |
| 477 |
four_cases(set1),four_cases(put1):begin if o>=set1 then |
| 478 |
@y |
| 479 |
@ Before we typeset a character we make sure that it exists. |
| 480 |
|
| 481 |
@<Special cases...@>= |
| 482 |
begin if o>=set1 then |
| 483 |
@z |
| 484 |
|
| 485 |
@x [129] End of block of code moved outside the case statement. |
| 486 |
end; |
| 487 |
@y |
| 488 |
end |
| 489 |
@z |
| 490 |
|
| 491 |
@x [131] Eliminate the |final_end| and |exit| labels. |
| 492 |
label final_end, exit; |
| 493 |
@y |
| 494 |
@z |
| 495 |
@x [131] |
| 496 |
vf_input:=true; return; |
| 497 |
final_end: vf_input:=false; |
| 498 |
exit: end; |
| 499 |
@y |
| 500 |
vf_input:=true; |
| 501 |
end; |
| 502 |
@z |
| 503 |
@x [131] |
| 504 |
label final_end, exit; |
| 505 |
@y |
| 506 |
@z |
| 507 |
@x [131] |
| 508 |
organize:=vf_input; return; |
| 509 |
final_end: organize:=false; |
| 510 |
exit: end; |
| 511 |
@y |
| 512 |
organize:=vf_input; |
| 513 |
end; |
| 514 |
@z |
| 515 |
|
| 516 |
@x [133] Eliminate the |final_end| and |exit| labels. |
| 517 |
label final_end,exit; |
| 518 |
@y |
| 519 |
@z |
| 520 |
@x [133] |
| 521 |
do_map:=true; return; |
| 522 |
final_end: do_map:=false; |
| 523 |
exit:end; |
| 524 |
@y |
| 525 |
do_map:=true; |
| 526 |
end; |
| 527 |
@z |
| 528 |
|
| 529 |
@x [134] No final newline unless verbose. |
| 530 |
print_ln('.');@/ |
| 531 |
@y |
| 532 |
if verbose then print_ln('.');@/ |
| 533 |
@z |
| 534 |
|
| 535 |
@x [135] System-dependent changes. |
| 536 |
This section should be replaced, if necessary, by changes to the program |
| 537 |
that are necessary to make \.{VFtoVP} work at a particular installation. |
| 538 |
It is usually best to design your change file so that all changes to |
| 539 |
previous sections preserve the section numbering; then everybody's version |
| 540 |
will be consistent with the printed program. More extensive changes, |
| 541 |
which introduce new sections, can be inserted here; then only the index |
| 542 |
itself will get a new section number. |
| 543 |
@^system dependencies@> |
| 544 |
@y |
| 545 |
Parse a Unix-style command line. |
| 546 |
|
| 547 |
@d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0) |
| 548 |
|
| 549 |
@<Define \(p)|parse_arguments|@> = |
| 550 |
procedure parse_arguments; |
| 551 |
const n_options = 4; {Pascal won't count array lengths for us.} |
| 552 |
var @!long_options: array[0..n_options] of getopt_struct; |
| 553 |
@!getopt_return_val: integer; |
| 554 |
@!option_index: c_int_type; |
| 555 |
@!current_option: 0..n_options; |
| 556 |
begin |
| 557 |
@<Initialize the option variables@>; |
| 558 |
@<Define the option table@>; |
| 559 |
repeat |
| 560 |
getopt_return_val := getopt_long_only (argc, argv, '', long_options, |
| 561 |
address_of (option_index)); |
| 562 |
if getopt_return_val = -1 then begin |
| 563 |
do_nothing; {End of arguments; we exit the loop below.} |
| 564 |
|
| 565 |
end else if getopt_return_val = "?" then begin |
| 566 |
usage (my_name); |
| 567 |
|
| 568 |
end else if argument_is ('help') then begin |
| 569 |
usage_help (VFTOVP_HELP, nil); |
| 570 |
|
| 571 |
end else if argument_is ('version') then begin |
| 572 |
print_version_and_exit (banner, nil, 'D.E. Knuth', nil); |
| 573 |
|
| 574 |
end else if argument_is ('charcode-format') then begin |
| 575 |
if strcmp (optarg, 'ascii') = 0 then |
| 576 |
charcode_format := charcode_ascii |
| 577 |
else if strcmp (optarg, 'octal') = 0 then |
| 578 |
charcode_format := charcode_octal |
| 579 |
else |
| 580 |
print_ln ('Bad character code format ', stringcast(optarg), '.'); |
| 581 |
|
| 582 |
end; {Else it was a flag; |getopt| has already done the assignment.} |
| 583 |
until getopt_return_val = -1; |
| 584 |
|
| 585 |
{Now |optind| is the index of first non-option on the command line. |
| 586 |
We must have one two three remaining arguments.} |
| 587 |
if (optind + 1 <> argc) and (optind + 2 <> argc) |
| 588 |
and (optind + 3 <> argc) then begin |
| 589 |
print_ln (my_name, ': Need one to three file arguments.'); |
| 590 |
usage (my_name); |
| 591 |
end; |
| 592 |
|
| 593 |
vf_name := cmdline (optind); |
| 594 |
if optind + 2 <= argc then begin |
| 595 |
tfm_name := cmdline (optind + 1); {The user specified the TFM name.} |
| 596 |
end else begin |
| 597 |
{User did not specify TFM name; default it from the VF name.} |
| 598 |
tfm_name := basename_change_suffix (vf_name, '.vf', '.tfm'); |
| 599 |
end; |
| 600 |
end; |
| 601 |
|
| 602 |
@ Here are the options we allow. The first is one of the standard GNU options. |
| 603 |
@.-help@> |
| 604 |
|
| 605 |
@<Define the option...@> = |
| 606 |
current_option := 0; |
| 607 |
long_options[current_option].name := 'help'; |
| 608 |
long_options[current_option].has_arg := 0; |
| 609 |
long_options[current_option].flag := 0; |
| 610 |
long_options[current_option].val := 0; |
| 611 |
incr (current_option); |
| 612 |
|
| 613 |
@ Another of the standard options. |
| 614 |
@.-version@> |
| 615 |
|
| 616 |
@<Define the option...@> = |
| 617 |
long_options[current_option].name := 'version'; |
| 618 |
long_options[current_option].has_arg := 0; |
| 619 |
long_options[current_option].flag := 0; |
| 620 |
long_options[current_option].val := 0; |
| 621 |
incr (current_option); |
| 622 |
|
| 623 |
@ Print progress information? |
| 624 |
@.-verbose@> |
| 625 |
|
| 626 |
@<Define the option...@> = |
| 627 |
long_options[current_option].name := 'verbose'; |
| 628 |
long_options[current_option].has_arg := 0; |
| 629 |
long_options[current_option].flag := address_of (verbose); |
| 630 |
long_options[current_option].val := 1; |
| 631 |
incr (current_option); |
| 632 |
|
| 633 |
@ The global variable |verbose| determines whether or not we print |
| 634 |
progress information. |
| 635 |
|
| 636 |
@<Glob...@> = |
| 637 |
@!verbose: c_int_type; |
| 638 |
|
| 639 |
@ It starts off |false|. |
| 640 |
|
| 641 |
@<Initialize the option...@> = |
| 642 |
verbose := false; |
| 643 |
|
| 644 |
@ Here is an option to change how we output character codes. |
| 645 |
@.-charcode-format@> |
| 646 |
|
| 647 |
@<Define the option...@> = |
| 648 |
long_options[current_option].name := 'charcode-format'; |
| 649 |
long_options[current_option].has_arg := 1; |
| 650 |
long_options[current_option].flag := 0; |
| 651 |
long_options[current_option].val := 0; |
| 652 |
incr (current_option); |
| 653 |
|
| 654 |
@ We use an ``enumerated'' type to store the information. |
| 655 |
|
| 656 |
@<Type...@> = |
| 657 |
@!charcode_format_type = charcode_ascii..charcode_default; |
| 658 |
|
| 659 |
@ @<Const...@> = |
| 660 |
@!charcode_ascii = 0; |
| 661 |
@!charcode_octal = 1; |
| 662 |
@!charcode_default = 2; |
| 663 |
|
| 664 |
@ @<Global...@> = |
| 665 |
@!charcode_format: charcode_format_type; |
| 666 |
|
| 667 |
@ It starts off as the default, that is, we output letters and digits as |
| 668 |
ASCII characters, everything else in octal. |
| 669 |
|
| 670 |
@<Initialize the option...@> = |
| 671 |
charcode_format := charcode_default; |
| 672 |
|
| 673 |
@ An element with all zeros always ends the list. |
| 674 |
|
| 675 |
@<Define the option...@> = |
| 676 |
long_options[current_option].name := 0; |
| 677 |
long_options[current_option].has_arg := 0; |
| 678 |
long_options[current_option].flag := 0; |
| 679 |
long_options[current_option].val := 0; |
| 680 |
|
| 681 |
@ Global filenames. |
| 682 |
|
| 683 |
@<Global...@> = |
| 684 |
@!tfm_name:c_string; |
| 685 |
@!vf_name, @!vpl_name:const_c_string; |
| 686 |
@z |