heredoc redirection done, looks to work OK

This commit is contained in:
Jack Halford 2017-02-15 00:13:02 +01:00
parent 3f984ad498
commit 16cfada91f
5 changed files with 34 additions and 2 deletions

View file

@ -72,6 +72,7 @@ exec/process_setexec.c\
exec/process_setgroup.c\ exec/process_setgroup.c\
exec/process_setsig.c\ exec/process_setsig.c\
exec/redirect_dgreat.c\ exec/redirect_dgreat.c\
exec/redirect_dless.c\
exec/redirect_great.c\ exec/redirect_great.c\
exec/redirect_greatand.c\ exec/redirect_greatand.c\
exec/redirect_less.c\ exec/redirect_less.c\

View file

@ -16,7 +16,7 @@ t_redirmap g_redirmap[] =
{ {
{TK_LESS, redirect_less}, {TK_LESS, redirect_less},
{TK_GREAT, redirect_great}, {TK_GREAT, redirect_great},
/* {TK_DLESS, redirect_dless}, */ {TK_DLESS, redirect_dless},
{TK_DGREAT, redirect_dgreat}, {TK_DGREAT, redirect_dgreat},
{TK_LESSAND, redirect_lessand}, {TK_LESSAND, redirect_lessand},
{TK_GREATAND, redirect_greatand}, {TK_GREATAND, redirect_greatand},

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect_dless.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
/* Updated: 2017/02/07 16:05:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int redirect_dless(t_redir *redir)
{
int fds[2];
char *str;
pipe(fds);
str = redir->word.word;
write(fds[PIPE_WRITE], str, ft_strlen(str));
close(fds[PIPE_WRITE]);
dup2(fds[PIPE_READ], 0);
close(fds[PIPE_READ]);
return (0);
}

View file

@ -30,6 +30,9 @@ int lexer_dless(t_list **alst, t_lexer *lexer)
pop(&lexer->heredoc_stack); pop(&lexer->heredoc_stack);
while (lexer->str[++lexer->pos]) while (lexer->str[++lexer->pos])
; ;
ft_strappend(&lexer->str, (char[]){'\n', 0});
lexer->pos++;
return (0);
} }
else else
while (lexer->str[lexer->pos]) while (lexer->str[lexer->pos])

View file

@ -26,7 +26,8 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst)
next_tok = (*lst)->next->content; next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD) if (next_tok->type != TK_WORD)
return (1); return (1);
node->data.redir.word.word = ft_strdup(next_tok->data); node->data.redir.word.word = ft_strdup(tok->data);
node->data.redir.n = 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start); ft_parse(&(*ast)->left, start);