@@ -6,7 +6,9 @@ use std::{ptr, slice};
66
77mod memory;
88
9- use crate :: c_api:: pool:: { rs_make_string, StringPool , EMPTY_STRING } ;
9+ use crate :: c_api:: pool:: {
10+ rs_make_string, rs_search_string, rs_slow_make_string, StringPool , EMPTY_STRING , TOO_BIG_CHAR ,
11+ } ;
1012pub use memory:: * ;
1113
1214pub const NULL_CS : usize = 0x220001 ;
@@ -547,6 +549,90 @@ pub fn rs_make_utf16_name(engine: &mut EngineCtx) {
547549 . map ( |s| s. encode_utf16 ( ) . collect ( ) ) ;
548550}
549551
552+ pub fn rs_begin_name ( globals : & mut Globals < ' _ , ' _ > ) {
553+ globals. engine . area_delimiter = 0 ;
554+ globals. engine . ext_delimiter = 0 ;
555+ globals. engine . quoted_filename = false ;
556+ globals. engine . file_name_quote_char = 0 ;
557+ }
558+
559+ pub fn rs_end_name ( globals : & mut Globals < ' _ , ' _ > ) {
560+ if globals. strings . str_ptr + 3 > globals. strings . max_strings {
561+ todo ! ( "overflow(\" number of strings\" , max_strings() - init_str_ptr)" ) ;
562+ }
563+
564+ /* area_delimiter is the length from the start of the filename to the
565+ * directory seperator "/", which we use to construct the stringpool
566+ * string `cur_area`. If there was already a string in the stringpool for
567+ * the area, reuse it. */
568+
569+ if globals. engine . area_delimiter == 0 {
570+ globals. engine . cur_area = EMPTY_STRING ;
571+ } else {
572+ globals. engine . cur_area = globals. strings . str_ptr as StrNumber ;
573+ globals. strings . str_start [ globals. strings . str_ptr + 1 - 0x10000 ] =
574+ globals. strings . str_start [ globals. strings . str_ptr - TOO_BIG_CHAR ]
575+ + globals. engine . area_delimiter as u32 ;
576+ globals. strings . str_ptr += 1 ;
577+
578+ let temp_str = rs_search_string ( globals. strings , globals. engine . cur_area ) ;
579+
580+ if temp_str > 0 {
581+ globals. engine . cur_area = temp_str;
582+ globals. strings . str_ptr -= 1 ;
583+
584+ for j in ( globals. strings . str_start [ globals. strings . str_ptr + 1 - 0x10000 ] as usize )
585+ ..globals. strings . pool_ptr
586+ {
587+ globals. strings . str_pool [ j - globals. engine . area_delimiter ] =
588+ globals. strings . str_pool [ j] ;
589+ }
590+
591+ globals. strings . pool_ptr -= globals. engine . area_delimiter ;
592+ }
593+ }
594+
595+ /* ext_delimiter is the length from the start of the filename to the
596+ * extension '.' delimiter, which we use to construct the stringpool
597+ * strings `cur_ext` and `cur_name`. */
598+
599+ if globals. engine . ext_delimiter == 0 {
600+ globals. engine . cur_ext = EMPTY_STRING ;
601+ globals. engine . cur_name = rs_slow_make_string ( globals. strings ) ;
602+ } else {
603+ globals. engine . cur_name = globals. strings . str_ptr as StrNumber ;
604+ globals. strings . str_start [ globals. strings . str_ptr + 1 - 0x10000 ] =
605+ globals. strings . str_start [ globals. strings . str_ptr - TOO_BIG_CHAR ]
606+ + globals. engine . ext_delimiter as u32
607+ - globals. engine . area_delimiter as u32
608+ - 1 ;
609+ globals. strings . str_ptr += 1 ;
610+
611+ globals. engine . cur_ext = rs_make_string ( globals. strings ) ;
612+ globals. strings . str_ptr -= 1 ;
613+
614+ let temp_str = rs_search_string ( globals. strings , globals. engine . cur_name ) ;
615+
616+ if temp_str > 0 {
617+ globals. engine . cur_name = temp_str;
618+ globals. strings . str_ptr -= 1 ;
619+
620+ for j in ( globals. strings . str_start [ globals. strings . str_ptr + 1 - 0x10000 ] as usize )
621+ ..globals. strings . pool_ptr
622+ {
623+ globals. strings . str_pool
624+ [ j - globals. engine . ext_delimiter + globals. engine . area_delimiter + 1 ] =
625+ globals. strings . str_pool [ j] ;
626+ }
627+
628+ globals. strings . pool_ptr -=
629+ globals. engine . ext_delimiter - globals. engine . area_delimiter - 1 ;
630+ }
631+ }
632+
633+ globals. engine . cur_ext = rs_slow_make_string ( globals. strings ) ;
634+ }
635+
550636#[ no_mangle]
551637pub unsafe extern "C" fn maketexstring ( str : * const libc:: c_char ) -> StrNumber {
552638 if str. is_null ( ) {
@@ -580,3 +666,13 @@ pub extern "C" fn pack_job_name(s: *const libc::c_char) {
580666pub extern "C" fn make_utf16_name ( ) {
581667 ENGINE_CTX . with_borrow_mut ( |engine| rs_make_utf16_name ( engine) )
582668}
669+
670+ #[ no_mangle]
671+ pub extern "C" fn begin_name ( ) {
672+ Globals :: with ( |globals| rs_begin_name ( globals) )
673+ }
674+
675+ #[ no_mangle]
676+ pub extern "C" fn end_name ( ) {
677+ Globals :: with ( |globals| rs_end_name ( globals) )
678+ }
0 commit comments