pipe ok with control flow
This commit is contained in:
commit
1a8f32286d
12 changed files with 50 additions and 37 deletions
|
|
@ -111,6 +111,7 @@ int add_branch(t_btree **ast, t_list **lst);
|
||||||
int add_redir_word(t_btree **ast, t_list **lst);
|
int add_redir_word(t_btree **ast, t_list **lst);
|
||||||
int add_redir_type(t_btree **ast, t_list **lst);
|
int add_redir_type(t_btree **ast, t_list **lst);
|
||||||
int add_redir_condition(t_btree **ast, t_list **lst);
|
int add_redir_condition(t_btree **ast, t_list **lst);
|
||||||
|
int redir_init(t_type type, t_redir *redir);
|
||||||
int add_case_cmd(t_btree **ast, t_list **lst);
|
int add_case_cmd(t_btree **ast, t_list **lst);
|
||||||
int add_case_sep(t_btree **ast, t_list **lst);
|
int add_case_sep(t_btree **ast, t_list **lst);
|
||||||
int add_pattern(t_btree **ast, t_list **lst);
|
int add_pattern(t_btree **ast, t_list **lst);
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6
|
Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 14:47:29 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 14:52:53 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,9 @@ int redirect_dless(t_redir *redir)
|
||||||
|
|
||||||
pipe(fds);
|
pipe(fds);
|
||||||
str = redir->heredoc_data;
|
str = redir->heredoc_data;
|
||||||
DG("[%s] && adr %p", str, str);
|
|
||||||
DG("redir @ %p", redir);
|
|
||||||
write(fds[PIPE_WRITE], str, ft_strlen(str));
|
write(fds[PIPE_WRITE], str, ft_strlen(str));
|
||||||
close(fds[PIPE_WRITE]);
|
close(fds[PIPE_WRITE]);
|
||||||
dup2(fds[PIPE_READ], 0);
|
dup2(fds[PIPE_READ], redir->n);
|
||||||
close(fds[PIPE_READ]);
|
close(fds[PIPE_READ]);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/11 14:17:06 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 14:53:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 13:22:22 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 15:29:09 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 14:29:15 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 15:41:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 13:21:55 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 15:41:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 16:36:42 by ariard ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -62,6 +61,7 @@ int handle_instruction(int fd)
|
||||||
if (parser.state == ERROR)
|
if (parser.state == ERROR)
|
||||||
error_syntax(&token, &parser, &ast);
|
error_syntax(&token, &parser, &ast);
|
||||||
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
||||||
|
DG("lexer.state=%i", lexer.state);
|
||||||
if (lexer.state)
|
if (lexer.state)
|
||||||
continue;
|
continue;
|
||||||
else if (parser.state == SUCCESS)
|
else if (parser.state == SUCCESS)
|
||||||
|
|
@ -76,7 +76,7 @@ int handle_instruction(int fd)
|
||||||
// if (ft_exec(&ast))
|
// if (ft_exec(&ast))
|
||||||
// return (1);
|
// return (1);
|
||||||
instruction_free(&token, &parser, &ast);
|
instruction_free(&token, &parser, &ast);
|
||||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
|
||||||
ft_add_str_in_history(lexer.str);
|
ft_add_str_in_history(lexer.str);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 15:57:10 by ariard ### ########.fr */
|
/* Updated: 2017/03/13 16:58:33 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -44,9 +44,8 @@ int add_ionumber(t_btree **ast, t_list **lst)
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
node->cache = node->type;
|
node->cache = node->type;
|
||||||
node->type = token->type;
|
node->type = token->type;
|
||||||
|
redir_init(token->type, &redir);
|
||||||
redir.n = ft_atoi(token->data);
|
redir.n = ft_atoi(token->data);
|
||||||
redir.word = NULL;
|
|
||||||
redir.heredoc_data = NULL;
|
|
||||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 15:56:25 by ariard ### ########.fr */
|
/* Updated: 2017/03/13 16:57:59 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -84,14 +84,27 @@ static int add_redir_type_number(t_btree **ast, t_list **lst)
|
||||||
t_redir *redir;
|
t_redir *redir;
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
t_list **queue;
|
||||||
|
t_list *redir_lst;
|
||||||
|
|
||||||
DG();
|
queue = &data_singleton()->heredoc_queue;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
redir = (ft_lstlast(node->data.cmd.redir))->content;
|
redir_lst = ft_lstlast(node->data.cmd.redir);
|
||||||
|
redir = redir_lst->content;
|
||||||
redir->type = token->type;
|
redir->type = token->type;
|
||||||
if (token->type == TK_DLESS)
|
if (token->type == TK_DLESS)
|
||||||
ft_lsteadd(&data_singleton()->heredoc_queue, ft_lstlast(node->data.cmd.redir));
|
ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*)));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int redir_init(t_type type, t_redir *redir)
|
||||||
|
{
|
||||||
|
redir->n = (type == TK_LESS || type == TK_DLESS
|
||||||
|
|| type == TK_LESSAND) ? STDIN : STDOUT;
|
||||||
|
redir->type = type;
|
||||||
|
redir->heredoc_data = NULL;
|
||||||
|
redir->word = NULL;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,23 +113,21 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_redir redir;
|
t_redir redir;
|
||||||
t_list *temp;
|
t_list *redir_lst;
|
||||||
|
t_list **queue;
|
||||||
|
|
||||||
|
queue = &data_singleton()->heredoc_queue;
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if (!(node->type == TK_IO_NUMBER))
|
if (!(node->type == TK_IO_NUMBER))
|
||||||
{
|
{
|
||||||
redir.n = (token->type == TK_LESS || token->type == TK_DLESS
|
redir_init(token->type, &redir);
|
||||||
|| token->type == TK_LESSAND) ? STDIN : STDOUT;
|
redir_lst = ft_lstnew(&redir, sizeof(redir));
|
||||||
redir.type = token->type;
|
ft_lsteadd(&node->data.cmd.redir, redir_lst);
|
||||||
redir.heredoc_data = NULL;
|
|
||||||
redir.word = NULL;
|
|
||||||
temp = ft_lstnew(&redir, sizeof(redir));
|
|
||||||
ft_lsteadd(&node->data.cmd.redir, temp);
|
|
||||||
if (token->type == TK_DLESS)
|
if (token->type == TK_DLESS)
|
||||||
ft_lsteadd(&data_singleton()->heredoc_queue, temp);
|
ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
add_redir_type_number(ast, lst);
|
add_redir_type_number(ast, lst);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/13 16:57:08 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,24 +15,27 @@
|
||||||
int pop_heredoc(t_list **lst)
|
int pop_heredoc(t_list **lst)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_list *temp;
|
t_list **head;
|
||||||
t_redir *head;
|
t_redir *redir;
|
||||||
|
|
||||||
temp = NULL;
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
|
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
|
||||||
{
|
{
|
||||||
temp = data_singleton()->heredoc_queue;
|
head = &data_singleton()->heredoc_queue;
|
||||||
head = temp->content;
|
redir = *(t_redir**)(*head)->content;
|
||||||
if (head && token)
|
if (head && token)
|
||||||
{
|
{
|
||||||
if (ft_strcmp((char *)token->data, head->word) == 0)
|
/* DG("comparing w/ input [%s], head @ %p", token->data, *head); */
|
||||||
ft_lst_removeif(&data_singleton()->heredoc_queue, temp->content, &ft_addrcmp);
|
/* DG("redir1 @ %p word=[%s]", redir, redir->word); */
|
||||||
|
if (ft_strcmp((char *)token->data, redir->word) == 0)
|
||||||
|
{
|
||||||
|
ft_lst_delif(head, (t_redir**)(*head)->content, ft_addrcmp, ft_lst_cfree);
|
||||||
|
/* DG("matched heredoc EOF, new head @ %p", *head); */
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
head->heredoc_data = ft_strjoin(head->heredoc_data,
|
redir->heredoc_data = ft_str3join(redir->heredoc_data,
|
||||||
token->data);
|
(char*)token->data, "\n");
|
||||||
head->heredoc_data = ft_strjoin(head->heredoc_data, "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ft_lstdel(lst, &token_free);
|
ft_lstdel(lst, &token_free);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue