fix and , or
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/05 18:22:15 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/19 10:40:13 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 14:42:50 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,7 +65,8 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
free_token(msh->tokens);
|
free_token(msh->tokens);
|
||||||
while (msh->cmds && !is_cmd_type(msh->cmds))
|
while (msh->cmds && !is_cmd_type(msh->cmds))
|
||||||
msh->cmds = msh->cmds->next;
|
msh->cmds = msh->cmds->next;
|
||||||
while (msh->cmds && is_cmd_type(msh->cmds))
|
while (msh->cmds && (is_cmd_type(msh->cmds) || is_input_type(msh->cmds)
|
||||||
|
|| is_output_type(msh->cmds)))
|
||||||
msh->cmds = msh->cmds->next;
|
msh->cmds = msh->cmds->next;
|
||||||
tmp = msh->cmds;
|
tmp = msh->cmds;
|
||||||
while (tmp && !is_cmd_type(tmp))
|
while (tmp && !is_cmd_type(tmp))
|
||||||
|
@ -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 13:46:21 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 14:53:53 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -28,6 +28,22 @@ void get_redirections(t_msh *msh, t_cmd *cmds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_cmd *get_next_command(t_cmd *cmd)
|
||||||
|
{
|
||||||
|
while(cmd)
|
||||||
|
{
|
||||||
|
while(cmd && !is_operand_type(cmd))
|
||||||
|
cmd = cmd->next;
|
||||||
|
if(cmd && cmd->cmd_type == AND && !g_return_code)
|
||||||
|
return(cmd->next);
|
||||||
|
if(cmd && cmd->cmd_type == OR && g_return_code)
|
||||||
|
return(cmd->next);
|
||||||
|
if(cmd)
|
||||||
|
cmd = cmd->next;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
void exec_command_bonus(t_msh *msh, char *cmd_str)
|
void exec_command_bonus(t_msh *msh, char *cmd_str)
|
||||||
{
|
{
|
||||||
t_cmd *cmds;
|
t_cmd *cmds;
|
||||||
@ -45,22 +61,15 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
}
|
}
|
||||||
while (cmds)
|
while (cmds)
|
||||||
{
|
{
|
||||||
if ((cmds->cmd_type == AND && !g_return_code) || (cmds->cmd_type == OR
|
print_parsed_cmd(cmds); // debug
|
||||||
&& g_return_code) || !is_operand_type(cmds))
|
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
||||||
{
|
msh->cmds = cmds;
|
||||||
if (is_operand_type(cmds))
|
//print_msh_struct(msh); // debug
|
||||||
cmds = cmds->next;
|
// print_parsed_token(msh->tokens); // debug
|
||||||
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
exec_commands(msh);
|
||||||
msh->cmds = cmds;
|
msh->in_fd = 0;
|
||||||
//print_msh_struct(msh); // debug
|
msh->out_fd = 0;
|
||||||
print_parsed_token(msh->tokens); // debug
|
cmds = get_next_command(cmds);
|
||||||
exec_commands(msh);
|
|
||||||
msh->in_fd = 0;
|
|
||||||
msh->out_fd = 0;
|
|
||||||
}
|
|
||||||
while (cmds && (is_cmd_type(cmds) || cmds->cmd_type == PIPE
|
|
||||||
|| is_output_type(cmds) || is_input_type(cmds)))
|
|
||||||
cmds = cmds->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,8 +140,7 @@ void end_execution(t_msh *msh, int cmd_count)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < cmd_count)
|
while (i < cmd_count)
|
||||||
waitpid(msh->pids[i++], &status, 0);
|
waitpid(msh->pids[i++], WIFEXITED(status))
|
||||||
if (!g_return_code && WIFEXITED(status))
|
|
||||||
g_return_code = WEXITSTATUS(status);
|
g_return_code = WEXITSTATUS(status);
|
||||||
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT)
|
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT)
|
||||||
printf("Quit\n");
|
printf("Quit\n");
|
||||||
|
@ -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 13:46:32 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 14:49:43 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ int open_input_file(t_msh *msh, t_cmd **cur_token)
|
|||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
msh->in_fd = open(filename->value, O_RDONLY);
|
msh->in_fd = open(filename->value, O_RDONLY);
|
||||||
free_token(filename);
|
free_token(filename);
|
||||||
if (msh->in_fd == -1 && !g_return_code)
|
if (msh->in_fd == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value);
|
fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value);
|
||||||
perror("");
|
perror("");
|
||||||
|
@ -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:51:04 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 14:09:25 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -98,7 +98,6 @@ void exec_commands(t_msh *msh);
|
|||||||
void handle_here_doc(t_msh *msh, char *eof);
|
void handle_here_doc(t_msh *msh, char *eof);
|
||||||
int 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);
|
|
||||||
int get_token_len(char *cmd, t_env *env);
|
int get_token_len(char *cmd, t_env *env);
|
||||||
void print_syntax_error_bonus(t_cmd *cmd);
|
void print_syntax_error_bonus(t_cmd *cmd);
|
||||||
void signal_handler_here_doc(int signum);
|
void signal_handler_here_doc(int signum);
|
||||||
|
@ -3,14 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* output_redirections.c :+: :+: :+: */
|
/* output_redirections.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
|
||||||
<<<<<<< HEAD
|
/* Updated: 2024/04/19 14:10:30 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)
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -60,13 +56,15 @@ int open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_out_type(t_msh *msh, t_cmd *cmds)
|
int get_out_type(t_msh *msh, t_cmd *cmds)
|
||||||
{
|
{
|
||||||
t_cmd *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
t_token *filename;
|
t_token *filename;
|
||||||
|
int ret;
|
||||||
|
|
||||||
msh->out_type = CMD;
|
msh->out_type = CMD;
|
||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
|
ret = 0;
|
||||||
cur_cmd = cmds;
|
cur_cmd = cmds;
|
||||||
while (cur_cmd && !is_cmd_type(cur_cmd))
|
while (cur_cmd && !is_cmd_type(cur_cmd))
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
@ -87,9 +85,10 @@ void get_out_type(t_msh *msh, t_cmd *cmds)
|
|||||||
filename = parse_tokens(cur_cmd->value, msh->env);
|
filename = parse_tokens(cur_cmd->value, msh->env);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
open_out_file(msh, &cur_cmd, filename->value);
|
ret = open_out_file(msh, &cur_cmd, filename->value);
|
||||||
free_token(filename);
|
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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user