subsh redir
This commit is contained in:
@@ -70,6 +70,7 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh);
|
|||||||
// redir
|
// redir
|
||||||
t_redir get_redir(t_node *node);
|
t_redir get_redir(t_node *node);
|
||||||
void create_redir(t_node *cpy, t_ast_n *self);
|
void create_redir(t_node *cpy, t_ast_n *self);
|
||||||
|
void create_redir_subsh(t_node *head, t_ast_n *self);
|
||||||
// cmd
|
// cmd
|
||||||
void create_cmd(t_ast_n *self, t_node *lst);
|
void create_cmd(t_ast_n *self, t_node *lst);
|
||||||
// subsh
|
// subsh
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 07:38:26 by nalebrun ### ########.fr */
|
/* Updated: 2025/02/05 11:41:23 by nalebrun ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -46,23 +46,58 @@ static void add_redir(t_redir redir, t_redir **redir_list)
|
|||||||
*redir_list = tmp;
|
*redir_list = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_redir(t_node *cpy, t_ast_n *self)
|
void create_redir(t_node *head, t_ast_n *self)
|
||||||
{
|
{
|
||||||
t_redir redir;
|
t_redir redir;
|
||||||
|
|
||||||
while (cpy)
|
while (head)
|
||||||
{
|
{
|
||||||
while (cpy && get_redir(cpy) == _NR)
|
while (head && get_redir(head) == _NR)
|
||||||
cpy = cpy->next;
|
head = head->next;
|
||||||
if (!cpy)
|
if (!head)
|
||||||
break;
|
break;
|
||||||
redir = get_redir(cpy);
|
redir = get_redir(head);
|
||||||
add_redir(redir, &self->redir);
|
add_redir(redir, &self->redir);
|
||||||
add_to_tab(&self->files, cpy->next->val);
|
add_to_tab(&self->files, head->next->val);
|
||||||
cpy = cpy->next;
|
head = head->next;
|
||||||
while (cpy && cpy->next && get_redir(cpy) == _NR)
|
while (head && head->next && get_redir(head) == _NR)
|
||||||
{
|
head = head->next;
|
||||||
cpy = cpy->next;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int in_parenthesis(t_node *head)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
while (head)
|
||||||
|
{
|
||||||
|
if (head->pressision == SUBSH_S)
|
||||||
|
count += 1;
|
||||||
|
if (head->pressision == SUBSH_E)
|
||||||
|
count -= 1;
|
||||||
|
head = head->next;
|
||||||
|
}
|
||||||
|
if (count != 0)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_redir_subsh(t_node *head, t_ast_n *self)
|
||||||
|
{
|
||||||
|
t_redir redir;
|
||||||
|
|
||||||
|
while (head)
|
||||||
|
{
|
||||||
|
while (head && (get_redir(head) == _NR || in_parenthesis(head)))
|
||||||
|
head = head->next;
|
||||||
|
if (!head)
|
||||||
|
break;
|
||||||
|
redir = get_redir(head);
|
||||||
|
add_redir(redir, &self->redir);
|
||||||
|
add_to_tab(&self->files, head->next->val);
|
||||||
|
head = head->next;
|
||||||
|
while (head && head->next && get_redir(head) == _NR)
|
||||||
|
head = head->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,24 +16,34 @@ t_node *remove_parentheses(t_node *lst)
|
|||||||
{
|
{
|
||||||
t_node *it;
|
t_node *it;
|
||||||
t_node *out;
|
t_node *out;
|
||||||
|
int deepness;
|
||||||
|
|
||||||
out = NULL;
|
out = NULL;
|
||||||
it = lst;
|
it = lst;
|
||||||
if (it->pressision == SUBSH_S)
|
|
||||||
it = it->next;
|
it = it->next;
|
||||||
while (it->pressision != SUBSH_E)
|
deepness = 1;
|
||||||
|
while (1)
|
||||||
{
|
{
|
||||||
|
if (it->pressision == SUBSH_S)
|
||||||
|
deepness += 1;
|
||||||
|
if (it->pressision == SUBSH_E)
|
||||||
|
deepness -= 1;
|
||||||
|
if (deepness == 0)
|
||||||
|
break;
|
||||||
add_node_back(&out, ft_strdup(it->val), it->token, it->pressision);
|
add_node_back(&out, ft_strdup(it->val), it->token, it->pressision);
|
||||||
it = it->next;
|
it = it->next;
|
||||||
}
|
}
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh)
|
void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh)
|
||||||
{
|
{
|
||||||
t_node *cpy;
|
|
||||||
t_node *cutted;
|
t_node *cutted;
|
||||||
|
|
||||||
cutted = remove_parentheses(lst);
|
cutted = remove_parentheses(lst);
|
||||||
parent->left = create_ast_n(cutted, parent, msh);
|
self->left = create_ast_n(cutted, self, msh);
|
||||||
|
self->files = NULL;
|
||||||
|
self->redir = ft_calloc(1, sizeof(t_redir));
|
||||||
|
self->redir[0] = _NR;
|
||||||
|
create_redir_subsh(lst, self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ static int last_tok_subsh(t_node *lst)
|
|||||||
{
|
{
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
if (lst->next == NULL && !ft_strncmp(lst->val, ")", 1))
|
if ((lst->next == NULL
|
||||||
|
|| lst->next->pressision == D_RED_R
|
||||||
|
|| lst->next->pressision == RED_R)
|
||||||
|
&& !ft_strncmp(lst->val, ")", 1))
|
||||||
return (1);
|
return (1);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user