"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

@@ -29,7 +29,7 @@ SRCS = main.c init.c free.c generic.c \
signals.c \ signals.c \
shell_loop.c shell_script.c \ shell_loop.c shell_script.c \
lexing.c fill_token.c check_operators.c \ lexing.c fill_token.c check_operators.c \
parsing.c cmd_array.c \ parsing.c create_pipeline.c \
valid_syntax.c valid_pipeline.c valid_command.c valid_io_redirect.c \ valid_syntax.c valid_pipeline.c valid_command.c valid_io_redirect.c \
words_expansions.c expand_token.c rejoin_after_expand.c new_token_for_each_field.c \ words_expansions.c expand_token.c rejoin_after_expand.c new_token_for_each_field.c \
ft_split_quotes.c ft_strdup_quotes.c \ ft_split_quotes.c ft_strdup_quotes.c \

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */ /* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
/* Updated: 2021/11/27 12:28:20 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:25:28 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -40,11 +40,11 @@ int valid_syntax(t_token *token_list);
int valid_token(t_token **token_list, enum e_token_id token_id); int valid_token(t_token **token_list, enum e_token_id token_id);
int valid_command_separator(const t_token *token_list); int valid_command_separator(const t_token *token_list);
size_t count_pipes(t_token *token_list); size_t count_pipes(t_token *token_list);
t_cmd **cmd_array_alloc(size_t cmd_nbr); t_cmd **pipeline_alloc(size_t cmd_nbr);
int cmd_array_fill_argv(t_token *token_list, t_cmd **cmd_arr); int pipeline_fill_argv(t_token *token_list, t_cmd **pipeline);
int words_expansions(t_token *token_list); int words_expansions(t_token *token_list);
int token_expansions(t_token **t); int token_expansions(t_token **t);
int redirections(t_token *token_list, t_cmd **cmd_arr); int redirections(t_token *token_list, t_cmd **pipeline);
// Exec // Exec
int exec_cmd_line(t_all *c); int exec_cmd_line(t_all *c);

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 02:35:52 by lperrey #+# #+# */ /* Created: 2021/10/08 02:35:52 by lperrey #+# #+# */
/* Updated: 2021/11/27 11:28:13 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:25:34 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -37,7 +37,7 @@ typedef struct s_cmd
typedef struct s_all typedef struct s_all
{ {
t_cmd **cmd_arr; t_cmd **pipeline;
char **path; char **path;
char *prompt_base; char *prompt_base;
char *prompt; char *prompt;

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/18 13:29:25 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:26:08 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -18,7 +18,7 @@ int exec_cmd_line(t_all *c)
{ {
if (!pipeline(c)) if (!pipeline(c))
{ {
free_pipeline(&c->cmd_arr); free_pipeline(&c->pipeline);
return (0); return (0);
} }
return (1); return (1);

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/27 10:48:13 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:26:27 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -18,15 +18,15 @@ static pid_t pipeline_exec(t_cmd *pipeline[], t_all *c);
int pipeline(t_all *c) int pipeline(t_all *c)
{ {
if (!open_pipes(c->cmd_arr)) if (!open_pipes(c->pipeline))
return (0); return (0);
if (!pipeline_find_access(c->cmd_arr, c->path)) if (!pipeline_find_access(c->pipeline, c->path))
return (0); return (0);
if (ft_2d_arrlen(c->cmd_arr) == 1 && c->cmd_arr[0]->builtin_func) if (ft_2d_arrlen(c->pipeline) == 1 && c->pipeline[0]->builtin_func)
simple_command_builtin(c->cmd_arr[0], c); simple_command_builtin(c->pipeline[0], c);
else else
wait_subshell(pipeline_exec(c->cmd_arr, c)); wait_subshell(pipeline_exec(c->pipeline, c));
free_pipeline(&c->cmd_arr); free_pipeline(&c->pipeline);
return (1); return (1);
} }
@@ -87,7 +87,7 @@ static pid_t pipeline_exec(t_cmd *pipeline[], t_all *c)
} }
i++; i++;
} }
close_pipeline_fd(c->cmd_arr); close_pipeline_fd(c->pipeline);
i -= 1; i -= 1;
if (pipeline[i]->error) if (pipeline[i]->error)
set_last_exit_status(pipeline[i]->error); set_last_exit_status(pipeline[i]->error);

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/27 11:11:12 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:26:33 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -27,7 +27,7 @@ int cmd_exec_in_subshell(t_cmd *cmd, t_all *c)
if (cmd->fd_out != STDOUT_FILENO) if (cmd->fd_out != STDOUT_FILENO)
if (dup2(cmd->fd_out, STDOUT_FILENO) == -1) if (dup2(cmd->fd_out, STDOUT_FILENO) == -1)
return (ft_reti_perror(EXIT_FAILURE, "dup2()")); return (ft_reti_perror(EXIT_FAILURE, "dup2()"));
close_pipeline_fd(c->cmd_arr); close_pipeline_fd(c->pipeline);
if (cmd->builtin_func) if (cmd->builtin_func)
free_exit(c, cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c)); free_exit(c, cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c));
else if (execve(cmd->path, cmd->argv, environ) == -1) else if (execve(cmd->path, cmd->argv, environ) == -1)

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */ /* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */
/* Updated: 2021/11/27 23:50:15 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:25:46 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -42,7 +42,7 @@ int free_exit(t_all *c, int exit_status)
//environ = g_ori_environ; // WIP free test //environ = g_ori_environ; // WIP free test
environ = NULL; // WIP free test environ = NULL; // WIP free test
ft_free_2d_arr(c->path); ft_free_2d_arr(c->path);
free_pipeline(&c->cmd_arr); free_pipeline(&c->pipeline);
//if (c->termios_changed) //if (c->termios_changed)
// tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios); // tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios);
rl_clear_history(); rl_clear_history();

View File

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

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */ /* 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; int i;
i = 0; 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); ft_putstr_fd(" |", 1);
print_matrix(cmd_arr[i]->argv, "|\n |"); print_matrix(pipeline[i]->argv, "|\n |");
i++; i++;
if (cmd_arr[i]) if (pipeline[i])
ft_putstr_fd("----------------\n", 1); ft_putstr_fd("----------------\n", 1);
} }
} }
t_cmd **parsing(t_token *token_list) t_cmd **parsing(t_token *token_list)
{ {
t_cmd **cmd_arr; t_cmd **pipeline;
if (!valid_syntax(token_list)) if (!valid_syntax(token_list))
return (NULL); return (NULL);
@@ -67,20 +67,20 @@ t_cmd **parsing(t_token *token_list)
//ft_lstprint((t_list *)token_list, 1); //ft_lstprint((t_list *)token_list, 1);
// Struct CMD alloc // Struct CMD alloc
cmd_arr = cmd_array_alloc(1 + count_pipes(token_list)); pipeline = pipeline_alloc(1 + count_pipes(token_list));
if (!cmd_arr) if (!pipeline)
return (NULL); return (NULL);
// 2.9.1 - 3) Redirection // 2.9.1 - 3) Redirection
if (!redirections(token_list, cmd_arr)) if (!redirections(token_list, pipeline))
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline)); return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
// Struct CMD fill // Struct CMD fill
if (!cmd_array_fill_argv(token_list, cmd_arr)) if (!pipeline_fill_argv(token_list, pipeline))
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline)); return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
print_cmd_array(cmd_arr); print_pipeline(pipeline);
return (cmd_arr); return (pipeline);
} }
/* ------------------------------------------------------- /* -------------------------------------------------------

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ /* 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_input(t_token *t, t_cmd *cmd);
static int redirect_cmd_output(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; int i;
i = 0; i = 0;
while (t) while (t)
{ {
if (!cmd_arr[i]->error) if (!pipeline[i]->error)
{ {
if (t->id == '<' || t->id == T_DLESS) if (t->id == '<' || t->id == T_DLESS)
{ {
if (!redirect_cmd_input(t, cmd_arr[i])) if (!redirect_cmd_input(t, pipeline[i]))
return (0); return (0);
} }
else if (t->id == '>' || t->id == T_DGREAT) 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); return (0);
} }
} }

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */ /* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
/* Updated: 2021/11/27 10:47:05 by lperrey ### ########.fr */ /* Updated: 2021/11/29 12:25:59 by lperrey ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -36,9 +36,9 @@ void shell_loop(t_all *c)
if (!c->token_list) if (!c->token_list)
continue ; continue ;
// Parsing // Parsing
c->cmd_arr = parsing(c->token_list); c->pipeline = parsing(c->token_list);
ft_lstclear((t_list **)&c->token_list, free); ft_lstclear((t_list **)&c->token_list, free);
if (!c->cmd_arr) if (!c->pipeline)
continue ; continue ;
// Exec Pipeline // Exec Pipeline
exec_cmd_line(c); exec_cmd_line(c);