Skip to content

Commit

Permalink
fixing function line limit in redirections
Browse files Browse the repository at this point in the history
  • Loading branch information
izzypt committed Aug 12, 2023
1 parent 133eb76 commit f2ed131
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions executor/redirections.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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 ">".
*/
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit f2ed131

Please sign in to comment.