This commit is contained in:
gazhonsepaskwa
2025-02-07 18:08:37 +01:00
parent cc57905fa9
commit d3849d196f
18 changed files with 178 additions and 186 deletions

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* minishell.h :+: :+: :+: */ /* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 11:25:25 by lderidde #+# #+# */ /* Created: 2025/01/27 11:25:25 by lderidde #+# #+# */
/* Updated: 2025/02/07 10:22:28 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:22:16 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -44,7 +44,7 @@ typedef struct s_msh
# include "exec/expander.h" # include "exec/expander.h"
t_msh *init_msh(char **envp); t_msh *init_msh(char **envp);
void free_msh(t_msh *msh); void free_msh(t_msh *msh);
void free_child(t_msh *msh); void free_child(t_msh *msh);
# define POW1 "\033[1;38;2;21;22;26;48;2;92;106;178m" # define POW1 "\033[1;38;2;21;22;26;48;2;92;106;178m"
@@ -53,5 +53,4 @@ void free_child(t_msh *msh);
# define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m" # define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m"
# define POW5 "\033[1;38;2;39;39;39m" # define POW5 "\033[1;38;2;39;39;39m"
#endif #endif

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* and_or.c :+: :+: :+: */ /* and_or.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 07:57:33 by nalebrun #+# #+# */ /* Created: 2025/02/05 07:57:33 by nalebrun #+# #+# */
/* Updated: 2025/02/05 07:57:33 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:57:01 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -14,7 +14,7 @@
void create_and_or(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh) void create_and_or(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh)
{ {
t_nodell *nodell; t_nodell *nodell;
nodell = cutll(lst, token, 1); nodell = cutll(lst, token, 1);
self->left = create_ast_n(nodell->node, self, msh, self->sh); self->left = create_ast_n(nodell->node, self, msh, self->sh);

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ast.c :+: :+: :+: */ /* ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */ /* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */
/* Updated: 2025/02/05 14:04:12 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:57:10 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -15,7 +15,7 @@
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh) t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh)
{ {
t_ast_n *node; t_ast_n *node;
t_node *token; t_node *token;
node = malloc(sizeof(t_ast_n)); node = malloc(sizeof(t_ast_n));
@@ -29,7 +29,7 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh)
node->_stdin = 0; node->_stdin = 0;
node->save_stdo = 1; node->save_stdo = 1;
node->save_stdi = 0; node->save_stdi = 0;
node->sh = subsh; node->sh = subsh;
if (node->state == _AND || node->state == _OR) if (node->state == _AND || node->state == _OR)
create_and_or(node, lst, token, msh); create_and_or(node, lst, token, msh);
else if (node->state == _SUBSH) else if (node->state == _SUBSH)
@@ -43,7 +43,7 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh)
t_ast_n *get_ast(t_msh *msh, t_node *lst) t_ast_n *get_ast(t_msh *msh, t_node *lst)
{ {
t_ast_n *head; t_ast_n *head;
head = create_ast_n(lst, NULL, msh, false); head = create_ast_n(lst, NULL, msh, false);
return (head); return (head);

View File

@@ -3,16 +3,16 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* commands.c :+: :+: :+: */ /* commands.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 07:48:37 by nalebrun #+# #+# */ /* Created: 2025/02/05 07:48:37 by nalebrun #+# #+# */
/* Updated: 2025/02/05 07:48:37 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 18:00:41 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
# include "../../../includes/minishell.h" #include "../../../includes/minishell.h"
char **lltotab(t_node *lst, t_node *limiter) char **lltotab(t_node *lst, t_node *limiter)
{ {
char **out; char **out;
int count; int count;
@@ -40,7 +40,7 @@ char **lltotab(t_node *lst, t_node *limiter)
return (out); return (out);
} }
char **get_args(t_node *start) char **get_args(t_node *start)
{ {
t_node *cpy; t_node *cpy;
char **out; char **out;
@@ -64,6 +64,7 @@ char **get_args(t_node *start)
void create_cmd(t_ast_n *self, t_node *lst) void create_cmd(t_ast_n *self, t_node *lst)
{ {
char **cmd_args; char **cmd_args;
int i;
self->state = _CMD; self->state = _CMD;
self->files = NULL; self->files = NULL;
@@ -73,14 +74,16 @@ void create_cmd(t_ast_n *self, t_node *lst)
self->args = cmd_args; self->args = cmd_args;
self->cmd = ft_strdup(cmd_args[0]); self->cmd = ft_strdup(cmd_args[0]);
create_redir(lst, self); create_redir(lst, self);
// debug if (DEBUG)
int i = -1; {
ft_debug("==== CMD REDIR\n"); i = -1;
while (self->files && self->files[++i]) ft_debug("==== CMD REDIR\n");
ft_debug("redi : [%d]%s\n",self->redir[i], self->files[i]); while (self->files && self->files[++i])
ft_debug("==== CMD ARGS\n"); ft_debug("redi : [%d]%s\n", self->redir[i], self->files[i]);
i = -1; ft_debug("==== CMD ARGS\n");
while (self->args && self->args[++i]) i = -1;
ft_debug("args : %s\n",self->args[i], self->args[i]); while (self->args && self->args[++i])
ft_debug("==== CMD DONE\n\n"); ft_debug("args : %s\n", self->args[i], self->args[i]);
ft_debug("==== CMD DONE\n\n");
}
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* cutll.c :+: :+: :+: */ /* cutll.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 09:56:34 by lderidde #+# #+# */ /* Created: 2025/01/31 09:56:34 by lderidde #+# #+# */
/* Updated: 2025/01/31 14:05:12 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:56:37 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -31,7 +31,7 @@ static void add_nodell(t_nodell **nodell, t_node *node)
tmp->next->next = NULL; tmp->next->next = NULL;
} }
static t_node *get_node(t_node **lst, t_node *expected, int limiter) static t_node *get_node(t_node **lst, t_node *expected, int limiter)
{ {
t_node *node; t_node *node;
@@ -41,7 +41,8 @@ static t_node *get_node(t_node **lst, t_node *expected, int limiter)
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;
} }
while (limiter == -1 && (*lst) && ft_strncmp((*lst)->val, expected->val, ft_strlen((*lst)->val))) while (limiter == -1 && (*lst) && ft_strncmp((*lst)->val, expected->val,
ft_strlen((*lst)->val)))
{ {
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;
@@ -54,6 +55,7 @@ t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter)
t_nodell *out; t_nodell *out;
t_node *node; t_node *node;
size_t i; size_t i;
t_nodell *tmp;
i = 0; i = 0;
out = NULL; out = NULL;
@@ -61,27 +63,27 @@ t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter)
{ {
node = get_node(&lst, expected, limiter); node = get_node(&lst, expected, limiter);
if (!node) if (!node)
break; break ;
add_nodell(&out, node); add_nodell(&out, node);
t_nodell *tmp = out; tmp = out;
while (tmp) while (tmp)
tmp = tmp->next; tmp = tmp->next;
if(lst && lst->next) if (lst && lst->next)
lst = lst->next; lst = lst->next;
i++; i++;
} }
return (out); return (out);
} }
void free_lltab(t_nodell *nodell) void free_lltab(t_nodell *nodell)
{ {
t_nodell *tmp; t_nodell *tmp;
while (nodell) while (nodell)
{ {
free_linked_list(nodell->node); free_linked_list(nodell->node);
tmp = nodell->next; tmp = nodell->next;
free(nodell); free(nodell);
nodell = tmp; nodell = tmp;
} }
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* free_ast.c :+: :+: :+: */ /* free_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 14:39:28 by lderidde #+# #+# */ /* Created: 2025/02/05 14:39:28 by lderidde #+# #+# */
/* Updated: 2025/02/07 09:20:16 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:57:21 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -19,20 +19,20 @@ static void free_redirs(t_ast_n *node)
free_tab(node->files); free_tab(node->files);
} }
static void free_cmd(t_ast_n *node) static void free_cmd(t_ast_n *node)
{ {
free(node->cmd); free(node->cmd);
free_redirs(node); free_redirs(node);
free_tab(node->args); free_tab(node->args);
} }
static void free_pline(t_ast_n *node) static void free_pline(t_ast_n *node)
{ {
int i; int i;
i = -1; i = -1;
while (node->pline[++i]) while (node->pline[++i])
free_ast(node->pline[i]); free_ast(node->pline[i]);
} }
void free_ast(t_ast_n *node) void free_ast(t_ast_n *node)
@@ -48,9 +48,9 @@ void free_ast(t_ast_n *node)
free_redirs(node); free_redirs(node);
} }
else if (node->state == _PLINE) else if (node->state == _PLINE)
free_pline(node); free_pline(node);
else else
free_cmd(node); free_cmd(node);
free(node); free(node);
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* redirections.c :+: :+: :+: */ /* redirections.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 07:38:26 by nalebrun #+# #+# */ /* Created: 2025/02/05 07:38:26 by nalebrun #+# #+# */
/* Updated: 2025/02/05 11:41:23 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:57:42 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -29,33 +29,33 @@ t_redir get_redir(t_node *node)
static void add_redir(t_redir redir, t_redir **redir_list) static void add_redir(t_redir redir, t_redir **redir_list)
{ {
int i; int i;
int j; int j;
t_redir *tmp; t_redir *tmp;
i = 0; i = 0;
while ((*redir_list)[i] != _NR) while ((*redir_list)[i] != _NR)
i++; i++;
tmp = ft_calloc(i + 2, sizeof(t_redir)); tmp = ft_calloc(i + 2, sizeof(t_redir));
j = -1; j = -1;
while ((*redir_list)[++j] != _NR) while ((*redir_list)[++j] != _NR)
tmp[j] = (*redir_list)[j]; tmp[j] = (*redir_list)[j];
tmp[j++] = redir; tmp[j++] = redir;
tmp[j] = _NR; tmp[j] = _NR;
free(*redir_list); free(*redir_list);
*redir_list = tmp; *redir_list = tmp;
} }
void create_redir(t_node *head, t_ast_n *self) void create_redir(t_node *head, t_ast_n *self)
{ {
t_redir redir; t_redir redir;
while (head) while (head)
{ {
while (head && get_redir(head) == _NR) while (head && get_redir(head) == _NR)
head = head->next; head = head->next;
if (!head) if (!head)
break; break ;
redir = get_redir(head); redir = get_redir(head);
add_redir(redir, &self->redir); add_redir(redir, &self->redir);
add_to_tab(&self->files, head->next->val); add_to_tab(&self->files, head->next->val);
@@ -65,7 +65,7 @@ void create_redir(t_node *head, t_ast_n *self)
} }
} }
int in_parenthesis(t_node *head) int in_parenthesis(t_node *head)
{ {
int count; int count;
@@ -85,14 +85,14 @@ int in_parenthesis(t_node *head)
void create_redir_subsh(t_node *head, t_ast_n *self) void create_redir_subsh(t_node *head, t_ast_n *self)
{ {
t_redir redir; t_redir redir;
while (head) while (head)
{ {
while (head && (get_redir(head) == _NR || in_parenthesis(head))) while (head && (get_redir(head) == _NR || in_parenthesis(head)))
head = head->next; head = head->next;
if (!head) if (!head)
break; break ;
redir = get_redir(head); redir = get_redir(head);
add_redir(redir, &self->redir); add_redir(redir, &self->redir);
add_to_tab(&self->files, head->next->val); add_to_tab(&self->files, head->next->val);

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* subsh.c :+: :+: :+: */ /* subsh.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 07:51:27 by lderidde #+# #+# */ /* Created: 2025/02/05 07:51:27 by lderidde #+# #+# */
/* Updated: 2025/02/07 09:12:41 by lderidde ### ########.fr */ /* Updated: 2025/02/07 18:01:31 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -31,7 +31,7 @@ t_node *remove_parentheses(t_node *lst)
if (it->pressision == SUBSH_E) if (it->pressision == SUBSH_E)
deepness -= 1; deepness -= 1;
if (deepness == 0) if (deepness == 0)
break; break ;
add_node_back(&out, str, it->token, it->pressision); add_node_back(&out, str, it->token, it->pressision);
free(str); free(str);
it = it->next; it = it->next;
@@ -40,23 +40,25 @@ t_node *remove_parentheses(t_node *lst)
return (out); return (out);
} }
void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh) void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh)
{ {
t_node *cutted; t_node *cutted;
int i;
self->sh = true; self->sh = true;
cutted = remove_parentheses(lst); cutted = remove_parentheses(lst);
self->left = create_ast_n(cutted, self, msh, self->sh); self->left = create_ast_n(cutted, self, msh, self->sh);
self->files = NULL; self->files = NULL;
self->redir = ft_calloc(1, sizeof(t_redir)); self->redir = ft_calloc(1, sizeof(t_redir));
self->redir[0] = _NR; self->redir[0] = _NR;
create_redir_subsh(lst, self); create_redir_subsh(lst, self);
// debug if (DEBUG)
int i = -1; {
ft_debug("==== SUBSH REDIR\n"); i = -1;
while (self->redir[++i]) ft_debug("==== SUBSH REDIR\n");
ft_debug("subsh_redir : [%d]%s\n", self->redir[i], self->files[i]); while (self->redir[++i])
ft_debug("==== SUBSH DONE\n\n"); ft_debug("subsh_redir : [%d]%s\n", self->redir[i], self->files[i]);
ft_debug("==== SUBSH DONE\n\n");
free_linked_list(cutted); free_linked_list(cutted);
}
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* top_token.c :+: :+: :+: */ /* top_token.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 17:14:26 by nalebrun #+# #+# */ /* Created: 2025/01/31 17:14:26 by nalebrun #+# #+# */
/* Updated: 2025/01/31 17:14:26 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:56:02 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -27,10 +27,9 @@ static int last_tok_redir(t_node *lst)
{ {
while (lst) while (lst)
{ {
if ((lst->next == NULL if ((lst->next == NULL || lst->next->pressision == D_RED_R
|| lst->next->pressision == D_RED_R || lst->next->pressision == RED_R) && !ft_strncmp(lst->val, ")",
|| lst->next->pressision == RED_R) 1))
&& !ft_strncmp(lst->val, ")", 1))
return (1); return (1);
lst = lst->next; lst = lst->next;
} }
@@ -62,7 +61,7 @@ static t_node *find_token(char *tok, t_node *lst)
return (NULL); return (NULL);
} }
t_node *get_top_token(t_node *lst, t_state *state) t_node *get_top_token(t_node *lst, t_state *state)
{ {
*state = _SUBSH; *state = _SUBSH;
if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst)) if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst))
@@ -82,7 +81,7 @@ t_node *get_top_token(t_node *lst, t_state *state)
*state = _PLINE; *state = _PLINE;
return (find_token("|", lst)); return (find_token("|", lst));
} }
else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst)) else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst))
return (lst); return (lst);
else else
{ {

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* drawio_ast_utils.c :+: :+: :+: */ /* drawio_ast_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/29 09:21:09 by nalebrun #+# #+# */ /* Created: 2025/01/29 09:21:09 by nalebrun #+# #+# */
/* Updated: 2025/01/29 09:21:09 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 18:02:51 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -31,21 +31,6 @@ const char *translate_state(t_state state)
return (out); return (out);
} }
// const char *translate_redir(t_redir redir)
// {
// const char *out;
//
// if (redir == _RED_L)
// out = "redir : RED_L&#10;";
// else if (redir == _RED_R)
// out = "redir : RED_R&#10;";
// else if (redir == _RED_DR)
// out = "redir : _RED_DR &#10;";
// else
// out = "Not redirected &#10;";
// return (out);
// }
t_dio_node get_cmd_txt(t_ast_n *node) t_dio_node get_cmd_txt(t_ast_n *node)
{ {
t_dio_node txt; t_dio_node txt;
@@ -59,9 +44,6 @@ t_dio_node get_cmd_txt(t_ast_n *node)
args = ft_tabstr(node->args); args = ft_tabstr(node->args);
txt.args = ft_sprintf("%s%s%s", NL, args, NL); txt.args = ft_sprintf("%s%s%s", NL, args, NL);
free(args); free(args);
// txt.redir = translate_redir(node->redir);
// txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL);
// txt.outf = ft_sprintf("Outfile : %s", node->outfile);
txt.files = ft_sprintf("redir: UNCHECKED\n"); txt.files = ft_sprintf("redir: UNCHECKED\n");
} }
else else

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* drawio_print_ast.c :+: :+: :+: */ /* drawio_print_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/29 09:54:31 by lderidde #+# #+# */ /* Created: 2025/01/29 09:54:31 by lderidde #+# #+# */
/* Updated: 2025/02/07 09:09:01 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:27:47 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -15,16 +15,15 @@
char *get_node_txt(t_ast_n *node) char *get_node_txt(t_ast_n *node)
{ {
t_dio_node txt; t_dio_node txt;
static char *subsh; static char *subsh;
char *out; char *out;
txt = get_cmd_txt(node); txt = get_cmd_txt(node);
if (node->sh == true) if (node->sh == true)
subsh = ft_strdup(" (subsh) "); subsh = ft_strdup(" (subsh) ");
else else
subsh = ft_strdup(""); subsh = ft_strdup("");
out = ft_sprintf("%s%s%s%s%s", txt.st, txt.cmd, txt.args, out = ft_sprintf("%s%s%s%s%s", txt.st, txt.cmd, txt.args, subsh, txt.files);
subsh, txt.files);
free(txt.cmd); free(txt.cmd);
free(txt.args); free(txt.args);
free(txt.files); free(txt.files);

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* drawio_utils.c :+: :+: :+: */ /* drawio_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 15:09:16 by nalebrun #+# #+# */ /* Created: 2025/01/27 15:09:16 by nalebrun #+# #+# */
/* Updated: 2025/01/27 15:09:16 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:36:08 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -28,6 +28,15 @@ static int get_char_count(char *str, char c)
return (count); return (count);
} }
void write_ampercent(char *out)
{
out[0] = '&';
out[1] = 'a';
out[2] = 'm';
out[3] = 'p';
out[4] = ';';
}
char *replace_ampercent(char *src) char *replace_ampercent(char *src)
{ {
int i; int i;
@@ -43,11 +52,7 @@ char *replace_ampercent(char *src)
{ {
if (src[i] == '&') if (src[i] == '&')
{ {
out[j] = '&'; write_ampercent(&out[j]);
out[j + 1] = 'a';
out[j + 2] = 'm';
out[j + 3] = 'p';
out[j + 4] = ';';
j += 5; j += 5;
} }
else else
@@ -58,6 +63,18 @@ char *replace_ampercent(char *src)
return (out); return (out);
} }
void write_left_redi(char *out)
{
out[0] = '&';
out[1] = 'a';
out[2] = 'm';
out[3] = 'p';
out[4] = ';';
out[5] = 'l';
out[6] = 't';
out[7] = ';';
}
char *replace_left_red(char *src) char *replace_left_red(char *src)
{ {
int i; int i;
@@ -73,14 +90,7 @@ char *replace_left_red(char *src)
{ {
if (src[i] == '<') if (src[i] == '<')
{ {
out[j] = '&'; write_left_redi(&out[j]);
out[j + 1] = 'a';
out[j + 2] = 'm';
out[j + 3] = 'p';
out[j + 4] = ';';
out[j + 5] = 'l';
out[j + 6] = 't';
out[j + 7] = ';';
j += 8; j += 8;
} }
else else

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* parser.c :+: :+: :+: */ /* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */ /* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */
/* Updated: 2025/02/07 12:08:40 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:59:43 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -36,11 +36,11 @@ void truncate_comment(char *str)
} }
} }
t_ast_n *parser(char *input, t_msh *msh) t_ast_n *parser(char *input, t_msh *msh)
{ {
t_node *lst; t_node *lst;
t_ast_n *ast; t_ast_n *ast;
int dio; int dio;
truncate_comment(input); truncate_comment(input);
lst = tokenize(input); lst = tokenize(input);
@@ -60,7 +60,6 @@ t_ast_n *parser(char *input, t_msh *msh)
{ {
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");
} }
free_linked_list(lst); free_linked_list(lst);
return (ast); return (ast);

View File

@@ -3,46 +3,45 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* syntax.c :+: :+: :+: */ /* syntax.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/07 12:08:53 by nalebrun #+# #+# */ /* Created: 2025/02/07 12:08:53 by nalebrun #+# #+# */
/* Updated: 2025/02/07 12:08:53 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:58:30 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../includes/parser/parsing.h" #include "../../includes/parser/parsing.h"
int only_operator(t_node *head) int only_operator(t_node *head)
{ {
if (!head->next && head->token == OPERATOR) if (!head->next && head->token == OPERATOR)
return (1); return (1);
return (0); return (0);
} }
int syntax_err_mess(char *token) int syntax_err_mess(char *token)
{ {
ft_fprintf(2, "minishell : syntax error near unexpected token `%s'\n", token); ft_fprintf(2, "minishell : syntax error near unexpected token `%s'\n",
token);
return (1); return (1);
} }
int unexpected_token(t_node *node) int unexpected_token(t_node *node)
{ {
if (!ft_strncmp(node->val, "%", 1) if (!ft_strncmp(node->val, "%", 1) || (!ft_strncmp(node->val, "&", 1)
|| (!ft_strncmp(node->val, "&", 1) && ft_strncmp(node->val, "&&", 2)) && ft_strncmp(node->val, "&&", 2)) || !ft_strncmp(node->val, ";", 1)
|| !ft_strncmp(node->val, ";", 1)
|| !ft_strncmp(node->val, "[", 1) || !ft_strncmp(node->val, "]", 1) || !ft_strncmp(node->val, "[", 1) || !ft_strncmp(node->val, "]", 1)
|| !ft_strncmp(node->val, "{", 1) || !ft_strncmp(node->val, "}", 1) || !ft_strncmp(node->val, "{", 1) || !ft_strncmp(node->val, "}", 1))
)
return (1); return (1);
return (0); return (0);
} }
int syntax_error(t_node *head) int syntax_error(t_node *head)
{ {
t_node *cpy; t_node *cpy;
if (only_operator(head)) if (only_operator(head))
return(syntax_err_mess(head->val)); return (syntax_err_mess(head->val));
cpy = head; cpy = head;
while (cpy) while (cpy)
{ {
@@ -50,6 +49,5 @@ int syntax_error(t_node *head)
return (syntax_err_mess(cpy->val)); return (syntax_err_mess(cpy->val));
cpy = cpy->next; cpy = cpy->next;
} }
return (0); return (0);
} }

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* linked_list.c :+: :+: :+: */ /* linked_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:38:49 by lderidde #+# #+# */ /* Created: 2025/01/15 13:38:49 by lderidde #+# #+# */
/* Updated: 2025/01/31 13:20:13 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:27:00 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -30,7 +30,7 @@ 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; t_node *tmp;
tmp = *head; tmp = *head;
if (!val) if (!val)

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* token_and_pres.c :+: :+: :+: */ /* token_and_pres.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/21 08:54:32 by nalebrun #+# #+# */ /* Created: 2025/01/21 08:54:32 by nalebrun #+# #+# */
/* Updated: 2025/01/21 08:54:32 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 17:26:33 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -39,22 +39,22 @@ t_token get_token(char *str)
{ {
t_token token; t_token token;
if (!ft_strncmp(str, "&", 1) || !ft_strncmp(str, "|", 1) if (!ft_strncmp(str, "&", 1) || !ft_strncmp(str, "|", 1) || !ft_strncmp(str,
|| !ft_strncmp(str, "(", 1) || !ft_strncmp(str, ")", 1) "(", 1) || !ft_strncmp(str, ")", 1) || !ft_strncmp(str, "<", 1)
|| !ft_strncmp(str, "<", 1) || !ft_strncmp(str, ">", 1)) || !ft_strncmp(str, ">", 1))
token = OPERATOR; token = OPERATOR;
else else
token = WORD; token = WORD;
return (token); return (token);
} }
t_pres get_pressision(char *s, t_token token, t_pres get_pressision(char *s, t_token token, t_token last_token,
t_token last_token, t_pres last_pres) t_pres last_pres)
{ {
if (token == OPERATOR) if (token == OPERATOR)
return (get_operator(s)); return (get_operator(s));
else if (last_token == OPERATOR && (last_pres == RED_R else if (last_token == OPERATOR && (last_pres == RED_R || last_pres == RED_L
|| last_pres == RED_L || last_pres == D_RED_R)) || last_pres == D_RED_R))
return (RED_FILE); return (RED_FILE);
else if (last_token == OPERATOR && last_pres == HEREDOC) else if (last_token == OPERATOR && last_pres == HEREDOC)
return (LIM); return (LIM);

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* tokenizer.c :+: :+: :+: */ /* tokenizer.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */ /* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */
/* Updated: 2025/01/31 13:24:28 by lderidde ### ########.fr */ /* Updated: 2025/02/07 17:26:04 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -45,7 +45,8 @@ static void set_token(t_node *head)
while (it != NULL) while (it != NULL)
{ {
it->token = get_token(it->val); it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token, last_token, last_pres); it->pressision = get_pressision(it->val, it->token, last_token,
last_pres);
last_token = it->token; last_token = it->token;
last_pres = it->pressision; last_pres = it->pressision;
it = it->next; it = it->next;

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* tokenizer_utils.c :+: :+: :+: */ /* tokenizer_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */ /* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */
/* Updated: 2025/01/22 14:24:05 by nalebrun ### ########.fr */ /* Updated: 2025/02/07 18:04:31 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -76,8 +76,6 @@ int trim_nodes(t_node *head)
if (!in_quote) if (!in_quote)
{ {
tmp = ft_strtrim(it->val, " \t\n"); tmp = ft_strtrim(it->val, " \t\n");
if (!tmp)
return (0);
free(it->val); free(it->val);
it->val = tmp; it->val = tmp;
} }