@@ -33,7 +33,7 @@ fn main() {
33
33
if let Some ( script) = matches. value_of ( "script" ) {
34
34
if matches. is_present ( "debug" ) {
35
35
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 ( ) ) ) {
37
37
Ok ( code) => code,
38
38
Err ( err) => {
39
39
println ! ( "Error! {err}" ) ;
@@ -42,7 +42,7 @@ fn main() {
42
42
} )
43
43
} else {
44
44
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 ( ) ) ) {
46
46
Ok ( code) => code,
47
47
Err ( err) => {
48
48
println ! ( "Error! {err}" ) ;
@@ -71,8 +71,8 @@ fn main() {
71
71
}
72
72
73
73
/// 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) ?;
76
76
let mut contents = String :: new ( ) ;
77
77
f. read_to_string ( & mut contents) ?;
78
78
Ok ( contents)
@@ -665,7 +665,7 @@ impl Executor {
665
665
666
666
// Write string in the file
667
667
"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 ( ) ) ) {
669
669
Ok ( file) => file,
670
670
Err ( e) => {
671
671
self . log_print ( format ! ( "Error! {e}\n " ) ) ;
@@ -681,8 +681,8 @@ impl Executor {
681
681
682
682
// Read string in the file
683
683
"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) {
686
686
Ok ( s) => self . stack . push ( Type :: String ( s) ) ,
687
687
Err ( e) => {
688
688
self . log_print ( format ! ( "Error! {}\n " , e) ) ;
0 commit comments