fixed some errors

This commit is contained in:
mdev9
2024-04-22 15:40:06 +02:00
parent 901ff34b7c
commit 9f14d1c1b6
6 changed files with 31 additions and 15 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:20:21 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); return (1);
else if (!ft_strcmp(msh->tokens->value, "export")) else if (!ft_strcmp(msh->tokens->value, "export"))
return (1); return (1);
else if (!ft_strcmp(msh->tokens->value, "unset"))
return (1);
else else
return (0); return (0);
return (1); return (1);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* 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)) if (!get_out_type(msh, cmds))
get_in_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) 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) 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 *)); msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i]) if (!msh->fds[i])
ft_exit(msh, 1); ft_exit(msh, 1);
if (!cmd_is_builtin(msh, msh->tokens->value)) if (!cmd_is_builtin(msh, msh->tokens->value))
get_cmd_path(msh); 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); remove_command_from_msh(msh);
} }
@ -173,9 +180,10 @@ void end_execution(t_msh *msh, int cmd_count)
int status; int status;
i = 0; i = 0;
status = 0;
while (i < cmd_count) while (i < cmd_count)
waitpid(msh->pids[i++], &status, 0); waitpid(msh->pids[i++], &status, 0);
if (WIFEXITED(status)) if (!g_return_code && WIFEXITED(status))
g_return_code = WEXITSTATUS(status); g_return_code = WEXITSTATUS(status);
if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
print_signaled(status); print_signaled(status);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 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) if (msh->in_type != PIPE)
{ {
//fprintf(stderr, "redirecting input\n");
if (dup2(msh->in_fd, 0) < 0) if (dup2(msh->in_fd, 0) < 0)
ft_exit(msh, 1); ft_exit(msh, 1);
close(msh->in_fd); close(msh->in_fd);
} }
else 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) if (dup2(msh->fds[i - 1][0], 0) < 0)
{ {
perror("dup2"); //debug perror("dup2"); //debug
@ -50,8 +47,12 @@ int open_input_file(t_msh *msh, t_cmd **cur_token)
free_token(filename); free_token(filename);
if (msh->in_fd == -1) 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(""); perror("");
free_token(filename);
return (1); return (1);
} }
} }
@ -77,7 +78,7 @@ int get_in_type(t_msh *msh, t_cmd *tokens)
if (open_input_file(msh, &cur_token)) if (open_input_file(msh, &cur_token))
return (1); 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 (get_in_type(msh, cur_token->next));
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ /* 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 remove_command_from_msh(t_msh *msh);
void ft_exit(t_msh *msh, int error_code); void ft_exit(t_msh *msh, int error_code);
void sort_wildcards_token(t_token *list); 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); int cmd_is_forkable_builtin(char *cmd_token);
void signal_handler_command(int signum); void signal_handler_command(int signum);
void ft_exit(t_msh *msh, int exit_code); void ft_exit(t_msh *msh, int exit_code);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/21 21:47:15 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 (ft_strchr(msh->tokens->value, '/'))
{ {
if (!file_access(msh, &found)) if (!file_access(msh, &found))
{
free(msh->tokens->value);
msh->tokens->value = 0;
return ; return ;
}
} }
else else
get_path(msh, &found); get_path(msh, &found);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 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) void ft_exit(t_msh *msh, int exit_code)
{ {
//ft_printf("exiting"); //ft_printf("exiting");
free_msh(msh);
set_echoctl(msh->echoctl); set_echoctl(msh->echoctl);
free_msh(msh);
exit(exit_code); exit(exit_code);
} }