Debian Codegraph @

texk/web2c/gftodvi.ch

raw
1 % gftodvi.ch for C compilation with web2c.
2 %
3 % (More recent changes in the ChangeLog)
4 % 01/20/90 Karl New gftodvi.web (same version number).
5 % 12/02/89 Karl Berry To version 3.
6 % Revision 1.7.1.5 86/02/01 15:29:58 richards
7 % Released again for MF 1.0 package
8 % Revision 1.7.1.4 86/02/01 15:06:50 richards
9 % Added: <nl> at end of successful run
10 % Revision 1.7.1.3 86/01/27 16:39:48 richards
11 % Fixed: syntax error in previous edits
12 % Revision 1.7.1.2 86/01/27 15:55:58 richards
13 % Added: dvi_buf_type declaration and redefined dvi_buf[] in
14 % terms of it, so we can use it as a parameter to b_write_buf()
15 % Revision 1.7.1.1 86/01/27 15:39:10 richards
16 % First edit to use new binary I/O routines
17 % Revision 1.7 85/10/21 21:55:50 richards
18 % Released for GFtoDVI 1.7
19 % Revision 1.3.7.1 85/10/18 22:59:01 richards
20 % Updated for GFtoDVI Version 1.7 (Distributed w/ MF84 Version 0.9999)
21 % Revision 1.3.5.1 85/10/09 17:02:35 richards
22 % First draft to run at 1.5 level
23 % Revision 1.3 85/05/27 21:15:30 richards
24 % Updated for GFtoDVI Version 1.3 (Distributed w/ MF84 Version 0.91)
25 % Revision 1.2 85/04/25 19:33:30 richards
26 % Updated to GFtoDVI Version 1.2 (Distributed w/ MF84 Version 0.81)
27 % Revision 1.1 85/03/03 21:47:17 richards
28 % Updated for GF utilities distributed with MF Version 0.77
29 % Revision 1.0 84/12/16 22:38:22 richards
30 % Updated for GFtoDVI Version 1.0 (New GF file format)
31 % Revision 0.6 84/12/05 13:32:01 richards
32 % Updated for GFtoDVI Version 0.6; merged in changes from sdcarl!rusty
33 % Note: still has BUGFIX in section 199 to keep GFtoDVI from trying
34 % to use non-existent characters in a gray font
35 % Revision 0.3 84/11/17 23:51:56 richards
36 % Base version for GFtoDVI Version 0.3
37
38 @x [0] l.29
39 \def\(#1){} % this is used to make section names sort themselves better
40 @y
41 \def\({} % this is used to make section names sort themselves better
42 @z
43
44 @x [0] l.32
45 \def\title{GF$\,$\lowercase{to}$\,$DVI}
46 @y
47 \def\title{GF$\,$\lowercase{to}$\,$DVI changes for C}
48 @z
49
50 @x [0] WEAVE: print changes only.
51 \pageno=\contentspagenumber \advance\pageno by 1
52 @y
53 \pageno=\contentspagenumber \advance\pageno by 1
54 \let\maybe=\iffalse
55 @z
56
57 @x [1] Define my_name
58 @d banner=='This is GFtoDVI, Version 3.0' {printed when the program starts}
59 @y
60 @d my_name=='gftodvi'
61 @d banner=='This is GFtoDVI, Version 3.0' {printed when the program starts}
62 @z
63
64 @x [3] Redirect output to term_out.
65 @d print(#)==write(#)
66 @d print_ln(#)==write_ln(#)
67 @d print_nl(#)==@+begin write_ln; write(#);@+end
68 @y
69 @d print(#)==write(stdout, #)
70 @d print_ln(#)==write_ln(stdout, #)
71 @d print_nl(#)==@+begin write_ln(stdout); write(stdout, #);@+end
72 @z
73
74 @x [still 3] Toss labels.
75 label @<Labels in the outer block@>@/
76 const @<Constants in the outer block@>@/
77 type @<Types in the outer block@>@/
78 var @<Globals in the outer block@>@/
79 procedure initialize; {this procedure gets things started properly}
80 var @!i,@!j,@!m,@!n:integer; {loop indices for initializations}
81 begin print_ln(banner);@/
82 @y
83 const @<Constants in the outer block@>@/
84 type @<Types in the outer block@>@/
85 var @<Globals in the outer block@>@/
86 @<Define \(|parse_arguments|@>
87 procedure initialize; {this procedure gets things started properly}
88 var @!i,@!j,@!m,@!n:integer; {loop indices for initializations}
89 begin
90 kpse_set_program_name (argv[0], my_name);
91 kpse_init_prog ('GFTODVI', 0, nil, nil);
92 parse_arguments;
93 if verbose then begin
94 print (banner);
95 print_ln (version_string);
96 end;
97 @z
98
99 @x [4] Remove the final_end label.
100 @ If the program has to stop prematurely, it goes to the
101 `|final_end|'.
102
103 @d final_end=9999 {label for the end of it all}
104
105 @<Labels...@>=final_end;
106 @y
107 @ This module deleted, since it only defined the label |final_end|.
108 @z
109
110 @x [8] Add newline to end of abort() message, and exit abnormally.
111 so a procedure called |jump_out| has been introduced. This procedure, which
112 simply transfers control to the label |final_end| at the end of the program,
113 contains the only non-local |goto| statement in \.{GFtoDVI}.
114 @^system dependencies@>
115
116 @d abort(#)==@+begin print(' ',#); jump_out;@+end
117 @y
118 so a procedure called |jump_out| has been introduced.
119 @^system dependencies@>
120
121 @d abort(#)==@+begin write_ln (stderr, #); jump_out;@+end
122 @z
123
124 @x [8] Remove nonlocal goto.
125 @p procedure jump_out;
126 begin goto final_end;
127 end;
128 @y
129 @p procedure jump_out;
130 begin uexit(1);
131 end;
132 @z
133
134 % [11] The text_char type is used as an array index into xord. The
135 % default type `char' produces signed integers, which are bad array
136 % indices in C.
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 @x [11]
139 @d text_char == char {the data type of characters in text files}
140 @y
141 @d text_char == ASCII_code {the data type of characters in text files}
142 @z
143
144 @x [14] Allow any input character.
145 for i:=0 to @'37 do xchr[i]:='?';
146 for i:=@'177 to @'377 do xchr[i]:='?';
147 @y
148 for i:=1 to @'37 do xchr[i]:=chr(i);
149 for i:=@'177 to @'377 do xchr[i]:=chr(i);
150 @z
151
152
153 @x [16] Change `update_terminal' to `flush', `term_in' is stdin.
154 Since the terminal is being used for both input and output, some systems
155 need a special routine to make sure that the user can see a prompt message
156 before waiting for input based on that message. (Otherwise the message
157 may just be sitting in a hidden buffer somewhere, and the user will have
158 no idea what the program is waiting for.) We shall call a system-dependent
159 subroutine |update_terminal| in order to avoid this problem.
160
161 @d update_terminal == break(output) {empty the terminal output buffer}
162
163 @<Glob...@>=
164 @!buffer:array[0..terminal_line_length] of 0..255;
165 @!term_in:text_file; {the terminal, considered as an input file}
166 @y
167 Since the terminal is being used for both input and output, some systems
168 need a special routine to make sure that the user can see a prompt message
169 before waiting for input based on that message. (Otherwise the message
170 may just be sitting in a hidden buffer somewhere, and the user will have
171 no idea what the program is waiting for.) We shall call a system-dependent
172 subroutine |update_terminal| in order to avoid this problem.
173 @^system dependencies@>
174
175 @d update_terminal == fflush (stdout) {empty the terminal output buffer}
176 @d term_in == stdin {standard input}
177
178 @<Glob...@>=
179 @!buffer:array[0..terminal_line_length] of 0..255;
180 @z
181
182 @x [17] Change term_in^, etc.
183 @p procedure input_ln; {inputs a line from the terminal}
184 begin update_terminal; reset(term_in);
185 if eoln(term_in) then read_ln(term_in);
186 line_length:=0;
187 while (line_length<terminal_line_length)and not eoln(term_in) do
188 begin buffer[line_length]:=xord[term_in^]; incr(line_length); get(term_in);
189 end;
190 end;
191 @y
192 @p procedure input_ln; {inputs a line from the terminal}
193 begin update_terminal;
194 if eoln(term_in) then read_ln(term_in);
195 line_length:=0;
196 while (line_length<terminal_line_length)and not eoln(term_in) do
197 begin buffer[line_length]:=xord[getc(term_in)]; incr(line_length);
198 end;
199 end;
200 @z
201
202 @x [47] Open files based on paths.
203 @p procedure open_gf_file; {prepares to read packed bytes in |gf_file|}
204 begin reset(gf_file,name_of_file);
205 cur_loc:=0;
206 end;
207 @#
208 procedure open_tfm_file; {prepares to read packed bytes in |tfm_file|}
209 begin reset(tfm_file,name_of_file);
210 end;
211 @#
212 procedure open_dvi_file; {prepares to write packed bytes in |dvi_file|}
213 begin rewrite(dvi_file,name_of_file);
214 end;
215 @y
216 In C, we do path searching based on the user's environment or the
217 default path. We also read the command line and print the banner here
218 (since we don't want to print the banner if the command line is
219 unreasonable).
220
221 @p procedure open_gf_file; {prepares to read packed bytes in |gf_file|}
222 begin
223 gf_file := kpse_open_file (stringcast(name_of_file), kpse_gf_format);
224 cur_loc := 0;
225 end;
226 @#
227 procedure open_tfm_file; {prepares to read packed bytes in |tfm_file|}
228 begin
229 tfm_file := kpse_open_file (stringcast(name_of_file), kpse_tfm_format);
230 end;
231 @#
232 procedure open_dvi_file; {prepares to write packed bytes in |dvi_file|}
233 begin rewritebin(dvi_file,stringcast(name_of_file));
234 end;
235 @z
236
237 % [48] Don't force a maximum length for name_of_file. See comments in
238 % tex.ch for why we change the element type to text_char.
239 @x [48]
240 @!name_of_file:packed array[1..file_name_size] of char; {external file name}
241 @y
242 @!name_of_file:^text_char;
243 @z
244
245 % [52] The memory_word structure is too hard to translate via web2c, so
246 % we use a hand-coded include file. Also, b0 (et al.) is used both as a
247 % field and as a regular variable. web2c puts field names in the global
248 % symbol table, so this loses. Rather than fix web2c (hard), we change
249 % the name of the field (ugly, but easy).
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 @x [52]
252 @!four_quarters = packed record@;@/
253 @!b0:quarterword;
254 @!b1:quarterword;
255 @!b2:quarterword;
256 @!b3:quarterword;
257 end;
258 @!memory_word = record@;@/
259 case boolean of
260 true: (@!sc:scaled);
261 false: (@!qqqq:four_quarters);
262 end;
263 @y
264 @!four_quarters = packed record@;@/
265 @!B0:quarterword;
266 @!B1:quarterword;
267 @!B2:quarterword;
268 @!B3:quarterword;
269 end;
270 @\@/@=#include "gftodmem.h";@>@\ {note the |;| so |web2c| will translate
271 types that come after this}
272 @z
273
274 @x [55] fix references to .b0
275 @d char_width_end(#)==#.b0].sc
276 @d char_width(#)==font_info[width_base[#]+char_width_end
277 @d char_exists(#)==(#.b0>min_quarterword)
278 @d char_italic_end(#)==(qo(#.b2)) div 4].sc
279 @d char_italic(#)==font_info[italic_base[#]+char_italic_end
280 @d height_depth(#)==qo(#.b1)
281 @d char_height_end(#)==(#) div 16].sc
282 @d char_height(#)==font_info[height_base[#]+char_height_end
283 @d char_depth_end(#)==# mod 16].sc
284 @d char_depth(#)==font_info[depth_base[#]+char_depth_end
285 @d char_tag(#)==((qo(#.b2)) mod 4)
286 @d skip_byte(#)==qo(#.b0)
287 @d next_char(#)==#.b1
288 @d op_byte(#)==qo(#.b2)
289 @d rem_byte(#)==#.b3
290 @y
291 @d char_width_end(#)==#.B0].sc
292 @d char_width(#)==font_info[width_base[#]+char_width_end
293 @d char_exists(#)==(#.B0>min_quarterword)
294 @d char_italic_end(#)==(qo(#.B2)) div 4].sc
295 @d char_italic(#)==font_info[italic_base[#]+char_italic_end
296 @d height_depth(#)==qo(#.B1)
297 @d char_height_end(#)==(#) div 16].sc
298 @d char_height(#)==font_info[height_base[#]+char_height_end
299 @d char_depth_end(#)==# mod 16].sc
300 @d char_depth(#)==font_info[depth_base[#]+char_depth_end
301 @d char_tag(#)==((qo(#.B2)) mod 4)
302 @d skip_byte(#)==qo(#.B0)
303 @d next_char(#)==#.B1
304 @d op_byte(#)==qo(#.B2)
305 @d rem_byte(#)==#.B3
306 @z
307
308 @x [62] More .b?'s.
309 qw.b0:=qi(b0); qw.b1:=qi(b1); qw.b2:=qi(b2); qw.b3:=qi(b3);
310 @y
311 qw.B0:=qi(b0); qw.B1:=qi(b1); qw.B2:=qi(b2); qw.B3:=qi(b3);
312 @z
313
314 @x [78] Change default extension to `.2602gf'.
315 l:=3; init_str3(".")("g")("f")(gf_ext);@/
316 @y
317 l:=7; init_str7(".")("2")("6")("0")("2")("g")("f")(gf_ext);@/
318 @z
319
320 @x [81] Diagnose impossible cases.
321 end; {there are no other cases}
322 @y
323 othercases abort('internal error');
324 endcases;
325 @z
326
327 @x [85] Diagnose impossible cases.
328 end; {there are no other cases}
329 @y
330 othercases abort('internal error');
331 endcases;
332 @z
333
334 @x [88] Change home_font_area to null_string.
335 l:=9; init_str9("T")("e")("X")("f")("o")("n")("t")("s")(":")(home_font_area);@/
336 @y
337 l:=0; init_str0(home_font_area);@/
338 @z
339
340 @x [90] Change more_name to understand Unix file name syntax.
341 else begin if (c=">")or(c=":") then
342 begin area_delimiter:=pool_ptr; ext_delimiter:=0;
343 end
344 else if (c=".")and(ext_delimiter=0) then ext_delimiter:=pool_ptr;
345 @y
346 else begin if c="/" then
347 begin area_delimiter:=pool_ptr; ext_delimiter:=0;
348 end
349 else if c="." then ext_delimiter:=pool_ptr;
350 @z
351
352 @x [92] pack_file_name must pack for C conventions.
353 @d append_to_name(#)==begin c:=#; incr(k);
354 if k<=file_name_size then name_of_file[k]:=xchr[c];
355 @y
356 @d append_to_name(#)==begin c:=#; incr(k);
357 name_of_file[k]:=xchr[c];
358 @z
359
360 @x [92]
361 @!name_length:0..file_name_size; {number of characters packed}
362 begin k:=0;
363 for j:=str_start[a] to str_start[a+1]-1 do append_to_name(str_pool[j]);
364 for j:=str_start[n] to str_start[n+1]-1 do append_to_name(str_pool[j]);
365 for j:=str_start[e] to str_start[e+1]-1 do append_to_name(str_pool[j]);
366 if k<=file_name_size then name_length:=k@+else name_length:=file_name_size;
367 for k:=name_length+1 to file_name_size do name_of_file[k]:=' ';
368 @y
369 @!name_length: integer;
370 begin
371 name_length := length (a) + length (n) + length (e);
372 name_of_file := xmalloc_array (ASCII_code, name_length);
373 k := -1; {C strings start at position zero.}
374 for j:=str_start[a] to str_start[a+1]-1 do append_to_name(str_pool[j]);
375 for j:=str_start[n] to str_start[n+1]-1 do append_to_name(str_pool[j]);
376 for j:=str_start[e] to str_start[e+1]-1 do append_to_name(str_pool[j]);
377 name_of_file[name_length] := 0;
378 @z
379
380 @x [94] Change start_gf to get file name from the command line.
381 @ The |start_gf| procedure prompts the user for the name of the generic
382 font file to be input. It opens the file, making sure that some input is
383 present; then it opens the output file.
384
385 Although this routine is system-independent, it should probably be
386 modified to take the file name from the command line (without an initial
387 prompt), on systems that permit such things.
388
389 @p procedure start_gf;
390 label found,done;
391 begin loop@+begin print_nl('GF file name: '); input_ln;
392 @.GF file name@>
393 buf_ptr:=0; buffer[line_length]:="?";
394 while buffer[buf_ptr]=" " do incr(buf_ptr);
395 if buf_ptr<line_length then
396 begin @<Scan the file name in the buffer@>;
397 if cur_ext=null_string then cur_ext:=gf_ext;
398 pack_file_name(cur_name,cur_area,cur_ext); open_gf_file;
399 if not eof(gf_file) then goto found;
400 print_nl('Oops... I can''t find file '); print(name_of_file);
401 @.Oops...@>
402 @.I can't find...@>
403 end;
404 end;
405 found:job_name:=cur_name; pack_file_name(job_name,null_string,dvi_ext);
406 open_dvi_file;
407 end;
408 @y
409 @ The |start_gf| procedure obtains the name of the generic font file to
410 be input from the command line. It opens the file, making sure that
411 some input is present; then it opens the output file.
412
413 @p procedure start_gf;
414 label done;
415 var arg_buffer: c_string;
416 arg_buf_ptr: integer;
417 begin
418 arg_buffer := cmdline (optind);
419 arg_buf_ptr := 0;
420 while (line_length < terminal_line_length)
421 and (arg_buffer[arg_buf_ptr] <> 0) do begin
422 buffer[line_length] := xord[ucharcast(arg_buffer[arg_buf_ptr])];
423 incr(line_length);
424 incr(arg_buf_ptr);
425 end;
426
427 buf_ptr:=0; buffer[line_length]:="?";
428 while buffer[buf_ptr]=" " do incr(buf_ptr);
429 if buf_ptr < line_length
430 then begin
431 @<Scan the file name in the buffer@>;
432 if cur_ext = null_string then cur_ext:=gf_ext;
433 pack_file_name (cur_name, cur_area, cur_ext);
434 open_gf_file;
435 end;
436 job_name := cur_name;
437 pack_file_name(job_name, null_string, dvi_ext);
438 open_dvi_file;
439 end;
440 @z
441
442 @x [107] `write_dvi' is now an external C routine.
443 @p procedure write_dvi(@!a,@!b:dvi_index);
444 var k:dvi_index;
445 begin for k:=a to b do write(dvi_file,dvi_buf[k]);
446 end;
447 @y
448 In C, we use a macro to call |fwrite| or |write| directly, writing all
449 the bytes in one shot. Much better even than writing four
450 bytes at a time.
451 @z
452
453 @x [108] dvi_swap: check dvi file size
454 begin if dvi_limit=dvi_buf_size then
455 @y
456 begin if dvi_ptr>(@"7FFFFFFF-dvi_offset) then
457 abort('dvi length exceeds "7FFFFFFF');
458 @.dvi length exceeds...@>
459 if dvi_limit=dvi_buf_size then
460 @z
461
462 @x [109] empty the last bytes: check dvi file size
463 if dvi_ptr>0 then write_dvi(0,dvi_ptr-1)
464 @y
465 if dvi_ptr>(@"7FFFFFFF-dvi_offset) then
466 abort('dvi length exceeds "7FFFFFFF');
467 @.dvi length exceeds...@>
468 if dvi_ptr>0 then write_dvi(0,dvi_ptr-1)
469 @z
470
471 @x [111] More .b?'s.
472 dvi_out(qo(font_check[f].b0));
473 dvi_out(qo(font_check[f].b1));
474 dvi_out(qo(font_check[f].b2));
475 dvi_out(qo(font_check[f].b3));@/
476 @y
477 dvi_out(qo(font_check[f].B0));
478 dvi_out(qo(font_check[f].B1));
479 dvi_out(qo(font_check[f].B2));
480 dvi_out(qo(font_check[f].B3));@/
481 @z
482
483 % [115] Don't go to final_end, just exit; this is the normal exit from
484 % the program, so we want to end with a newline if we are being verbose.
485 @x [115]
486 goto final_end;
487 @y
488 if verbose then print_ln (' ');
489 uexit (0);
490 @z
491
492 @x [118] And still more .b?'s.
493 dummy_info.b0:=qi(0); dummy_info.b1:=qi(0); dummy_info.b2:=qi(0);
494 dummy_info.b3:=qi(0);
495 @y
496 dummy_info.B0:=qi(0); dummy_info.B1:=qi(0); dummy_info.B2:=qi(0);
497 dummy_info.B3:=qi(0);
498 @z
499
500 @x [138] write_ln formatting.
501 begin if abs(r-slant_reported)>0.001 then
502 begin print_nl('Sorry, I can''t make diagonal rules of slant ',r:10:5,'!');
503 @y
504 begin if fabs(r-slant_reported)>0.001 then
505 begin print_nl('Sorry, I can''t make diagonal rules of slant ');
506 print_real(r,10,5); print('!');
507 @z
508
509 @x [164] No progress report unless verbose.
510 print('[',total_pages:1); update_terminal; {print a progress report}
511 @y
512 if verbose
513 then begin
514 print('[',total_pages:1);
515 update_terminal; {print a progress report}
516 end;
517 @z
518
519 @x [164]
520 print(']'); update_terminal;
521 @y
522 if verbose
523 then begin
524 print(']');
525 if total_pages mod 13 = 0
526 then print_ln (' ')
527 else print (' ');
528 update_terminal;
529 end;
530 @z
531
532 % [170] Change offset for overflow labels. The defaults adds about 2.1
533 % inches to the right edge of the diagram, which puts it off the paper
534 % for even moderately large fonts. Instead, we make it a command-line
535 % option.
536 @x [170]
537 over_col:=over_col+delta_x+10000000;
538 @y
539 over_col := over_col + delta_x + overflow_label_offset;
540 @z
541
542 % [215] Some broken compilers cannot handle 165 labels for the same
543 % branch of a switch.
544 @x [215]
545 @<Read and process...@>=
546 loop @+begin continue: case cur_gf of
547 sixty_four_cases(0): k:=cur_gf;
548 paint1:k:=get_byte;
549 paint2:k:=get_two_bytes;
550 paint3:k:=get_three_bytes;
551 eoc:goto done1;
552 skip0:end_with(blank_rows:=0; do_skip);
553 skip1:end_with(blank_rows:=get_byte; do_skip);
554 skip2:end_with(blank_rows:=get_two_bytes; do_skip);
555 skip3:end_with(blank_rows:=get_three_bytes; do_skip);
556 sixty_four_cases(new_row_0),sixty_four_cases(new_row_0+64),
557 thirty_two_cases(new_row_0+128),five_cases(new_row_0+160):
558 end_with(z:=cur_gf-new_row_0;paint_black:=true);
559 xxx1,xxx2,xxx3,xxx4,yyy,no_op:begin skip_nop; goto continue;
560 end;
561 othercases bad_gf('Improper opcode')
562 endcases;@/
563 @y
564 @<Read and process...@>=
565 loop @+begin continue:
566 if (cur_gf>=new_row_0)and(cur_gf<=new_row_0+164) then
567 end_with(z:=cur_gf-new_row_0;paint_black:=true)
568 else case cur_gf of
569 sixty_four_cases(0): k:=cur_gf;
570 paint1:k:=get_byte;
571 paint2:k:=get_two_bytes;
572 paint3:k:=get_three_bytes;
573 eoc:goto done1;
574 skip0:end_with(blank_rows:=0; do_skip);
575 skip1:end_with(blank_rows:=get_byte; do_skip);
576 skip2:end_with(blank_rows:=get_two_bytes; do_skip);
577 skip3:end_with(blank_rows:=get_three_bytes; do_skip);
578 xxx1,xxx2,xxx3,xxx4,yyy,no_op:begin skip_nop; goto continue;
579 end;
580 othercases bad_gf('Improper opcode')
581 endcases;@/
582 @z
583
584 @x [219] If verbose, output a newline at the end.
585 final_end:end.
586 @y
587 if verbose and (total_pages mod 13 <> 0) then print_ln (' ');
588 end.
589 @z
590
591 @x [222] System-dependent changes.
592 This section should be replaced, if necessary, by changes to the program
593 that are necessary to make \.{GFtoDVI} work at a particular installation.
594 It is usually best to design your change file so that all changes to
595 previous sections preserve the section numbering; then everybody's version
596 will be consistent with the printed program. More extensive changes,
597 which introduce new sections, can be inserted here; then only the index
598 itself will get a new section number.
599 @^system dependencies@>
600 @y
601 Parse a Unix-style command line.
602
603 @d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0)
604
605 @<Define \(|parse_arguments|@> =
606 procedure parse_arguments;
607 const n_options = 4; {Pascal won't count array lengths for us.}
608 var @!long_options: array[0..n_options] of getopt_struct;
609 @!getopt_return_val: integer;
610 @!option_index: c_int_type;
611 @!current_option: 0..n_options;
612 begin
613 @<Initialize the option variables@>;
614 @<Define the option table@>;
615 repeat
616 getopt_return_val := getopt_long_only (argc, argv, '', long_options,
617 address_of (option_index));
618 if getopt_return_val = -1 then begin
619 do_nothing; {End of arguments; we exit the loop below.}
620
621 end else if getopt_return_val = "?" then begin
622 usage (my_name);
623
624 end else if argument_is ('help') then begin
625 usage_help (GFTODVI_HELP, nil);
626
627 end else if argument_is ('version') then begin
628 print_version_and_exit (banner, nil, 'D.E. Knuth', nil);
629
630 end else if argument_is ('overflow-label-offset') then begin
631 offset_in_points := atof (optarg);
632 overflow_label_offset := round (offset_in_points * 65536);
633
634 end; {Else it was a flag; |getopt| has already done the assignment.}
635 until getopt_return_val = -1;
636
637 {Now |optind| is the index of first non-option on the command line.
638 We must have one remaining argument.}
639 if (optind + 1 <> argc) then begin
640 write_ln (stderr, my_name, ': Need exactly one file argument.');
641 usage (my_name);
642 end;
643 end;
644
645 @ Here are the options we allow. The first is one of the standard GNU options.
646 @.-help@>
647
648 @<Define the option...@> =
649 current_option := 0;
650 long_options[current_option].name := 'help';
651 long_options[current_option].has_arg := 0;
652 long_options[current_option].flag := 0;
653 long_options[current_option].val := 0;
654 incr (current_option);
655
656 @ Another of the standard options.
657 @.-version@>
658
659 @<Define the option...@> =
660 long_options[current_option].name := 'version';
661 long_options[current_option].has_arg := 0;
662 long_options[current_option].flag := 0;
663 long_options[current_option].val := 0;
664 incr (current_option);
665
666 @ Print progress information?
667
668 @<Define the option...@> =
669 long_options[current_option].name := 'verbose';
670 long_options[current_option].has_arg := 0;
671 long_options[current_option].flag := address_of (verbose);
672 long_options[current_option].val := 1;
673 incr (current_option);
674
675 @ @<Glob...@> =
676 @!verbose: c_int_type;
677
678 @ @<Initialize the option...@> =
679 verbose := false;
680
681 @ Change how far from the right edge of the character boxes we print
682 overflow labels.
683 @.-overflow-label-offset@>
684
685 @<Define the option...@> =
686 long_options[current_option].name := 'overflow-label-offset';
687 long_options[current_option].has_arg := 1;
688 long_options[current_option].flag := 0;
689 long_options[current_option].val := 0;
690 incr (current_option);
691
692 @ It's easier on the user to specify the value in \TeX\ points, but we
693 want to store it in scaled points.
694
695 @<Glob...@> =
696 @!overflow_label_offset: integer; {in scaled points}
697 @!offset_in_points: real;
698
699 @ The default offset is ten million scaled points---a little more than
700 two inches.
701
702 @<Initialize the option...@> =
703 overflow_label_offset := 10000000;
704
705 @ An element with all zeros always ends the list.
706
707 @<Define the option...@> =
708 long_options[current_option].name := 0;
709 long_options[current_option].has_arg := 0;
710 long_options[current_option].flag := 0;
711 long_options[current_option].val := 0;
712 @z