Lorenz Bung 8 роки тому
джерело
коміт
7cdee6f4bb
3 змінених файлів з 17 додано та 16 видалено
  1. 2
    4
      hw6/task2/src/command.rs
  2. 10
    0
      hw6/task2/src/main.rs
  3. 5
    12
      hw6/task2/src/shell.rs

+ 2
- 4
hw6/task2/src/command.rs Переглянути файл

@@ -4,10 +4,8 @@ enum Command {
4 4
     Cd(Option<OsString>),
5 5
 }
6 6
 
7
-impl Command {
8
-}
7
+impl Command {}
9 8
 
10 9
 impl FromStr for Command {
11
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
12
-    }
10
+    fn from_str(s: &str) -> Result<Self, Self::Err> {}
13 11
 }

+ 10
- 0
hw6/task2/src/main.rs Переглянути файл

@@ -0,0 +1,10 @@
1
+use std::process;
2
+mod shell;
3
+
4
+fn main() {
5
+    let mut s = Shell::new(..);
6
+    match s.start() {
7
+        Ok(_) => process::exit(0),
8
+        Err(_) => process::exit(1),
9
+    }
10
+}

+ 5
- 12
hw6/task2/src/shell.rs Переглянути файл

@@ -1,5 +1,6 @@
1 1
 use std::io;
2 2
 use std::io::prelude::*;
3
+use command;
3 4
 
4 5
 struct Shell<R, W> {
5 6
     pub reader: R,
@@ -20,9 +21,12 @@ impl Shell<R, W> {
20 21
     }
21 22
     /// Initializes the Shell Loop
22 23
     pub fn start() -> Result<Self, &str> {
24
+        shell_loop();
23 25
     }
24 26
     /// Waits for user inputs.
25 27
     fn shell_loop() -> Result {
28
+        loop {
29
+        }
26 30
     }
27 31
     /// Prints the shell prompt.
28 32
     fn prompt() -> Result<Option, &str> {
@@ -34,11 +38,7 @@ impl Shell<R, W> {
34 38
 
35 39
 impl BufRead for Shell<R, W> {
36 40
     fn fill_buf(&mut self) -> Result<&[u8]> {
37
-        let buf = match stdin.fill_buf() {
38
-            Ok(res) => res,
39
-            Err(e) => return Err(e),
40
-        }
41
-        buf.unwrap()
41
+        stdin.fill_buf()
42 42
     }
43 43
     fn consume(&mut self, amt: usize) {
44 44
     }
@@ -50,10 +50,3 @@ impl Write for Shell<R, W> {
50 50
     fn flush(&mut self) -> Result<()> {
51 51
     }
52 52
 }
53
-
54
-
55
-let mut s = Shell::new();
56
-    match s.start() {
57
-        Ok(_) => process::exit(0),
58
-        Err(_) => process::exit(1),
59
-    }

Завантаження…
Відмінити
Зберегти