Grand remaniement du code en modules partie 1

This commit is contained in:
Hippolyte Chauvin 2023-11-01 13:48:25 +01:00
parent 80e80fab8d
commit 03d44852c3
3 changed files with 37 additions and 35 deletions

View file

@ -1,3 +1,39 @@
use std::io;
use io::{
stdin,
stdout,
Write,
};
mod parser;
pub fn run() -> i32 {
todo!();
let mut buffer = String::new();
let mut bytes_read_result: io::Result<usize>;
let mut bytes_read: usize = 1;
while bytes_read != 0 {
buffer.clear();
print!("$ ");
if stdout().flush().is_err() {
eprintln!("error: can't fully flush stdout or reached EOF");
}
bytes_read_result = stdin().read_line(&mut buffer);
if bytes_read_result.is_err() {
eprintln!("error: invalid UTF-8 characters were read");
bytes_read = 1;
} else {
bytes_read = bytes_read_result.unwrap();
if bytes_read != 0 {
let command_vec: Vec<String> = parser::parse(&buffer);
println!("{:?}", command_vec);
}
}
}
println!();
0
}

View file

@ -1,43 +1,9 @@
use std::io as stdio;
use stdio::{
stdin,
stdout,
Write,
};
use std::process::exit;
mod parser;
mod io;
fn main() {
let mut buffer = String::new();
let mut bytes_read_result: stdio::Result<usize>;
let mut bytes_read: usize = 1;
let last_exit_code: i32 = io::run();
exit(last_exit_code);
while bytes_read != 0 {
buffer.clear();
print!("$ ");
if stdout().flush().is_err() {
eprintln!("error: can't fully flush stdout or reached EOF");
}
bytes_read_result = stdin().read_line(&mut buffer);
if bytes_read_result.is_err() {
eprintln!("error: invalid UTF-8 characters were read");
bytes_read = 1;
} else {
bytes_read = bytes_read_result.unwrap();
if bytes_read != 0 {
let command_vec: Vec<String> = parser::parse(&buffer);
println!("{:?}", command_vec);
}
}
}
println!();
}