with show me heredoc data

This commit is contained in:
Antoine Riard 2017-03-11 19:57:27 +01:00
parent 83f218f152
commit 2e137390be
9 changed files with 39 additions and 17 deletions

View file

@ -154,6 +154,8 @@ int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
int superflous_token(t_btree **ast, t_list **list);
int ft_show_heredoc_data(t_btree **ast);
struct s_distrostree
{
int (*test)(t_btree **ast, t_list **lst);

@ -1 +1 @@
Subproject commit 934ff3af934eaecf04575a0a7e7e1b76628ae53b
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/11 16:40:13 by jhalford ### ########.fr */
/* Updated: 2017/03/11 19:44:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,6 +33,7 @@ int process_redirect(t_process *p)
while (redirs)
{
redir = redirs->content;
DG("redirs content : %p", redirs->content);
DG("redir.type [%i]", redir->type);
DG("redir.word [%s]", redir->word);
DG("redir.n [%i]", redir->n);

View file

@ -18,7 +18,7 @@ int redirect_dless(t_redir *redir)
pipe(fds);
str = redir->heredoc_data;
DG("[%s]", str);
DG("[%s] && adr %p", str, redir);
write(fds[PIPE_WRITE], str, ft_strlen(str));
close(fds[PIPE_WRITE]);
dup2(fds[PIPE_READ], 0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/11 14:19:08 by jhalford ### ########.fr */
/* Updated: 2017/03/11 19:19:57 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/11 16:24:37 by ariard ### ########.fr */
/* Updated: 2017/03/11 19:56:53 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,6 +70,7 @@ int handle_instruction(int fd)
return (error_syntax(&token, &parser, &ast));
}
}
ft_show_heredoc_data(&ast);
btree_print(STDBUG, ast, &ft_putast);
if (ft_exec(&ast))
return (1);

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 18:41:34 by ariard ### ########.fr */
/* Updated: 2017/03/11 19:57:02 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -106,6 +106,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
t_redir redir;
t_list *temp;
if (!*ast)
gen_node(ast);
@ -118,10 +119,13 @@ int add_redir_type(t_btree **ast, t_list **lst)
redir.type = token->type;
redir.heredoc_data = NULL;
redir.word = NULL;
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
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,
ft_lstnew(&redir, sizeof(redir)));
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/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/11 18:50:14 by ariard ### ########.fr */
/* Updated: 2017/03/11 19:40:43 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ int pop_heredoc(t_list **lst)
temp = NULL;
token = (*lst)->content;
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue)
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
{
head = data_singleton()->heredoc_queue->content;
temp = data_singleton()->heredoc_queue;
@ -30,18 +30,15 @@ int pop_heredoc(t_list **lst)
if (ft_strcmp((char *)token->data, head->word) == 0)
{
temp2 = temp->next;
free(temp);
// free(temp);
data_singleton()->heredoc_queue = temp2;
DG("type is :%s", read_state(head->type));
DG("heredoc data after clear: %s", head->heredoc_data);
DG("data is %s et adr %p", head->heredoc_data, temp);
}
else
{
DG("type is :%s", read_state(head->type));
head->heredoc_data = ft_strjoin(head->heredoc_data,
token->data);
head->heredoc_data = ft_strjoin(head->heredoc_data, "\n");
DG("heredoc data + one: %s", head->heredoc_data);
}
}
ft_lstdel(lst, &token_free);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/10 14:44:52 by ariard ### ########.fr */
/* Updated: 2017/03/11 19:55:57 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -222,3 +222,20 @@ int ft_read_stack(t_sym *stack)
DG("%s", read_state(*stack--));
return (0);
}
int ft_show_heredoc_data(t_btree **ast)
{
t_astnode *node;
t_redir *redir;
if (*ast)
if ((*ast)->left)
{
node = ((*ast)->left)->item;
redir = (node->data.cmd.redir)->content;
if (redir->type == TK_DLESS)
DG("Show me heredoc data from node :%s", redir->heredoc_data);
}
return (0);
}