Skip to content

Commit b7935c5

Browse files
committed
v0.1.1
1 parent 7e158a9 commit b7935c5

File tree

5 files changed

+255
-16
lines changed

5 files changed

+255
-16
lines changed

.DS_Store

2 KB
Binary file not shown.

Cargo.lock

Lines changed: 180 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[package]
22
name = "turing"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
fancy-regex = "0.10.0"
9+
fancy-regex = "0.10.0"
10+
colored = "2.0.4"

build_all.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Apple Silicon
2+
cargo build --target aarch64-apple-darwin --release
3+
4+
# Intel Mac
5+
cargo build --target x86_64-apple-darwin --release
6+
7+
# Windows
8+
cargo build --target x86_64-pc-windows-gnu --release

src/main.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
use colored::*;
2+
use fancy_regex::Regex;
13
use std::{
24
env,
35
fs::File,
46
io::{prelude::*, BufReader},
57
path::Path,
8+
process::exit,
69
};
710

8-
use fancy_regex::Regex;
9-
1011
fn main() {
1112
let args: Vec<String> = env::args().collect();
12-
let file_name = &args[1];
1313

14-
println!("Program file: {:?}", file_name);
14+
if args.len() < 2 {
15+
print_ascii_art();
16+
17+
println!("{}", "Turing is a turing-complete programing language. It is designed to emulate a turing machine.".green().bold());
18+
println!("{}", "Usage: turing <file>".italic());
19+
exit(0);
20+
}
21+
22+
let file_name = &args[1];
23+
println!();
24+
println!("{} {:?}", "Program file:".bright_blue().bold(), file_name);
1525

1626
let lines: Vec<String> = lines_from_file(file_name);
1727

@@ -250,13 +260,26 @@ fn main() {
250260
}
251261

252262
fn lines_from_file(filename: impl AsRef<Path>) -> Vec<String> {
253-
let file = File::open(filename).expect("no such file");
263+
let file = match File::open(filename) {
264+
Ok(file) => file,
265+
Err(error) => {
266+
red_error(format!("Problem opening the file: {}", error).as_str());
267+
return Vec::new();
268+
}
269+
};
254270
let buf = BufReader::new(file);
255271
buf.lines()
256272
.map(|l| l.expect("Could not parse line"))
257273
.collect()
258274
}
259275

276+
fn red_error(error: &str) {
277+
println!();
278+
println!("{}", error.red().bold());
279+
println!();
280+
exit(1);
281+
}
282+
260283
fn binary_vector_to_int(vector: Vec<bool>) -> usize {
261284
let mut result: usize = 0;
262285
for i in 0..(vector.len()) {
@@ -271,3 +294,39 @@ fn bool_to_int(bool: bool) -> usize {
271294
0
272295
}
273296
}
297+
298+
fn print_ascii_art() {
299+
println!(
300+
r".----------------. .----------------. .----------------. .----------------. .-----------------. .----------------. "
301+
);
302+
println!(
303+
r"| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |"
304+
);
305+
println!(
306+
r"| | _________ | || | _____ _____ | || | _______ | || | _____ | || | ____ _____ | || | ______ | |"
307+
);
308+
println!(
309+
r"| | | _ _ | | || ||_ _||_ _|| || | |_ __ \ | || | |_ _| | || ||_ \|_ _| | || | .' ___ | | |"
310+
);
311+
println!(
312+
r"| | |_/ | | \_| | || | | | | | | || | | |__) | | || | | | | || | | \ | | | || | / .' \_| | |"
313+
);
314+
println!(
315+
r"| | | | | || | | ' ' | | || | | __ / | || | | | | || | | |\ \| | | || | | | ____ | |"
316+
);
317+
println!(
318+
r"| | _| |_ | || | \ `--' / | || | _| | \ \_ | || | _| |_ | || | _| |_\ |_ | || | \ `.___] _| | |"
319+
);
320+
println!(
321+
r"| | |_____| | || | `.__.' | || | |____| |___| | || | |_____| | || ||_____|\____| | || | `._____.' | |"
322+
);
323+
println!(
324+
r"| | | || | | || | | || | | || | | || | | |"
325+
);
326+
println!(
327+
r"| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |"
328+
);
329+
println!(
330+
r"'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' "
331+
);
332+
}

0 commit comments

Comments
 (0)