feature/variables #3

Merged
ahurac merged 4 commits from feature/variables into main 2023-12-11 19:44:35 +01:00
3 changed files with 13 additions and 10 deletions
Showing only changes of commit 7f2755c3cb - Show all commits

View file

@ -1,15 +1,20 @@
use std::io as stdio;
use stdio::stdin;
use crate::parser;
use crate::job;
use std::process::ExitStatus;
use std::io::Result;
pub struct Buffer {
buffer: String,
argv: Vec<String>,
}
impl Buffer {
pub fn new() -> Self {
Self {
buffer: String::new(),
argv: vec![],
}
}
@ -28,9 +33,10 @@ impl Buffer {
}
}
pub fn parse(&self) -> Option<Vec<String>> {
pub fn try_spawn(&mut self) -> Option<Result<ExitStatus>> {
if ! self.buffer.is_empty() {
Some(parser::parse(&self.buffer))
self.argv = parser::parse(&self.buffer);
Some(job::execute(&mut self.argv))
} else {
None
}

View file

@ -8,7 +8,7 @@ use std::io::{
ErrorKind,
};
pub fn execute(mut argv: Vec<String>) -> Result<ExitStatus> {
pub fn execute(argv: &mut Vec<String>) -> Result<ExitStatus> {
let mut command = Command::new(&argv[0]);
argv.remove(0);
command.args(argv);

View file

@ -12,25 +12,22 @@ mod job;
fn main() {
let mut buffer = input::Buffer::new();
let mut bytes_read: usize = 1;
let mut argv: Option<Vec<String>>;
let mut exit_status: Result<ExitStatus>;
let mut exit_status: Option<Result<ExitStatus>>;
let mut exit_code: i32 = 0;
while bytes_read != 0 {
output::print_ps1();
bytes_read = buffer.read_line();
argv = buffer.parse();
if argv.is_some() {
exit_status = job::execute(argv.unwrap());
exit_status = buffer.try_spawn();
if exit_status.is_some() {
let exit_status = exit_status.unwrap();
if exit_status.is_ok() {
let exit_status = exit_status.unwrap();
if exit_status.code().is_some() {
exit_code = exit_status.code().unwrap();
} else {
exit_code = 1;
}
} else {
exit_code = 1;