Skip to content

Commit

Permalink
heredoc handles input "cat << END < Makefile > outfile"
Browse files Browse the repository at this point in the history
  • Loading branch information
izzypt committed Aug 12, 2023
1 parent 3f1d589 commit 8715750
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions executor/command_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: simao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/03 23:14:14 by simao #+# #+# */
/* Updated: 2023/08/12 20:24:05 by simao ### ########.fr */
/* Updated: 2023/08/12 22:40:12 by simao ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -63,7 +63,7 @@ t_list *handle_heredoc(t_list *curr)
get_hdoc()->command = curr;
heredoc(curr->next);
curr = curr->next;
while (its_heredoc(curr->next->next) || its_output(curr->next->next))
while (its_heredoc(curr->next->next) || its_output(curr->next->next) || its_input(curr->next->next))
curr = curr->next->next;
printf("command chain current node after heredoc: %s\n", curr->token[0]);
printf("command chain current next node after heredoc: %s\n", curr->next->token[0]);
Expand Down
19 changes: 14 additions & 5 deletions executor/heredoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: simao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/21 18:41:23 by esali #+# #+# */
/* Updated: 2023/08/12 20:39:08 by simao ### ########.fr */
/* Updated: 2023/08/12 23:01:03 by simao ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -47,10 +47,7 @@ void exec_heredoc(t_list *cur)
if (its_a_pipe(cur->next->next))
heredoc_to_pipe(cur);
if (its_output(cur->next->next))
{
ft_printf("CAlling heredoc_to_fd\n");
heredoc_to_fd(cur);
}
if (its_append(cur->next->next))
heredoc_to_append(cur);
}
Expand Down Expand Up @@ -88,7 +85,7 @@ void heredoc(t_list *cur)
return ;
}
write_heredoc(cur, new_line, hdoc->fd);
while (its_heredoc(cur->next->next))
while (its_heredoc(cur->next->next) || its_input(cur->next->next))
{
if (its_heredoc(cur->next->next))
{
Expand All @@ -97,6 +94,18 @@ void heredoc(t_list *cur)
unlink(cur->next->token[0]);
return ;
}
else if (its_input(cur->next->next))
{
if (access(cur->next->next->next->token[0], R_OK) == -1)
{
write(2, "no such file or dir\n", 42);
printf("failed acess to %s\n", cur->next->next->next->token[0]);
get_data()->exit = 1;
return ;
}
else
cur = cur->next->next;
}
}
close(hdoc->fd);
ft_printf("execing heredoc with current node: %s\n", cur->token[0]);
Expand Down
6 changes: 3 additions & 3 deletions executor/heredoc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: simao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 13:44:58 by esali #+# #+# */
/* Updated: 2023/08/12 22:12:16 by simao ### ########.fr */
/* Updated: 2023/08/12 23:01:38 by simao ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,7 +31,7 @@ void write_to_command(t_list *cur)
if (WIFEXITED(status))
get_data()->exit = WEXITSTATUS(status);
dup2(get_pipe()->stdin, STDIN_FILENO);
unlink(cur->next->token[0]);
//unlink(cur->next->token[0]);
}

void heredoc_to_pipe(t_list *cur)
Expand Down Expand Up @@ -88,7 +88,7 @@ void heredoc_to_fd(t_list *cur)
get_data()->exit = WEXITSTATUS(status);
close(in);
close(outfile);
unlink(tmp->next->token[0]);
//unlink(tmp->next->token[0]);
}

void heredoc_to_append(t_list *cur)
Expand Down

0 comments on commit 8715750

Please sign in to comment.