merge
This commit is contained in:
@ -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/19 10:44:36 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 13:46:21 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,14 +18,12 @@ void get_redirections(t_msh *msh, t_cmd *cmds)
|
|||||||
msh->out_type = 0;
|
msh->out_type = 0;
|
||||||
if (first_is_in_type(cmds))
|
if (first_is_in_type(cmds))
|
||||||
{
|
{
|
||||||
get_in_type(msh, cmds);
|
if (!get_in_type(msh, cmds))
|
||||||
if (!g_return_code)
|
|
||||||
get_out_type(msh, cmds);
|
get_out_type(msh, cmds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
get_out_type(msh, cmds);
|
if (!get_out_type(msh, cmds))
|
||||||
if (!g_return_code)
|
|
||||||
get_in_type(msh, cmds);
|
get_in_type(msh, cmds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 09:43:39 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 13:46:32 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ void redirect_input(t_msh *msh, int i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_input_file(t_msh *msh, t_cmd **cur_token)
|
int open_input_file(t_msh *msh, t_cmd **cur_token)
|
||||||
{
|
{
|
||||||
t_token *filename;
|
t_token *filename;
|
||||||
|
|
||||||
@ -52,12 +52,13 @@ void open_input_file(t_msh *msh, t_cmd **cur_token)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value);
|
fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value);
|
||||||
perror("");
|
perror("");
|
||||||
g_return_code = 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_in_type(t_msh *msh, t_cmd *tokens)
|
int get_in_type(t_msh *msh, t_cmd *tokens)
|
||||||
{
|
{
|
||||||
t_cmd *cur_token;
|
t_cmd *cur_token;
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ void get_in_type(t_msh *msh, t_cmd *tokens)
|
|||||||
if (cur_token && cur_token->cmd_type == PIPE)
|
if (cur_token && cur_token->cmd_type == PIPE)
|
||||||
{
|
{
|
||||||
msh->in_type = PIPE;
|
msh->in_type = PIPE;
|
||||||
return ;
|
return (0);
|
||||||
}
|
}
|
||||||
while (cur_token && (cur_token->cmd_type == CMD
|
while (cur_token && (cur_token->cmd_type == CMD
|
||||||
|| cur_token->cmd_type == PAREN))
|
|| cur_token->cmd_type == PAREN))
|
||||||
@ -73,10 +74,12 @@ void get_in_type(t_msh *msh, t_cmd *tokens)
|
|||||||
if (cur_token && is_input_type(cur_token))
|
if (cur_token && is_input_type(cur_token))
|
||||||
{
|
{
|
||||||
msh->in_type = cur_token->cmd_type;
|
msh->in_type = cur_token->cmd_type;
|
||||||
open_input_file(msh, &cur_token);
|
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))
|
||||||
get_in_type(msh, cur_token->next);
|
return (get_in_type(msh, cur_token->next));
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int first_is_in_type(t_cmd *cmd)
|
int first_is_in_type(t_cmd *cmd)
|
||||||
|
@ -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/19 13:19:48 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 13:51:04 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -92,8 +92,11 @@ void child(t_msh *msh, char **cmd_args, int i);
|
|||||||
t_token *parse_tokens(char *command, t_env *env);
|
t_token *parse_tokens(char *command, t_env *env);
|
||||||
void parent(t_msh *msh, int i, int cmd_count);
|
void parent(t_msh *msh, int i, int cmd_count);
|
||||||
char *ft_get_env(t_env *env, char *var_name);
|
char *ft_get_env(t_env *env, char *var_name);
|
||||||
|
int is_fd_open(int fd);
|
||||||
|
int get_out_type(t_msh *msh, t_cmd *cmds);
|
||||||
|
void exec_commands(t_msh *msh);
|
||||||
void handle_here_doc(t_msh *msh, char *eof);
|
void handle_here_doc(t_msh *msh, char *eof);
|
||||||
void get_in_type(t_msh *msh, t_cmd *tokens);
|
int get_in_type(t_msh *msh, t_cmd *tokens);
|
||||||
void signal_handler_interactive(int signum);
|
void signal_handler_interactive(int signum);
|
||||||
void get_out_type(t_msh *msh, t_cmd *cmds);
|
void get_out_type(t_msh *msh, t_cmd *cmds);
|
||||||
int get_token_len(char *cmd, t_env *env);
|
int get_token_len(char *cmd, t_env *env);
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
||||||
|
<<<<<<< HEAD
|
||||||
/* Updated: 2024/04/19 09:45:21 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 09:45:21 by tomoron ### ########.fr */
|
||||||
|
=======
|
||||||
|
/* Updated: 2024/04/19 13:33:50 by marde-vr ### ########.fr */
|
||||||
|
>>>>>>> 7ae7a09 (fixed priorities and return codes)
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,7 +38,7 @@ void redirect_output(t_msh *msh, int i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
|
int open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
|
||||||
{
|
{
|
||||||
if (msh->out_type == RED_O)
|
if (msh->out_type == RED_O)
|
||||||
msh->out_fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
msh->out_fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
||||||
@ -42,10 +46,9 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
|
|||||||
msh->out_fd = open(filename, O_CREAT | O_RDWR | O_APPEND, 0644);
|
msh->out_fd = open(filename, O_CREAT | O_RDWR | O_APPEND, 0644);
|
||||||
if (msh->out_fd == -1)
|
if (msh->out_fd == -1)
|
||||||
{
|
{
|
||||||
g_return_code = 1;
|
|
||||||
ft_putstr_fd("minishell: ", 2);
|
ft_putstr_fd("minishell: ", 2);
|
||||||
perror(filename);
|
perror(filename);
|
||||||
return ;
|
return (1);
|
||||||
}
|
}
|
||||||
if ((*cur_cmd)->cmd_type != PIPE)
|
if ((*cur_cmd)->cmd_type != PIPE)
|
||||||
{
|
{
|
||||||
@ -54,6 +57,7 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
|
|||||||
if ((*cur_cmd)->next && is_output_type((*cur_cmd)->next))
|
if ((*cur_cmd)->next && is_output_type((*cur_cmd)->next))
|
||||||
get_out_type(msh, *cur_cmd);
|
get_out_type(msh, *cur_cmd);
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_out_type(t_msh *msh, t_cmd *cmds)
|
void get_out_type(t_msh *msh, t_cmd *cmds)
|
||||||
|
Reference in New Issue
Block a user