heredoc changes
This commit is contained in:
parent
163c93c0c2
commit
6b78971807
8 changed files with 48 additions and 41 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 14:47:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 16:02:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -62,6 +62,7 @@ int handle_instruction(int fd)
|
|||
if (parser.state == ERROR)
|
||||
error_syntax(&token, &parser, &ast);
|
||||
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
||||
DG("lexer.state=%i", lexer.state);
|
||||
if (lexer.state)
|
||||
continue;
|
||||
else if (parser.state == SUCCESS)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 13:06:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 16:11:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ int add_redir_word(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
t_token *token;
|
||||
t_redir *redir;
|
||||
t_redir *temp;
|
||||
/* t_redir *temp; */
|
||||
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
|
|
@ -73,11 +73,12 @@ int add_redir_word(t_btree **ast, t_list **lst)
|
|||
{
|
||||
redir = (ft_lstlast(node->data.cmd.redir))->content;
|
||||
redir->word = ft_strdup(token->data);
|
||||
if (redir->type == TK_DLESS)
|
||||
{
|
||||
temp = ft_lstlast((data_singleton()->heredoc_queue))->content;
|
||||
temp->word = redir->word;
|
||||
}
|
||||
/* DG("redir1 @ %p word=[%s]", redir, redir->word); */
|
||||
/* if (redir->type == TK_DLESS) */
|
||||
/* { */
|
||||
/* temp = ft_lstlast((data_singleton()->heredoc_queue))->content; */
|
||||
/* temp->word = redir->word; */
|
||||
/* } */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -101,31 +102,40 @@ static int add_redir_type_number(t_btree **ast, t_list **lst)
|
|||
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);
|
||||
}
|
||||
|
||||
int add_redir_type(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
t_redir redir;
|
||||
t_list *temp;
|
||||
t_list *redir_lst;
|
||||
t_list **queue;
|
||||
|
||||
queue = &data_singleton()->heredoc_queue;
|
||||
if (!*ast)
|
||||
gen_node(ast);
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if (!(node->type == TK_IO_NUMBER))
|
||||
{
|
||||
redir.n = (token->type == TK_LESS || token->type == TK_DLESS
|
||||
|| token->type == TK_LESSAND) ? STDIN : STDOUT;
|
||||
redir.type = token->type;
|
||||
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);
|
||||
redir_init(token->type, &redir);
|
||||
redir_lst = ft_lstnew(&redir, sizeof(redir));
|
||||
ft_lsteadd(&node->data.cmd.redir, redir_lst);
|
||||
/* DG("redir1 @ %p word=[%s]", redir_lst->content, ((t_redir*)redir_lst->content)->word); */
|
||||
if (token->type == TK_DLESS)
|
||||
ft_lsteadd(&data_singleton()->heredoc_queue, temp);
|
||||
DG("adr is %p", data_singleton()->heredoc_queue);
|
||||
{
|
||||
ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*)));
|
||||
/* DG("redir2 @ %p word=[%s]", *(t_redir**)(*queue)->content, (*(t_redir**)(*queue)->content)->word); */
|
||||
}
|
||||
}
|
||||
else
|
||||
add_redir_type_number(ast, lst);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 14:01:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 16:10:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,31 +15,27 @@
|
|||
int pop_heredoc(t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
t_list *temp;
|
||||
t_list *temp2;
|
||||
t_redir *head;
|
||||
t_list **head;
|
||||
t_redir *redir;
|
||||
|
||||
temp = NULL;
|
||||
token = (*lst)->content;
|
||||
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
|
||||
{
|
||||
head = data_singleton()->heredoc_queue->content;
|
||||
temp = data_singleton()->heredoc_queue;
|
||||
head = &data_singleton()->heredoc_queue;
|
||||
redir = *(t_redir**)(*head)->content;
|
||||
if (head && token)
|
||||
{
|
||||
if (ft_strcmp((char *)token->data, head->word) == 0)
|
||||
/* DG("comparing w/ input [%s], head @ %p", token->data, *head); */
|
||||
/* DG("redir1 @ %p word=[%s]", redir, redir->word); */
|
||||
if (ft_strcmp((char *)token->data, redir->word) == 0)
|
||||
{
|
||||
temp2 = temp->next;
|
||||
// free(temp);
|
||||
data_singleton()->heredoc_queue = temp2;
|
||||
DG("data is %s et adr %p", head->heredoc_data, head->heredoc_data);
|
||||
DG("redir @ %p", head);
|
||||
ft_lst_delif(head, (t_redir**)(*head)->content, ft_addrcmp, ft_lst_cfree);
|
||||
/* DG("matched heredoc EOF, new head @ %p", *head); */
|
||||
}
|
||||
else
|
||||
{
|
||||
head->heredoc_data = ft_strjoin(head->heredoc_data,
|
||||
token->data);
|
||||
head->heredoc_data = ft_strjoin(head->heredoc_data, "\n");
|
||||
redir->heredoc_data = ft_str3join(redir->heredoc_data,
|
||||
(char*)token->data, "\n");
|
||||
}
|
||||
}
|
||||
ft_lstdel(lst, &token_free);
|
||||
|
|
|
|||
Loading…
Reference in a new issue