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

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ minishell
test.c test.c
parser parser
ast.xml ast.xml
.TEST_objs

View File

@@ -6,11 +6,11 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */ /* 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) 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 = created_ast_n(_AND, NULL, NULL);
head->env = init_env(envp); head->env = init_env(envp);
head->left = created_ast_n(_CMD, head, head); 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 = created_ast_n(_AND, head, head);
// head->right->left = created_ast_n(_CMD, head->right, head); // head->right->left = created_ast_n(_CMD, head->right, head);
// setup_cmd(head->right->left, "echo", "echo $PWD"); // 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 = created_ast_n(_PLINE, head, head);
head->right->pline = malloc(sizeof(t_ast_n *) * 5); head->right->pline = malloc(sizeof(t_ast_n *) * 5);
head->right->pline[0] = created_ast_n(_CMD, head->right, head); 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); 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); 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); head->right->pline[3] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[3], "cat", "cat"); setup_cmd(head->right->pline[3], "wc", "wc -l");
head->right->pline[1]->redir = _RED_R; // head->right->pline[1]->redir = _RED_R;
head->right->pline[1]->outfile = "file"; // head->right->pline[1]->outfile = "file";
// head->right->pline[3]->redir = _RED_R; // head->right->pline[3]->redir = _RED_R;
// head->right->pline[3]->outfile = "file"; // head->right->pline[3]->outfile = "file";
head->right->pline[4] = NULL; head->right->pline[4] = NULL;

View File

@@ -6,11 +6,13 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */ /* 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) void handle_file(t_ast_n *node, int check)
{ {
@@ -225,14 +227,10 @@ int err_fork_pline(int *pipes)
return (1); 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)) if (is_builtin(pcmd->cmd))
{ {
ret = exec_builtin(pcmd); ret = exec_builtin(pcmd);
@@ -242,6 +240,18 @@ void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
exec(pcmd); 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 end_pline(pid_t last_pid, t_ast_n **pline)
{ {
int status; int status;

View File

@@ -6,7 +6,7 @@
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* cutll.c :+: :+: :+: */ /* cutll.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 09:56:34 by nalebrun #+# #+# */ /* Created: 2025/01/31 09:56:34 by lderidde #+# #+# */
/* Updated: 2025/01/31 10:32:03 by nalebrun ### ########.fr */ /* Updated: 2025/01/31 13:38:45 by lderidde ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -14,22 +14,31 @@
void add_nodell(t_nodell **nodell, t_node *node) void add_nodell(t_nodell **nodell, t_node *node)
{ {
while (*nodell) t_nodell *tmp;
*nodell = (*nodell)->next;
(*nodell) = malloc(sizeof(t_nodell)); if (!nodell || !(*nodell))
{
*nodell = malloc(sizeof(t_nodell));
(*nodell)->node = node; (*nodell)->node = node;
(*nodell)->next = NULL; (*nodell)->next = NULL;
}
tmp = *nodell;
while (tmp->next)
tmp = tmp->next;
tmp->next = malloc(sizeof(t_nodell));
tmp->next->node = node;
tmp->next->next = NULL;
} }
t_node *get_node(t_node *lst, char *expected) t_node *get_node(t_node **lst, char *expected)
{ {
t_node *node; t_node *node;
node = NULL; node = NULL;
while (lst && ft_strncmp(lst->val, expected, ft_strlen(expected))) while ((*lst) && ft_strncmp((*lst)->val, expected, ft_strlen(expected)))
{ {
add_node_back(&node, lst->val, lst->token, lst->pressision); add_node_back(&node, (*lst)->val, (*lst)->token, (*lst)->pressision);
lst = lst->next; (*lst) = (*lst)->next;
} }
return (node); return (node);
} }
@@ -44,10 +53,12 @@ t_nodell *cutll(t_node *lst, char *expected, size_t limiter)
out = NULL; out = NULL;
while (i <= limiter) while (i <= limiter)
{ {
node = get_node(lst, expected); node = get_node(&lst, expected);
if (!node) if (!node)
break; break;
add_nodell(&out, node); add_nodell(&out, node);
if(lst && lst->next)
lst = lst->next;
i++; i++;
} }
return (out); return (out);

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* parse.c :+: :+: :+: */ /* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */ /* Created: 2025/01/15 08:23:41 by lderidde #+# #+# */
/* Updated: 2025/01/20 13:15:47 by nalebrun ### ########.fr */ /* Updated: 2025/01/31 13:40:10 by lderidde ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -60,19 +60,20 @@ int main(int ac, char **av, char **envp)
// ast = get_ast(envp, lst); // ast = get_ast(envp, lst);
// if (!ast) // if (!ast)
// return (1); // return (1);
// tmp
t_nodell *lls = cutll(lst, "||", -1);
while (lls)
{
gen_dio_linked_list(lls->node, dio);
lls = lls->next;
}
if (DEBUG) if (DEBUG)
{ {
// gen_dio_ast(ast, dio); // gen_dio_ast(ast, dio);
drawio_end_file(dio); drawio_end_file(dio);
ft_debug(" draw.io file generated !\n"); ft_debug(" draw.io file generated !\n");
} }
// tmp
t_nodell *lls = cutll(lst, "||", 1);
while (lls)
{
gen_dio_linked_list(lls->node, dio);
lls = lls->next;
}
free_linked_list(lst); free_linked_list(lst);
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* linked_list.c :+: :+: :+: */ /* linked_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:38:49 by nalebrun #+# #+# */ /* Created: 2025/01/15 13:38:49 by lderidde #+# #+# */
/* Updated: 2025/01/20 13:15:03 by nalebrun ### ########.fr */ /* Updated: 2025/01/31 13:20:13 by lderidde ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -30,19 +30,22 @@ t_node *create_node(char *val, t_token token)
int add_node_back(t_node **head, char *val, t_token token, t_pres pres) int add_node_back(t_node **head, char *val, t_token token, t_pres pres)
{ {
t_node *tmp;
tmp = *head;
if (!val) if (!val)
return (0); return (0);
if (!(*head)) if (!head || !(*head))
{ {
(*head) = create_node(val, token); (*head) = create_node(val, token);
(*head)->pressision = pres; (*head)->pressision = pres;
return (1); return (1);
} }
while ((*head)->next != NULL) while (tmp->next != NULL)
(*head) = (*head)->next; tmp = tmp->next;
(*head)->next = create_node(val, token); tmp->next = create_node(val, token);
(*head)->next->pressision = pres; tmp->next->pressision = pres;
if ((*head)->next == NULL) if (tmp->next == NULL)
return (0); return (0);
return (1); return (1);
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* tokenizer.c :+: :+: :+: */ /* tokenizer.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:27:57 by nalebrun #+# #+# */ /* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */
/* Updated: 2025/01/20 13:15:25 by nalebrun ### ########.fr */ /* Updated: 2025/01/31 13:24:28 by lderidde ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -21,10 +21,8 @@ static t_node *tokenize_base(char *str)
tab = ft_split_keep(str, " \t\n"); tab = ft_split_keep(str, " \t\n");
if (!tab) if (!tab)
return (NULL); return (NULL);
head = create_node(tab[0], 0); head = NULL;
if (!head) i = 0;
return (free(tab), NULL);
i = 1;
while (tab[i]) while (tab[i])
{ {
if (!add_node_back(&head, tab[i], 0, 0)) if (!add_node_back(&head, tab[i], 0, 0))