heredoc + subshell correction

This commit is contained in:
Antoine Riard 2017-03-13 15:01:54 +01:00
parent 5c6abae6dc
commit 484621f786
7 changed files with 27 additions and 28 deletions

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/11 20:07:57 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:37:18 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/03/11 15:44:47 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:23:53 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
/* Updated: 2017/03/11 16:45:07 by ariard ### ########.fr */
/* Updated: 2017/03/13 15:01:22 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,7 +38,6 @@ int add_ionumber(t_btree **ast, t_list **lst)
t_token *token;
t_redir redir;
DG("add io_number");
if (!*ast)
gen_node(ast);
token = (*lst)->content;
@ -46,6 +45,8 @@ int add_ionumber(t_btree **ast, t_list **lst)
node->cache = node->type;
node->type = token->type;
redir.n = ft_atoi(token->data);
redir.word = NULL;
redir.heredoc_data = NULL;
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/11 20:36:19 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:58:13 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -68,39 +68,41 @@ int add_redir_word(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
t_redir *redir;
t_redir *temp;
t_redir *other;
token = (*lst)->content;
node = (*ast)->item;
other = NULL;
if (node->data.cmd.redir)
{
redir = (ft_lstlast(node->data.cmd.redir))->content;
redir->word = ft_strdup(token->data);
if (redir->type == TK_DLESS)
if (TK_DLESS)
{
temp = ft_lstlast((data_singleton()->heredoc_queue))->content;
temp->word = redir->word;
DG();
other = ft_lstlast(data_singleton()->heredoc_queue)->content;
DG();
DG("type is %s", read_state(other->type));
DG("word is %s", other->word);
}
}
}
return (0);
}
static int add_redir_type_number(t_btree **ast, t_list **lst)
{
t_redir *temp;
t_redir *temp_heredoc;
// t_redir *temp_heredoc;
t_astnode *node;
t_token *token;
DG();
token = (*lst)->content;
node = (*ast)->item;
temp = (ft_lstlast(node->data.cmd.redir))->content;
temp->type = token->type;
if (token->type == TK_DLESS)
{
temp_heredoc = data_singleton()->heredoc_queue->content;
temp_heredoc->n = temp->n;
}
ft_lsteadd(&data_singleton()->heredoc_queue, ft_lstlast(node->data.cmd.redir));
return (0);
}
@ -123,12 +125,9 @@ int add_redir_type(t_btree **ast, t_list **lst)
redir.heredoc_data = NULL;
redir.word = NULL;
temp = ft_lstnew(&redir, sizeof(redir));
DG("adr is %p", temp);
ft_lsteadd(&node->data.cmd.redir, temp);
DG("adr is %p", node->data.cmd.redir);
if (token->type == TK_DLESS)
ft_lsteadd(&data_singleton()->heredoc_queue, temp);
DG("adr is %p", data_singleton()->heredoc_queue);
}
else
add_redir_type_number(ast, lst);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 by ariard #+# #+# */
/* Updated: 2017/03/11 15:56:12 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:25:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,10 @@ int issubshell(t_btree **ast, t_list **lst)
if (*ast)
{
node = (*ast)->item;
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP || node->type == TK_PIPE)
&& issubshell(&(*ast)->right, lst) == 1)
return (1);
if (node->type == SUBSHELL && node->full == 0)
return (1);
if (node->type == TK_LBRACE && node->full == 0)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/11 16:08:26 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:37:11 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -78,6 +78,7 @@ int build_tree(t_btree **ast, t_list **lst)
{
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
{
DG("build %s", read_state(g_treematch[i].type));
cache = token->type;
return (g_treematch[i].add(ast, lst));
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/11 20:01:42 by ariard ### ########.fr */
/* Updated: 2017/03/13 14:58:27 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,6 @@ int pop_heredoc(t_list **lst)
{
t_token *token;
t_list *temp;
t_list *temp2;
t_redir *head;
temp = NULL;
@ -28,12 +27,7 @@ int pop_heredoc(t_list **lst)
if (head && token)
{
if (ft_strcmp((char *)token->data, head->word) == 0)
{
temp2 = temp->next;
// free(temp);
data_singleton()->heredoc_queue = temp2;
DG("data is %s et adr %p", head->heredoc_data, temp);
}
data_singleton()->heredoc_queue = temp->next;
else
{
head->heredoc_data = ft_strjoin(head->heredoc_data,