diff --git a/.nfs00000000098c85f700000036 b/.nfs00000000098c85f700000036 deleted file mode 100755 index 75b9d45..0000000 Binary files a/.nfs00000000098c85f700000036 and /dev/null differ diff --git a/builtins/.echo.c.swp b/builtins/.echo.c.swp new file mode 100644 index 0000000..7361b42 Binary files /dev/null and b/builtins/.echo.c.swp differ diff --git a/builtins/echo.c b/builtins/echo.c index d88fc9d..eeff226 100644 --- a/builtins/echo.c +++ b/builtins/echo.c @@ -6,7 +6,15 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ +<<<<<<< HEAD /* Updated: 2023/02/21 22:24:51 by erey-bet ### ########.fr */ +======= +<<<<<<< HEAD +/* Updated: 2023/02/21 21:45:38 by cchauvet ### ########.fr */ +======= +/* Updated: 2023/02/21 22:09:55 by erey-bet ### ########.fr */ +>>>>>>> 1fdc51a668e616de94c33d5b3b1e9cb51182916d +>>>>>>> eb4a8ed663b2f93cd955f7608aa686bd8e767a65 /* */ /* ************************************************************************** */ diff --git a/cmd.c b/cmd.c index 54b0dee..a3de42c 100644 --- a/cmd.c +++ b/cmd.c @@ -6,7 +6,7 @@ /* By: cchauvet args); if (content->executable != NULL) free(content->executable); + if (content->fd_in > 2) + close(content->fd_in); + if (content->fd_out > 2) + close(content->fd_in); free(content); } diff --git a/execution.c b/execution.c index bb5d7d7..410f994 100644 --- a/execution.c +++ b/execution.c @@ -6,7 +6,7 @@ /* By: cchauvet fd_out = fds[1]; ((t_cmd *) current->next->content)->fd_in = fds[0]; } - cmd_return = ft_own_cmd(env, content); + cmd_return = ft_own_cmd(data->env, content); if (cmd_return == -1) { content->executable = ft_get_executable_path( - content->executable, env); + content->executable, data->env); if (content->executable != NULL) - cmd_return = ft_excutor(content, env); + cmd_return = ft_excutor(content, data->env); } - if (content->fd_in != 0) - close(content->fd_in); - if (content->fd_out != 1 && content->fd_out != 2) - close(content->fd_out); + else if (cmd_return == -2) + return (-1); + data->exit_code = cmd_return; return_value = ft_itoa(cmd_return); if (return_value == NULL) { ft_eprintf("minishell: malloc failed\n"); return (1); } - set_value_by_key("?", return_value, env); + set_value_by_key("?", return_value, data->env); current = current->next; } return (0); diff --git a/main.c b/main.c index 41e02c6..ad1eef6 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: cchauvet env, infile, outfile); if (cmds == NULL) { close(outfile); @@ -74,7 +74,7 @@ static int ft_minishell(t_list **env, char *line) free(line_clean); return (1); } - code = ft_cmds_executor(cmds, env); + code = ft_cmds_executor(data, cmds); ft_lstclear(cmds, ft_cmddel); free(cmds); free(line_clean); @@ -129,7 +129,7 @@ int main(int ac, char **av, char **env) } while (line != NULL) { - if (ft_minishell(data.env, line) == 2) + if (ft_minishell(&data, line) == -1) break ; free(line); line = ft_get_user_input(data.env); @@ -142,6 +142,7 @@ int main(int ac, char **av, char **env) } ft_lstclear(data.env, env_del); free(data.env); + return (data.exit_code); } #endif diff --git a/minishell.h b/minishell.h index f2b3571..2485e11 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: cchauvet # define DEBUG 0 +typedef struct s_data +{ + t_list **env; + int exit_code; +} t_data; + int ft_syntatic_verif(const char *str); int ft_file_is_readable(const char *path); int ft_file_is_writable(const char *path); @@ -35,7 +41,7 @@ int ft_infile(char *line); int ft_outfile(char *line); int ft_heredoc(char *stop); size_t ft_seglen_quoted(const char *str, char c); -int ft_cmds_executor(t_list **cmds, t_list **env); +int ft_cmds_executor(t_data *data, t_list **cmds); char **ft_split_quoted(const char *s, char c); void ft_cmddel(void *content); void env_del(void *content); @@ -82,12 +88,6 @@ typedef struct s_cmd char **args; } t_cmd; -typedef struct s_data -{ - t_list **env; - int heredoc; -} t_data; - typedef struct s_env { void *key;