-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
heredoc handles input "cat << END < Makefile > outfile"
- Loading branch information
Showing
3 changed files
with
19 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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)) | ||
{ | ||
|
@@ -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]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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) | ||
|
@@ -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) | ||
|