debug
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ minishell
|
||||
test.c
|
||||
parser
|
||||
ast.xml
|
||||
.TEST_objs
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* cutll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/31 09:56:34 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/31 10:32:03 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/31 09:56:34 by lderidde #+# #+# */
|
||||
/* Updated: 2025/01/31 13:38:45 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,22 +14,31 @@
|
||||
|
||||
void add_nodell(t_nodell **nodell, t_node *node)
|
||||
{
|
||||
while (*nodell)
|
||||
*nodell = (*nodell)->next;
|
||||
(*nodell) = malloc(sizeof(t_nodell));
|
||||
t_nodell *tmp;
|
||||
|
||||
if (!nodell || !(*nodell))
|
||||
{
|
||||
*nodell = malloc(sizeof(t_nodell));
|
||||
(*nodell)->node = node;
|
||||
(*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;
|
||||
|
||||
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);
|
||||
lst = lst->next;
|
||||
add_node_back(&node, (*lst)->val, (*lst)->token, (*lst)->pressision);
|
||||
(*lst) = (*lst)->next;
|
||||
}
|
||||
return (node);
|
||||
}
|
||||
@@ -44,10 +53,12 @@ t_nodell *cutll(t_node *lst, char *expected, size_t limiter)
|
||||
out = NULL;
|
||||
while (i <= limiter)
|
||||
{
|
||||
node = get_node(lst, expected);
|
||||
node = get_node(&lst, expected);
|
||||
if (!node)
|
||||
break;
|
||||
add_nodell(&out, node);
|
||||
if(lst && lst->next)
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
|
||||
25
test/test.c
25
test/test.c
@@ -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 #+# #+# */
|
||||
/* Updated: 2025/01/20 13:15:47 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/15 08:23:41 by lderidde #+# #+# */
|
||||
/* 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);
|
||||
// if (!ast)
|
||||
// return (1);
|
||||
|
||||
|
||||
// tmp
|
||||
t_nodell *lls = cutll(lst, "||", -1);
|
||||
while (lls)
|
||||
{
|
||||
gen_dio_linked_list(lls->node, dio);
|
||||
lls = lls->next;
|
||||
}
|
||||
if (DEBUG)
|
||||
{
|
||||
// gen_dio_ast(ast, dio);
|
||||
drawio_end_file(dio);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* linked_list.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/15 13:38:49 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/20 13:15:03 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/15 13:38:49 by lderidde #+# #+# */
|
||||
/* 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)
|
||||
{
|
||||
t_node *tmp;
|
||||
|
||||
tmp = *head;
|
||||
if (!val)
|
||||
return (0);
|
||||
if (!(*head))
|
||||
if (!head || !(*head))
|
||||
{
|
||||
(*head) = create_node(val, token);
|
||||
(*head)->pressision = pres;
|
||||
return (1);
|
||||
}
|
||||
while ((*head)->next != NULL)
|
||||
(*head) = (*head)->next;
|
||||
(*head)->next = create_node(val, token);
|
||||
(*head)->next->pressision = pres;
|
||||
if ((*head)->next == NULL)
|
||||
while (tmp->next != NULL)
|
||||
tmp = tmp->next;
|
||||
tmp->next = create_node(val, token);
|
||||
tmp->next->pressision = pres;
|
||||
if (tmp->next == NULL)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* tokenizer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/15 13:27:57 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/20 13:15:25 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */
|
||||
/* 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");
|
||||
if (!tab)
|
||||
return (NULL);
|
||||
head = create_node(tab[0], 0);
|
||||
if (!head)
|
||||
return (free(tab), NULL);
|
||||
i = 1;
|
||||
head = NULL;
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
{
|
||||
if (!add_node_back(&head, tab[i], 0, 0))
|
||||
|
||||
Reference in New Issue
Block a user