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