diff --git a/srcs/builtins.c b/srcs/builtins.c index 7a4ceb5..7eaae19 100755 --- a/srcs/builtins.c +++ b/srcs/builtins.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ -/* Updated: 2024/04/22 13:38:41 by marde-vr ### ########.fr */ +/* Updated: 2024/04/22 13:40:49 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,8 @@ int exec_builtin(t_msh *msh) return (1); else if (!ft_strcmp(msh->tokens->value, "export")) return (1); + else if (!ft_strcmp(msh->tokens->value, "unset")) + return (1); else return (0); return (1); diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index dc75b18..cbaaa11 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/22 12:40:41 by marde-vr ### ########.fr */ +/* Updated: 2024/04/22 15:39:40 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,12 @@ void get_redirections(t_msh *msh, t_cmd *cmds) if (!get_out_type(msh, cmds)) get_in_type(msh, cmds); } + + printf("in_type:"); + print_cmd_type(msh->in_type, 0); + printf("\nout_type:"); + print_cmd_type(msh->out_type, 0); + printf("\n"); } t_cmd *get_next_command(t_cmd *cmd) @@ -110,13 +116,14 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) void exec_command(t_msh *msh, int i, int cmd_count) { - //g_return_code = 0; + g_return_code = 0; msh->fds[i] = ft_calloc(2, sizeof(int *)); if (!msh->fds[i]) ft_exit(msh, 1); if (!cmd_is_builtin(msh, msh->tokens->value)) get_cmd_path(msh); - exec(msh, get_cmd_args(msh), i, cmd_count); + if (msh->tokens->value) + exec(msh, get_cmd_args(msh), i, cmd_count); remove_command_from_msh(msh); } @@ -173,9 +180,10 @@ void end_execution(t_msh *msh, int cmd_count) int status; i = 0; + status = 0; while (i < cmd_count) waitpid(msh->pids[i++], &status, 0); - if (WIFEXITED(status)) + if (!g_return_code && WIFEXITED(status)) g_return_code = WEXITSTATUS(status); if (WIFSIGNALED(status)) print_signaled(status); diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 861071c..db43631 100755 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/04/19 14:49:43 by tomoron ### ########.fr */ +/* Updated: 2024/04/22 15:35:08 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,12 @@ void redirect_input(t_msh *msh, int i) { if (msh->in_type != PIPE) { - //fprintf(stderr, "redirecting input\n"); if (dup2(msh->in_fd, 0) < 0) ft_exit(msh, 1); close(msh->in_fd); } else { - //fprintf(stderr, "redirecting pipe input\n"); - //fprintf(stderr, "input of cmd %d: %d -> 0\n", i, msh->fds[i - 1][0]); if (dup2(msh->fds[i - 1][0], 0) < 0) { perror("dup2"); //debug @@ -50,8 +47,12 @@ int open_input_file(t_msh *msh, t_cmd **cur_token) free_token(filename); if (msh->in_fd == -1) { - fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value); + filename = parse_tokens((*cur_token)->value, msh->env); + if (!filename) + ft_exit(msh, 1); + fprintf(stderr, "minishell: %s: ", filename->value); perror(""); + free_token(filename); return (1); } } @@ -77,7 +78,7 @@ int get_in_type(t_msh *msh, t_cmd *tokens) if (open_input_file(msh, &cur_token)) return (1); } - if (cur_token && cur_token->next && !is_operand_type(cur_token->next)) + if (cur_token && cur_token->next && !is_operand_type(cur_token->next) && cur_token->next->cmd_type != PIPE) return (get_in_type(msh, cur_token->next)); return (0); } diff --git a/srcs/minishell.h b/srcs/minishell.h index ec772a6..94f4e4d 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/22 13:10:38 by marde-vr ### ########.fr */ +/* Updated: 2024/04/22 15:25:22 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,6 +107,7 @@ int file_access(t_msh *msh, int *found); void remove_command_from_msh(t_msh *msh); void ft_exit(t_msh *msh, int error_code); void sort_wildcards_token(t_token *list); +void print_cmd_type(t_cmd_type type, char *value); int cmd_is_forkable_builtin(char *cmd_token); void signal_handler_command(int signum); void ft_exit(t_msh *msh, int exit_code); diff --git a/srcs/path.c b/srcs/path.c index 9e17a6f..5fb9762 100755 --- a/srcs/path.c +++ b/srcs/path.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */ +/* Updated: 2024/04/22 14:33:46 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,7 +84,11 @@ void get_cmd_path(t_msh *msh) if (ft_strchr(msh->tokens->value, '/')) { if (!file_access(msh, &found)) + { + free(msh->tokens->value); + msh->tokens->value = 0; return ; + } } else get_path(msh, &found); diff --git a/srcs/utils.c b/srcs/utils.c index f9e39c8..e31ebae 100755 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ -/* Updated: 2024/04/21 21:56:47 by tomoron ### ########.fr */ +/* Updated: 2024/04/22 14:33:56 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,8 +46,8 @@ void free_msh(t_msh *msh) void ft_exit(t_msh *msh, int exit_code) { //ft_printf("exiting"); - free_msh(msh); set_echoctl(msh->echoctl); + free_msh(msh); exit(exit_code); }