@@ -33,7 +33,7 @@ fn main() {
3333 if let Some ( script) = matches. value_of ( "script" ) {
3434 if matches. is_present ( "debug" ) {
3535 let mut stack = Executor :: new ( Mode :: Debug ) ;
36- stack. evaluate_program ( match get_file_contents ( script. to_string ( ) ) {
36+ stack. evaluate_program ( match get_file_contents ( Path :: new ( & script. to_string ( ) ) ) {
3737 Ok ( code) => code,
3838 Err ( err) => {
3939 println ! ( "Error! {err}" ) ;
@@ -42,7 +42,7 @@ fn main() {
4242 } )
4343 } else {
4444 let mut stack = Executor :: new ( Mode :: Script ) ;
45- stack. evaluate_program ( match get_file_contents ( script. to_string ( ) ) {
45+ stack. evaluate_program ( match get_file_contents ( Path :: new ( & script. to_string ( ) ) ) {
4646 Ok ( code) => code,
4747 Err ( err) => {
4848 println ! ( "Error! {err}" ) ;
@@ -71,8 +71,8 @@ fn main() {
7171}
7272
7373/// Read string of the file
74- fn get_file_contents ( name : String ) -> Result < String , Error > {
75- let mut f = File :: open ( name. trim ( ) ) ?;
74+ fn get_file_contents ( name : & Path ) -> Result < String , Error > {
75+ let mut f = File :: open ( name) ?;
7676 let mut contents = String :: new ( ) ;
7777 f. read_to_string ( & mut contents) ?;
7878 Ok ( contents)
@@ -665,7 +665,7 @@ impl Executor {
665665
666666 // Write string in the file
667667 "write-file" => {
668- let mut file = match File :: create ( self . pop_stack ( ) . get_string ( ) ) {
668+ let mut file = match File :: create ( Path :: new ( & self . pop_stack ( ) . get_string ( ) ) ) {
669669 Ok ( file) => file,
670670 Err ( e) => {
671671 self . log_print ( format ! ( "Error! {e}\n " ) ) ;
@@ -681,8 +681,8 @@ impl Executor {
681681
682682 // Read string in the file
683683 "read-file" => {
684- let name = self . pop_stack ( ) . get_string ( ) ;
685- match get_file_contents ( name) {
684+ let name = Path :: new ( & self . pop_stack ( ) . get_string ( ) ) . to_owned ( ) ;
685+ match get_file_contents ( & name) {
686686 Ok ( s) => self . stack . push ( Type :: String ( s) ) ,
687687 Err ( e) => {
688688 self . log_print ( format ! ( "Error! {}\n " , e) ) ;
0 commit comments