Browse Source

[mod] redirection: organize f() and clarify they names.

Moul 2 years ago
parent
commit
2c95435b65
3 changed files with 23 additions and 23 deletions
  1. 2 2
      src/pipe_exec.c
  2. 19 19
      src/redirect.c
  3. 2 2
      src/sh.h

+ 2 - 2
src/pipe_exec.c

@@ -17,7 +17,7 @@ void	launch_pipes(t_e *e, t_pipe *p, t_pipe_redir **t)
 			p->cmd_opt[p->i] = cmd_splitting(e, t[p->i]->itxt, ' ');
 			remove_cotes(p->cmd_opt[p->i]);
 		}
-		open_redirections(e, p, t[p->i]);
+		open_left_redirections(e, p, t[p->i]);
 		if (ft_strcmp(t[p->i]->operator, "<<") != 0)
 			handle_multi_piping(e, p, t[p->i]);
 		if (ft_strstr(t[p->i]->operator, ">") == NULL)
@@ -79,7 +79,7 @@ void	handle_multi_piping(t_e *e, t_pipe *p, t_pipe_redir *t)
 void	inside_pipe(t_e *e, t_pipe *p, t_pipe_redir *t)
 {
 	if (ft_strstr(t->operator, ">") != NULL)
-		right_redirections(e, p, t);
+		open_right_redirections(e, p, t);
 	if (t->itxt != NULL)
 		manage_cmd_2(e, p->cmd_opt[p->i]);
 	if (ft_strstr(t->operator, ">") != NULL)

+ 19 - 19
src/redirect.c

@@ -7,7 +7,7 @@
 ** if > or >>: dup STDERR or STDOUT in to STDIN
 */
 
-void	open_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
+void	open_left_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
 {
 	if (t->operator[0] == '|')
 		return ;
@@ -23,30 +23,13 @@ void	open_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
 }
 
 /*
-** if != <<: close fd, restore stdfd
-*/
-
-void	close_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
-{
-	if (ft_strcmp(t->operator, "<<") != 0 && t->operator[0] != '|')
-	{
-		close(p->fd[p->i][0]);
-		if (ft_strcmp(t->operator, "<") != 0)
-			t->ifd == '2' ? close(STDERR) : close(STDOUT);
-		else
-			close(0);
-		dup(p->fd[p->i][1]);
-	}
-}
-
-/*
 ** for file writting: open, append or trunc
 ** for fd redirecting: ofd: output fd: dup ofd
 ** for '>&-': open '/dev/null'
 ** save stdfd, dup new fd in STDIN
 */
 
-void	right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
+void	open_right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
 {
 	int		fd_file;
 
@@ -66,3 +49,20 @@ void	right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
 			dup2(t->ifd, t->ofd);
 	}
 }
+
+/*
+** if != <<: close fd, restore stdfd
+*/
+
+void	close_redirections(t_e *e, t_pipe *p, t_pipe_redir *t)
+{
+	if (ft_strcmp(t->operator, "<<") != 0 && t->operator[0] != '|')
+	{
+		close(p->fd[p->i][0]);
+		if (ft_strcmp(t->operator, "<") != 0)
+			t->ifd == '2' ? close(STDERR) : close(STDOUT);
+		else
+			close(0);
+		dup(p->fd[p->i][1]);
+	}
+}

+ 2 - 2
src/sh.h

@@ -58,9 +58,9 @@ void	remove_cotes(char **cmd);
 /*
 ** redirect.c
 */
-void	open_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
+void	open_left_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
+void	open_right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
 void	close_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
-void	right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
 /*
 ** heredoc.c
 */