diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-23 23:21:54 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-23 23:21:54 +0200 |
| commit | d7d48bb2195df25f5caf3fe2232eab83e0edddc2 (patch) | |
| tree | cbdf18d0b324c99df152450e08762d328ee5422f /src | |
| parent | 732910ad461ae94a876d9e661922717553181b07 (diff) | |
simplify function calls
Diffstat (limited to 'src')
| -rw-r--r-- | src/exec.c | 14 | ||||
| -rw-r--r-- | src/main.c | 3 | ||||
| -rw-r--r-- | src/preproc.c | 2 | ||||
| -rw-r--r-- | src/stages.h | 2 |
4 files changed, 4 insertions, 17 deletions
@@ -47,8 +47,6 @@ void source_script(char* fname, ShellState* shstate) { bool handle_builtin(ExecutableCommand cmd, ShellState* shstate) { MaybeStrPair m_assignment; assert(cmd.args[0] != NULL); - // TODO: handle id=value assignments - m_assignment = parse_assignment(cmd.args[0]); if (m_assignment.some) { set_map_pair(&shstate->shell_vars, m_assignment.value); @@ -154,24 +152,19 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd, int* pgid, ShellState* sh pipe(ps_pipe_fds); Channel write_cha = {.fd = ps_pipe_fds[1], .parent_proc_closable = true, .child_proc_closable = true}; execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, STDIN_CHA, write_cha, false, pgid, shstate); - //close(ps_pipe_fds[1]); - push_to_ChannelVec(&other_open_channels, (Channel){.fd = ps_pipe_fds[0], .parent_proc_closable = true, .child_proc_closable = false}); char pname[64]; snprintf(pname, sizeof(pname), "/dev/fd/%d", ps_pipe_fds[0]); push_to_StrVec(&arg_vec, strdup(pname)); break; case ARG_PS_OUT: - // TODO: do waiting correctly pipe(ps_pipe_fds); - // TODO: don't do fcntl? fcntl(ps_pipe_fds[1], F_SETFD, FD_CLOEXEC); Channel read_cha = {.fd = ps_pipe_fds[0], .parent_proc_closable = true, .child_proc_closable = true}; execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, read_cha, STDOUT_CHA, false, pgid, shstate); fcntl(ps_pipe_fds[1], F_SETFD, 0); push_to_ChannelVec(&other_open_channels, (Channel){.fd = ps_pipe_fds[0], .parent_proc_closable = true, .child_proc_closable = false}); - //close(ps_pipe_fds[0]); char name[64]; snprintf(name, sizeof(name), "/dev/fd/%d", ps_pipe_fds[1]); push_to_StrVec(&arg_vec, strdup(name)); @@ -286,10 +279,3 @@ void execute_command_pipeline(Pipeline pipeline, Channel read_cha, Channel write tcsetpgrp(STDIN_FILENO, getpgrp()); } } - -void execute_pipeline_tree(Pipeline root_pl, ShellState* shstate, int stdin_fd, int stdout_fd) { - int pgid = -1; - Channel read_cha = {.fd = stdin_fd, .parent_proc_closable = false, .child_proc_closable = false}; - Channel write_cha = {.fd = stdout_fd, .parent_proc_closable = false, .child_proc_closable = false}; - execute_command_pipeline(root_pl, read_cha, write_cha, true, &pgid, shstate); -} @@ -12,9 +12,10 @@ void execute_string_line(char *line, ShellState *shstate) { + int pgid = -1; Ast ast = lex(line); PipelineTree pltree = process_ast(*ast.root, shstate); - execute_pipeline_tree(*pltree.root, shstate, STDIN_FILENO, STDOUT_FILENO); + execute_command_pipeline(*pltree.root, STDIN_CHA, STDOUT_CHA, true, &pgid, shstate); } diff --git a/src/preproc.c b/src/preproc.c index 9c26c5f..8d5525e 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -46,7 +46,7 @@ char* get_cmdsub_output(TokenVec sub_region, ShellState* shstate) { PipelineTree sub_tree = process_ast(sub_region, shstate); // TODO: tree cleanup - execute_pipeline_tree(*sub_tree.root, shstate, STDIN_FILENO, pipe_fds[1]); + //execute_pipeline_tree(*sub_tree.root, shstate, STDIN_FILENO, pipe_fds[1]); String output_buf = make_String(256); diff --git a/src/stages.h b/src/stages.h index 6bcdd51..dd6e294 100644 --- a/src/stages.h +++ b/src/stages.h @@ -5,6 +5,6 @@ Ast lex(char* input); PipelineTree process_ast(TokenVec root, ShellState* shstate); -void execute_pipeline_tree(Pipeline root_pl, ShellState* shstate, int stdin_fd, int stdout_fd); void source_script(char* fname, ShellState* shstate); void execute_string_line(char* line, ShellState* shstate); +void execute_command_pipeline(Pipeline pipeline, Channel read_cha, Channel write_cha, bool wait_here, int* pgid, ShellState* shstate); |
