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