fixed some errors
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/04/29 10:28:55 by marde-vr ### ########.fr #
|
# Updated: 2024/05/03 14:12:21 by marde-vr ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ SRCS_RAW = main.c\
|
|||||||
here_doc_utils.c\
|
here_doc_utils.c\
|
||||||
export.c\
|
export.c\
|
||||||
input_redirections.c\
|
input_redirections.c\
|
||||||
|
redirection_utils.c\
|
||||||
sort_wildcard_list.c\
|
sort_wildcard_list.c\
|
||||||
output_redirections.c\
|
output_redirections.c\
|
||||||
builtins.c\
|
builtins.c\
|
||||||
|
@ -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/30 14:42:26 by marde-vr ### ########.fr */
|
/* Updated: 2024/05/03 13:10:12 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -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/28 14:52:19 by tomoron ### ########.fr */
|
/* Updated: 2024/05/03 14:11:52 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -33,23 +33,14 @@ void redirect_input(t_msh *msh, int i, char **cmd_args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ambiguous_redirect(char *str, t_msh *msh)
|
int open_input_redirection_file(t_msh *msh, t_cmd **cur_token)
|
||||||
{
|
|
||||||
ft_printf_fd(2, "minishell: %s: ambiguous redirect\n", str);
|
|
||||||
msh->in_fd = -2;
|
|
||||||
g_return_code = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int open_input_file(t_msh *msh, t_cmd **cur_token)
|
|
||||||
{
|
{
|
||||||
t_token *filename;
|
t_token *filename;
|
||||||
|
|
||||||
if ((*cur_token)->cmd_type == HERE_DOC)
|
|
||||||
handle_here_doc(msh, (*cur_token)->value);
|
|
||||||
if ((*cur_token)->cmd_type == RED_I)
|
|
||||||
{
|
|
||||||
if (msh->in_fd != 0)
|
if (msh->in_fd != 0)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
|
if (ft_strchr((*cur_token)->value, '$'))
|
||||||
|
ambiguous_redirect((*cur_token)->value, msh);
|
||||||
filename = parse_tokens((*cur_token)->value, msh->env);
|
filename = parse_tokens((*cur_token)->value, msh->env);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
@ -65,7 +56,15 @@ int open_input_file(t_msh *msh, t_cmd **cur_token)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
free_token(filename);
|
free_token(filename);
|
||||||
}
|
return (msh->in_fd == -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_input_file(t_msh *msh, t_cmd **cur_token)
|
||||||
|
{
|
||||||
|
if ((*cur_token)->cmd_type == HERE_DOC)
|
||||||
|
handle_here_doc(msh, (*cur_token)->value);
|
||||||
|
if ((*cur_token)->cmd_type == RED_I)
|
||||||
|
return (open_input_redirection_file(msh, cur_token));
|
||||||
return (msh->in_fd == -2);
|
return (msh->in_fd == -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,22 +88,11 @@ int get_in_type(t_msh *msh, t_cmd *t_strt, t_cmd *tokens, int here_doc)
|
|||||||
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) && !is_operand_type(cur_token->next)
|
||||||
&& cur_token->cmd_type != PIPE && cur_token->next->cmd_type != PIPE)
|
&& cur_token->cmd_type != PIPE && cur_token->next->cmd_type != PIPE)
|
||||||
return (get_in_type(msh, t_strt, cur_token->next, here_doc));
|
return (get_in_type(msh, t_strt, cur_token->next, here_doc));
|
||||||
if (here_doc)
|
if (here_doc)
|
||||||
return (get_in_type(msh, t_strt, t_strt, 0));
|
return (get_in_type(msh, t_strt, t_strt, 0));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int first_is_in_type(t_cmd *cmd)
|
|
||||||
{
|
|
||||||
t_cmd *cur_token;
|
|
||||||
|
|
||||||
cur_token = cmd;
|
|
||||||
while (cur_token && cur_token->cmd_type == CMD && cur_token->next)
|
|
||||||
cur_token = cur_token->next;
|
|
||||||
if (is_input_type(cur_token) || cur_token->cmd_type == PIPE)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
|
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/28 14:52:53 by tomoron ### ########.fr */
|
/* Updated: 2024/05/03 14:07:43 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,9 +65,25 @@ void go_to_next_out_type(t_cmd **cur_cmd)
|
|||||||
*cur_cmd = (*cur_cmd)->next;
|
*cur_cmd = (*cur_cmd)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_out_type(t_msh *msh, t_cmd *cur_cmd)
|
void get_out_file(t_msh *msh, t_cmd *cur_cmd, int *ret)
|
||||||
{
|
{
|
||||||
t_token *filename;
|
t_token *filename;
|
||||||
|
|
||||||
|
msh->out_type = cur_cmd->cmd_type;
|
||||||
|
if (ft_strchr(cur_cmd->value, '$'))
|
||||||
|
ambiguous_redirect(cur_cmd->value, msh);
|
||||||
|
filename = parse_tokens(cur_cmd->value, msh->env);
|
||||||
|
if (!filename)
|
||||||
|
ft_exit(msh, 1);
|
||||||
|
if (filename->next)
|
||||||
|
ambiguous_redirect(cur_cmd->value, msh);
|
||||||
|
if (!filename->next)
|
||||||
|
*ret = open_out_file(msh, &cur_cmd, filename->value);
|
||||||
|
free_token(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_out_type(t_msh *msh, t_cmd *cur_cmd)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
msh->out_type = CMD;
|
msh->out_type = CMD;
|
||||||
@ -78,17 +94,7 @@ int get_out_type(t_msh *msh, t_cmd *cur_cmd)
|
|||||||
msh->out_type = 0;
|
msh->out_type = 0;
|
||||||
else if (cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd)
|
else if (cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd)
|
||||||
&& cur_cmd->cmd_type != PIPE)
|
&& cur_cmd->cmd_type != PIPE)
|
||||||
{
|
get_out_file(msh, cur_cmd, &ret);
|
||||||
msh->out_type = cur_cmd->cmd_type;
|
|
||||||
filename = parse_tokens(cur_cmd->value, msh->env);
|
|
||||||
if (!filename)
|
|
||||||
ft_exit(msh, 1);
|
|
||||||
if (filename->next)
|
|
||||||
ambiguous_redirect(cur_cmd->value, msh);
|
|
||||||
if (!filename->next)
|
|
||||||
ret = open_out_file(msh, &cur_cmd, filename->value);
|
|
||||||
free_token(filename);
|
|
||||||
}
|
|
||||||
else if (cur_cmd && cur_cmd->cmd_type == PIPE)
|
else if (cur_cmd && cur_cmd->cmd_type == PIPE)
|
||||||
msh->out_type = PIPE;
|
msh->out_type = PIPE;
|
||||||
return (ret || msh->in_fd == -2);
|
return (ret || msh->in_fd == -2);
|
||||||
|
@ -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/05/03 08:34:53 by marde-vr ### ########.fr */
|
/* Updated: 2024/05/03 12:51:56 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/30 13:56:03 by marde-vr ### ########.fr */
|
/* Updated: 2024/05/03 13:13:36 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -92,6 +92,10 @@ void child(t_msh *msh, char **cmd_args, int i)
|
|||||||
|| msh->out_type == RED_O_APP)
|
|| msh->out_type == RED_O_APP)
|
||||||
redirect_output(msh, i, cmd_args);
|
redirect_output(msh, i, cmd_args);
|
||||||
close_pipe_fds(msh, i);
|
close_pipe_fds(msh, i);
|
||||||
|
if (msh->in_fd > 2)
|
||||||
|
close(msh->in_fd);
|
||||||
|
if (msh->out_fd > 2)
|
||||||
|
close(msh->out_fd);
|
||||||
execute_command(msh, cmd_args);
|
execute_command(msh, cmd_args);
|
||||||
close(0);
|
close(0);
|
||||||
close(1);
|
close(1);
|
||||||
|
32
srcs/redirection_utils.c
Normal file
32
srcs/redirection_utils.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/03 14:11:22 by marde-vr #+# #+# */
|
||||||
|
/* Updated: 2024/05/03 14:11:50 by marde-vr ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void ambiguous_redirect(char *str, t_msh *msh)
|
||||||
|
{
|
||||||
|
ft_printf_fd(2, "minishell: %s: ambiguous redirect\n", str);
|
||||||
|
msh->in_fd = -2;
|
||||||
|
g_return_code = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int first_is_in_type(t_cmd *cmd)
|
||||||
|
{
|
||||||
|
t_cmd *cur_token;
|
||||||
|
|
||||||
|
cur_token = cmd;
|
||||||
|
while (cur_token && cur_token->cmd_type == CMD && cur_token->next)
|
||||||
|
cur_token = cur_token->next;
|
||||||
|
if (is_input_type(cur_token) || cur_token->cmd_type == PIPE)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
7
todo
7
todo
@ -1,14 +1,7 @@
|
|||||||
- Leak lors des redirection out
|
|
||||||
- export c=
|
- export c=
|
||||||
- export a="export b="export""
|
- export a="export b="export""
|
||||||
- ./aa = permission denied != Is a directory
|
|
||||||
- env -i ./minishell => unset ALL => export a (nes pas export)
|
- env -i ./minishell => unset ALL => export a (nes pas export)
|
||||||
- export a=b && cat <<A
|
|
||||||
> A
|
|
||||||
> A
|
|
||||||
- lolcat && cat <<A = > n affiche pas le heredoc
|
|
||||||
- export a="Makefile out"
|
- export a="Makefile out"
|
||||||
- marde-vr@2A7:/tmp/bberkrou$ cat < $a
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user