| 1 |
% Change file for BibTeX in C, originally by Howard Trickey. |
| 2 |
% |
| 3 |
% 05/28/84 Initial implementation, version 0.41 of BibTeX |
| 4 |
% 07/01/84 Version 0.41a of BibTeX. |
| 5 |
% 12/17/84 Version 0.97c of BibTeX. |
| 6 |
% 02/12/85 Version 0.98c of BibTeX. |
| 7 |
% 02/25/85 Newer version 0.98c of BibTeX. |
| 8 |
% 03/25/85 Version 0.98f of BibTeX |
| 9 |
% 05/23/85 Version 0.98i of BibTeX |
| 10 |
% 02/11/88 Version 0.99b of BibTeX |
| 11 |
% 04/04/88 Version 0.99c; converted for use with web2c (ETM). |
| 12 |
% 11/30/89 Use FILENAMESIZE instead of 1024 (KB). |
| 13 |
% 03/09/90 `int' is a bad variable name for C. |
| 14 |
% (more recent changes in the ChangeLog) |
| 15 |
|
| 16 |
@x [0] |
| 17 |
\font\sc=cmcsc10 |
| 18 |
@y |
| 19 |
\font\sc=cmcsc10 |
| 20 |
|
| 21 |
\let\maybe = \iffalse % process only changed sections |
| 22 |
@z |
| 23 |
|
| 24 |
@x [1] Define my_name |
| 25 |
@d banner=='This is BibTeX, Version 0.99e' {printed when the program starts} |
| 26 |
@y |
| 27 |
@d my_name=='bibtex' |
| 28 |
@d banner=='This is BibTeX, Version 0.99e' {printed when the program starts} |
| 29 |
@z |
| 30 |
|
| 31 |
% [2] `term_in' and `term_out' are standard input and output. But |
| 32 |
% there is a complication: BibTeX passes `term_out' to some routines as |
| 33 |
% a var parameter. web2c turns a var parameter f into &f at the calling |
| 34 |
% side -- and stdout is sometimes implemented as `&_iob[1]' or some |
| 35 |
% such. An address of an address is invalid. Therefore, we define |
| 36 |
% variables `standardinput' and `standardoutput' in openinout.c. |
| 37 |
@x [2] |
| 38 |
@d term_out == tty |
| 39 |
@d term_in == tty |
| 40 |
@y |
| 41 |
@d term_out == standard_output |
| 42 |
@d term_in == standard_input |
| 43 |
|
| 44 |
@<Globals in the outer block@>= |
| 45 |
standard_input, standard_output: text; |
| 46 |
@z |
| 47 |
|
| 48 |
@x [3] Add log_pr macros. |
| 49 |
@d trace_pr_newline == begin write_ln(log_file); end |
| 50 |
@y |
| 51 |
@d trace_pr_newline == begin write_ln(log_file); end |
| 52 |
@# |
| 53 |
@d log_pr(#) == trace_pr(#) |
| 54 |
@d log_pr_ln(#) == trace_pr_ln(#) |
| 55 |
@d log_pr_newline == trace_pr_newline |
| 56 |
@z |
| 57 |
|
| 58 |
@x [4] Turn debug..gubed et al. into #ifdef's. |
| 59 |
@d debug == @{ { remove the `|@{|' when debugging } |
| 60 |
@d gubed == @t@>@} { remove the `|@}|' when debugging } |
| 61 |
@f debug == begin |
| 62 |
@f gubed == end |
| 63 |
@# |
| 64 |
@d stat == @{ { remove the `|@{|' when keeping statistics } |
| 65 |
@d tats == @t@>@} { remove the `|@}|' when keeping statistics } |
| 66 |
@f stat == begin |
| 67 |
@f tats == end |
| 68 |
@# |
| 69 |
@d trace == @{ { remove the `|@{|' when in |trace| mode } |
| 70 |
@d ecart == @t@>@} { remove the `|@}|' when in |trace| mode } |
| 71 |
@f trace == begin |
| 72 |
@f ecart == end |
| 73 |
@y |
| 74 |
@d debug == ifdef('TEXMF_DEBUG') |
| 75 |
@d gubed == endif('TEXMF_DEBUG') |
| 76 |
@f debug == begin |
| 77 |
@f gubed == end |
| 78 |
@# |
| 79 |
@d stat == ifndef('NO_BIBTEX_STAT') |
| 80 |
@d tats == endifn('NO_BIBTEX_STAT') |
| 81 |
@f stat==begin |
| 82 |
@f tats==end |
| 83 |
@# |
| 84 |
@d trace == ifdef@&('TRACE') |
| 85 |
@d ecart == endif@&('TRACE') |
| 86 |
@f trace == begin |
| 87 |
@f ecart == end |
| 88 |
@z |
| 89 |
|
| 90 |
@x [10] Eliminate the |exit_program| label. |
| 91 |
label close_up_shop,@!exit_program @<Labels in the outer block@>; |
| 92 |
@y |
| 93 |
label close_up_shop @<Labels in the outer block@>; |
| 94 |
@z |
| 95 |
|
| 96 |
@x [10] Don't print the banner unless verbose, and initialize dynamic arrays. |
| 97 |
@# |
| 98 |
begin |
| 99 |
initialize; |
| 100 |
print_ln(banner);@/ |
| 101 |
@y |
| 102 |
@;@<Define \(p)|parse_arguments|@> |
| 103 |
@# |
| 104 |
begin |
| 105 |
standard_input := stdin; |
| 106 |
standard_output := stdout; |
| 107 |
@# |
| 108 |
pool_size := POOL_SIZE; |
| 109 |
buf_size := BUF_SIZE; |
| 110 |
max_bib_files := MAX_BIB_FILES; |
| 111 |
max_glob_strs := MAX_GLOB_STRS; |
| 112 |
max_fields := MAX_FIELDS; |
| 113 |
max_cites := MAX_CITES; |
| 114 |
wiz_fn_space := WIZ_FN_SPACE; |
| 115 |
lit_stk_size := LIT_STK_SIZE; |
| 116 |
@# |
| 117 |
@<Process a \(o)possible command line@>@; |
| 118 |
setup_params; |
| 119 |
@# |
| 120 |
{Add one to the sizes because that's what bibtex uses.} |
| 121 |
bib_file := XTALLOC (max_bib_files + 1, alpha_file); |
| 122 |
bib_list := XTALLOC (max_bib_files + 1, str_number); |
| 123 |
entry_ints := nil; |
| 124 |
entry_strs := nil; |
| 125 |
wiz_functions := XTALLOC (wiz_fn_space + 1, hash_ptr2); |
| 126 |
field_info := XTALLOC (max_fields + 1, str_number); |
| 127 |
s_preamble := XTALLOC (max_bib_files + 1, str_number); |
| 128 |
str_pool := XTALLOC (pool_size + 1, ASCII_code); |
| 129 |
buffer := XTALLOC (buf_size + 1, ASCII_code); |
| 130 |
sv_buffer := XTALLOC (buf_size + 1, ASCII_code); |
| 131 |
ex_buf := XTALLOC (buf_size + 1, ASCII_code); |
| 132 |
out_buf := XTALLOC (buf_size + 1, ASCII_code); |
| 133 |
name_tok := XTALLOC (buf_size + 1, buf_pointer); |
| 134 |
name_sep_char := XTALLOC (buf_size + 1, ASCII_code); |
| 135 |
@# |
| 136 |
glb_str_ptr := XTALLOC (max_glob_strs, str_number); |
| 137 |
global_strs := XTALLOC (max_glob_strs * (glob_str_size + 1), ASCII_code); |
| 138 |
glb_str_end := XTALLOC (max_glob_strs, integer); |
| 139 |
@# |
| 140 |
cite_list := XTALLOC (max_cites + 1, str_number); |
| 141 |
type_list := XTALLOC (max_cites + 1, hash_ptr2); |
| 142 |
entry_exists := XTALLOC (max_cites + 1, boolean); |
| 143 |
cite_info := XTALLOC (max_cites + 1, str_number); |
| 144 |
@# |
| 145 |
str_start := XTALLOC (max_strings + 1, pool_pointer); |
| 146 |
@# |
| 147 |
hash_next := XTALLOC (hash_max + 1, hash_pointer); |
| 148 |
hash_text := XTALLOC (hash_max + 1, str_number); |
| 149 |
hash_ilk := XTALLOC (hash_max + 1, str_ilk); |
| 150 |
ilk_info := XTALLOC (hash_max + 1, integer); |
| 151 |
fn_type := XTALLOC (hash_max + 1, fn_class); |
| 152 |
@# |
| 153 |
lit_stack := XTALLOC (lit_stk_size + 1, integer); |
| 154 |
lit_stk_type := XTALLOC (lit_stk_size + 1, stk_type); |
| 155 |
@# |
| 156 |
compute_hash_prime; |
| 157 |
@# |
| 158 |
initialize; |
| 159 |
{This initializes the jmp9998 buffer, which can be used early} |
| 160 |
hack0; |
| 161 |
if verbose then begin |
| 162 |
print (banner); |
| 163 |
print_ln (version_string); |
| 164 |
end |
| 165 |
else begin |
| 166 |
log_pr (banner); |
| 167 |
log_pr_ln (version_string); |
| 168 |
end; |
| 169 |
log_pr_ln ('Capacity: max_strings=', max_strings:1, |
| 170 |
', hash_size=', hash_size:1, ', hash_prime=', hash_prime:1); |
| 171 |
@z |
| 172 |
|
| 173 |
% [10] Possibly exit with bad status. It doesn't seem worth it to move |
| 174 |
% the definitions of the |history| values to above this module; hence the 1. |
| 175 |
@x [10] |
| 176 |
exit_program: |
| 177 |
end. |
| 178 |
@y |
| 179 |
if (history > 1) then uexit (history); |
| 180 |
end. |
| 181 |
@z |
| 182 |
|
| 183 |
@x [13] Remove nonlocal goto. |
| 184 |
goto exit_program; |
| 185 |
@y |
| 186 |
uexit (1); |
| 187 |
@z |
| 188 |
|
| 189 |
@x [14] Increase some constants, and uppercase others for dynamic arrays. |
| 190 |
@<Constants in the outer block@>= |
| 191 |
@y |
| 192 |
@<Constants in the outer block@>= |
| 193 |
@!hash_base = empty + 1; {lowest numbered hash-table location} |
| 194 |
@!quote_next_fn = hash_base - 1; {special marker used in defining functions} |
| 195 |
@z |
| 196 |
|
| 197 |
@x [still 14] |
| 198 |
@!buf_size=1000; {maximum number of characters in an input line (or string)} |
| 199 |
@!min_print_line=3; {minimum \.{.bbl} line length: must be |>=3|} |
| 200 |
@!max_print_line=79; {the maximum: must be |>min_print_line| and |<buf_size|} |
| 201 |
@y |
| 202 |
@!BUF_SIZE=20000; {initial maximum number of characters in an input line |
| 203 |
(or string)} |
| 204 |
@!min_print_line=3; {minimum \.{.bbl} line length: must be |>=3|} |
| 205 |
@!MAX_PRINT_LINE=60; {the maximum: must be |>min_print_line| and |<buf_size|} |
| 206 |
@z |
| 207 |
|
| 208 |
@x [still 14] |
| 209 |
@!max_bib_files=20; {maximum number of \.{.bib} files allowed} |
| 210 |
@!pool_size=65000; {maximum number of characters in strings} |
| 211 |
@!max_strings=4000; {maximum number of strings, including pre-defined; |
| 212 |
must be |<=hash_size|} |
| 213 |
@!max_cites=750; {maximum number of distinct cite keys; must be |
| 214 |
|<=max_strings|} |
| 215 |
@!min_crossrefs=2; {minimum number of cross-refs required for automatic |
| 216 |
|cite_list| inclusion} |
| 217 |
@!wiz_fn_space=3000; {maximum amount of |wiz_defined|-function space} |
| 218 |
@y [still 14] |
| 219 |
@!MAX_BIB_FILES=20; {initial number of \.{.bib} files allowed} |
| 220 |
@!POOL_SIZE=65000; {initial number of characters in strings} |
| 221 |
@!MAX_STRINGS=4000; {minimum value for |max_strings|} |
| 222 |
@!MAX_CITES=750; {initial number of distinct cite keys; must be |
| 223 |
|<=max_strings|} |
| 224 |
@!WIZ_FN_SPACE=3000; {initial amount of |wiz_defined|-function space} |
| 225 |
{|min_crossrefs| can be set at runtime now.} |
| 226 |
@z |
| 227 |
|
| 228 |
@x [still 14] |
| 229 |
@!single_fn_space=100; {maximum amount for a single |wiz_defined|-function} |
| 230 |
@y |
| 231 |
@!SINGLE_FN_SPACE=50; {initial amount for a single |wiz_defined|-function} |
| 232 |
@z |
| 233 |
|
| 234 |
@x [still 14] handle long citation strings |
| 235 |
@!max_ent_ints=3000; {maximum number of |int_entry_var|s |
| 236 |
(entries $\times$ |int_entry_var|s)} |
| 237 |
@!max_ent_strs=3000; {maximum number of |str_entry_var|s |
| 238 |
(entries $\times$ |str_entry_var|s)} |
| 239 |
@!ent_str_size=100; {maximum size of a |str_entry_var|; must be |<=buf_size|} |
| 240 |
@!glob_str_size=1000; {maximum size of a |str_global_var|; |
| 241 |
must be |<=buf_size|} |
| 242 |
@!max_fields=17250; {maximum number of fields (entries $\times$ fields, |
| 243 |
@y |
| 244 |
@!ENT_STR_SIZE=100; {maximum size of a |str_entry_var|; must be |<=buf_size|} |
| 245 |
@!GLOB_STR_SIZE=1000; {maximum size of a |str_global_var|; |
| 246 |
must be |<=buf_size|} |
| 247 |
@!MAX_GLOB_STRS=10; {initial number of |str_global_var| names} |
| 248 |
@!MAX_FIELDS=5000; {initial number of fields (entries $\times$ fields, |
| 249 |
@z |
| 250 |
|
| 251 |
@x [still 14] |
| 252 |
@!lit_stk_size=100; {maximum number of literal functions on the stack} |
| 253 |
@y |
| 254 |
@!LIT_STK_SIZE=50; {initial space for literal functions on the stack} |
| 255 |
@z |
| 256 |
|
| 257 |
@x [15] Increase more constants in the web defines. |
| 258 |
@d hash_size=5000 {must be |>= max_strings| and |>= hash_prime|} |
| 259 |
@d hash_prime=4253 {a prime number about 85\% of |hash_size| and |>= 128| |
| 260 |
and |< @t$2^{14}-2^6$@>|} |
| 261 |
@d file_name_size=40 {file names shouldn't be longer than this} |
| 262 |
@d max_glob_strs=10 {maximum number of |str_global_var| names} |
| 263 |
@d max_glb_str_minus_1 = max_glob_strs-1 {to avoid wasting a |str_global_var|} |
| 264 |
@y |
| 265 |
{|hash_size| and |hash_prime| are now computed.} |
| 266 |
@d HASH_SIZE=5000 {minimum value for |hash_size|} |
| 267 |
@# |
| 268 |
@d file_name_size==maxint {file names have no arbitrary maximum length} |
| 269 |
@# |
| 270 |
{For dynamic allocation.} |
| 271 |
@d x_entry_strs_tail(#) == (#)] |
| 272 |
@d x_entry_strs(#) == entry_strs[(#) * (ent_str_size+1) + x_entry_strs_tail |
| 273 |
@d x_global_strs_tail(#) == (#)] |
| 274 |
@d x_global_strs(#) == global_strs[(#) * (glob_str_size+1) + x_global_strs_tail |
| 275 |
@z |
| 276 |
|
| 277 |
@x [16] Add new variables-that-used-to-be-constants for dynamic arrays. |
| 278 |
@<Globals in the outer block@>= |
| 279 |
@y |
| 280 |
@<Globals in the outer block@>= |
| 281 |
@!pool_size: integer; |
| 282 |
@!max_print_line: integer; |
| 283 |
@!max_bib_files: integer; |
| 284 |
@!max_cites: integer; |
| 285 |
@!wiz_fn_space: integer; |
| 286 |
@!ent_str_size: integer; |
| 287 |
@!glob_str_size: integer; |
| 288 |
@!max_glob_strs: integer; |
| 289 |
@!max_fields: integer; |
| 290 |
@!lit_stk_size: integer; |
| 291 |
@# |
| 292 |
@!max_strings: integer; |
| 293 |
@!hash_size: integer; |
| 294 |
@!hash_prime: integer; |
| 295 |
@# |
| 296 |
@!hash_max: integer; {highest numbered hash-table location} |
| 297 |
@!end_of_def: integer; {another special marker used in defining functions} |
| 298 |
@!undefined: integer; {a special marker used for |type_list|} |
| 299 |
@z |
| 300 |
|
| 301 |
@x [17] max_strings=hash_size settable at runtime. |
| 302 |
if (hash_prime >= (16384-64)) then bad:=10*bad+6; |
| 303 |
@y |
| 304 |
if (hash_base <> 1) then bad:=10*bad+6; |
| 305 |
@z |
| 306 |
|
| 307 |
@x [still 17] remove buf_size checks, since buf_size changes dynamically. |
| 308 |
if (ent_str_size > buf_size) then bad:=10*bad+9; |
| 309 |
if (glob_str_size > buf_size) then bad:=100*bad+11; |
| 310 |
@y |
| 311 |
@z |
| 312 |
|
| 313 |
@x [22] Allow any character as input. |
| 314 |
@!ASCII_code=0..127; {seven-bit numbers} |
| 315 |
@y |
| 316 |
@!ASCII_code=0..255; {eight-bit numbers} |
| 317 |
@z |
| 318 |
|
| 319 |
@x [23] |
| 320 |
@d text_char == char {the data type of characters in text files} |
| 321 |
@d first_text_char=0 {ordinal number of the smallest element of |text_char|} |
| 322 |
@d last_text_char=127 {ordinal number of the largest element of |text_char|} |
| 323 |
|
| 324 |
@<Local variables for initialization@>= |
| 325 |
i:0..last_text_char; {this is the first one declared} |
| 326 |
@y |
| 327 |
@d text_char == ASCII_code {the data type of characters in text files} |
| 328 |
@d first_text_char=0 {ordinal number of the smallest element of |text_char|} |
| 329 |
@d last_text_char=255 {ordinal number of the largest element of |text_char|} |
| 330 |
|
| 331 |
@<Local variables for initialization@>= |
| 332 |
i:integer; |
| 333 |
@z |
| 334 |
|
| 335 |
@x [27] |
| 336 |
for i:=1 to @'37 do xchr[i]:=' '; |
| 337 |
xchr[tab]:=chr(tab); |
| 338 |
@y |
| 339 |
for i:=0 to @'37 do xchr[i]:=chr(i); |
| 340 |
for i:=@'177 to @'377 do xchr[i]:=chr(i); |
| 341 |
@z |
| 342 |
|
| 343 |
@x [28] |
| 344 |
for i:=first_text_char to last_text_char do xord[chr(i)]:=invalid_code; |
| 345 |
for i:=1 to @'176 do xord[xchr[i]]:=i; |
| 346 |
@y |
| 347 |
for i:=first_text_char to last_text_char do xord[xchr[i]]:=i; |
| 348 |
@z |
| 349 |
|
| 350 |
@x [32] Put the [128..255] range into lex_class alpha. |
| 351 |
for i:=0 to @'177 do lex_class[i] := other_lex; |
| 352 |
@y |
| 353 |
for i:=0 to @'177 do lex_class[i] := other_lex; |
| 354 |
for i:=@'200 to @'377 do lex_class[i] := alpha; |
| 355 |
@z |
| 356 |
|
| 357 |
% [still 32] Make RET a `white_space' character, so we won't choke on DOS |
| 358 |
% files, which use CR/LF for line endings. |
| 359 |
@x [32] |
| 360 |
lex_class[tab] := white_space; |
| 361 |
@y |
| 362 |
lex_class[tab] := white_space; |
| 363 |
lex_class[13] := white_space; |
| 364 |
@z |
| 365 |
|
| 366 |
@x [33] Allow the [128..255] range in legal_id_char. |
| 367 |
for i:=0 to @'177 do id_class[i] := legal_id_char; |
| 368 |
@y |
| 369 |
for i:=0 to @'377 do id_class[i] := legal_id_char; |
| 370 |
@z |
| 371 |
|
| 372 |
% [37] file_name_size no longer exists. See comments in tex.ch for why |
| 373 |
% we change the element type to text_char. |
| 374 |
@x [37] |
| 375 |
@!name_of_file:packed array[1..file_name_size] of char; |
| 376 |
{on some systems this is a \&{record} variable} |
| 377 |
@!name_length:0..file_name_size; |
| 378 |
{this many characters are relevant in |name_of_file| (the rest are blank)} |
| 379 |
@!name_ptr:0..file_name_size+1; {index variable into |name_of_file|} |
| 380 |
@y |
| 381 |
@!name_of_file:^text_char; |
| 382 |
@!name_length:integer; |
| 383 |
{this many characters are relevant in |name_of_file| } |
| 384 |
@!name_ptr:integer; {index variable into |name_of_file|} |
| 385 |
@z |
| 386 |
|
| 387 |
@x [38] File opening. |
| 388 |
@ |
| 389 |
@^system dependencies@> |
| 390 |
@:PASCAL H}{\ph@> |
| 391 |
The \ph\ compiler with which the present version of \TeX\ was prepared has |
| 392 |
extended the rules of \PASCAL\ in a very convenient way. To open file~|f|, |
| 393 |
we can write |
| 394 |
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr |
| 395 |
|reset(f,@t\\{name}@>,'/O')|&for input;\cr |
| 396 |
|rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$ |
| 397 |
The `\\{name}' parameter, which is of type `\ignorespaces|packed |
| 398 |
array[@t\<\\{any}>@>] of text_char|', stands for the name of |
| 399 |
the external file that is being opened for input or output. |
| 400 |
Blank spaces that might appear in \\{name} are ignored. |
| 401 |
|
| 402 |
The `\.{/O}' parameter tells the operating system not to issue its own |
| 403 |
error messages if something goes wrong. If a file of the specified name |
| 404 |
cannot be found, or if such a file cannot be opened for some other reason |
| 405 |
(e.g., someone may already be trying to write the same file), we will have |
| 406 |
|@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|. This allows |
| 407 |
\TeX\ to undertake appropriate corrective action. |
| 408 |
|
| 409 |
\TeX's file-opening procedures return |false| if no file identified by |
| 410 |
|name_of_file| could be opened. |
| 411 |
|
| 412 |
@d reset_OK(#)==erstat(#)=0 |
| 413 |
@d rewrite_OK(#)==erstat(#)=0 |
| 414 |
|
| 415 |
@<Procedures and functions for file-system interacting@>= |
| 416 |
function erstat(var f:file):integer; extern; {in the runtime library} |
| 417 |
@#@t\2@> |
| 418 |
function a_open_in(var f:alpha_file):boolean; {open a text file for input} |
| 419 |
begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f); |
| 420 |
end; |
| 421 |
@# |
| 422 |
function a_open_out(var f:alpha_file):boolean; {open a text file for output} |
| 423 |
begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f); |
| 424 |
end; |
| 425 |
@y |
| 426 |
@ File opening will be done in C. But we want an auxiliary function to |
| 427 |
change a \BibTeX\ string into a C string, to keep string pool stuff |
| 428 |
out of the C code in \.{lib/openclose.c}. |
| 429 |
@.lib/openclose.c@> |
| 430 |
|
| 431 |
@d no_file_path = -1 |
| 432 |
|
| 433 |
@<Procedures and functions for all file...@>= |
| 434 |
function bib_makecstring(s:str_number):cstring; |
| 435 |
var cstr:cstring; |
| 436 |
i:pool_pointer; |
| 437 |
begin |
| 438 |
cstr := xmalloc_array (ASCII_code, length (s) + 1); |
| 439 |
for i := 0 to length(s) - 1 do begin |
| 440 |
cstr[i] := str_pool[str_start[s] + i]; |
| 441 |
end; |
| 442 |
cstr[length(s)] := 0; |
| 443 |
bib_makecstring := cstr; |
| 444 |
exit: end; |
| 445 |
@z |
| 446 |
|
| 447 |
@x [39] Do file closing in C. |
| 448 |
@<Procedures and functions for file-system interacting@>= |
| 449 |
procedure a_close(var f:alpha_file); {close a text file} |
| 450 |
begin close(f); |
| 451 |
end; |
| 452 |
@y |
| 453 |
File closing will be done in C, too. |
| 454 |
@z |
| 455 |
|
| 456 |
@x [41] Dynamic buf_size. |
| 457 |
@!buffer:buf_type; {usually, lines of characters being read} |
| 458 |
@y |
| 459 |
@!buf_size:integer; {size of buffer} |
| 460 |
@!buffer:buf_type; {usually, lines of characters being read} |
| 461 |
@z |
| 462 |
|
| 463 |
@x [42] Dynamic buf_size. |
| 464 |
@!buf_pointer = 0..buf_size; {an index into a |buf_type|} |
| 465 |
@!buf_type = array[buf_pointer] of ASCII_code; {for various buffers} |
| 466 |
@y |
| 467 |
@!buf_pointer = integer; {an index into a |buf_type|} |
| 468 |
@!buf_type = ^ASCII_code; {for various buffers} |
| 469 |
@z |
| 470 |
|
| 471 |
@x [46] Dynamic buf_size. |
| 472 |
overflow('buffer size ',buf_size); |
| 473 |
@y |
| 474 |
{These are all the arrays of |buf_type| or that use |buf_pointer|, that |
| 475 |
is, they all depend on the |buf_size| value. Therefore we have to |
| 476 |
reallocate them all at once, even though only one of them has |
| 477 |
overflowed. The alternative seems worse: even more surgery on the program, |
| 478 |
to have a separate variable for each array size instead of the common |
| 479 |
|buf_size|.} |
| 480 |
BIB_XRETALLOC_NOSET ('buffer', buffer, ASCII_code, |
| 481 |
buf_size, buf_size + BUF_SIZE); |
| 482 |
BIB_XRETALLOC_NOSET ('sv_buffer', sv_buffer, ASCII_code, |
| 483 |
buf_size, buf_size + BUF_SIZE); |
| 484 |
BIB_XRETALLOC_NOSET ('ex_buf', ex_buf, ASCII_code, |
| 485 |
buf_size, buf_size + BUF_SIZE); |
| 486 |
BIB_XRETALLOC_NOSET ('out_buf', out_buf, ASCII_code, |
| 487 |
buf_size, buf_size + BUF_SIZE); |
| 488 |
BIB_XRETALLOC_NOSET ('name_tok', name_tok, buf_pointer, |
| 489 |
buf_size, buf_size + BUF_SIZE); |
| 490 |
BIB_XRETALLOC ('name_sep_char', name_sep_char, ASCII_code, |
| 491 |
buf_size, buf_size + BUF_SIZE); |
| 492 |
@z |
| 493 |
|
| 494 |
@x [47] web2c doesn't understand f^. |
| 495 |
buffer[last]:=xord[f^]; |
| 496 |
get(f); incr(last); |
| 497 |
end; |
| 498 |
get(f); |
| 499 |
@y |
| 500 |
buffer[last] := xord[getc (f)]; |
| 501 |
incr (last); |
| 502 |
end; |
| 503 |
vgetc (f); {skip the eol} |
| 504 |
@z |
| 505 |
|
| 506 |
@x [48] Dynamically allocate str_pool. |
| 507 |
@!str_pool : packed array[pool_pointer] of ASCII_code; {the characters} |
| 508 |
@!str_start : packed array[str_number] of pool_pointer; {the starting pointers} |
| 509 |
@y |
| 510 |
@!str_pool : ^ASCII_code; {the characters} |
| 511 |
@!str_start :^pool_pointer; {the starting pointers} |
| 512 |
@z |
| 513 |
|
| 514 |
@x [49] pool_size is a variable now, so can't be used as a constant. |
| 515 |
@!pool_pointer = 0..pool_size; {for variables that point into |str_pool|} |
| 516 |
@!str_number = 0..max_strings; {for variables that point into |str_start|} |
| 517 |
@y |
| 518 |
@!pool_pointer = integer; {for variables that point into |str_pool|} |
| 519 |
@!str_number = integer; {for variables that point into |str_start|} |
| 520 |
@z |
| 521 |
|
| 522 |
@x [50] Add log_pr_pool_str macro. |
| 523 |
@d trace_pr_pool_str(#) == begin |
| 524 |
out_pool_str(log_file,#); |
| 525 |
end |
| 526 |
@y |
| 527 |
@d trace_pr_pool_str(#) == begin |
| 528 |
out_pool_str(log_file,#); |
| 529 |
end |
| 530 |
@# |
| 531 |
@d log_pr_pool_str(#) == trace_pr_pool_str(#) |
| 532 |
@z |
| 533 |
|
| 534 |
@x [53] Reallocate str_pool. We may need more than POOL_SIZE. |
| 535 |
if (pool_ptr+# > pool_size) then |
| 536 |
@y |
| 537 |
while (pool_ptr+# > pool_size) do |
| 538 |
@z |
| 539 |
@x [still 53] Reallocate str_pool. |
| 540 |
overflow('pool size ',pool_size); |
| 541 |
@y |
| 542 |
BIB_XRETALLOC ('str_pool', str_pool, ASCII_code, pool_size, |
| 543 |
pool_size + POOL_SIZE); |
| 544 |
@z |
| 545 |
|
| 546 |
% [58] (start_name) reallocate name_of_file for the new name and |
| 547 |
% terminate with null. |
| 548 |
@x [58] |
| 549 |
if (length(file_name) > file_name_size) then |
| 550 |
begin |
| 551 |
print ('File='); |
| 552 |
print_pool_str (file_name); |
| 553 |
print_ln (','); |
| 554 |
file_nm_size_overflow; |
| 555 |
end; |
| 556 |
@y |
| 557 |
free (name_of_file); |
| 558 |
name_of_file := xmalloc_array (ASCII_code, length (file_name) + 1); |
| 559 |
@z |
| 560 |
|
| 561 |
@x [58] |
| 562 |
name_length := length(file_name); |
| 563 |
@y |
| 564 |
name_length := length(file_name); |
| 565 |
name_of_file[name_length + 1] := 0; |
| 566 |
@z |
| 567 |
|
| 568 |
@x [59] (file_nm_size_overflow) This procedure is not used. |
| 569 |
procedure file_nm_size_overflow; |
| 570 |
begin |
| 571 |
overflow('file name size ',file_name_size); |
| 572 |
end; |
| 573 |
@y |
| 574 |
@z |
| 575 |
|
| 576 |
% [60] (add_extension) Don't pad name_of_file with blanks, terminate |
| 577 |
% with null. And junk the overflow check, since Web2c can't translate |
| 578 |
% the print statement properly and it can never happen, anyway. |
| 579 |
@x [60] |
| 580 |
if (name_length + length(ext) > file_name_size) then |
| 581 |
begin |
| 582 |
print ('File=',name_of_file,', extension='); |
| 583 |
print_pool_str (ext); print_ln (','); |
| 584 |
file_nm_size_overflow; |
| 585 |
end; |
| 586 |
@y |
| 587 |
@z |
| 588 |
@x [60] |
| 589 |
name_ptr := name_length+1; |
| 590 |
while (name_ptr <= file_name_size) do {pad with blanks} |
| 591 |
begin |
| 592 |
name_of_file[name_ptr] := ' '; |
| 593 |
incr(name_ptr); |
| 594 |
end; |
| 595 |
@y |
| 596 |
name_of_file[name_length + 1] := 0; |
| 597 |
@z |
| 598 |
|
| 599 |
@x [61] (add_area) This procedure is not used. |
| 600 |
procedure add_area(@!area:str_number); |
| 601 |
var p_ptr: pool_pointer; {running index} |
| 602 |
begin |
| 603 |
if (name_length + length(area) > file_name_size) then |
| 604 |
begin |
| 605 |
print ('File='); |
| 606 |
print_pool_str (area); print (name_of_file,','); |
| 607 |
file_nm_size_overflow; |
| 608 |
end; |
| 609 |
name_ptr := name_length; |
| 610 |
while (name_ptr > 0) do {shift up name} |
| 611 |
begin |
| 612 |
name_of_file[name_ptr+length(area)] := name_of_file[name_ptr]; |
| 613 |
decr(name_ptr); |
| 614 |
end; |
| 615 |
name_ptr := 1; |
| 616 |
p_ptr := str_start[area]; |
| 617 |
while (p_ptr < str_start[area+1]) do |
| 618 |
begin |
| 619 |
name_of_file[name_ptr] := chr (str_pool[p_ptr]); |
| 620 |
incr(name_ptr); incr(p_ptr); |
| 621 |
end; |
| 622 |
name_length := name_length + length(area); |
| 623 |
end; |
| 624 |
@y |
| 625 |
{procedure |add_area| not used} |
| 626 |
@z |
| 627 |
|
| 628 |
@x [64] now Pascal consts or vars, instead of web macros. |
| 629 |
@d hash_base = empty + 1 {lowest numbered hash-table location} |
| 630 |
@d hash_max = hash_base + hash_size - 1 {highest numbered hash-table location} |
| 631 |
@y |
| 632 |
@z |
| 633 |
|
| 634 |
@x [still 64] max_strings=hash_size settable at runtime. |
| 635 |
@!hash_loc=hash_base..hash_max; {a location within the hash table} |
| 636 |
@!hash_pointer=empty..hash_max; {either |empty| or a |hash_loc|} |
| 637 |
@y |
| 638 |
@!hash_loc=integer; {a location within the hash table} |
| 639 |
@!hash_pointer=integer; {either |empty| or a |hash_loc|} |
| 640 |
@z |
| 641 |
|
| 642 |
@x [65] max_strings=hash_size settable at runtime. |
| 643 |
@ |
| 644 |
@<Globals in the outer block@>= |
| 645 |
@!hash_next : packed array[hash_loc] of hash_pointer; {coalesced-list link} |
| 646 |
@!hash_text : packed array[hash_loc] of str_number; {pointer to a string} |
| 647 |
@!hash_ilk : packed array[hash_loc] of str_ilk; {the type of string} |
| 648 |
@!ilk_info : packed array[hash_loc] of integer; {|ilk|-specific info} |
| 649 |
@!hash_used : hash_base..hash_max+1; {allocation pointer for hash table} |
| 650 |
@y |
| 651 |
@ @<Globals in the outer block@>= |
| 652 |
@!hash_next : ^hash_pointer; {coalesced-list link} |
| 653 |
@!hash_text : ^str_number; {pointer to a string} |
| 654 |
@!hash_ilk : ^str_ilk; {the type of string} |
| 655 |
@!ilk_info : ^integer; {|ilk|-specific info} |
| 656 |
@!hash_used : integer; {allocation pointer for hash table} |
| 657 |
@z |
| 658 |
|
| 659 |
@x [68] Not used anymore. |
| 660 |
@d max_hash_value = hash_prime+hash_prime-2+127 {|h|'s maximum value} |
| 661 |
@y |
| 662 |
@z |
| 663 |
|
| 664 |
@x [still 68] max_strings=hash_size settable at runtime. |
| 665 |
var h:0..max_hash_value; {hash code} |
| 666 |
@y |
| 667 |
var h:integer; {hash code} |
| 668 |
@z |
| 669 |
|
| 670 |
@x [still 68] str_lookup - Avoid 'uninitialized' warning. |
| 671 |
@!old_string:boolean; {set to |true| if it's an already encountered string} |
| 672 |
@y |
| 673 |
@z |
| 674 |
|
| 675 |
@x [still 68] str_lookup - Avoid 'uninitialized' warning. |
| 676 |
old_string := false; |
| 677 |
@y |
| 678 |
str_num := 0; {set to |>0| if it's an already encountered string} |
| 679 |
@z |
| 680 |
|
| 681 |
@x [70] str_lookup - Avoid 'uninitialized' warning. |
| 682 |
old_string := true; |
| 683 |
@y |
| 684 |
@z |
| 685 |
|
| 686 |
@x [71] str_lookup - Avoid 'uninitialized' warning. |
| 687 |
if (old_string) then {it's an already encountered string} |
| 688 |
@y |
| 689 |
if (str_num>0) then {it's an already encountered string} |
| 690 |
@z |
| 691 |
|
| 692 |
@x [73] Pascal Web's char type will be a const char *. |
| 693 |
@!pds_type = packed array [pds_loc] of char; |
| 694 |
@y |
| 695 |
@!pds_type = const_cstring; |
| 696 |
@z |
| 697 |
|
| 698 |
@x [77] C strings start at zero instead of one. |
| 699 |
for i:=1 to len do |
| 700 |
buffer[i] := xord[pds[i]]; |
| 701 |
@y |
| 702 |
for i:=1 to len do |
| 703 |
buffer[i] := xord[ucharcast(pds[i-1])]; |
| 704 |
@z |
| 705 |
|
| 706 |
@x [97] Can't do this tangle-time arithmetic with file_name_size. |
| 707 |
@!aux_name_length : 0..file_name_size+1; {\.{.aux} name sans extension} |
| 708 |
@y |
| 709 |
@!aux_name_length : integer; |
| 710 |
@z |
| 711 |
|
| 712 |
@x [100] Reading the aux file name and command-line processing. |
| 713 |
This procedure consists of a loop that reads and processes a (nonnull) |
| 714 |
\.{.aux} file name. It's this module and the next two that must be |
| 715 |
changed on those systems using command-line arguments. Note: The |
| 716 |
|term_out| and |term_in| files are system dependent. |
| 717 |
|
| 718 |
@<Procedures and functions for the reading and processing of input files@>= |
| 719 |
procedure get_the_top_level_aux_file_name; |
| 720 |
label aux_found,@!aux_not_found; |
| 721 |
var @<Variables for possible command-line processing@>@/ |
| 722 |
begin |
| 723 |
check_cmnd_line := false; {many systems will change this} |
| 724 |
loop |
| 725 |
begin |
| 726 |
if (check_cmnd_line) then |
| 727 |
@<Process a \(o)possible command line@> |
| 728 |
else |
| 729 |
begin |
| 730 |
write (term_out,'Please type input file name (no extension)--'); |
| 731 |
if (eoln(term_in)) then {so the first |read| works} |
| 732 |
read_ln (term_in); |
| 733 |
aux_name_length := 0; |
| 734 |
while (not eoln(term_in)) do |
| 735 |
begin |
| 736 |
if (aux_name_length = file_name_size) then |
| 737 |
begin |
| 738 |
while (not eoln(term_in)) do {discard the rest of the line} |
| 739 |
get(term_in); |
| 740 |
sam_you_made_the_file_name_too_long; |
| 741 |
end; |
| 742 |
incr(aux_name_length); |
| 743 |
name_of_file[aux_name_length] := term_in^; |
| 744 |
get(term_in); |
| 745 |
end; |
| 746 |
end; |
| 747 |
@<Handle this \.{.aux} name@>; |
| 748 |
aux_not_found: |
| 749 |
check_cmnd_line := false; |
| 750 |
end; |
| 751 |
aux_found: {now we're ready to read the \.{.aux} file} |
| 752 |
end; |
| 753 |
@y |
| 754 |
This module and the next two must be changed on those systems using |
| 755 |
command-line arguments. |
| 756 |
@^system dependencies@> |
| 757 |
|
| 758 |
@<Procedures and functions for the reading and processing of input files@>= |
| 759 |
procedure get_the_top_level_aux_file_name; |
| 760 |
label aux_found,@!aux_not_found; |
| 761 |
begin |
| 762 |
{Leave room for the \.., the extension, the junk byte at the |
| 763 |
beginning, and the null byte at the end.} |
| 764 |
name_of_file := xmalloc_array (ASCII_code, strlen (cmdline (optind)) + 5); |
| 765 |
strcpy (stringcast(name_of_file + 1), cmdline (optind)); |
| 766 |
aux_name_length := strlen (stringcast(name_of_file + 1)); |
| 767 |
@<Handle this \.{.aux} name@>; |
| 768 |
aux_not_found: uexit (1); |
| 769 |
aux_found: {now we're ready to read the \.{.aux} file} |
| 770 |
end; |
| 771 |
@z |
| 772 |
|
| 773 |
% [101] Don't need this variable; we use argc to check if we have a |
| 774 |
% command line. |
| 775 |
@x |
| 776 |
@<Variables for possible command-line processing@>= |
| 777 |
@!check_cmnd_line : boolean; {|true| if we're to check the command line} |
| 778 |
@y |
| 779 |
@z |
| 780 |
|
| 781 |
@x [102] Get the aux file name from the command line. |
| 782 |
@<Process a \(o)possible command line@>= |
| 783 |
begin |
| 784 |
do_nothing; {the ``default system'' doesn't use the command line} |
| 785 |
end |
| 786 |
@y |
| 787 |
@<Process a \(o)possible command line@>= |
| 788 |
parse_arguments; |
| 789 |
@z |
| 790 |
|
| 791 |
% [106] Don't use a path to find the aux file, and don't add the |
| 792 |
% extension if it's already there. |
| 793 |
@x [106] |
| 794 |
add_extension (s_aux_extension); {this also sets |name_length|} |
| 795 |
aux_ptr := 0; {initialize the \.{.aux} file stack} |
| 796 |
if (not a_open_in(cur_aux_file)) then |
| 797 |
@y |
| 798 |
if (name_length < 4) or |
| 799 |
(strcmp (stringcast(name_of_file + 1 + name_length - 4), '.aux') <> 0) |
| 800 |
then |
| 801 |
add_extension (s_aux_extension) {this also sets |name_length|} |
| 802 |
else |
| 803 |
aux_name_length := aux_name_length - 4; {set to length without \.{.aux}} |
| 804 |
aux_ptr := 0; {initialize the \.{.aux} file stack} |
| 805 |
if (not kpse_in_name_ok(stringcast(name_of_file+1)) or |
| 806 |
not a_open_in(cur_aux_file,no_file_path)) then |
| 807 |
@z |
| 808 |
|
| 809 |
@x [still 106] Check log_file name. |
| 810 |
if (not a_open_out(log_file)) then |
| 811 |
@y |
| 812 |
if (not kpse_out_name_ok(stringcast(name_of_file+1)) or |
| 813 |
not a_open_out(log_file)) then |
| 814 |
@z |
| 815 |
|
| 816 |
@x [still 106] Check bbl_file name. |
| 817 |
if (not a_open_out(bbl_file)) then |
| 818 |
@y |
| 819 |
if (not kpse_out_name_ok(stringcast(name_of_file+1)) or |
| 820 |
not a_open_out(bbl_file)) then |
| 821 |
@z |
| 822 |
|
| 823 |
@x [108] Add log_pr_aux_name. |
| 824 |
procedure print_aux_name; |
| 825 |
begin |
| 826 |
print_pool_str (cur_aux_str); |
| 827 |
print_newline; |
| 828 |
end; |
| 829 |
@y |
| 830 |
procedure print_aux_name; |
| 831 |
begin |
| 832 |
print_pool_str (cur_aux_str); |
| 833 |
print_newline; |
| 834 |
end; |
| 835 |
@# |
| 836 |
procedure log_pr_aux_name; |
| 837 |
begin |
| 838 |
log_pr_pool_str (cur_aux_str); |
| 839 |
log_pr_newline; |
| 840 |
end; |
| 841 |
@z |
| 842 |
|
| 843 |
@x [110] Be silent unless verbose. |
| 844 |
print ('The top-level auxiliary file: '); |
| 845 |
print_aux_name; |
| 846 |
@y |
| 847 |
if verbose then begin |
| 848 |
print ('The top-level auxiliary file: '); |
| 849 |
print_aux_name; |
| 850 |
end |
| 851 |
else begin |
| 852 |
log_pr ('The top-level auxiliary file: '); |
| 853 |
log_pr_aux_name; |
| 854 |
end; |
| 855 |
@z |
| 856 |
|
| 857 |
@x [117] bib_list is dynamically allocated. |
| 858 |
@!bib_list : array[bib_number] of str_number; {the \.{.bib} file list} |
| 859 |
@y |
| 860 |
@!bib_list : ^str_number; {the \.{.bib} file list} |
| 861 |
@z |
| 862 |
@x [still 117] bib_file also. |
| 863 |
@!bib_file : array[bib_number] of alpha_file; {corresponding |file| variables} |
| 864 |
@y |
| 865 |
@!bib_file : ^alpha_file; {corresponding |file| variables} |
| 866 |
@z |
| 867 |
|
| 868 |
@x [118] max_bib_files is a variable now, so can't be used as a const. |
| 869 |
@!bib_number = 0..max_bib_files; {gives the |bib_list| range} |
| 870 |
@y |
| 871 |
@!bib_number = integer; {gives the |bib_list| range} |
| 872 |
@z |
| 873 |
|
| 874 |
@x [121] Don't print extension twice; add log_pr_bib_name function. |
| 875 |
procedure print_bib_name; |
| 876 |
begin |
| 877 |
print_pool_str (cur_bib_str); |
| 878 |
print_pool_str (s_bib_extension); |
| 879 |
print_newline; |
| 880 |
end; |
| 881 |
@y |
| 882 |
{Return true if the |ext| string is at the end of the |s| string. There |
| 883 |
are surely far more clever ways to do this, but it doesn't matter.} |
| 884 |
function str_ends_with (@!s:str_number; @!ext:str_number) : boolean; |
| 885 |
var i : integer; |
| 886 |
str_idx,ext_idx : integer; |
| 887 |
str_char,ext_char : ASCII_code; |
| 888 |
begin |
| 889 |
str_ends_with := false; |
| 890 |
if (length (ext) > length (s)) then |
| 891 |
return; {if extension is longer, they don't match} |
| 892 |
str_idx := length (s) - 1; |
| 893 |
ext_idx := length (ext) - 1; |
| 894 |
while (ext_idx >= 0) do begin {|>=| so we check the |'.'| char.} |
| 895 |
str_char := str_pool[str_start[s]+str_idx]; |
| 896 |
ext_char := str_pool[str_start[ext]+ext_idx]; |
| 897 |
if (str_char <> ext_char) then |
| 898 |
return; |
| 899 |
decr (str_idx); |
| 900 |
decr (ext_idx); |
| 901 |
end; |
| 902 |
str_ends_with := true; |
| 903 |
exit: end; |
| 904 |
|
| 905 |
{The above is needed because the file name specified in the |
| 906 |
\.{\\bibdata} command may or may not have the \.{.bib} extension. If it |
| 907 |
does, we don't want to print \.{.bib} twice.} |
| 908 |
procedure print_bib_name; |
| 909 |
begin |
| 910 |
print_pool_str (cur_bib_str); |
| 911 |
if not str_ends_with (cur_bib_str, s_bib_extension) then |
| 912 |
print_pool_str (s_bib_extension); |
| 913 |
print_newline; |
| 914 |
end; |
| 915 |
@# |
| 916 |
procedure log_pr_bib_name; |
| 917 |
begin |
| 918 |
log_pr_pool_str (cur_bib_str); |
| 919 |
if not str_ends_with (cur_bib_str, s_bib_extension) then |
| 920 |
log_pr_pool_str (s_bib_extension); |
| 921 |
log_pr_newline; |
| 922 |
end; |
| 923 |
@z |
| 924 |
|
| 925 |
@x [123] Reallocate when we run out of bib files. |
| 926 |
overflow('number of database files ',max_bib_files); |
| 927 |
@y |
| 928 |
begin |
| 929 |
{Keep old value of |max_bib_files| for the last array.} |
| 930 |
BIB_XRETALLOC_NOSET ('bib_list', bib_list, str_number, max_bib_files, |
| 931 |
max_bib_files + MAX_BIB_FILES);@/ |
| 932 |
BIB_XRETALLOC_NOSET ('bib_file', bib_file, alpha_file, max_bib_files, |
| 933 |
max_bib_files + MAX_BIB_FILES);@/ |
| 934 |
BIB_XRETALLOC ('s_preamble', s_preamble, str_number, max_bib_files, |
| 935 |
max_bib_files + MAX_BIB_FILES); |
| 936 |
end; |
| 937 |
@z |
| 938 |
|
| 939 |
@x [still 123] Use BIBINPUTS to search for the .bib file. |
| 940 |
add_extension (s_bib_extension); |
| 941 |
if (not a_open_in(cur_bib_file)) then |
| 942 |
begin |
| 943 |
add_area (s_bib_area); |
| 944 |
if (not a_open_in(cur_bib_file)) then |
| 945 |
open_bibdata_aux_err ('I couldn''t open database file '); |
| 946 |
end; |
| 947 |
@y |
| 948 |
if (not kpse_in_name_ok(stringcast(name_of_file+1)) or |
| 949 |
not a_open_in(cur_bib_file, kpse_bib_format)) then |
| 950 |
open_bibdata_aux_err ('I couldn''t open database file '); |
| 951 |
@z |
| 952 |
|
| 953 |
@x [127] Use BSTINPUTS/TEXINPUTS to search for .bst files. |
| 954 |
add_extension (s_bst_extension); |
| 955 |
if (not a_open_in(bst_file)) then |
| 956 |
begin |
| 957 |
add_area (s_bst_area); |
| 958 |
if (not a_open_in(bst_file)) then |
| 959 |
begin |
| 960 |
print ('I couldn''t open style file '); |
| 961 |
print_bst_name;@/ |
| 962 |
bst_str := 0; {mark as unused again} |
| 963 |
aux_err_return; |
| 964 |
end; |
| 965 |
end; |
| 966 |
@y |
| 967 |
if (not kpse_in_name_ok(stringcast(name_of_file+1)) or |
| 968 |
not a_open_in(bst_file, kpse_bst_format)) then |
| 969 |
begin |
| 970 |
print ('I couldn''t open style file '); |
| 971 |
print_bst_name;@/ |
| 972 |
bst_str := 0; {mark as unused again} |
| 973 |
aux_err_return; |
| 974 |
end; |
| 975 |
@z |
| 976 |
|
| 977 |
@x [127] Be silent unless verbose. |
| 978 |
print ('The style file: '); |
| 979 |
print_bst_name; |
| 980 |
@y |
| 981 |
if verbose then begin |
| 982 |
print ('The style file: '); |
| 983 |
print_bst_name; |
| 984 |
end |
| 985 |
else begin |
| 986 |
log_pr ('The style file: '); |
| 987 |
log_pr_bst_name; |
| 988 |
end; |
| 989 |
@z |
| 990 |
|
| 991 |
@x [128] Add log_pr_bst_name. |
| 992 |
procedure print_bst_name; |
| 993 |
begin |
| 994 |
print_pool_str (bst_str); |
| 995 |
print_pool_str (s_bst_extension); |
| 996 |
print_newline; |
| 997 |
end; |
| 998 |
@y |
| 999 |
procedure print_bst_name; |
| 1000 |
begin |
| 1001 |
print_pool_str (bst_str); |
| 1002 |
print_pool_str (s_bst_extension); |
| 1003 |
print_newline; |
| 1004 |
end; |
| 1005 |
@# |
| 1006 |
procedure log_pr_bst_name; |
| 1007 |
begin |
| 1008 |
log_pr_pool_str (bst_str); |
| 1009 |
log_pr_pool_str (s_bst_extension); |
| 1010 |
log_pr_newline; |
| 1011 |
end; |
| 1012 |
@z |
| 1013 |
|
| 1014 |
@x [129] cite_list is dynamically allocated. |
| 1015 |
@!cite_list : packed array[cite_number] of str_number; {the cite-key list} |
| 1016 |
@y |
| 1017 |
@!cite_list : ^str_number; {the cite-key list} |
| 1018 |
@z |
| 1019 |
|
| 1020 |
@x [130] max_cites is no longer const. |
| 1021 |
@!cite_number = 0..max_cites; {gives the |cite_list| range} |
| 1022 |
@y |
| 1023 |
@!cite_number = integer; {gives the |cite_list| range} |
| 1024 |
@z |
| 1025 |
|
| 1026 |
@x [138] Dynamic max_cites. |
| 1027 |
if (last_cite = max_cites) then |
| 1028 |
begin |
| 1029 |
print_pool_str (hash_text[cite_loc]); |
| 1030 |
print_ln (' is the key:'); |
| 1031 |
overflow('number of cite keys ',max_cites); |
| 1032 |
@y |
| 1033 |
if (last_cite = max_cites) then |
| 1034 |
begin |
| 1035 |
BIB_XRETALLOC_NOSET ('cite_list', cite_list, str_number, |
| 1036 |
max_cites, max_cites + MAX_CITES); |
| 1037 |
BIB_XRETALLOC_NOSET ('type_list', type_list, hash_ptr2, |
| 1038 |
max_cites, max_cites + MAX_CITES); |
| 1039 |
BIB_XRETALLOC_NOSET ('entry_exists', entry_exists, boolean, |
| 1040 |
max_cites, max_cites + MAX_CITES); |
| 1041 |
BIB_XRETALLOC ('cite_info', cite_info, str_number, |
| 1042 |
max_cites, max_cites + MAX_CITES); |
| 1043 |
while (last_cite < max_cites) do |
| 1044 |
begin |
| 1045 |
type_list[last_cite] := empty;@/ |
| 1046 |
cite_info[last_cite] := any_value; {to appease \PASCAL's boolean evaluation} |
| 1047 |
incr(last_cite); |
| 1048 |
end; |
| 1049 |
@z |
| 1050 |
|
| 1051 |
% [141] Don't pad with blanks, terminate with null. |
| 1052 |
% Don't use a path to search for subsidiary aux files, |
| 1053 |
% but do check the directory of the main .aux file. |
| 1054 |
% |
| 1055 |
% This last is useful, for example, when --output-dir is used with TeX and the |
| 1056 |
% .aux file has an \@input directive resulting from a LaTeX \include; |
| 1057 |
% see bibtex-auxinclude.test. It's necessary because BibTeX itself does |
| 1058 |
% not have --output-directory. |
| 1059 |
% |
| 1060 |
% We should probably implement the --output-directory option and |
| 1061 |
% TEXMF_OUTPUT_DIRECTORY envvar in BibTeX. What this amounts to is |
| 1062 |
% changing the add_extension function to look for those overrides to the |
| 1063 |
% aux file dirname, so that when we call kpse_*_name_ok below, we're |
| 1064 |
% calling it on the actual file that will be used. |
| 1065 |
% |
| 1066 |
% And we need to call kpse_*_name_ok because bibtex is included in the |
| 1067 |
% shell_escape_commands list that can be invoked by TeX in restricted mode. |
| 1068 |
% |
| 1069 |
@x [141] |
| 1070 |
while (name_ptr <= file_name_size) do {pad with blanks} |
| 1071 |
begin |
| 1072 |
name_of_file[name_ptr] := ' '; |
| 1073 |
incr(name_ptr); |
| 1074 |
end; |
| 1075 |
if (not a_open_in(cur_aux_file)) then |
| 1076 |
@y |
| 1077 |
name_of_file[name_ptr] := 0; |
| 1078 |
if (not kpse_in_name_ok(stringcast(name_of_file+1)) |
| 1079 |
or (not a_open_in(cur_aux_file, no_file_path) |
| 1080 |
and not a_open_in_with_dirname(cur_aux_file, no_file_path, |
| 1081 |
bib_makecstring(top_lev_str))) |
| 1082 |
) then |
| 1083 |
@z |
| 1084 |
|
| 1085 |
@x [still 141] Be silent unless verbose. |
| 1086 |
print ('A level-',aux_ptr:0,' auxiliary file: '); |
| 1087 |
print_aux_name; |
| 1088 |
@y |
| 1089 |
log_pr ('A level-',aux_ptr:0,' auxiliary file: '); |
| 1090 |
log_pr_aux_name; |
| 1091 |
@z |
| 1092 |
|
| 1093 |
% [151] This goto gets turned into a setjmp/longjmp by ./convert -- |
| 1094 |
% unfortunately, it is a nonlocal goto. [email protected] |
| 1095 |
% implemented the conversion. |
| 1096 |
@x [151] |
| 1097 |
buf_ptr2 := last; {to get the first input line} |
| 1098 |
loop |
| 1099 |
begin |
| 1100 |
if (not eat_bst_white_space) then {the end of the \.{.bst} file} |
| 1101 |
goto bst_done; |
| 1102 |
get_bst_command_and_process; |
| 1103 |
end; |
| 1104 |
bst_done: a_close (bst_file); |
| 1105 |
@y |
| 1106 |
buf_ptr2 := last; {to get the first input line} |
| 1107 |
hack1; |
| 1108 |
begin |
| 1109 |
if (not eat_bst_white_space) then {the end of the \.{.bst} file} |
| 1110 |
hack2; |
| 1111 |
get_bst_command_and_process; |
| 1112 |
end; |
| 1113 |
bst_done: a_close (bst_file); |
| 1114 |
@z |
| 1115 |
|
| 1116 |
% [160] quote_next_fn and end_of_def are Pascal consts, instead of web macros. |
| 1117 |
% max_ent_ints and max_ent_strs are gone, max_fields is no longer const. |
| 1118 |
@x [160] |
| 1119 |
@d quote_next_fn = hash_base - 1 {special marker used in defining functions} |
| 1120 |
@d end_of_def = hash_max + 1 {another such special marker} |
| 1121 |
|
| 1122 |
@<Types in the outer block@>= |
| 1123 |
@!fn_class = 0..last_fn_class; {the \.{.bst} function classes} |
| 1124 |
@!wiz_fn_loc = 0..wiz_fn_space; {|wiz_defined|-function storage locations} |
| 1125 |
@!int_ent_loc = 0..max_ent_ints; {|int_entry_var| storage locations} |
| 1126 |
@!str_ent_loc = 0..max_ent_strs; {|str_entry_var| storage locations} |
| 1127 |
@!str_glob_loc = 0..max_glb_str_minus_1; {|str_global_var| storage locations} |
| 1128 |
@!field_loc = 0..max_fields; {individual field storage locations} |
| 1129 |
@y |
| 1130 |
@<Types in the outer block@>= |
| 1131 |
@!fn_class = 0..last_fn_class; {the \.{.bst} function classes} |
| 1132 |
@!wiz_fn_loc = integer; {|wiz_defined|-function storage locations} |
| 1133 |
@!int_ent_loc = integer; {|int_entry_var| storage locations} |
| 1134 |
@!str_ent_loc = integer; {|str_entry_var| storage locations} |
| 1135 |
@!str_glob_loc = integer; {|str_global_var| storage locations} |
| 1136 |
@!field_loc = integer; {individual field storage locations} |
| 1137 |
@z |
| 1138 |
|
| 1139 |
@x [161] max_strings=hash_size settable at runtime. |
| 1140 |
@!fn_type : packed array[hash_loc] of fn_class; |
| 1141 |
@y |
| 1142 |
@!fn_type : ^fn_class; |
| 1143 |
@z |
| 1144 |
|
| 1145 |
@x [still 161] Dynamically allocate wiz_functions. |
| 1146 |
@!wiz_functions : packed array[wiz_fn_loc] of hash_ptr2; |
| 1147 |
@y |
| 1148 |
@!wiz_functions : ^hash_ptr2; |
| 1149 |
@z |
| 1150 |
|
| 1151 |
% [still 161] Convert entry_ints and entry_strs to dynamically-allocated |
| 1152 |
% one-dimensional arrays; too bad C and Pascal lag Fortran in supporting |
| 1153 |
% run-time dimensioning of multidimensional arrays. Other changes that |
| 1154 |
% follow this one will convert every reference to entry_strs[p][q] to |
| 1155 |
% x_entry_strs(p)(q), the equivalent of entry_strs[p*(ent_str_size+1) + |
| 1156 |
% q], but hidden inside a macro to mask the addressing computation. |
| 1157 |
% Although WEB does not have multi-argument macros, webman.tex shows how |
| 1158 |
% to get the equivalent effect. |
| 1159 |
@x [161] |
| 1160 |
@!entry_ints : array[int_ent_loc] of integer; |
| 1161 |
@!num_ent_ints : int_ent_loc; {the number of distinct |int_entry_var| names} |
| 1162 |
@!str_ent_ptr : str_ent_loc; {general |str_entry_var| location} |
| 1163 |
@!entry_strs : array[str_ent_loc] of |
| 1164 |
packed array[0..ent_str_size] of ASCII_code; |
| 1165 |
@y |
| 1166 |
@!entry_ints : ^integer; {dynamically-allocated array} |
| 1167 |
@!num_ent_ints : int_ent_loc; {the number of distinct |int_entry_var| names} |
| 1168 |
@!str_ent_ptr : str_ent_loc; {general |str_entry_var| location} |
| 1169 |
@!entry_strs : ^ASCII_code; {dynamically-allocated array} |
| 1170 |
@z |
| 1171 |
|
| 1172 |
@x [still 161] Dynamically allocate global strings |
| 1173 |
@!str_glb_ptr : 0..max_glob_strs; {general |str_global_var| location} |
| 1174 |
@!glb_str_ptr : array[str_glob_loc] of str_number; |
| 1175 |
@!global_strs : array[str_glob_loc] of array[0..glob_str_size] of ASCII_code; |
| 1176 |
@!glb_str_end : array[str_glob_loc] of 0..glob_str_size; {end markers} |
| 1177 |
@!num_glb_strs : 0..max_glob_strs; {number of distinct |str_global_var| names} |
| 1178 |
@y |
| 1179 |
@!str_glb_ptr : integer; {general |str_global_var| location} |
| 1180 |
@!glb_str_ptr : ^str_number; |
| 1181 |
@!global_strs : ^ASCII_code; |
| 1182 |
@!glb_str_end : ^integer; {end markers} |
| 1183 |
@!num_glb_strs : integer; {number of distinct |str_global_var| names} |
| 1184 |
@z |
| 1185 |
|
| 1186 |
@x [still 161] Dynamically allocate field_info. |
| 1187 |
@!field_info : packed array[field_loc] of str_number; |
| 1188 |
@y |
| 1189 |
@!field_info : ^str_number; |
| 1190 |
@z |
| 1191 |
|
| 1192 |
@x [187] Dynamically allocate singl_function. |
| 1193 |
type @!fn_def_loc = 0..single_fn_space; {for a single |wiz_defined|-function} |
| 1194 |
var singl_function : packed array[fn_def_loc] of hash_ptr2; |
| 1195 |
@y |
| 1196 |
type @!fn_def_loc = integer; {for a single |wiz_defined|-function} |
| 1197 |
var singl_function : ^hash_ptr2; |
| 1198 |
@!single_fn_space : integer; {space allocated for this |singl_function| instance} |
| 1199 |
@z |
| 1200 |
|
| 1201 |
@x [still 187] Dynamically allocate singl_function. |
| 1202 |
begin |
| 1203 |
eat_bst_white_and_eof_check ('function'); |
| 1204 |
@y |
| 1205 |
begin |
| 1206 |
single_fn_space := SINGLE_FN_SPACE; |
| 1207 |
singl_function := XTALLOC (single_fn_space + 1, hash_ptr2); |
| 1208 |
eat_bst_white_and_eof_check ('function'); |
| 1209 |
@z |
| 1210 |
|
| 1211 |
@x [still 187] Dynamically allocate singl_function. |
| 1212 |
exit: |
| 1213 |
end; |
| 1214 |
@y |
| 1215 |
exit: |
| 1216 |
libc_free (singl_function); |
| 1217 |
end; |
| 1218 |
@z |
| 1219 |
|
| 1220 |
@x [188] Reallocate if out of single function space. |
| 1221 |
singl_fn_overflow; |
| 1222 |
@y |
| 1223 |
begin |
| 1224 |
BIB_XRETALLOC ('singl_function', singl_function, hash_ptr2, |
| 1225 |
single_fn_space, single_fn_space + SINGLE_FN_SPACE); |
| 1226 |
end; |
| 1227 |
@z |
| 1228 |
|
| 1229 |
@x [still 188] Procedure |singl_fn_overflow| replaced by inline code. |
| 1230 |
procedure singl_fn_overflow; |
| 1231 |
begin |
| 1232 |
overflow('single function space ',single_fn_space); |
| 1233 |
end; |
| 1234 |
@y |
| 1235 |
@z |
| 1236 |
|
| 1237 |
@x [198] A variable named `int' is no good in C. |
| 1238 |
@<Procedures and functions for handling numbers, characters, and strings@>= |
| 1239 |
@y |
| 1240 |
@d int == the_int |
| 1241 |
@<Procedures and functions for handling numbers, characters, and strings@>= |
| 1242 |
@z |
| 1243 |
|
| 1244 |
@x [200] Reallocate if out of wizard space. |
| 1245 |
if (single_ptr + wiz_def_ptr > wiz_fn_space) then |
| 1246 |
begin |
| 1247 |
print (single_ptr + wiz_def_ptr : 0,': '); |
| 1248 |
overflow('wizard-defined function space ',wiz_fn_space); |
| 1249 |
end; |
| 1250 |
@y |
| 1251 |
while (single_ptr + wiz_def_ptr > wiz_fn_space) do |
| 1252 |
begin |
| 1253 |
BIB_XRETALLOC ('wiz_functions', wiz_functions, hash_ptr2, |
| 1254 |
wiz_fn_space, wiz_fn_space + WIZ_FN_SPACE); |
| 1255 |
end; |
| 1256 |
@z |
| 1257 |
|
| 1258 |
@x [216] Reallocate if out of global strings. |
| 1259 |
overflow('number of string global-variables ',max_glob_strs); |
| 1260 |
@y |
| 1261 |
begin |
| 1262 |
BIB_XRETALLOC_NOSET ('glb_str_ptr', glb_str_ptr, str_number, |
| 1263 |
max_glob_strs, max_glob_strs + MAX_GLOB_STRS);@/ |
| 1264 |
BIB_XRETALLOC_STRING ('global_strs', global_strs, glob_str_size, |
| 1265 |
max_glob_strs, max_glob_strs + MAX_GLOB_STRS);@/ |
| 1266 |
BIB_XRETALLOC ('glb_str_end', glb_str_end, integer, |
| 1267 |
max_glob_strs, max_glob_strs + MAX_GLOB_STRS);@/ |
| 1268 |
str_glb_ptr := num_glb_strs; |
| 1269 |
while (str_glb_ptr < max_glob_strs) do {make new |str_global_var|s empty} |
| 1270 |
begin |
| 1271 |
glb_str_ptr[str_glb_ptr] := 0; |
| 1272 |
glb_str_end[str_glb_ptr] := 0; |
| 1273 |
incr(str_glb_ptr); |
| 1274 |
end; |
| 1275 |
end; |
| 1276 |
@z |
| 1277 |
|
| 1278 |
@x [still 219] undefined is now a Pascal const, instead of a web macro |
| 1279 |
@d undefined = hash_max + 1 {a special marker used for |type_list|} |
| 1280 |
@y |
| 1281 |
@z |
| 1282 |
|
| 1283 |
@x [still 219] type_list is dynamically allocated. |
| 1284 |
@!type_list : packed array[cite_number] of hash_ptr2; |
| 1285 |
@y |
| 1286 |
@!type_list : ^hash_ptr2; |
| 1287 |
@z |
| 1288 |
@x [still 219] entry_exists also. |
| 1289 |
@!entry_exists : packed array[cite_number] of boolean; |
| 1290 |
@y |
| 1291 |
@!entry_exists : ^boolean; |
| 1292 |
@z |
| 1293 |
@x [still 219] cite_info also. |
| 1294 |
@!cite_info : packed array[cite_number] of str_number; {extra |cite_list| info} |
| 1295 |
@y |
| 1296 |
@!cite_info : ^str_number; {extra |cite_list| info} |
| 1297 |
@z |
| 1298 |
|
| 1299 |
@x [223] Be silent unless verbose. |
| 1300 |
print ('Database file #',bib_ptr+1:0,': '); |
| 1301 |
print_bib_name;@/ |
| 1302 |
@y |
| 1303 |
if verbose then begin |
| 1304 |
print ('Database file #',bib_ptr+1:0,': '); |
| 1305 |
print_bib_name; |
| 1306 |
end |
| 1307 |
else begin |
| 1308 |
log_pr ('Database file #',bib_ptr+1:0,': '); |
| 1309 |
log_pr_bib_name; |
| 1310 |
end; |
| 1311 |
@z |
| 1312 |
|
| 1313 |
@x [226] Reallocate if out of fields. |
| 1314 |
procedure check_field_overflow (@!total_fields : integer); |
| 1315 |
begin |
| 1316 |
if (total_fields > max_fields) then |
| 1317 |
begin |
| 1318 |
print_ln (total_fields:0,' fields:'); |
| 1319 |
overflow('total number of fields ',max_fields); |
| 1320 |
@y |
| 1321 |
procedure check_field_overflow (@!total_fields : integer); |
| 1322 |
var @!f_ptr: field_loc; |
| 1323 |
@!start_fields: field_loc; |
| 1324 |
begin |
| 1325 |
if (total_fields > max_fields) then |
| 1326 |
begin |
| 1327 |
start_fields := max_fields; |
| 1328 |
BIB_XRETALLOC ('field_info', field_info, str_number, max_fields, |
| 1329 |
total_fields + MAX_FIELDS); |
| 1330 |
{Initialize to |missing|.} |
| 1331 |
for f_ptr := start_fields to max_fields - 1 do begin |
| 1332 |
field_info[f_ptr] := missing; |
| 1333 |
end; |
| 1334 |
@z |
| 1335 |
|
| 1336 |
@x [242] Reallocate when we run out of s_preamble's. |
| 1337 |
bib_err ('You''ve exceeded ',max_bib_files:0,' preamble commands'); |
| 1338 |
@y |
| 1339 |
begin |
| 1340 |
{Keep old value of |max_bib_files| for the last array.} |
| 1341 |
BIB_XRETALLOC_NOSET ('bib_list', bib_list, str_number, max_bib_files, |
| 1342 |
max_bib_files + MAX_BIB_FILES);@/ |
| 1343 |
BIB_XRETALLOC_NOSET ('bib_file', bib_file, alpha_file, max_bib_files, |
| 1344 |
max_bib_files + MAX_BIB_FILES);@/ |
| 1345 |
BIB_XRETALLOC ('s_preamble', s_preamble, str_number, max_bib_files, |
| 1346 |
max_bib_files + MAX_BIB_FILES);@/ |
| 1347 |
end; |
| 1348 |
@z |
| 1349 |
|
| 1350 |
% emacs-page |
| 1351 |
@x [251] Reallocate field_vl_str (aka ex_buf); see tests/bibtex-bigauth.test. |
| 1352 |
@d copy_char(#) == begin |
| 1353 |
if (field_end = buf_size) then |
| 1354 |
bib_field_too_long_err |
| 1355 |
else |
| 1356 |
begin |
| 1357 |
field_vl_str[field_end] := #; |
| 1358 |
incr(field_end); |
| 1359 |
end; |
| 1360 |
end |
| 1361 |
@y |
| 1362 |
@d copy_char(#) == begin |
| 1363 |
{We don't always increment by 1, so have to check |>=|.} |
| 1364 |
if (field_end >= buf_size) then |
| 1365 |
begin |
| 1366 |
log_pr ('Field filled up at ', #, ', reallocating.'); |
| 1367 |
log_pr_newline; |
| 1368 |
buffer_overflow; {reallocates all |buf_size| buffers} |
| 1369 |
end; |
| 1370 |
field_vl_str[field_end] := #; |
| 1371 |
incr(field_end); |
| 1372 |
end |
| 1373 |
@z |
| 1374 |
|
| 1375 |
@x [263] Add check for fieldinfo[] overflow. |
| 1376 |
field_ptr := entry_cite_ptr * num_fields + fn_info[field_name_loc]; |
| 1377 |
@y |
| 1378 |
field_ptr := entry_cite_ptr * num_fields + fn_info[field_name_loc]; |
| 1379 |
if (field_ptr >= max_fields) then |
| 1380 |
confusion ('field_info index is out of range'); |
| 1381 |
@z |
| 1382 |
|
| 1383 |
@x [265] Fix bug in the add_database_cite procedure. |
| 1384 |
check_field_overflow (num_fields*new_cite); |
| 1385 |
@y |
| 1386 |
check_field_overflow (num_fields*(new_cite+1)); |
| 1387 |
@z |
| 1388 |
|
| 1389 |
@x [277] Add check for fieldinfo[] overflow. |
| 1390 |
@<Add cross-reference information@>= |
| 1391 |
begin |
| 1392 |
@y |
| 1393 |
@<Add cross-reference information@>= |
| 1394 |
begin |
| 1395 |
if ((num_cites - 1) * num_fields + crossref_num >= max_fields) then |
| 1396 |
confusion ('field_info index is out of range'); |
| 1397 |
@z |
| 1398 |
|
| 1399 |
@x [279] Add check for fieldinfo[] overflow. |
| 1400 |
@<Subtract cross-reference information@>= |
| 1401 |
begin |
| 1402 |
@y |
| 1403 |
@<Subtract cross-reference information@>= |
| 1404 |
begin |
| 1405 |
if ((num_cites - 1) * num_fields + crossref_num >= max_fields) then |
| 1406 |
confusion ('field_info index is out of range'); |
| 1407 |
@z |
| 1408 |
|
| 1409 |
@x [285] Add check for fieldinfo[] overflow. |
| 1410 |
@<Slide this cite key down to its permanent spot@>= |
| 1411 |
begin |
| 1412 |
@y |
| 1413 |
@<Slide this cite key down to its permanent spot@>= |
| 1414 |
begin |
| 1415 |
if ((cite_xptr + 1) * num_fields > max_fields) then |
| 1416 |
confusion ('field_info index is out of range'); |
| 1417 |
@z |
| 1418 |
|
| 1419 |
@x [287] Allocate entry_ints as needed. |
| 1420 |
if (num_ent_ints*num_cites > max_ent_ints) then |
| 1421 |
begin |
| 1422 |
print (num_ent_ints*num_cites,': '); |
| 1423 |
overflow('total number of integer entry-variables ',max_ent_ints); |
| 1424 |
end; |
| 1425 |
@y |
| 1426 |
entry_ints := XTALLOC ((num_ent_ints + 1) * (num_cites + 1), integer); |
| 1427 |
@z |
| 1428 |
|
| 1429 |
@x [288] Allocate entry_strs as needed. |
| 1430 |
if (num_ent_strs*num_cites > max_ent_strs) then |
| 1431 |
begin |
| 1432 |
print (num_ent_strs*num_cites,': '); |
| 1433 |
overflow('total number of string entry-variables ',max_ent_strs); |
| 1434 |
end; |
| 1435 |
@y |
| 1436 |
entry_strs := XTALLOC ((num_ent_strs + 1) * (num_cites + 1) * (ent_str_size + 1), ASCII_code); |
| 1437 |
@z |
| 1438 |
|
| 1439 |
@x [still 288] Macroize entry_strs[][]. |
| 1440 |
entry_strs[str_ent_ptr][0] := end_of_string; |
| 1441 |
@y |
| 1442 |
x_entry_strs(str_ent_ptr)(0) := end_of_string; |
| 1443 |
@z |
| 1444 |
|
| 1445 |
@x [290] Dynamic lit_stk_size. |
| 1446 |
@!lit_stack : array[lit_stk_loc] of integer; {the literal function stack} |
| 1447 |
@!lit_stk_type : array[lit_stk_loc] of stk_type; {their corresponding types} |
| 1448 |
@y |
| 1449 |
@!lit_stack : ^integer; {the literal function stack} |
| 1450 |
@!lit_stk_type : ^stk_type; {their corresponding types} |
| 1451 |
@z |
| 1452 |
|
| 1453 |
@x [291] Dynamic lit_stk_size. |
| 1454 |
@!lit_stk_loc = 0..lit_stk_size; {the stack range} |
| 1455 |
@y |
| 1456 |
@!lit_stk_loc = integer; {the stack range} |
| 1457 |
@z |
| 1458 |
|
| 1459 |
@x [301] Macroize entry_strs[][]. |
| 1460 |
char1 := entry_strs[ptr1][char_ptr]; |
| 1461 |
char2 := entry_strs[ptr2][char_ptr]; |
| 1462 |
@y |
| 1463 |
char1 := x_entry_strs(ptr1)(char_ptr); |
| 1464 |
char2 := x_entry_strs(ptr2)(char_ptr); |
| 1465 |
@z |
| 1466 |
|
| 1467 |
@x [307] Reallocate literal stack. |
| 1468 |
overflow('literal-stack size ',lit_stk_size); |
| 1469 |
@y |
| 1470 |
begin |
| 1471 |
BIB_XRETALLOC_NOSET ('lit_stack', lit_stack, integer, |
| 1472 |
lit_stk_size, lit_stk_size + LIT_STK_SIZE); |
| 1473 |
BIB_XRETALLOC ('lit_stk_type', lit_stk_type, stk_type, |
| 1474 |
lit_stk_size, lit_stk_size + LIT_STK_SIZE); |
| 1475 |
end; |
| 1476 |
@z |
| 1477 |
|
| 1478 |
@x [322] Dynamic buf_size. |
| 1479 |
if (out_buf_length+(p_ptr2-p_ptr1) > buf_size) then |
| 1480 |
overflow('output buffer size ',buf_size); |
| 1481 |
@y |
| 1482 |
while (out_buf_length+(p_ptr2-p_ptr1) > buf_size) do |
| 1483 |
buffer_overflow; |
| 1484 |
@z |
| 1485 |
|
| 1486 |
@x [327] Add check for fieldinfo[] overflow. |
| 1487 |
field_ptr := cite_ptr*num_fields + fn_info[ex_fn_loc]; |
| 1488 |
@y |
| 1489 |
field_ptr := cite_ptr*num_fields + fn_info[ex_fn_loc]; |
| 1490 |
if (field_ptr >= max_fields) then |
| 1491 |
confusion ('field_info index is out of range'); |
| 1492 |
@z |
| 1493 |
|
| 1494 |
@x [329] Macroize entry_strs[][] |
| 1495 |
while (entry_strs[str_ent_ptr][ex_buf_ptr] <> end_of_string) do |
| 1496 |
{copy characters into the buffer} |
| 1497 |
append_ex_buf_char (entry_strs[str_ent_ptr][ex_buf_ptr]); |
| 1498 |
@y |
| 1499 |
while (x_entry_strs(str_ent_ptr)(ex_buf_ptr) <> end_of_string) do |
| 1500 |
{copy characters into the buffer} |
| 1501 |
append_ex_buf_char (x_entry_strs(str_ent_ptr)(ex_buf_ptr)); |
| 1502 |
@z |
| 1503 |
|
| 1504 |
@x [330] Macroize global_strs[][] |
| 1505 |
append_char (global_strs[str_glb_ptr][glob_chr_ptr]); |
| 1506 |
@y |
| 1507 |
append_char (x_global_strs(str_glb_ptr)(glob_chr_ptr)); |
| 1508 |
@z |
| 1509 |
|
| 1510 |
@x [334] Bug fix: remove duplicate entry. |
| 1511 |
build_in('width$ ',6,b_width,n_width); |
| 1512 |
build_in('while$ ',6,b_while,n_while); |
| 1513 |
build_in('width$ ',6,b_width,n_width); |
| 1514 |
@y |
| 1515 |
build_in('while$ ',6,b_while,n_while); |
| 1516 |
build_in('width$ ',6,b_width,n_width); |
| 1517 |
@z |
| 1518 |
|
| 1519 |
@x [337] s_preamble is dynamically allocated. |
| 1520 |
@!s_preamble : array[bib_number] of str_number; |
| 1521 |
@y |
| 1522 |
@!s_preamble : ^str_number; |
| 1523 |
@z |
| 1524 |
|
| 1525 |
@x [344] Dynamic buf_size. |
| 1526 |
@!name_tok : packed array[buf_pointer] of buf_pointer; {name-token ptr list} |
| 1527 |
@!name_sep_char : packed array[buf_pointer] of ASCII_code; {token-ending chars} |
| 1528 |
@y |
| 1529 |
@!name_tok : ^buf_pointer; {name-token ptr list} |
| 1530 |
@!name_sep_char : ^ASCII_code; {token-ending chars} |
| 1531 |
@z |
| 1532 |
|
| 1533 |
@x [357] Macroize entry_strs[][]. |
| 1534 |
while (sp_ptr < sp_xptr1) do |
| 1535 |
begin {copy characters into |entry_strs|} |
| 1536 |
entry_strs[str_ent_ptr][ent_chr_ptr] := str_pool[sp_ptr]; |
| 1537 |
incr(ent_chr_ptr); |
| 1538 |
incr(sp_ptr); |
| 1539 |
end; |
| 1540 |
entry_strs[str_ent_ptr][ent_chr_ptr] := end_of_string; |
| 1541 |
@y |
| 1542 |
while (sp_ptr < sp_xptr1) do |
| 1543 |
begin {copy characters into |entry_strs|} |
| 1544 |
x_entry_strs(str_ent_ptr)(ent_chr_ptr) := str_pool[sp_ptr]; |
| 1545 |
incr(ent_chr_ptr); |
| 1546 |
incr(sp_ptr); |
| 1547 |
end; |
| 1548 |
x_entry_strs(str_ent_ptr)(ent_chr_ptr) := end_of_string; |
| 1549 |
@z |
| 1550 |
|
| 1551 |
@x [359] Macroize global_strs[][] |
| 1552 |
global_strs[str_glb_ptr][glob_chr_ptr] := str_pool[sp_ptr]; |
| 1553 |
@y |
| 1554 |
x_global_strs(str_glb_ptr)(glob_chr_ptr) := str_pool[sp_ptr]; |
| 1555 |
@z |
| 1556 |
|
| 1557 |
% [388] bibtex.web has mutually exclusive tests here; Oren said he |
| 1558 |
% doesn't want to fix it until 1.0, since it's obviously of no practical |
| 1559 |
% import (or someone would have found it before GCC 2 did). Changing |
| 1560 |
% the second `and' to an `or' makes all but the last of multiple authors |
| 1561 |
% be omitted in the bbl file, so I simply removed the statement. |
| 1562 |
@x [388] |
| 1563 |
while ((ex_buf_xptr < ex_buf_ptr) and |
| 1564 |
(lex_class[ex_buf[ex_buf_ptr]] = white_space) and |
| 1565 |
(lex_class[ex_buf[ex_buf_ptr]] = sep_char)) do |
| 1566 |
incr(ex_buf_xptr); {this removes leading stuff} |
| 1567 |
@y |
| 1568 |
@z |
| 1569 |
|
| 1570 |
% Forgot to check for pool overflow here. Triggered by test case linked |
| 1571 |
% from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520920. |
| 1572 |
@x [438] |
| 1573 |
while (sp_ptr < sp_end) do {shift the substring} |
| 1574 |
@y |
| 1575 |
str_room(sp_end - sp_ptr); |
| 1576 |
while (sp_ptr < sp_end) do {shift the substring} |
| 1577 |
@z |
| 1578 |
|
| 1579 |
% Forgot to check for pool overflow here. Triggered by bibtex-mem.test (3). |
| 1580 |
@x [444] |
| 1581 |
if (pop_lit2 >= cmd_str_ptr) then {no shifting---merely change pointers} |
| 1582 |
@y |
| 1583 |
str_room(sp_brace_level + sp_end - sp_ptr); |
| 1584 |
if (pop_lit2 >= cmd_str_ptr) then {no shifting---merely change pointers} |
| 1585 |
@z |
| 1586 |
|
| 1587 |
% [459] Eliminate unreferenced statement label, because `undefined' is |
| 1588 |
% now a constant expression that is not evaluated at the Web level. If |
| 1589 |
% this label were ever required, it could be replaced by the constant |
| 1590 |
% 9997, which is not used as a statement label in BibTeX. |
| 1591 |
@x [459] |
| 1592 |
undefined : trace_pr ('unknown') |
| 1593 |
@y |
| 1594 |
trace_pr ('unknown') |
| 1595 |
@z |
| 1596 |
|
| 1597 |
@x [460] Macroize entry_strs[][]. |
| 1598 |
while (entry_strs[str_ent_ptr][ent_chr_ptr] <> end_of_string) do |
| 1599 |
begin |
| 1600 |
trace_pr (xchr[entry_strs[str_ent_ptr][ent_chr_ptr]]); |
| 1601 |
incr(ent_chr_ptr); |
| 1602 |
end; |
| 1603 |
@y |
| 1604 |
while (x_entry_strs(str_ent_ptr)(ent_chr_ptr) <> end_of_string) do |
| 1605 |
begin |
| 1606 |
trace_pr (xchr[x_entry_strs(str_ent_ptr)(ent_chr_ptr)]); |
| 1607 |
incr(ent_chr_ptr); |
| 1608 |
end; |
| 1609 |
@z |
| 1610 |
|
| 1611 |
@x [462] Add check for fieldinfo[] overflow. |
| 1612 |
field_ptr := cite_ptr * num_fields; |
| 1613 |
field_end_ptr := field_ptr + num_fields; |
| 1614 |
@y |
| 1615 |
field_ptr := cite_ptr * num_fields; |
| 1616 |
field_end_ptr := field_ptr + num_fields; |
| 1617 |
if (field_end_ptr > max_fields) then |
| 1618 |
confusion ('field_info index is out of range'); |
| 1619 |
@z |
| 1620 |
|
| 1621 |
% emacs-page |
| 1622 |
@x [467] System-dependent changes. |
| 1623 |
This section should be replaced, if necessary, by changes to the program |
| 1624 |
that are necessary to make \BibTeX\ work at a particular installation. |
| 1625 |
It is usually best to design your change file so that all changes to |
| 1626 |
previous sections preserve the section numbering; then everybody's version |
| 1627 |
will be consistent with the printed program. More extensive changes, |
| 1628 |
which introduce new sections, can be inserted here; then only the index |
| 1629 |
itself will get a new section number. |
| 1630 |
@y |
| 1631 |
@d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0) |
| 1632 |
|
| 1633 |
@<Define \(p)|parse_arguments|@> = |
| 1634 |
procedure parse_arguments; |
| 1635 |
const n_options = 4; {Pascal won't count array lengths for us.} |
| 1636 |
var @!long_options: array[0..n_options] of getopt_struct; |
| 1637 |
@!getopt_return_val: integer; |
| 1638 |
@!option_index: c_int_type; |
| 1639 |
@!current_option: 0..n_options; |
| 1640 |
begin |
| 1641 |
@<Initialize the option variables@>; |
| 1642 |
@<Define the option table@>; |
| 1643 |
repeat |
| 1644 |
getopt_return_val := getopt_long_only (argc, argv, '', long_options, |
| 1645 |
address_of (option_index)); |
| 1646 |
if getopt_return_val = -1 then begin |
| 1647 |
do_nothing; {End of arguments; we exit the loop below.} |
| 1648 |
|
| 1649 |
end else if getopt_return_val = "?" then begin |
| 1650 |
usage (my_name); |
| 1651 |
|
| 1652 |
end else if argument_is ('min-crossrefs') then begin |
| 1653 |
min_crossrefs := atoi (optarg); |
| 1654 |
|
| 1655 |
end else if argument_is ('help') then begin |
| 1656 |
usage_help (BIBTEX_HELP, nil); |
| 1657 |
|
| 1658 |
end else if argument_is ('version') then begin |
| 1659 |
print_version_and_exit (banner, 'Oren Patashnik', nil, nil); |
| 1660 |
|
| 1661 |
end; {Else it was a flag; |getopt| has already done the assignment.} |
| 1662 |
until getopt_return_val = -1; |
| 1663 |
|
| 1664 |
{Now |optind| is the index of first non-option on the command line. |
| 1665 |
We must have one remaining argument.} |
| 1666 |
if (optind + 1 <> argc) then begin |
| 1667 |
write_ln (stderr, my_name, ': Need exactly one file argument.'); |
| 1668 |
usage (my_name); |
| 1669 |
end; |
| 1670 |
end; |
| 1671 |
|
| 1672 |
@ Here is the first of the options we allow. |
| 1673 |
@.-terse@> |
| 1674 |
|
| 1675 |
@<Define the option...@> = |
| 1676 |
current_option := 0; |
| 1677 |
long_options[0].name := 'terse'; |
| 1678 |
long_options[0].has_arg := 0; |
| 1679 |
long_options[0].flag := address_of (verbose); |
| 1680 |
long_options[0].val := 0; |
| 1681 |
incr (current_option); |
| 1682 |
|
| 1683 |
@ The global variable |verbose| determines whether or not we print |
| 1684 |
progress information. |
| 1685 |
|
| 1686 |
@<Glob...@> = |
| 1687 |
@!verbose: c_int_type; |
| 1688 |
|
| 1689 |
@ Start off |true|, to match the default behavior. |
| 1690 |
|
| 1691 |
@<Initialize the option...@> = |
| 1692 |
verbose := true; |
| 1693 |
|
| 1694 |
@ Here is an option to change the minimum number of cross-refs required |
| 1695 |
for automatic |cite_list| inclusion. |
| 1696 |
@.-min-crossrefs@> |
| 1697 |
|
| 1698 |
@<Define the option...@> = |
| 1699 |
long_options[current_option].name := 'min-crossrefs'; |
| 1700 |
long_options[current_option].has_arg := 1; |
| 1701 |
long_options[current_option].flag := 0; |
| 1702 |
long_options[current_option].val := 0; |
| 1703 |
incr (current_option); |
| 1704 |
|
| 1705 |
@ @<Glob...@> = |
| 1706 |
@!min_crossrefs: integer; |
| 1707 |
|
| 1708 |
@ Set |min_crossrefs| to two by default, so we match the |
| 1709 |
documentation (\.{btxdoc.tex}). |
| 1710 |
|
| 1711 |
@<Initialize the option...@> = |
| 1712 |
min_crossrefs := 2; |
| 1713 |
|
| 1714 |
@ One of the standard options. |
| 1715 |
@.-help@> |
| 1716 |
|
| 1717 |
@<Define the option...@> = |
| 1718 |
long_options[current_option].name := 'help'; |
| 1719 |
long_options[current_option].has_arg := 0; |
| 1720 |
long_options[current_option].flag := 0; |
| 1721 |
long_options[current_option].val := 0; |
| 1722 |
incr (current_option); |
| 1723 |
|
| 1724 |
@ Another of the standard options. |
| 1725 |
@.-version@> |
| 1726 |
|
| 1727 |
@<Define the option...@> = |
| 1728 |
long_options[current_option].name := 'version'; |
| 1729 |
long_options[current_option].has_arg := 0; |
| 1730 |
long_options[current_option].flag := 0; |
| 1731 |
long_options[current_option].val := 0; |
| 1732 |
incr (current_option); |
| 1733 |
|
| 1734 |
@ An element with all zeros always ends the list. |
| 1735 |
|
| 1736 |
@<Define the option...@> = |
| 1737 |
long_options[current_option].name := 0; |
| 1738 |
long_options[current_option].has_arg := 0; |
| 1739 |
long_options[current_option].flag := 0; |
| 1740 |
long_options[current_option].val := 0; |
| 1741 |
|
| 1742 |
@ Determine |ent_str_size|, |glob_str_size|, and |max_strings| from the |
| 1743 |
environment, configuration file, or default value. Set |
| 1744 |
|hash_size:=max_strings|, but not less than |HASH_SIZE|. |
| 1745 |
|
| 1746 |
{|setup_bound_var| stuff adapted from \.{tex.ch}.} |
| 1747 |
@d setup_bound_var(#)==bound_default:=#; setup_bound_var_end |
| 1748 |
@d setup_bound_var_end(#)==bound_name:=#; setup_bound_var_end_end |
| 1749 |
@d setup_bound_var_end_end(#)== |
| 1750 |
setup_bound_variable(address_of(#), bound_name, bound_default); |
| 1751 |
if # < bound_default then # := bound_default |
| 1752 |
|
| 1753 |
@<Procedures and functions for about everything@>= |
| 1754 |
procedure setup_params; |
| 1755 |
var bound_default: integer; {for setup} |
| 1756 |
@!bound_name: const_cstring; {for setup} |
| 1757 |
begin kpse_set_program_name (argv[0], 'bibtex'); |
| 1758 |
setup_bound_var (ENT_STR_SIZE)('ent_str_size')(ent_str_size); |
| 1759 |
setup_bound_var (GLOB_STR_SIZE)('glob_str_size')(glob_str_size); |
| 1760 |
setup_bound_var (MAX_STRINGS)('max_strings')(max_strings); |
| 1761 |
setup_bound_var (MAX_PRINT_LINE)('max_print_line')(max_print_line); |
| 1762 |
@# |
| 1763 |
hash_size := max_strings; |
| 1764 |
if hash_size < HASH_SIZE then hash_size := HASH_SIZE; |
| 1765 |
hash_max := hash_size + hash_base - 1; |
| 1766 |
end_of_def := hash_max + 1; |
| 1767 |
undefined := hash_max + 1; |
| 1768 |
end; |
| 1769 |
|
| 1770 |
@ We use the algorithm from Knuth's \.{primes.web} to compute |hash_prime| |
| 1771 |
as the smallest prime number not less than 85\% of |hash_size| (and |
| 1772 |
|>=128|). |
| 1773 |
|
| 1774 |
@d primes == hash_next {array holding the first |k| primes} |
| 1775 |
@d mult == hash_text {array holding odd multiples of the first |o| primes} |
| 1776 |
|
| 1777 |
@<Procedures and functions for about everything@>= |
| 1778 |
procedure compute_hash_prime; |
| 1779 |
var hash_want: integer; {85\% of |hash_size|} |
| 1780 |
@!k: integer; {number of prime numbers $p_i$ in |primes|} |
| 1781 |
@!j: integer; {a prime number candidate} |
| 1782 |
@!o: integer; {number of odd multiples of primes in |mult|} |
| 1783 |
@!square: integer; {$p_o^2$} |
| 1784 |
@!n: integer; {loop index} |
| 1785 |
@!j_prime: boolean; {is |j| a prime?} |
| 1786 |
begin hash_want := (hash_size div 20) * 17; |
| 1787 |
j := 1; |
| 1788 |
k := 1; |
| 1789 |
hash_prime := 2; |
| 1790 |
primes[k] := hash_prime; |
| 1791 |
o := 2; |
| 1792 |
square := 9; |
| 1793 |
while hash_prime < hash_want do |
| 1794 |
begin |
| 1795 |
repeat |
| 1796 |
j := j + 2; |
| 1797 |
if j = square then |
| 1798 |
begin |
| 1799 |
mult[o] := j; |
| 1800 |
j := j + 2; |
| 1801 |
incr (o); |
| 1802 |
square := primes[o] * primes[o]; |
| 1803 |
end; |
| 1804 |
n := 2; |
| 1805 |
j_prime := true; |
| 1806 |
while (n < o) and j_prime do |
| 1807 |
begin |
| 1808 |
while mult[n] < j do mult[n] := mult[n] + 2 * primes[n]; |
| 1809 |
if mult[n] = j then j_prime := false; |
| 1810 |
incr (n); |
| 1811 |
end; |
| 1812 |
until j_prime; |
| 1813 |
incr (k); |
| 1814 |
hash_prime := j; |
| 1815 |
primes[k] := hash_prime; |
| 1816 |
end; |
| 1817 |
end; |
| 1818 |
@z |