Debian Codegraph @

texk/web2c/tftopl.ch

raw
1 % tftopl.ch for C compilation with web2c.
2 %
3 % 04/04/83 (PC) Original version, made to work with version 1.0 of TFtoPL,
4 % released with version 0.96 of TeX in February, 1983.
5 % 04/16/83 (PC) Brought up to version 1.0 released with version 0.97 of TeX
6 % in April, 1983.
7 % 06/30/83 (HWT) Revised changefile format, for use with version 1.7 Tangle.
8 % 07/28/83 (HWT) Brought up to version 2
9 % 11/21/83 (HWT) Brought up to version 2.1
10 % 03/24/84 (HWT) Brought up to version 2.2
11 % 07/12/84 (HWT) Brought up to version 2.3
12 % 07/05/87 (ETM) Brought up to version 2.5
13 % 03/22/88 (ETM) Converted for use with WEB to C.
14 % 11/30/89 (KB) Version 3.
15 % 01/16/90 (SR) Version 3.1.
16 % (more recent changes in the ChangeLog)
17
18 @x [0] l.25
19 \def\(#1){} % this is used to make section names sort themselves better
20 @y
21 \def\({} % this is used to make section names sort themselves better
22 @z
23
24 @x [0] l.28
25 \def\title{TF\lowercase{to}PL}
26 @y
27 \def\title{TF\lowercase{to}PL changes for C}
28 @z
29
30 @x [0] l.46 WEAVE: print changes only.
31 \pageno=\contentspagenumber \advance\pageno by 1
32 @y
33 \pageno=\contentspagenumber \advance\pageno by 1
34 \let\maybe=\iffalse
35 @z
36
37 @x [1] l.67 Define my_name
38 @d banner=='This is TFtoPL, Version 3.3' {printed when the program starts}
39 @y
40 @d my_name=='tftopl'
41 @d banner=='This is TFtoPL, Version 3.3' {printed when the program starts}
42 @z
43
44 @x [2] l.80 Print all terminal output on stderr, so the pl can be sent to stdout.
45 @d print(#)==write(#)
46 @d print_ln(#)==write_ln(#)
47 @y
48 @d print(#)==write(stderr,#)
49 @d print_ln(#)==write_ln(stderr,#)
50 @z
51
52 % [2] Fix files in program statement. We need to tell web2c about one
53 % special variable. Perhaps it would be better to allow @define's
54 % anywhere in a source file, but that seemed just as painful as this.
55 @x [2] l.83
56 @p program TFtoPL(@!tfm_file,@!pl_file,@!output);
57 @y
58 @p
59 {Tangle doesn't recognize @@ when it's right after the \.=.}
60 @\@= @@define var tfm;@>@\
61 program TFtoPL(@!tfm_file,@!pl_file,@!output);
62 @z
63
64 @x [2] l.84 No global label.
65 label @<Labels in the outer block@>@/
66 @y
67 @z
68
69 @x [still 2] l.88 Don't print banner until later (and unless verbose).
70 procedure initialize; {this procedure gets things started properly}
71 begin print_ln(banner);@/
72 @y
73 @<Define \(|parse_arguments|@>
74 procedure initialize; {this procedure gets things started properly}
75 begin
76 kpse_set_program_name (argv[0], my_name);
77 kpse_init_prog ('TFTOPL', 0, nil, nil);
78 {We |xrealloc| when we know how big the file is. The 1000 comes
79 from the negative lower bound.}
80 tfm_file_array := xmalloc_array (byte, 1002);
81 parse_arguments;
82 @z
83
84 @x [3] l.98 No global label.
85 @<Labels...@>=final_end;
86 @y
87 @z
88
89 @x [4] l.104 Increase sizes to match vptovf.
90 @!tfm_size=30000; {maximum length of |tfm| data, in bytes}
91 @!lig_size=5000; {maximum length of |lig_kern| program, in words}
92 @!hash_size=5003; {preferably a prime number, a bit larger than the number
93 of character pairs in lig/kern steps}
94 @y
95 @!lig_size=32510; {maximum length of |lig_kern| program, in words ($<2^{15}$)}
96 @!hash_size=32579; {preferably a prime number, a bit larger than the number
97 of character pairs in lig/kern steps}
98 @z
99
100 @x [7] l.132 Open the TFM file.
101 @ On some systems you may have to do something special to read a
102 packed file of bytes. For example, the following code didn't work
103 when it was first tried at Stanford, because packed files have to be
104 opened with a special switch setting on the \PASCAL\ that was used.
105 @^system dependencies@>
106
107 @<Set init...@>=
108 reset(tfm_file);
109 @y
110 @ On some systems you may have to do something special to read a
111 packed file of bytes. With C under Unix, we just open the file by name
112 and read characters from it.
113
114 @<Set init...@>=
115 tfm_file := kpse_open_file (tfm_name, kpse_tfm_format);
116 if verbose then begin
117 print (banner);
118 print_ln (version_string);
119 end;
120 @z
121
122 @x [17] l.413 Open the PL file.
123 @ @<Set init...@>=
124 rewrite(pl_file);
125 @y
126 @ If an explicit filename isn't given, we write to |stdout|.
127
128 @<Set init...@>=
129 if optind + 1 = argc then begin
130 pl_file := stdout;
131 end else begin
132 pl_name := extend_filename (cmdline (optind + 1), 'pl');
133 rewrite (pl_file, pl_name);
134 end;
135 @z
136
137 @x [18,19] l.420 Make |tfm| be dynamically allocated, and rename `index'.
138 @<Types...@>=
139 @!byte=0..255; {unsigned eight-bit quantity}
140 @!index=0..tfm_size; {address of a byte in |tfm|}
141
142 @ @<Glob...@>=
143 @!tfm:array [-1000..tfm_size] of byte; {the input data all goes here}
144 @y
145 @d index == index_type
146
147 @<Types...@>=
148 @!byte=0..255; {unsigned eight-bit quantity}
149 @!index=integer; {address of a byte in |tfm|}
150
151 @ @<Glob...@>=
152 {Kludge here to define |tfm| as a macro which takes care of the negative
153 lower bound. We've defined |tfm| for the benefit of web2c above.}
154 @=#define tfm (tfmfilearray + 1001);@>@\
155 @!tfm_file_array: ^byte; {the input data all goes here}
156 @z
157
158 @x [20] l.446 Allow arbitrarily large input files.
159 if 4*lf-1>tfm_size then abort('The file is bigger than I can handle!');
160 @.The file is bigger...@>
161 @y
162 tfm_file_array := xrealloc_array (tfm_file_array, byte, 4 * lf + 1000);
163 @z
164
165 % [27, 28] Change strings to C char pointers. The Pascal strings are
166 % indexed starting at 1, so we pad with a blank.
167 @x [27] l.582
168 @!ASCII_04,@!ASCII_10,@!ASCII_14: packed array [1..32] of char;
169 {strings for output in the user's external character set}
170 @!MBL_string,@!RI_string,@!RCE_string:packed array [1..3] of char;
171 {handy string constants for |face| codes}
172 @y
173 @!ASCII_04,@!ASCII_10,@!ASCII_14: const_c_string;
174 {strings for output in the user's external character set}
175 @!ASCII_all: packed array[0..256] of char;
176 @!MBL_string,@!RI_string,@!RCE_string: const_c_string;
177 {handy string constants for |face| codes}
178 @z
179
180 @x [28] l.588
181 ASCII_04:=' !"#$%&''()*+,-./0123456789:;<=>?';@/
182 ASCII_10:='@@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';@/
183 ASCII_14:='`abcdefghijklmnopqrstuvwxyz{|}~ ';@/
184 MBL_string:='MBL'; RI_string:='RI '; RCE_string:='RCE';
185 @y
186 ASCII_04:=' !"#$%&''()*+,-./0123456789:;<=>?';@/
187 ASCII_10:=' @@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';@/
188 ASCII_14:=' `abcdefghijklmnopqrstuvwxyz{|}~ ';@/
189 strcpy (ASCII_all, ASCII_04);
190 strcat (ASCII_all, '@@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_');
191 strcat (ASCII_all, '`abcdefghijklmnopqrstuvwxyz{|}~');@/
192 MBL_string:=' MBL'; RI_string:=' RI '; RCE_string:=' RCE';
193 @z
194
195 @x [36] l.680
196 while l>0 do @<Reduce \(1)|l| by one, preserving the invariants@>;
197 @y
198 while l>0 do @<Reduce \(|l| by one, preserving the invariants@>;
199 @z
200
201 @x [37] l.687
202 @ @<Reduce \(1)|l|...@>=
203 @y
204 @ @<Reduce \(|l|...@>=
205 @z
206
207 @x [38] l.708 How we output the character code depends on |charcode_format|.
208 begin if font_type>vanilla then
209 begin tfm[0]:=c; out_octal(0,1)
210 end
211 else if (c>="0")and(c<="9") then
212 out(' C ',c-"0":1)
213 else if (c>="A")and(c<="Z") then
214 out(' C ',ASCII_10[c-"A"+2])
215 else if (c>="a")and(c<="z") then
216 out(' C ',ASCII_14[c-"a"+2])
217 else begin tfm[0]:=c; out_octal(0,1);
218 @y
219 begin if (font_type > vanilla) or (charcode_format = charcode_octal) then
220 begin tfm[0]:=c; out_octal(0,1)
221 end
222 else if (charcode_format = charcode_ascii) and (c > " ") and (c <= "~")
223 and (c <> "(") and (c <> ")") then
224 out(' C ', ASCII_all[c - " " + 1])
225 {default case, use \.C only for letters and digits}
226 else if (c>="0")and(c<="9") then
227 out(' C ',c-"0":1)
228 else if (c>="A")and(c<="Z") then
229 out(' C ',ASCII_10[c-"A"+2])
230 else if (c>="a")and(c<="z") then
231 out(' C ',ASCII_14[c-"a"+2])
232 else begin tfm[0]:=c; out_octal(0,1);
233 @z
234
235 @x [39] l.730 Don't output the face code as an integer.
236 out(MBL_string[1+(b mod 3)]);
237 out(RI_string[1+s]);
238 out(RCE_string[1+(b div 3)]);
239 @y
240 put_byte(MBL_string[1+(b mod 3)], pl_file);
241 put_byte(RI_string[1+s], pl_file);
242 put_byte(RCE_string[1+(b div 3)], pl_file);
243 @z
244
245 @x [40] l.751
246 if a>@'3777 then @<Reduce \(2)negative to positive@>;
247 @y
248 if a>@'3777 then @<Reduce negative to positive@>;
249 @z
250
251 @x [43] l.775
252 @ @<Reduce \(2)negative to positive@>=
253 @y
254 @ @<Reduce negative to positive@>=
255 @z
256
257 @x [78] l.1246 No progress reports unless verbose.
258 incr(chars_on_line);
259 end;
260 print_octal(c); {progress report}
261 @y
262 if verbose then incr(chars_on_line);
263 end;
264 if verbose then print_octal(c); {progress report}
265 @z
266
267 % [89] Change the name of the variable `class', since AIX 3.1's <math.h>
268 % defines a function by that name.
269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 @x [89] l.1408
271 @d pending=4 {$f(x,y)$ is being evaluated}
272 @y
273 @d pending=4 {$f(x,y)$ is being evaluated}
274
275 @d class == class_var
276 @z
277
278 @x [90] l.1435
279 goto final_end;
280 @y
281 uexit(1);;
282 @z
283
284 @x [90] l.1440 Change name of the function `f'.
285 r:=f(r,(hash[r]-1)div 256,(hash[r]-1)mod 256);
286 @y
287 r:=f_fn(r,(hash[r]-1)div 256,(hash[r]-1)mod 256);
288 @z
289
290 @x [90] l.1447
291 out('(INFINITE LIGATURE LOOP MUST BE BROKEN!)'); goto final_end;
292 @y
293 out('(INFINITE LIGATURE LOOP MUST BE BROKEN!)'); uexit(1);
294 @z
295
296 % [94] web2c can't handle these mutually recursive procedures.
297 % But let's do a fake definition of f here, so that it gets into web2c's
298 % symbol table. We also have to change the name, because there is also a
299 % variable named `f', and some C compilers can't deal with that.
300 @x [94] l.1500
301 @p function f(@!h,@!x,@!y:index):index; forward;@t\2@>
302 {compute $f$ for arguments known to be in |hash[h]|}
303 @y
304 @p
305 ifdef('notdef')
306 function f_fn(@!h,@!x,@!y:index):index; begin end;@t\2@>
307 {compute $f$ for arguments known to be in |hash[h]|}
308 endif('notdef')
309 @z
310 @x [94] l.1508
311 else eval:=f(h,x,y);
312 @y
313 else eval:=f_fn(h,x,y);
314 @z
315
316 @x [95] l.1514 The real definition of f.
317 @p function f;
318 @y
319 @p function f_fn(@!h,@!x,@!y:index):index;
320 @z
321 @x [95] l.1527
322 f:=lig_z[h];
323 @y
324 f_fn:=lig_z[h];
325 @z
326
327 @x [99] l.1570
328 if not organize then goto final_end;
329 @y
330 if not organize then uexit(1);
331 @z
332
333 @x [99] l.1574 No final newline unless verbose.
334 do_characters; print_ln('.');@/
335 @y
336 do_characters; if verbose then print_ln('.');@/
337 @z
338
339 @x [99] l.1582
340 final_end:end.
341 @y
342 end.
343 @z
344
345 @x [100] l.1585 System-dependent changes.
346 This section should be replaced, if necessary, by changes to the program
347 that are necessary to make \.{TFtoPL} work at a particular installation.
348 It is usually best to design your change file so that all changes to
349 previous sections preserve the section numbering; then everybody's version
350 will be consistent with the printed program. More extensive changes,
351 which introduce new sections, can be inserted here; then only the index
352 itself will get a new section number.
353 @^system dependencies@>
354 @y
355 Parse a Unix-style command line.
356
357 @d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0)
358
359 @<Define \(|parse_arguments|@> =
360 procedure parse_arguments;
361 const n_options = 4; {Pascal won't count array lengths for us.}
362 var @!long_options: array[0..n_options] of getopt_struct;
363 @!getopt_return_val: integer;
364 @!option_index: c_int_type;
365 @!current_option: 0..n_options;
366 begin
367 @<Initialize the option variables@>;
368 @<Define the option table@>;
369 repeat
370 getopt_return_val := getopt_long_only (argc, argv, '', long_options,
371 address_of (option_index));
372 if getopt_return_val = -1 then begin
373 do_nothing; {End of arguments; we exit the loop below.}
374
375 end else if getopt_return_val = "?" then begin
376 usage (my_name);
377
378 end else if argument_is ('help') then begin
379 usage_help (TFTOPL_HELP, nil);
380
381 end else if argument_is ('version') then begin
382 print_version_and_exit (banner, nil, 'D.E. Knuth', nil);
383
384 end else if argument_is ('charcode-format') then begin
385 if strcmp (optarg, 'ascii') = 0 then
386 charcode_format := charcode_ascii
387 else if strcmp (optarg, 'octal') = 0 then
388 charcode_format := charcode_octal
389 else
390 print_ln ('Bad character code format ', stringcast(optarg), '.');
391
392 end; {Else it was a flag; |getopt| has already done the assignment.}
393 until getopt_return_val = -1;
394
395 {Now |optind| is the index of first non-option on the command line.}
396 if (optind + 1 <> argc) and (optind + 2 <> argc) then begin
397 print_ln (my_name, ': Need one or two file arguments.');
398 usage (my_name);
399 end;
400
401 tfm_name := cmdline (optind);
402 end;
403
404 @ Here are the options we allow. The first is one of the standard GNU options.
405 @.-help@>
406
407 @<Define the option...@> =
408 current_option := 0;
409 long_options[current_option].name := 'help';
410 long_options[current_option].has_arg := 0;
411 long_options[current_option].flag := 0;
412 long_options[current_option].val := 0;
413 incr (current_option);
414
415 @ Another of the standard options.
416 @.-version@>
417
418 @<Define the option...@> =
419 long_options[current_option].name := 'version';
420 long_options[current_option].has_arg := 0;
421 long_options[current_option].flag := 0;
422 long_options[current_option].val := 0;
423 incr (current_option);
424
425 @ Print progress information?
426 @.-verbose@>
427
428 @<Define the option...@> =
429 long_options[current_option].name := 'verbose';
430 long_options[current_option].has_arg := 0;
431 long_options[current_option].flag := address_of (verbose);
432 long_options[current_option].val := 1;
433 incr (current_option);
434
435 @ @<Glob...@> =
436 @!verbose: c_int_type;
437
438 @ @<Initialize the option...@> =
439 verbose := false;
440
441 @ This option changes how we output character codes.
442 @.-charcode-format@>
443
444 @<Define the option...@> =
445 long_options[current_option].name := 'charcode-format';
446 long_options[current_option].has_arg := 1;
447 long_options[current_option].flag := 0;
448 long_options[current_option].val := 0;
449 incr (current_option);
450
451 @ We use an ``enumerated'' type to store the information.
452
453 @<Type...@> =
454 @!charcode_format_type = charcode_ascii..charcode_default;
455
456 @ @<Const...@> =
457 @!charcode_ascii = 0;
458 @!charcode_octal = 1;
459 @!charcode_default = 2;
460
461 @ @<Global...@> =
462 @!charcode_format: charcode_format_type;
463
464 @ It starts off as the default, that is, we output letters and digits as
465 ASCII characters, everything else in octal.
466
467 @<Initialize the option...@> =
468 charcode_format := charcode_default;
469
470 @ An element with all zeros always ends the list.
471
472 @<Define the option...@> =
473 long_options[current_option].name := 0;
474 long_options[current_option].has_arg := 0;
475 long_options[current_option].flag := 0;
476 long_options[current_option].val := 0;
477
478 @ Global filenames.
479
480 @<Global...@> =
481 @!tfm_name, @!pl_name:const_c_string;
482 @z