Browse Source

fix: heredocs

master
narnaud 3 years ago
parent
commit
72e3243c21
  1. 2
      minishell.c
  2. 13
      parser.c

2
minishell.c

@ -41,9 +41,9 @@ int caller(t_command *cmd)
close(cmd->fd[1]);
if (cmd->next)
return (caller(cmd->next));
waitpid(pid, &status, 0);
if (cmd->fd[0])
close(cmd->fd[0]);
waitpid(pid, &status, 0);
return (1);
}

13
parser.c

@ -12,18 +12,22 @@
#include "minishell.h"
void push_heredoc(char *str, int fd)
int push_heredoc(char *str)
{
char *line;
int pip[2];
pipe(pip);
while(1)
{
line = readline(">");
if (!ft_strncmp(line, str, ft_strlen(str) + 1))
break;
ft_putstr_fd(line, fd);
write(fd, "\n", 1);
ft_putstr_fd(line, pip[1]);
write(pip[1], "\n", 1);
}
close(pip[1]);
return (pip[0]);
}
size_t count_arguments(t_token *tok)
@ -64,8 +68,7 @@ void update_redir(t_command *cmd, t_token *tok)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = 0;
cmd->heredoc = tok->value;
cmd->fd[0] = push_heredoc(tok->value);
}
}

Loading…
Cancel
Save