1- use bytemuck:: NoUninit ;
21use byteorder:: { BigEndian , ByteOrder , LittleEndian , NativeEndian , WriteBytesExt } ;
32use clap:: Parser ;
43use gettextrs:: { bind_textdomain_codeset, setlocale, textdomain, LocaleCategory } ;
@@ -8,7 +7,7 @@ use std::{
87 collections:: BTreeMap ,
98 fmt:: Display ,
109 fs:: File ,
11- io:: { self , Cursor , Read , Seek , SeekFrom , Write } ,
10+ io:: { self , Cursor , Read , Seek , Write } ,
1211 num:: ParseIntError ,
1312 path:: PathBuf ,
1413 rc:: Rc ,
@@ -18,11 +17,15 @@ const NL_SETMAX: u32 = 255; //max set number(the limits.h defines it and is ment
1817const NL_SETD : u32 = 1 ; // the default set number for the messages that are not in any set
1918const GLIBC_MAGIC : u32 = 0x960408de ;
2019
21- const OSX_MAGIC : & [ u8 ; 8 ] = b"*nazgul*" ;
22- const OSX_MAJOR_VER : i32 = 1 ;
23- const OSX_MINOR_VER : i32 = 0 ;
24- const OSX_BYTE_ORDER : i32 = 0x01 ; // denotes BIG ENDIAN for now
25- const OSX_NOT_INVALID_FLAG : i32 = 0 ;
20+ #[ cfg( target_os = "macos" ) ]
21+ pub mod osx {
22+ pub const OSX_MAGIC : & [ u8 ; 8 ] = b"*nazgul*" ;
23+ pub const OSX_MAJOR_VER : i32 = 1 ;
24+ pub const OSX_MINOR_VER : i32 = 0 ;
25+ pub const OSX_BYTE_ORDER : i32 = 0x01 ; // denotes BIG ENDIAN for now
26+ pub const OSX_NOT_INVALID_FLAG : i32 = 0 ;
27+ pub const FIRST_SET_OFFSET : i64 = 32 ;
28+ }
2629
2730/// gencat - generate a formatted message catalog
2831#[ derive( Parser , Debug ) ]
@@ -78,6 +81,7 @@ pub struct Set {
7881}
7982
8083impl Set {
84+ #[ cfg( target_os = "macos" ) ]
8185 fn get_msgs_count ( & self ) -> i32 {
8286 let mut count = 0 ;
8387 let mut current = self . first_msg . clone ( ) ;
@@ -180,7 +184,8 @@ pub struct MessageCatalog {
180184}
181185
182186/// Magic Header structure for the catalog file
183- #[ derive( NoUninit , Clone , Copy ) ]
187+ #[ cfg( target_os = "macos" ) ]
188+ #[ derive( bytemuck:: NoUninit , Clone , Copy ) ]
184189#[ repr( C ) ]
185190struct CatFileMagicHeader {
186191 /// Magic cookie "*nazgul*"
@@ -261,6 +266,7 @@ impl MessageCatalog {
261266 } ,
262267 } ;
263268
269+ #[ cfg( not( target_os = "macos" ) ) ]
264270 if build_default {
265271 catalog. add_set ( NL_SETD , String :: from ( "Default Set" ) ) ;
266272 }
@@ -603,9 +609,9 @@ impl MessageCatalog {
603609 Ok ( catalog)
604610 }
605611
606- /// Write to the cat file **GNU compatible(anything not macos for now) **
607- // #[cfg(not(target_os = "macos"))]
608- pub fn write_catfile_another < T : Write + Seek > (
612+ /// Write to the cat file **for GNU only **
613+ #[ cfg( not( target_os = "macos" ) ) ]
614+ pub fn write_catfile < T : Write + Seek > (
609615 & self ,
610616 file : & mut T ,
611617 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -638,19 +644,19 @@ impl MessageCatalog {
638644 }
639645
640646 /// Write to the cat file **for OSX only**
641- // #[cfg(target_os = "macos")]
647+ #[ cfg( target_os = "macos" ) ]
642648 pub fn write_catfile < T : Write + Seek > (
643649 & self ,
644650 file : & mut T ,
645651 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
646652 let header = CatFileMagicHeader {
647- magic : * OSX_MAGIC ,
648- major_ver : OSX_MAJOR_VER . to_be ( ) ,
649- minor_ver : OSX_MINOR_VER . to_be ( ) ,
650- flags : OSX_BYTE_ORDER . to_be ( ) ,
653+ magic : * osx :: OSX_MAGIC ,
654+ major_ver : osx :: OSX_MAJOR_VER . to_be ( ) ,
655+ minor_ver : osx :: OSX_MINOR_VER . to_be ( ) ,
656+ flags : osx :: OSX_BYTE_ORDER . to_be ( ) ,
651657 num_sets : self . cat . total_sets ( ) . to_be ( ) ,
652- // for now we have set it to 0 , but we will change this later on as we lay the first set details
653- first_set : 0 ,
658+ // for now we have set it to 32 , but we will change this later on as we lay the first set details
659+ first_set : osx :: FIRST_SET_OFFSET . to_be ( ) ,
654660 } ;
655661
656662 file. write_all ( bytemuck:: bytes_of ( & header) ) ?;
@@ -667,9 +673,9 @@ impl MessageCatalog {
667673 let set_pos = file. stream_position ( ) ?;
668674
669675 if set. set_id == 1 {
670- file. seek ( SeekFrom :: Start ( first_set_pos) ) ?;
676+ file. seek ( io :: SeekFrom :: Start ( first_set_pos) ) ?;
671677 file. write_u64 :: < BigEndian > ( set_pos) ?;
672- file. seek ( SeekFrom :: Start ( set_pos) ) ?;
678+ file. seek ( io :: SeekFrom :: Start ( set_pos) ) ?;
673679 }
674680
675681 file. write_u32 :: < BigEndian > ( set. set_id ) ?;
@@ -688,7 +694,7 @@ impl MessageCatalog {
688694
689695 let num_msgs = set. get_msgs_count ( ) ;
690696 file. write_i32 :: < BigEndian > ( num_msgs) ?;
691- file. write_i32 :: < BigEndian > ( OSX_NOT_INVALID_FLAG ) ?;
697+ file. write_i32 :: < BigEndian > ( osx :: OSX_NOT_INVALID_FLAG ) ?;
692698
693699 // We'll write the string data now
694700 let data_offset = file. stream_position ( ) ?;
@@ -714,23 +720,23 @@ impl MessageCatalog {
714720
715721 file. write_i32 :: < BigEndian > ( msg. msg_id as i32 ) ?;
716722 file. write_i64 :: < BigEndian > ( msg. offset ) ?;
717- file. write_i32 :: < BigEndian > ( OSX_NOT_INVALID_FLAG ) ?;
723+ file. write_i32 :: < BigEndian > ( osx :: OSX_NOT_INVALID_FLAG ) ?;
718724
719725 current_msg = msg. next . clone ( ) ;
720726 }
721727
722728 let current_pos = file. stream_position ( ) ?;
723729
724730 // go back and write first msg offset
725- file. seek ( SeekFrom :: Start ( first_msg_offset_pos) ) ?;
731+ file. seek ( io :: SeekFrom :: Start ( first_msg_offset_pos) ) ?;
726732 file. write_i64 :: < BigEndian > ( first_msg_offset as i64 ) ?;
727733
728734 // go back and write data offset
729- file. seek ( SeekFrom :: Start ( data_offset_pos) ) ?;
735+ file. seek ( io :: SeekFrom :: Start ( data_offset_pos) ) ?;
730736 file. write_i64 :: < BigEndian > ( data_offset as i64 ) ?;
731737
732738 // go back and write data length
733- file. seek ( SeekFrom :: Start ( data_length_pos) ) ?;
739+ file. seek ( io :: SeekFrom :: Start ( data_length_pos) ) ?;
734740 file. write_i32 :: < BigEndian > ( data_length) ?;
735741
736742 let last_set = cat. last_set . as_ref ( ) . unwrap ( ) ;
@@ -739,11 +745,11 @@ impl MessageCatalog {
739745 // if not last then we need to write the next set offset
740746 if set. set_id != last_set. set_id {
741747 // go back and write next set offset
742- file. seek ( SeekFrom :: Start ( next_set_offset) ) ?;
748+ file. seek ( io :: SeekFrom :: Start ( next_set_offset) ) ?;
743749 file. write_i64 :: < BigEndian > ( current_pos as i64 ) ?;
744750 }
745751
746- file. seek ( SeekFrom :: Start ( current_pos) ) ?;
752+ file. seek ( io :: SeekFrom :: Start ( current_pos) ) ?;
747753
748754 current_set = set. next . clone ( ) ;
749755 }
0 commit comments