Browse Source

initial commit

Jared Dunbar 1 year ago
commit
5fec250bcb
Signed by: Jared Dunbar <jrddunbr@gmail.com> GPG Key ID: CF202CC859BAC692
5 changed files with 73 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 4
    0
      Cargo.lock
  3. 11
    0
      Cargo.toml
  4. 36
    0
      src/lib.rs
  5. 20
    0
      src/main.rs

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/target
2
+**/*.rs.bk

+ 4
- 0
Cargo.lock View File

@@ -0,0 +1,4 @@
1
+[[package]]
2
+name = "mc_lang"
3
+version = "0.1.0"
4
+

+ 11
- 0
Cargo.toml View File

@@ -0,0 +1,11 @@
1
+[package]
2
+name = "mc_lang"
3
+version = "0.1.0"
4
+authors = ["Jared Dunbar <jrddunbr@gmail.com>"]
5
+edition = "2018"
6
+
7
+[lib]
8
+name = "mc_lang"
9
+path = "src/lib.rs"
10
+
11
+[dependencies]

+ 36
- 0
src/lib.rs View File

@@ -0,0 +1,36 @@
1
+use std::io;
2
+use std::io::Read;
3
+use std::fs::File;
4
+
5
+pub fn read_file(filename: &str) -> Result<String, std::io::Error> {
6
+    // get the first filename
7
+    let mut en_us_lang_file = String::new();
8
+    let mut en_us_lang = String::new();
9
+
10
+    println!("Please specify the location of the {} file:", &filename);
11
+    match io::stdin().read_line(&mut en_us_lang_file) {
12
+        Ok(_) => (),
13
+        Err(e) => return Err(e),
14
+    };
15
+
16
+    let en_us_lang_file = en_us_lang_file.trim();
17
+
18
+    let f = File::open(&en_us_lang_file);
19
+    let mut f = match f {
20
+        Ok(file) => file,
21
+        Err(e) => {
22
+            println!("There was an error opening the file.");
23
+            return Err(e);
24
+        },
25
+    };
26
+
27
+    match f.read_to_string(&mut en_us_lang) {
28
+        Ok(_) => (),
29
+        Err(e) => {
30
+            println!("There was an error reading the file.");
31
+            return Err(e);
32
+        },
33
+    };
34
+    
35
+    Ok(en_us_lang)
36
+}

+ 20
- 0
src/main.rs View File

@@ -0,0 +1,20 @@
1
+use mc_lang;
2
+
3
+fn main() {
4
+    println!("Welcome to the Minecraft language file parsing utility.");
5
+
6
+    let mut en_us_lang = String::new();
7
+
8
+    loop {
9
+        // get the canonical file
10
+        en_us_lang = match mc_lang::read_file("en_US.lang") {
11
+            Ok(contents) => {
12
+                contents
13
+            },
14
+            Err(_) => continue,
15
+        };
16
+        break;
17
+    }
18
+
19
+    println!("{}", en_us_lang);
20
+}

Loading…
Cancel
Save