WIP exec_cmd_line()

+ fix error handle in redirections()
+ rename ft_free_cmd_arr() to free_pipeline()
+ "char **path" added to "struct t_all"
+ misc
This commit is contained in:
LuckyLaszlo
2021-11-16 08:49:57 +01:00
parent bb77de0588
commit 140549db00
11 changed files with 239 additions and 51 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
/* Updated: 2021/11/14 10:13:38 by lperrey ### ########.fr */
/* Updated: 2021/11/16 03:45:15 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -63,7 +63,7 @@ int token_expansions(t_token **t)
if (!tmp_split)
return (0);
// 4
tmp = ft_dup_2d_arr(tmp_split, (t_dup_func)ft_strdup_quotes);
tmp = ft_dup_2d_arr(tmp_split, (t_dup_f)ft_strdup_quotes);
ft_free_2d_arr(tmp_split);
tmp_split = tmp;
if (!tmp_split)

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
/* Updated: 2021/11/14 12:53:40 by lperrey ### ########.fr */
/* Updated: 2021/11/16 08:02:56 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -79,11 +79,11 @@ t_cmd **parsing(t_token *token_list)
// 2.9.1 - 3) Redirection
if (!redirections(token_list, cmd_arr))
return (ft_retp_free(NULL, cmd_arr, (void(*)(void *))ft_free_cmd_arr));
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
// Struct CMD fill
if (!cmd_array_fill_argv(token_list, cmd_arr))
return (ft_retp_free(NULL, cmd_arr, (void(*)(void *))ft_free_cmd_arr));
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
print_cmd_array(cmd_arr);
// HUGO WIP

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
/* Updated: 2021/11/14 10:04:21 by lperrey ### ########.fr */
/* Updated: 2021/11/16 08:08:18 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,15 +24,18 @@ int redirections(t_token *t, t_cmd **cmd_arr)
i = 0;
while (t)
{
if (t->id == '<' || t->id == T_DLESS)
if (cmd_arr[i]->pid == 0) // Pid var as error mark, WIP
{
if (!redirect_cmd_input(t, cmd_arr[i]))
return (0);
}
else if (t->id == '>' || t->id == T_DGREAT)
{
if (!redirect_cmd_output(t, cmd_arr[i]))
return (0);
if (t->id == '<' || t->id == T_DLESS)
{
if (!redirect_cmd_input(t, cmd_arr[i]))
return (0);
}
else if (t->id == '>' || t->id == T_DGREAT)
{
if (!redirect_cmd_output(t, cmd_arr[i]))
return (0);
}
}
else if (t->id == '|')
i++;
@@ -43,7 +46,7 @@ int redirections(t_token *t, t_cmd **cmd_arr)
static int redirect_cmd_input(t_token *t, t_cmd *cmd)
{
if (cmd->fd_in != STDIN_FILENO && cmd->fd_in > 0)
if (cmd->fd_in != STDIN_FILENO)
if (close(cmd->fd_in) == -1)
perror("close()");
if (t->id == '<')
@@ -55,7 +58,10 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd)
//EXPAND_AND_QUOTE_REMOVAL_PLACEHOLDER();
cmd->fd_in = open(t->next->content, O_RDONLY);
if (cmd->fd_in == -1)
ft_perror_io("open() ", t->next->content);
{
ft_perror_io("open() ", t->next->content); // todo error
cmd->pid = -1; // Pid var as error mark, WIP
}
}
else if (t->id == T_DLESS)
{
@@ -70,7 +76,7 @@ static int redirect_cmd_output(t_token *t, t_cmd *cmd)
{
int flags;
if (cmd->fd_out != STDOUT_FILENO && cmd->fd_out > 0)
if (cmd->fd_out != STDOUT_FILENO)
if (close(cmd->fd_out) == -1)
perror("close()");
// TODO : Expansion + quote removal sur le word t->next->content.
@@ -85,6 +91,9 @@ static int redirect_cmd_output(t_token *t, t_cmd *cmd)
flags = flags | O_APPEND;
cmd->fd_out = open(t->next->content, flags, S_IRWXU);
if (cmd->fd_out == -1)
return (ft_reti_perror_io(0, "open() ", t->next->content));
{
ft_perror_io("open() ", t->next->content);
cmd->pid = -1; // Pid var as error mark, WIP
}
return (1);
}