1% pooltype.ch for C compilation with web2c. 2% 3% 03/23/88 (ETM) Created for use with WEB to C. 4% 11/29/89 (KB) Version released with 8-bit TeX. 5% (more recent changes in the ChangeLog) 6 7@x [0] WEAVE: print changes only 8\pageno=\contentspagenumber \advance\pageno by 1 9@y 10\pageno=\contentspagenumber \advance\pageno by 1 11\let\maybe=\iffalse 12\def\title{POOL\lowercase{type} changes for C} 13@z 14 15@x [1] Define my_name 16copied from \TeX82. 17@y 18copied from \TeX82. 19 20@d my_name=='pooltype' 21@z 22 23@x [2] main program changes: no global labels, read command line. 24label 9999; {this labels the end of the program} 25@y 26@z 27@x 28procedure initialize; {this procedure gets things started properly} 29 var @<Local variables for initialization@>@; 30 begin @<Set initial values of key variables@>@/ 31@y 32@<Define |parse_arguments|@> 33procedure initialize; {this procedure gets things started properly} 34 var @<Local variables for initialization@>@; 35 begin 36 kpse_set_program_name (argv[0], my_name); 37 parse_arguments; 38 @<Set initial values of key variables@> 39@z 40 41% [??] The text_char type is used as an array index into xord. The 42% default type `char' produces signed integers, which are bad array 43% indices in C. 44%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45@x 46@d text_char == char {the data type of characters in text files} 47@y 48@d text_char == ASCII_code {the data type of characters in text files} 49@z 50 51@x [12] Permissiveness 52for i:=0 to @'37 do xchr[i]:=' '; 53for i:=@'177 to @'377 do xchr[i]:=' '; 54@y 55for i:=0 to @'37 do xchr[i]:=chr(i); 56for i:=@'177 to @'377 do xchr[i]:=chr(i); 57@z 58 59@x Write errors to stderr, avoid nonlocal label. 60@d abort(#)==begin write_ln(#); goto 9999; 61 end 62@y 63@d abort(#)==begin write_ln(stderr, #); uexit(1); end 64@z 65 66@x Remove unused label from end of program; add uexit(0) call 679999:end. 68@y 69uexit(0); 70end. 71@z 72 73@x Add pool_name variable. 74@!pool_file:packed file of text_char; 75 {the string-pool file output by \.{TANGLE}} 76@y 77@!pool_file:packed file of text_char; 78 {the string-pool file output by \.{TANGLE}} 79@!pool_name:const_c_string; 80@z 81 82% The name of the pool file is dynamically determined. We open it at the 83% end of parse_arguments. 84@x 85reset(pool_file); xsum:=false; 86@y 87xsum:=false; 88@z 89 90@x Change single read into two reads 91read(pool_file,m,n); {read two digits of string length} 92@y 93read(pool_file,m); read(pool_file,n); {read two digits of string length} 94@z 95 96@x System-dependent changes. 97This section should be replaced, if necessary, by changes to the program 98that are necessary to make \.{POOLtype} work at a particular installation. 99It is usually best to design your change file so that all changes to 100previous sections preserve the section numbering; then everybody's version 101will be consistent with the printed program. More extensive changes, 102which introduce new sections, can be inserted here; then only the index 103itself will get a new section number. 104@^system dependencies@> 105@y 106Parse a Unix-style command line. 107 108@d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0) 109 110@<Define |parse_arguments|@> = 111procedure parse_arguments; 112const n_options = 2; {Pascal won't count array lengths for us.} 113var @!long_options: array[0..n_options] of getopt_struct; 114 @!getopt_return_val: integer; 115 @!option_index: c_int_type; 116 @!current_option: 0..n_options; 117begin 118 @<Define the option table@>; 119 repeat 120 getopt_return_val := getopt_long_only (argc, argv, '', long_options, 121 address_of (option_index)); 122 if getopt_return_val = -1 then begin 123 do_nothing; 124 125 end else if getopt_return_val = '?' then begin 126 usage (my_name); 127 128 end else if argument_is ('help') then begin 129 usage_help (POOLTYPE_HELP, nil); 130 131 end else if argument_is ('version') then begin 132 print_version_and_exit ('This is POOLtype, Version 3.0', nil, 133 'D.E. Knuth', 134 nil); 135 136 end; {Else it was just a flag; |getopt| has already done the assignment.} 137 until getopt_return_val = -1; 138 139 {Now |optind| is the index of first non-option on the command line.} 140 if (optind + 1 <> argc) then begin 141 write_ln (stderr, my_name, ': Need exactly one file argument.'); 142 usage (my_name); 143 end; 144 145 pool_name := extend_filename (cmdline (optind), 'pool'); 146 {Try opening the file here, to avoid printing the first 256 strings if 147 they give a bad filename.} 148 resetbin (pool_file, pool_name); 149end; 150 151@ Here are the options we allow. The first is one of the standard GNU options. 152@.-help@> 153 154@<Define the option...@> = 155current_option := 0; 156long_options[current_option].name := 'help'; 157long_options[current_option].has_arg := 0; 158long_options[current_option].flag := 0; 159long_options[current_option].val := 0; 160incr (current_option); 161 162@ Another of the standard options. 163@.-version@> 164 165@<Define the option...@> = 166long_options[current_option].name := 'version'; 167long_options[current_option].has_arg := 0; 168long_options[current_option].flag := 0; 169long_options[current_option].val := 0; 170incr (current_option); 171 172@ An element with all zeros always ends the list. 173 174@<Define the option...@> = 175long_options[current_option].name := 0; 176long_options[current_option].has_arg := 0; 177long_options[current_option].flag := 0; 178long_options[current_option].val := 0; 179@z 180