@@ -22,60 +22,41 @@ use tectonic_bridge_core::FileFormat;
2222
2323const AUX_STACK_SIZE : usize = 20 ;
2424
25+ pub ( crate ) struct AuxFile {
26+ pub ( crate ) name : StrNumber ,
27+ pub ( crate ) file : Box < PeekableInput > ,
28+ pub ( crate ) line : i32 ,
29+ }
30+
2531pub ( crate ) struct AuxData {
26- aux_list : [ StrNumber ; AUX_STACK_SIZE + 1 ] ,
27- aux_file : [ Option < Box < PeekableInput > > ; AUX_STACK_SIZE + 1 ] ,
28- aux_ln_stack : [ i32 ; AUX_STACK_SIZE + 1 ] ,
29- aux_ptr : AuxNumber ,
32+ aux : Vec < AuxFile > ,
3033}
3134
3235impl AuxData {
3336 fn new ( ) -> AuxData {
34- AuxData {
35- aux_list : [ 0 ; AUX_STACK_SIZE + 1 ] ,
36- aux_file : [ ( ) ; AUX_STACK_SIZE + 1 ] . map ( |_| None ) ,
37- aux_ln_stack : [ 0 ; AUX_STACK_SIZE + 1 ] ,
38- aux_ptr : 0 ,
39- }
40- }
41-
42- pub fn ptr ( & self ) -> AuxNumber {
43- self . aux_ptr
44- }
45-
46- pub fn set_ptr ( & mut self , ptr : AuxNumber ) {
47- self . aux_ptr = ptr;
48- }
49-
50- pub fn at_ptr ( & self ) -> StrNumber {
51- self . aux_list [ self . aux_ptr ]
52- }
53-
54- pub fn set_at_ptr ( & mut self , num : StrNumber ) {
55- self . aux_list [ self . aux_ptr ] = num;
37+ AuxData { aux : Vec :: new ( ) }
5638 }
5739
58- pub fn file_at_ptr ( & mut self ) -> & mut PeekableInput {
59- self . aux_file [ self . aux_ptr ] . as_mut ( ) . unwrap ( )
40+ pub fn push_file ( & mut self , file : AuxFile ) {
41+ self . aux . push ( file ) ;
6042 }
6143
62- pub fn set_file_at_ptr ( & mut self , file : Box < PeekableInput > ) {
63- self . aux_file [ self . aux_ptr ] = Some ( file) ;
44+ pub fn pop_file ( & mut self ) -> ( AuxFile , bool ) {
45+ let out = self . aux . pop ( ) . unwrap ( ) ;
46+ let last = self . aux . len ( ) == 0 ;
47+ ( out, last)
6448 }
6549
66- pub fn pop_file ( & mut self ) -> ( Box < PeekableInput > , bool ) {
67- let out = self . aux_file [ self . aux_ptr ] . take ( ) . unwrap ( ) ;
68- let last = self . aux_ptr == 0 ;
69- self . aux_ptr = self . aux_ptr . saturating_sub ( 1 ) ;
70- ( out, last)
50+ pub fn top_file ( & self ) -> & AuxFile {
51+ self . aux . last ( ) . unwrap ( )
7152 }
7253
73- pub fn ln_at_ptr ( & self ) -> i32 {
74- self . aux_ln_stack [ self . aux_ptr ]
54+ pub fn top_file_mut ( & mut self ) -> & mut AuxFile {
55+ self . aux . last_mut ( ) . unwrap ( )
7556 }
7657
77- pub fn set_ln_at_ptr ( & mut self , ln : i32 ) {
78- self . aux_ln_stack [ self . aux_ptr ] = ln ;
58+ pub fn ptr ( & self ) -> AuxNumber {
59+ self . aux . len ( )
7960 }
8061}
8162
@@ -367,7 +348,6 @@ fn aux_input_command(
367348 return Ok ( ( ) ) ;
368349 }
369350
370- aux. set_ptr ( aux. ptr ( ) + 1 ) ;
371351 if aux. ptr ( ) == AUX_STACK_SIZE {
372352 print_a_token ( buffers) ;
373353 write_logs ( ": " ) ;
@@ -386,42 +366,41 @@ fn aux_input_command(
386366 if !aux_extension_ok {
387367 print_a_token ( buffers) ;
388368 write_logs ( " has a wrong extension" ) ;
389- aux. set_ptr ( aux. ptr ( ) - 1 ) ;
390369 aux_err_print ( buffers, aux, pool) ?;
391370 return Ok ( ( ) ) ;
392371 }
393372
394373 let file = & buffers. buffer ( BufTy :: Base )
395374 [ buffers. offset ( BufTy :: Base , 1 ) ..buffers. offset ( BufTy :: Base , 2 ) ] ;
396375 let res = pool. lookup_str_insert ( hash, file, StrIlk :: AuxFile ) ?;
397- aux. set_at_ptr ( hash. text ( res. loc ) ) ;
398376 if res. exists {
399377 write_logs ( "Already encountered file " ) ;
400- print_aux_name ( aux, pool) ?;
401- aux. set_ptr ( aux. ptr ( ) - 1 ) ;
378+ print_aux_name ( pool, res. loc ) ?;
402379 aux_err_print ( buffers, aux, pool) ?;
403380 return Ok ( ( ) ) ;
404381 }
405382
406- let name = pool. get_str ( aux . at_ptr ( ) ) ;
383+ let name = pool. get_str ( hash . text ( res . loc ) ) ;
407384 let fname = CString :: new ( name) . unwrap ( ) ;
408385 let file = PeekableInput :: open ( ctx, & fname, FileFormat :: Tex ) ;
409386 match file {
410387 Err ( _) => {
411388 write_logs ( "I couldn't open auxiliary file " ) ;
412- print_aux_name ( aux, pool) ?;
413- aux. set_ptr ( aux. ptr ( ) - 1 ) ;
389+ print_aux_name ( pool, res. loc ) ?;
414390 aux_err_print ( buffers, aux, pool) ?;
415391 return Ok ( ( ) ) ;
416392 }
417393 Ok ( file) => {
418- aux. set_file_at_ptr ( file) ;
394+ aux. push_file ( AuxFile {
395+ name : hash. text ( res. loc ) ,
396+ file,
397+ line : 0 ,
398+ } ) ;
419399 }
420400 }
421401
422- write_logs ( & format ! ( "A level-{} auxiliary file: " , aux. ptr( ) ) ) ;
402+ write_logs ( & format ! ( "A level-{} auxiliary file: " , aux. ptr( ) - 1 ) ) ;
423403 log_pr_aux_name ( aux, pool) ?;
424- aux. set_ln_at_ptr ( 0 ) ;
425404
426405 Ok ( ( ) )
427406}
@@ -484,49 +463,53 @@ pub(crate) fn get_aux_command_and_process(
484463 Ok ( ( ) )
485464}
486465
487- pub ( crate ) fn pop_the_aux_stack ( ctx : & mut Bibtex < ' _ , ' _ > , aux : & mut AuxData ) -> bool {
466+ pub ( crate ) fn pop_the_aux_stack ( ctx : & mut Bibtex < ' _ , ' _ > , aux : & mut AuxData ) -> Option < StrNumber > {
488467 let ( file, last) = aux. pop_file ( ) ;
489- file. close ( ctx) . unwrap ( ) ;
490- last
468+ file. file . close ( ctx) . unwrap ( ) ;
469+ if last {
470+ Some ( file. name )
471+ } else {
472+ None
473+ }
491474}
492475
493476pub ( crate ) fn last_check_for_aux_errors (
494477 ctx : & mut Bibtex < ' _ , ' _ > ,
495- aux : & AuxData ,
496478 pool : & StringPool ,
497479 cites : & mut CiteInfo ,
498480 bibs : & BibData ,
481+ last_aux : StrNumber ,
499482) -> Result < ( ) , BibtexError > {
500483 cites. set_num_cites ( cites. ptr ( ) ) ;
501484 ctx. num_bib_files = bibs. ptr ( ) ;
502485 if !ctx. citation_seen {
503486 aux_end1_err_print ( ) ;
504487 write_logs ( "\\ citation commands" ) ;
505- aux_end2_err_print ( aux , pool ) ?;
488+ aux_end2_err_print ( pool , last_aux ) ?;
506489 } else if cites. num_cites ( ) == 0 && !ctx. all_entries {
507490 aux_end1_err_print ( ) ;
508491 write_logs ( "cite keys" ) ;
509- aux_end2_err_print ( aux , pool ) ?;
492+ aux_end2_err_print ( pool , last_aux ) ?;
510493 }
511494
512495 if !ctx. bib_seen {
513496 aux_end1_err_print ( ) ;
514497 write_logs ( "\\ bibdata command" ) ;
515- aux_end2_err_print ( aux , pool ) ?;
498+ aux_end2_err_print ( pool , last_aux ) ?;
516499 } else if ctx. num_bib_files == 0 {
517500 aux_end1_err_print ( ) ;
518501 write_logs ( "database files" ) ;
519- aux_end2_err_print ( aux , pool ) ?;
502+ aux_end2_err_print ( pool , last_aux ) ?;
520503 }
521504
522505 if !ctx. bst_seen {
523506 aux_end1_err_print ( ) ;
524507 write_logs ( "\\ bibstyle command" ) ;
525- aux_end2_err_print ( aux , pool ) ?;
508+ aux_end2_err_print ( pool , last_aux ) ?;
526509 } else if ctx. bst_str == 0 {
527510 aux_end1_err_print ( ) ;
528511 write_logs ( "style file" ) ;
529- aux_end2_err_print ( aux , pool ) ?;
512+ aux_end2_err_print ( pool , last_aux ) ?;
530513 }
531514
532515 Ok ( ( ) )
0 commit comments