Implemented logic for loops and if statements

This commit is contained in:
2025-03-16 14:28:49 -04:00
parent 51d735073f
commit da51be27a7
24 changed files with 811 additions and 299 deletions

View File

@@ -9,7 +9,6 @@ pub fn echo(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<(
let (argv,io_frame) = setup_builtin(argv, job, Some((io_stack,node.redirs)))?;
let stdout = borrow_fd(STDOUT_FILENO);
flog!(DEBUG, argv);
let mut echo_output = argv.into_iter()
.map(|a| a.0) // Extract the String from the tuple of (String,Span)
@@ -17,7 +16,6 @@ pub fn echo(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<(
.join(" ");
echo_output.push('\n');
flog!(DEBUG, echo_output);
write(stdout, echo_output.as_bytes())?;

View File

@@ -29,7 +29,7 @@ pub const BUILTINS: [&str;9] = [
/// # Parameters
/// * argv - The vector of raw argument tokens
/// * job - A mutable reference to a `JobBldr`
/// * io_info - An optional 2-tuple consisting of a mutable reference to an `IoStack` and a vector of `Redirs`
/// * io_mode - An optional 2-tuple consisting of a mutable reference to an `IoStack` and a vector of `Redirs`
///
/// # Behavior
/// * Cleans, expands, and word splits the arg vector
@@ -47,7 +47,7 @@ pub const BUILTINS: [&str;9] = [
pub fn setup_builtin<'t>(
argv: Vec<Tk<'t>>,
job: &'t mut JobBldr,
io_info: Option<(&mut IoStack,Vec<Redir>)>,
io_mode: Option<(&mut IoStack,Vec<Redir>)>,
) -> ShResult<(Vec<(String,Span<'t>)>, Option<IoFrame>)> {
let mut argv: Vec<(String,Span)> = prepare_argv(argv);
@@ -61,7 +61,7 @@ pub fn setup_builtin<'t>(
let child = ChildProc::new(Pid::this(), Some(&cmd_name), Some(child_pgid))?;
job.push_child(child);
let io_frame = if let Some((io_stack,redirs)) = io_info {
let io_frame = if let Some((io_stack,redirs)) = io_mode {
io_stack.append_to_frame(redirs);
let mut io_frame = io_stack.pop_frame();
io_frame.redirect()?;