MCPcopy Index your code
hub / github.com/endbasic/endbasic / safe_main

Function safe_main

std/examples/script-runner.rs:27–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25use std::process;
26
27fn safe_main() -> i32 {
28 let args: Vec<String> = env::args().collect();
29 let path = match args.as_slice() {
30 [_, path] => path,
31 _ => {
32 eprintln!("Usage error: expected a file name");
33 process::exit(1);
34 }
35 };
36
37 let mut machine = endbasic_std::MachineBuilder::default().build();
38
39 let mut input = match fs::File::open(path) {
40 Ok(file) => file,
41 Err(e) => {
42 eprintln!("ERROR: {}", e);
43 process::exit(1);
44 }
45 };
46
47 match machine.compile(&mut input) {
48 Ok(()) => match block_on(machine.exec()) {
49 Ok(None) => 0,
50 Ok(Some(code)) => code,
51 Err(e) => {
52 eprintln!("ERROR: {}", e);
53 1
54 }
55 },
56 Err(e) => {
57 eprintln!("ERROR: {}", e);
58 1
59 }
60 }
61}
62
63fn main() {
64 // We must ensure that all destructors run (in particular, the console's destructor) before

Callers 1

mainFunction · 0.85

Calls 4

as_sliceMethod · 0.45
buildMethod · 0.45
compileMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected