This commit is contained in:
Loic Deridder
2025-01-31 13:45:16 +01:00
parent 304eeb73eb
commit 17361832c1
8 changed files with 83 additions and 59 deletions

View File

@@ -6,11 +6,11 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */
/* Updated: 2025/01/30 13:19:40 by lderidde ### ########.fr */
/* Updated: 2025/01/31 11:01:25 by lderidde ### ########.fr */
/* */
/* ************************************************************************** */
#include "ast.h"
#include "../../includes/ast.h"
t_ast_n *created_ast_n(t_state st, t_ast_n *prt, t_ast_n *he)
{
@@ -84,7 +84,7 @@ t_ast_n *return_hardcode_ast(char **envp)
head = created_ast_n(_AND, NULL, NULL);
head->env = init_env(envp);
head->left = created_ast_n(_CMD, head, head);
setup_cmd(head->left, "export", "export test=");
setup_cmd(head->left, "cd", "cd srcs");
// head->right = created_ast_n(_AND, head, head);
// head->right->left = created_ast_n(_CMD, head->right, head);
// setup_cmd(head->right->left, "echo", "echo $PWD");
@@ -93,15 +93,15 @@ t_ast_n *return_hardcode_ast(char **envp)
head->right = created_ast_n(_PLINE, head, head);
head->right->pline = malloc(sizeof(t_ast_n *) * 5);
head->right->pline[0] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[0], "export", "export");
setup_cmd(head->right->pline[0], "ls", "ls -la");
head->right->pline[1] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[1], "grep", "grep test");
setup_cmd(head->right->pline[1], "cat", "cat -e");
head->right->pline[2] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[2], "cat", "cat");
setup_cmd(head->right->pline[2], "grep", "grep builtins");
head->right->pline[3] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[3], "cat", "cat");
head->right->pline[1]->redir = _RED_R;
head->right->pline[1]->outfile = "file";
setup_cmd(head->right->pline[3], "wc", "wc -l");
// head->right->pline[1]->redir = _RED_R;
// head->right->pline[1]->outfile = "file";
// head->right->pline[3]->redir = _RED_R;
// head->right->pline[3]->outfile = "file";
head->right->pline[4] = NULL;

View File

@@ -6,11 +6,13 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */
/* Updated: 2025/01/30 12:41:55 by lderidde ### ########.fr */
/* Updated: 2025/01/31 11:47:38 by lderidde ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "../../includes/exec.h"
#include "../../lib/libft/libft.h"
#include "../../includes/builtins.h"
void handle_file(t_ast_n *node, int check)
{
@@ -225,14 +227,10 @@ int err_fork_pline(int *pipes)
return (1);
}
void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
void exec_pcmd(t_ast_n *pcmd)
{
int ret;
int ret;
if (index < cmds - 1)
dup2(pipes[1], STDOUT_FILENO);
close(pipes[0]);
close(pipes[1]);
if (is_builtin(pcmd->cmd))
{
ret = exec_builtin(pcmd);
@@ -242,6 +240,18 @@ void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
exec(pcmd);
}
void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
{
if (index < cmds - 1)
dup2(pipes[1], STDOUT_FILENO);
close(pipes[0]);
close(pipes[1]);
if (pcmd->state == _CMD)
exec_pcmd(pcmd);
// else if (pcmd->state == _SUBSH);
// exec_psubsh(pcmd);
}
int end_pline(pid_t last_pid, t_ast_n **pline)
{
int status;

View File

@@ -6,7 +6,7 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
/* Updated: 2025/01/29 13:28:35 by lderidde ### ########.fr */
/* Updated: 2025/01/31 09:57:17 by lderidde ### ########.fr */
/* */
/* ************************************************************************** */