Compare commits
No commits in common. "f5940ee99e6c92099569a26d13bd5a63e913a052" and "08261b192186b30ad54f2b0188520ed93e71b53f" have entirely different histories.
f5940ee99e
...
08261b1921
@ -11,6 +11,7 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "execution_private.h"
|
||||
#include <unistd.h>
|
||||
|
||||
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
{
|
||||
@ -41,7 +42,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
return (return_code);
|
||||
}
|
||||
|
||||
static bool ft_executor(t_cmd *cmd, char **env, int fd)
|
||||
static bool ft_executor(t_cmd *cmd, char **env)
|
||||
{
|
||||
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
|
||||
return (0);
|
||||
@ -50,14 +51,12 @@ static bool ft_executor(t_cmd *cmd, char **env, int fd)
|
||||
return (1);
|
||||
if (cmd->pid == 0)
|
||||
{
|
||||
/* if (cmd->fd_in[1] != -1) */
|
||||
/* dup2(cmd->fd_in[1], 0); */
|
||||
/* if (cmd->fd_out[1] != -1) */
|
||||
/* dup2(cmd->fd_out[1], 1); */
|
||||
if (cmd->fd_in[1] != -1)
|
||||
dup2(cmd->fd_in[1], 0);
|
||||
if (cmd->fd_out[1] != -1)
|
||||
dup2(cmd->fd_out[1], 1);
|
||||
dup2(cmd->fd_in[0], 0);
|
||||
dup2(cmd->fd_out[0], 1);
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
execve(cmd->executable, cmd->args, env);
|
||||
@ -67,7 +66,7 @@ static bool ft_executor(t_cmd *cmd, char **env, int fd)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
||||
static int ft_cmd_executor(t_data *data, t_cmd *cmd)
|
||||
{
|
||||
int exit_code;
|
||||
char **env;
|
||||
@ -75,8 +74,6 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
||||
if (cmd->own_cmd == 1)
|
||||
{
|
||||
exit_code = ft_own_cmd(data, cmd);
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
if (exit_code == -1)
|
||||
return (1);
|
||||
}
|
||||
@ -85,9 +82,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
||||
env = env_to_strs(data->env);
|
||||
if (env == NULL)
|
||||
return (1);
|
||||
exit_code = ft_executor(cmd, env, fd);
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
exit_code = ft_executor(cmd, env);
|
||||
ft_freer_tab_ultimate(1, env);
|
||||
if (exit_code == 1)
|
||||
return (1);
|
||||
@ -107,8 +102,6 @@ int ft_cmds_executor(t_data *data)
|
||||
while (current != NULL)
|
||||
{
|
||||
content = current->content;
|
||||
fds[0] = -1;
|
||||
fds[1] = -1;
|
||||
if (current->next != NULL)
|
||||
{
|
||||
if (pipe(fds) == -1)
|
||||
@ -116,8 +109,10 @@ int ft_cmds_executor(t_data *data)
|
||||
ft_add_fd(content->fd_out, fds[1]);
|
||||
ft_add_fd(((t_cmd *) (current->next->content))->fd_in, fds[0]);
|
||||
}
|
||||
if (ft_cmd_executor(data, content, fds[0]))
|
||||
if (ft_cmd_executor(data, content))
|
||||
return (1);
|
||||
ft_closer(content->fd_in);
|
||||
ft_closer(content->fd_out);
|
||||
current = current->next;
|
||||
}
|
||||
return (0);
|
||||
|
@ -24,10 +24,8 @@ static char *ft_spacer_after(const char *str)
|
||||
i = 1;
|
||||
while (out[i] != '\0')
|
||||
{
|
||||
while (ft_is_in_quote(out, i - 1))
|
||||
while (ft_is_in_quote(out, i))
|
||||
i++;
|
||||
if (out[i] == '\0')
|
||||
break ;
|
||||
if (ft_is_in("><|", out[i - 1]))
|
||||
{
|
||||
while (out[i] == out[i - 1])
|
||||
@ -58,8 +56,6 @@ static char *ft_spacer_before(const char *str)
|
||||
{
|
||||
while (ft_is_in_quote(out, i))
|
||||
i++;
|
||||
if (out[i] == '\0')
|
||||
break ;
|
||||
if (ft_is_in("><|", out[i + 1]))
|
||||
{
|
||||
while (out[i] == ' ')
|
||||
@ -87,8 +83,6 @@ static void ft_space_simplifier(char *str)
|
||||
{
|
||||
if (ft_is_in_quote(str, i))
|
||||
i++;
|
||||
if (str[i] != '\0')
|
||||
break ;
|
||||
y = 0;
|
||||
while (str[y + i] == ' ')
|
||||
y++;
|
||||
|
@ -84,7 +84,7 @@ static int ft_special_char_dub(const char *str)
|
||||
}
|
||||
i = i + y;
|
||||
}
|
||||
else if (str[i] != '\0')
|
||||
else
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
|
@ -1,18 +1,11 @@
|
||||
#include "./utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void ft_closer(int fds[2])
|
||||
{
|
||||
if (fds[0] > 2)
|
||||
{
|
||||
//dprintf(2, "close(%d)\n", fds[0]);
|
||||
close(fds[0]);
|
||||
}
|
||||
if (fds[1] > 2)
|
||||
{
|
||||
//dprintf(2, "close(%d)\n", fds[1]);
|
||||
close(fds[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void ft_add_fd(int fds[2], int fd)
|
||||
|
@ -14,32 +14,26 @@
|
||||
|
||||
int ft_is_in_quote(const char *str, size_t n)
|
||||
{
|
||||
size_t double_quoted;
|
||||
size_t simple_quoted;
|
||||
size_t i;
|
||||
|
||||
double_quoted = 0;
|
||||
simple_quoted = 0;
|
||||
i = 0;
|
||||
while (str[i] != '\0' && i < n)
|
||||
{
|
||||
if (str[i] == '\'')
|
||||
{
|
||||
i++;
|
||||
while (str[i] != '\'' && str[i] != '\0')
|
||||
{
|
||||
if (i == n)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (str[i] == '"')
|
||||
{
|
||||
i++;
|
||||
while (str[i] != '"' && str[i] != '\0')
|
||||
{
|
||||
if (i == n)
|
||||
return (2);
|
||||
i++;
|
||||
}
|
||||
if (simple_quoted == 0)
|
||||
double_quoted = !double_quoted;
|
||||
}
|
||||
else if (str[i] == '\'')
|
||||
{
|
||||
if (double_quoted == 0)
|
||||
simple_quoted = !simple_quoted;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
return (simple_quoted + double_quoted * 2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user