"cmd_arr/cmd_array" renamed to "pipeline"

This commit is contained in:
LuckyLaszlo
2021-11-29 12:32:03 +01:00
parent aa7efdab15
commit cb5c2dcb30
11 changed files with 64 additions and 64 deletions

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_array.c :+: :+: :+: */
/* create_pipeline.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/02 22:46:23 by lperrey #+# #+# */
/* Updated: 2021/11/14 12:24:39 by lperrey ### ########.fr */
/* Updated: 2021/11/29 12:29:27 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,47 +28,47 @@ size_t count_pipes(t_token *t)
return (count);
}
t_cmd **cmd_array_alloc(size_t cmd_nbr)
t_cmd **pipeline_alloc(size_t cmd_nbr)
{
t_cmd **cmd_arr;
t_cmd **pipeline;
size_t i;
cmd_arr = ft_calloc(cmd_nbr + 1, sizeof (void *));
if (!cmd_arr)
return (ft_retp_perror(NULL, "cmd_array_alloc()"));
pipeline = ft_calloc(cmd_nbr + 1, sizeof (void *));
if (!pipeline)
return (ft_retp_perror(NULL, "pipeline_alloc()"));
i = 0;
while (i < cmd_nbr)
{
cmd_arr[i] = ft_calloc(1, sizeof (*cmd_arr[i]));
if (!cmd_arr[i])
pipeline[i] = ft_calloc(1, sizeof (*pipeline[i]));
if (!pipeline[i])
{
ft_free_2d_arr(cmd_arr);
return (ft_retp_perror(NULL, "cmd_array_alloc()"));
ft_free_2d_arr(pipeline);
return (ft_retp_perror(NULL, "pipeline_alloc()"));
}
cmd_arr[i]->fd_in = STDIN_FILENO;
cmd_arr[i]->fd_out = STDOUT_FILENO;
pipeline[i]->fd_in = STDIN_FILENO;
pipeline[i]->fd_out = STDOUT_FILENO;
i++;
}
return (cmd_arr);
return (pipeline);
}
int cmd_array_fill_argv(t_token *t, t_cmd **cmd_arr)
int pipeline_fill_argv(t_token *t, t_cmd **pipeline)
{
size_t i;
size_t arg_i;
i = 0;
while (cmd_arr[i])
while (pipeline[i])
{
cmd_arr[i]->argv = ft_calloc(cmd_words_count(t) + 1, sizeof (char *));
if (!cmd_arr[i]->argv)
return (ft_reti_perror(0, "cmd_array_fill_argv()"));
pipeline[i]->argv = ft_calloc(cmd_words_count(t) + 1, sizeof (char *));
if (!pipeline[i]->argv)
return (ft_reti_perror(0, "pipeline_fill_argv()"));
arg_i = 0;
while (t && t->id != '|')
{
if (t->id == T_WORD)
{
cmd_arr[i]->argv[arg_i++] = t->content;
pipeline[i]->argv[arg_i++] = t->content;
t->content = NULL;
}
t = t->next;

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
/* Updated: 2021/11/27 11:09:48 by lperrey ### ########.fr */
/* Updated: 2021/11/29 12:28:07 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,25 +26,25 @@ void save_redirections_words(t_token *t)
}
}
void print_cmd_array(t_cmd **cmd_arr)
void print_pipeline(t_cmd **pipeline)
{
int i;
i = 0;
while (cmd_arr[i])
while (pipeline[i])
{
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, cmd_arr[i]->fd_in, cmd_arr[i]->fd_out);
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out);
ft_putstr_fd(" |", 1);
print_matrix(cmd_arr[i]->argv, "|\n |");
print_matrix(pipeline[i]->argv, "|\n |");
i++;
if (cmd_arr[i])
if (pipeline[i])
ft_putstr_fd("----------------\n", 1);
}
}
t_cmd **parsing(t_token *token_list)
{
t_cmd **cmd_arr;
t_cmd **pipeline;
if (!valid_syntax(token_list))
return (NULL);
@@ -67,20 +67,20 @@ t_cmd **parsing(t_token *token_list)
//ft_lstprint((t_list *)token_list, 1);
// Struct CMD alloc
cmd_arr = cmd_array_alloc(1 + count_pipes(token_list));
if (!cmd_arr)
pipeline = pipeline_alloc(1 + count_pipes(token_list));
if (!pipeline)
return (NULL);
// 2.9.1 - 3) Redirection
if (!redirections(token_list, cmd_arr))
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
if (!redirections(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
// Struct CMD fill
if (!cmd_array_fill_argv(token_list, cmd_arr))
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
print_cmd_array(cmd_arr);
if (!pipeline_fill_argv(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
print_pipeline(pipeline);
return (cmd_arr);
return (pipeline);
}
/* -------------------------------------------------------

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
/* Updated: 2021/11/26 20:00:42 by lperrey ### ########.fr */
/* Updated: 2021/11/29 12:28:25 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,23 +17,23 @@ int here_doc(char *delimiter);
static int redirect_cmd_input(t_token *t, t_cmd *cmd);
static int redirect_cmd_output(t_token *t, t_cmd *cmd);
int redirections(t_token *t, t_cmd **cmd_arr)
int redirections(t_token *t, t_cmd **pipeline)
{
int i;
i = 0;
while (t)
{
if (!cmd_arr[i]->error)
if (!pipeline[i]->error)
{
if (t->id == '<' || t->id == T_DLESS)
{
if (!redirect_cmd_input(t, cmd_arr[i]))
if (!redirect_cmd_input(t, pipeline[i]))
return (0);
}
else if (t->id == '>' || t->id == T_DGREAT)
{
if (!redirect_cmd_output(t, cmd_arr[i]))
if (!redirect_cmd_output(t, pipeline[i]))
return (0);
}
}