-
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.
fixing function line limit in redirections
- Loading branch information
Showing
1 changed file
with
19 additions
and
9 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/06/19 18:12:01 by simao #+# #+# */ | ||
/* Updated: 2023/08/10 13:10:15 by simao ### ########.fr */ | ||
/* Updated: 2023/08/13 00:01:55 by simao ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -37,6 +37,22 @@ t_list *check_red_after_ouput(t_list *node) | |
return (tmp); | ||
} | ||
|
||
/* | ||
- Will return the fd of outfile. | ||
- The file to open will depend on if there is tmp or not. | ||
- tmp will point to the last redirection if there are multiple. | ||
*/ | ||
int choose_file_to_open(t_list *tmp, t_list *node) | ||
{ | ||
int outfile; | ||
|
||
if (tmp) | ||
outfile = open_file(tmp->next); | ||
else | ||
outfile = open_file(node->next->next); | ||
return (outfile); | ||
} | ||
|
||
/* | ||
- Checks if there are any input redirections after the output ">". | ||
*/ | ||
|
@@ -80,10 +96,7 @@ void write_to_fd(t_list *node) | |
redirect_stdin_to_pipe(node); | ||
tmp = check_red_after_ouput(node->next); | ||
infile = ouput_to_input(node->next); | ||
if (tmp) | ||
outfile = open_file(tmp->next); | ||
else | ||
outfile = open_file(node->next->next); | ||
outfile = choose_file_to_open(tmp, node); | ||
pid = fork(); | ||
if (pid == 0) | ||
{ | ||
|
@@ -117,10 +130,7 @@ void append_to_fd(t_list *node) | |
redirect_stdin_to_pipe(node); | ||
tmp = check_red_after_ouput(node->next); | ||
infile = ouput_to_input(node->next); | ||
if (tmp) | ||
outfile = open_file(tmp->next); | ||
else | ||
outfile = open_file(node->next->next); | ||
outfile = choose_file_to_open(tmp, node); | ||
pid = fork(); | ||
if (pid == 0) | ||
{ | ||
|