subsh redir

This commit is contained in:
gazhonsepaskwa
2025-02-05 13:44:43 +01:00
parent 001b4b67e2
commit 2369795bd2
4 changed files with 69 additions and 20 deletions

View File

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
void create_redir(t_node *cpy, t_ast_n *self)
void create_redir(t_node *head, t_ast_n *self)
{
t_redir redir;
while (cpy)
while (head)
{
while (cpy && get_redir(cpy) == _NR)
cpy = cpy->next;
if (!cpy)
while (head && get_redir(head) == _NR)
head = head->next;
if (!head)
break;
redir = get_redir(cpy);
redir = get_redir(head);
add_redir(redir, &self->redir);
add_to_tab(&self->files, cpy->next->val);
cpy = cpy->next;
while (cpy && cpy->next && get_redir(cpy) == _NR)
{
cpy = cpy->next;
}
add_to_tab(&self->files, head->next->val);
head = head->next;
while (head && head->next && get_redir(head) == _NR)
head = head->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;
}
}