working on bonus execution
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:20:21 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/28 13:28:19 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 18:40:49 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token)
|
|||||||
return (0);
|
return (0);
|
||||||
else if (!ft_strcmp(cmd_token, "cd"))
|
else if (!ft_strcmp(cmd_token, "cd"))
|
||||||
{
|
{
|
||||||
cd(msh->cmds);
|
cd(msh->tokens);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if (!ft_strcmp(cmd_token, "exit"))
|
else if (!ft_strcmp(cmd_token, "exit"))
|
||||||
@ -54,7 +54,7 @@ int exec_builtin(t_msh *msh)
|
|||||||
if (!msh->cmds->value)
|
if (!msh->cmds->value)
|
||||||
return (0);
|
return (0);
|
||||||
if (!ft_strcmp(msh->cmds->value, "echo"))
|
if (!ft_strcmp(msh->cmds->value, "echo"))
|
||||||
g_return_code = echo(msh->cmds->next);
|
g_return_code = echo(msh->tokens->next);
|
||||||
else if (!ft_strcmp(msh->cmds->value, "ret"))
|
else if (!ft_strcmp(msh->cmds->value, "ret"))
|
||||||
g_return_code = ft_atoi(msh->cmds->next->value);
|
g_return_code = ft_atoi(msh->cmds->next->value);
|
||||||
else if (!ft_strcmp(msh->cmds->value, "env"))
|
else if (!ft_strcmp(msh->cmds->value, "env"))
|
||||||
@ -64,7 +64,7 @@ int exec_builtin(t_msh *msh)
|
|||||||
else if (!ft_strcmp(msh->cmds->value, "pwd"))
|
else if (!ft_strcmp(msh->cmds->value, "pwd"))
|
||||||
g_return_code = pwd();
|
g_return_code = pwd();
|
||||||
else if (!ft_strcmp(msh->cmds->value, "cd"))
|
else if (!ft_strcmp(msh->cmds->value, "cd"))
|
||||||
g_return_code = cd(msh->cmds);
|
g_return_code = cd(msh->tokens);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -6,46 +6,45 @@
|
|||||||
/* 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/03/28 13:35:09 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 17:25:20 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int get_cmd_count(t_token *cmds)
|
int get_cmd_count(t_cmd *cmds)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
t_token *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
|
(void)cmds;
|
||||||
count = 0;
|
count = 0;
|
||||||
cur_cmd = cmds;
|
cur_cmd = cmds;
|
||||||
while (cur_cmd->next != 0)
|
while (cur_cmd->next != 0)
|
||||||
{
|
{
|
||||||
if (cur_cmd->type != ARG)
|
if (cur_cmd->cmd_type != PIPE)
|
||||||
if (/*cur_cmd->type == PIPE*/ 0)
|
|
||||||
count++;
|
count++;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
}
|
}
|
||||||
if (cur_cmd->type == ARG)
|
if (cur_cmd->cmd_type != PIPE)
|
||||||
count++;
|
count++;
|
||||||
return (count);
|
return (count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_args_count(t_token *cmds)
|
int get_args_count(t_cmd *cmds)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
t_token *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
cur_cmd = cmds;
|
cur_cmd = cmds;
|
||||||
if (cur_cmd->type == ARG)
|
if (cur_cmd->cmd_type == ARG)
|
||||||
count++;
|
count++;
|
||||||
while (cur_cmd->next)
|
while (cur_cmd->next)
|
||||||
{
|
{
|
||||||
if (/*cur_cmd->type == PIPE*/ 0)
|
if (/*cur_cmd->type == PIPE*/ 0)
|
||||||
break ;
|
break ;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
if (cur_cmd->type == ARG)
|
if (cur_cmd->cmd_type == ARG)
|
||||||
count++;
|
count++;
|
||||||
else if (/*cur_cmd->type != PIPE*/ 1)
|
else if (/*cur_cmd->type != PIPE*/ 1)
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
@ -56,7 +55,7 @@ int get_args_count(t_token *cmds)
|
|||||||
char **get_cmd_args(t_msh *msh)
|
char **get_cmd_args(t_msh *msh)
|
||||||
{
|
{
|
||||||
char **cmd_args;
|
char **cmd_args;
|
||||||
t_token *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
int args_count;
|
int args_count;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ char **get_cmd_args(t_msh *msh)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (i < args_count)
|
while (i < args_count)
|
||||||
{
|
{
|
||||||
if (cur_cmd->type == ARG)
|
if (cur_cmd->cmd_type == ARG)
|
||||||
{
|
{
|
||||||
if (!i)
|
if (!i)
|
||||||
cmd_args[i++] = remove_path(cur_cmd->value);
|
cmd_args[i++] = remove_path(cur_cmd->value);
|
||||||
@ -84,8 +83,8 @@ char **get_cmd_args(t_msh *msh)
|
|||||||
|
|
||||||
void remove_command_from_msh(t_msh *msh)
|
void remove_command_from_msh(t_msh *msh)
|
||||||
{
|
{
|
||||||
t_token *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
t_token *cmd_tmp;
|
t_cmd *cmd_tmp;
|
||||||
|
|
||||||
cur_cmd = msh->cmds;
|
cur_cmd = msh->cmds;
|
||||||
while (cur_cmd && cur_cmd->next)
|
while (cur_cmd && cur_cmd->next)
|
||||||
@ -94,7 +93,7 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
{
|
{
|
||||||
cmd_tmp = cur_cmd;
|
cmd_tmp = cur_cmd;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
msh->in_type = cmd_tmp->type;
|
//msh->in_type = cmd_tmp->cmd_type;
|
||||||
free(cmd_tmp->value);
|
free(cmd_tmp->value);
|
||||||
free(cmd_tmp);
|
free(cmd_tmp);
|
||||||
msh->cmds = cur_cmd;
|
msh->cmds = cur_cmd;
|
||||||
@ -102,10 +101,10 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
}
|
}
|
||||||
cmd_tmp = cur_cmd;
|
cmd_tmp = cur_cmd;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
msh->in_type = cur_cmd->type;
|
//msh->in_type = cur_cmd->type;
|
||||||
free(cmd_tmp->value);
|
free(cmd_tmp->value);
|
||||||
free(cmd_tmp);
|
free(cmd_tmp);
|
||||||
msh->cmds = cur_cmd;
|
msh->cmds = cur_cmd;
|
||||||
}
|
}
|
||||||
msh->in_type = msh->cmds->type;
|
//msh->in_type = msh->cmds->type;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/27 16:52:02 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 16:55:17 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
@ -110,4 +111,4 @@ void exec_commands(t_msh *msh)
|
|||||||
while (++i < cmd_count)
|
while (++i < cmd_count)
|
||||||
exec_command(msh, i, cmd_count);
|
exec_command(msh, i, cmd_count);
|
||||||
end_execution(msh, cmd_count);
|
end_execution(msh, cmd_count);
|
||||||
}
|
}*/
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* exec_bonus.c :+: :+: :+: */
|
/* exec_bonus.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tomoron <marvin@42.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/03/29 14:47:40 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 17:29:07 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,11 +14,115 @@
|
|||||||
|
|
||||||
void exec_command_bonus(t_msh *msh, char *cmd_str)
|
void exec_command_bonus(t_msh *msh, char *cmd_str)
|
||||||
{
|
{
|
||||||
t_cmd *cmd;
|
t_cmd *cmds;
|
||||||
|
|
||||||
(void)msh;
|
(void)msh;
|
||||||
printf("cmd : %s\n",cmd_str);
|
printf("cmd : %s\n",cmd_str);
|
||||||
cmd = parsing_bonus(cmd_str);
|
cmds = parsing_bonus(cmd_str);
|
||||||
printf("%p\n", cmd);
|
printf("%p\n", cmds);
|
||||||
print_parsed_cmd(cmd);
|
msh->tokens = parse_command(cmd_str, msh->env);
|
||||||
|
msh->cmds = cmds;
|
||||||
|
print_parsed_cmd(cmds);
|
||||||
|
exec_commands(msh);
|
||||||
|
}
|
||||||
|
|
||||||
|
int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
if (i != cmd_count - 1)
|
||||||
|
{
|
||||||
|
if (pipe(msh->fds[i]) == -1)
|
||||||
|
{
|
||||||
|
perror("pipe");
|
||||||
|
ft_exit(msh, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pid = fork();
|
||||||
|
if (pid == -1)
|
||||||
|
{
|
||||||
|
perror("fork");
|
||||||
|
ft_exit(msh, 1);
|
||||||
|
}
|
||||||
|
if (pid == 0)
|
||||||
|
child(msh, cmd_args, i);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parent(msh, i, cmd_count);
|
||||||
|
msh->pids[i] = pid;
|
||||||
|
free(cmd_args);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exec_command(t_msh *msh, int i, int cmd_count)
|
||||||
|
{
|
||||||
|
g_return_code = 0;
|
||||||
|
msh->fds[i] = ft_calloc(2, sizeof(int *));
|
||||||
|
if (!msh->fds[i])
|
||||||
|
ft_exit(msh, 1);
|
||||||
|
if (first_is_in_type(msh))
|
||||||
|
{
|
||||||
|
get_in_type(msh, msh->tokens);
|
||||||
|
if (!g_return_code)
|
||||||
|
get_out_type(msh, msh->tokens);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
get_out_type(msh, msh->tokens);
|
||||||
|
if (!g_return_code)
|
||||||
|
get_in_type(msh, msh->tokens);
|
||||||
|
}
|
||||||
|
if (!cmd_is_builtin(msh, msh->cmds->value))
|
||||||
|
get_cmd_path(msh);
|
||||||
|
exec(msh, get_cmd_args(msh), i, cmd_count);
|
||||||
|
remove_command_from_msh(msh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void end_execution(t_msh *msh, int cmd_count)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < cmd_count)
|
||||||
|
waitpid(msh->pids[i++], &status, 0);
|
||||||
|
if (!g_return_code && WIFEXITED(status))
|
||||||
|
g_return_code = WEXITSTATUS(status);
|
||||||
|
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT)
|
||||||
|
printf("Quit (core dumped)\n");
|
||||||
|
i = 0;
|
||||||
|
while (i < cmd_count)
|
||||||
|
{
|
||||||
|
free(msh->fds[i]);
|
||||||
|
msh->fds[i] = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(msh->fds);
|
||||||
|
msh->fds = 0;
|
||||||
|
free(msh->pids);
|
||||||
|
msh->pids = 0;
|
||||||
|
//signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
||||||
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
|
set_echoctl(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exec_commands(t_msh *msh)
|
||||||
|
{
|
||||||
|
int cmd_count;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
ft_printf("yes\n");
|
||||||
|
if (!msh->cmds)
|
||||||
|
return ;
|
||||||
|
cmd_count = get_cmd_count(msh->cmds);
|
||||||
|
ft_printf("cmd_count: %d\n", cmd_count);
|
||||||
|
msh->fds = ft_calloc(cmd_count, sizeof(int **));
|
||||||
|
msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
||||||
|
if (!msh->pids || !msh->fds)
|
||||||
|
ft_exit(msh, 1);
|
||||||
|
while (++i < cmd_count)
|
||||||
|
exec_command(msh, i, cmd_count);
|
||||||
|
end_execution(msh, cmd_count);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/27 16:24:45 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 18:41:32 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
|||||||
{
|
{
|
||||||
t_token *cur_cmd;
|
t_token *cur_cmd;
|
||||||
|
|
||||||
cur_cmd = msh->cmds->next;
|
cur_cmd = msh->tokens->next;
|
||||||
if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->value))
|
if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->value))
|
||||||
numeric_arg_err(cur_cmd->value, exit_code);
|
numeric_arg_err(cur_cmd->value, exit_code);
|
||||||
else if (cur_cmd && cur_cmd->type == ARG)
|
else if (cur_cmd && cur_cmd->type == ARG)
|
||||||
@ -39,7 +39,7 @@ int exit_bt(t_msh *msh)
|
|||||||
int exit_code;
|
int exit_code;
|
||||||
int cmd_count;
|
int cmd_count;
|
||||||
|
|
||||||
cur_cmd = msh->cmds->next;
|
cur_cmd = msh->tokens->next;
|
||||||
ft_printf("exit\n");
|
ft_printf("exit\n");
|
||||||
if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG
|
if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG
|
||||||
&& ft_strisnbr(cur_cmd->value))
|
&& ft_strisnbr(cur_cmd->value))
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/27 16:55:22 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 18:45:02 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ int ft_export(t_msh *msh)
|
|||||||
char *value;
|
char *value;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
cmd = msh->cmds;
|
cmd = msh->tokens;
|
||||||
if (cmd && (!cmd->next || (cmd->next && cmd->next->type != ARG)))
|
if (cmd && (!cmd->next || (cmd->next && cmd->next->type != ARG)))
|
||||||
print_env_declare(msh->env);
|
print_env_declare(msh->env);
|
||||||
if (cmd && cmd->next && cmd->next->type == ARG && (!cmd->next->next
|
if (cmd && cmd->next && cmd->next->type == ARG && (!cmd->next->next
|
||||||
@ -94,7 +94,7 @@ int ft_unset(t_msh *msh)
|
|||||||
{
|
{
|
||||||
t_token *cmd;
|
t_token *cmd;
|
||||||
|
|
||||||
cmd = msh->cmds;
|
cmd = msh->tokens;
|
||||||
if (cmd)
|
if (cmd)
|
||||||
cmd = cmd->next;
|
cmd = cmd->next;
|
||||||
while (cmd && cmd->type == ARG)
|
while (cmd && cmd->type == ARG)
|
||||||
|
@ -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/03/28 13:26:42 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 17:09:09 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,53 +27,52 @@ void redirect_input(t_msh *msh, int i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_input_file(t_msh *msh, t_token **cur_cmd)
|
void open_input_file(t_msh *msh, t_token **cur_token)
|
||||||
{
|
{
|
||||||
if ((*cur_cmd)->type == HERE_DOC)
|
if ((*cur_token)->type == HERE_DOC)
|
||||||
handle_here_doc(msh, (*cur_cmd)->next->value);
|
handle_here_doc(msh, (*cur_token)->next->value);
|
||||||
if ((*cur_cmd)->type == RED_I)
|
if ((*cur_token)->type == RED_I)
|
||||||
{
|
{
|
||||||
if (msh->in_fd != 0)
|
if (msh->in_fd != 0)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
msh->in_fd = open((*cur_cmd)->next->value, O_RDONLY);
|
msh->in_fd = open((*cur_token)->next->value, O_RDONLY);
|
||||||
if (msh->in_fd == -1 && !g_return_code)
|
if (msh->in_fd == -1 && !g_return_code)
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: %s: ", (*cur_cmd)->next->value);
|
ft_printf_fd(2, "minishell: %s: ", (*cur_token)->next->value);
|
||||||
perror("");
|
perror("");
|
||||||
g_return_code = 1;
|
g_return_code = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_in_type(t_msh *msh, t_token *cmds)
|
void get_in_type(t_msh *msh, t_token *tokens)
|
||||||
{
|
{
|
||||||
t_token *cur_cmd;
|
t_token *cur_token;
|
||||||
|
|
||||||
cur_cmd = cmds;
|
cur_token = tokens;
|
||||||
while (cur_cmd && cur_cmd->next && cur_cmd->type == ARG)
|
while (cur_token && cur_token->next && cur_token->type == ARG)
|
||||||
cur_cmd = cur_cmd->next;
|
cur_token = cur_token->next;
|
||||||
if (cur_cmd->type)
|
if (cur_token->type)
|
||||||
{
|
{
|
||||||
msh->in_type = cur_cmd->type;
|
msh->in_type = cur_token->type;
|
||||||
if (cur_cmd->type == HERE_DOC || cur_cmd->type == RED_I)
|
if (cur_token->type == HERE_DOC || cur_token->type == RED_I)
|
||||||
open_input_file(msh, &cur_cmd);
|
open_input_file(msh, &cur_token);
|
||||||
}
|
}
|
||||||
while (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG)
|
while (cur_token && cur_token->next && cur_token->next->type == ARG)
|
||||||
cur_cmd = cur_cmd->next;
|
cur_token = cur_token->next;
|
||||||
if (cur_cmd->next && (cur_cmd->next->type == HERE_DOC
|
if (cur_token->next && (cur_token->next->type == HERE_DOC
|
||||||
|| cur_cmd->next->type == RED_I))
|
|| cur_token->next->type == RED_I))
|
||||||
get_in_type(msh, cur_cmd);
|
get_in_type(msh, cur_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
int first_is_in_type(t_msh *msh)
|
int first_is_in_type(t_msh *msh)
|
||||||
{
|
{
|
||||||
t_token *cur_cmd;
|
t_token *cur_token;
|
||||||
|
|
||||||
cur_cmd = msh->cmds;
|
cur_token = msh->tokens;
|
||||||
while (cur_cmd && cur_cmd->type == ARG && cur_cmd->next)
|
while (cur_token && cur_token->type == ARG && cur_token->next)
|
||||||
cur_cmd = cur_cmd->next;
|
cur_token = cur_token->next;
|
||||||
if (/*cur_cmd->type == PIPE || */cur_cmd->type == RED_I
|
if (cur_token->type == RED_I || cur_token->type == HERE_DOC)
|
||||||
|| cur_cmd->type == HERE_DOC)
|
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/29 14:45:43 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 17:21:23 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
|||||||
(*msh)->env = get_env(envp);
|
(*msh)->env = get_env(envp);
|
||||||
tcgetattr(1, &t_p);
|
tcgetattr(1, &t_p);
|
||||||
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
||||||
//signal(SIGINT, signal_handler_interactive);
|
//signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
||||||
signal(SIGQUIT, signal_handler_interactive);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
if (set_echoctl(0))
|
if (set_echoctl(0))
|
||||||
ft_exit(*msh, 1);
|
ft_exit(*msh, 1);
|
||||||
|
@ -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/03/29 14:36:18 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 17:15:14 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ typedef enum e_cmd_type
|
|||||||
|
|
||||||
typedef struct s_cmd
|
typedef struct s_cmd
|
||||||
{
|
{
|
||||||
t_cmd_type cmd_type;
|
t_cmd_type cmd_type;
|
||||||
char *value;
|
char *value;
|
||||||
struct s_cmd *next;
|
struct s_cmd *next;
|
||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
@ -67,16 +67,17 @@ typedef struct s_env
|
|||||||
|
|
||||||
typedef struct s_msh
|
typedef struct s_msh
|
||||||
{
|
{
|
||||||
struct s_env *env;
|
t_env *env;
|
||||||
struct s_token *cmds;
|
t_cmd *cmds;
|
||||||
int **fds;
|
t_token *tokens;
|
||||||
int *pids;
|
int **fds;
|
||||||
enum e_token_type in_type;
|
int *pids;
|
||||||
enum e_token_type out_type;
|
t_token_type in_type;
|
||||||
int in_fd;
|
t_token_type out_type;
|
||||||
int out_fd;
|
int in_fd;
|
||||||
int locked_return_code;
|
int out_fd;
|
||||||
int echoctl;
|
int locked_return_code;
|
||||||
|
int echoctl;
|
||||||
} t_msh;
|
} t_msh;
|
||||||
|
|
||||||
extern int g_return_code;
|
extern int g_return_code;
|
||||||
@ -95,7 +96,7 @@ 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);
|
||||||
void get_out_type(t_msh *msh, t_token *cmds);
|
void get_out_type(t_msh *msh, t_token *cmds);
|
||||||
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_token *cmds);
|
void get_in_type(t_msh *msh, t_token *tokens);
|
||||||
void signal_handler_interactive(int signum);
|
void signal_handler_interactive(int signum);
|
||||||
int get_token_len(char *cmd, t_env *env);
|
int get_token_len(char *cmd, t_env *env);
|
||||||
void signal_handler_here_doc(int signum);
|
void signal_handler_here_doc(int signum);
|
||||||
@ -115,10 +116,10 @@ void print_parsed_token(t_token *cmd);//debug
|
|||||||
int get_var_name_len(char *command);
|
int get_var_name_len(char *command);
|
||||||
void handle_minishellrc(t_msh *msh);
|
void handle_minishellrc(t_msh *msh);
|
||||||
char *get_tmp_file_name(t_msh *msh);
|
char *get_tmp_file_name(t_msh *msh);
|
||||||
int get_args_count(t_token *cmds);
|
int get_args_count(t_cmd *cmds);
|
||||||
char **env_to_char_tab(t_env *env);
|
char **env_to_char_tab(t_env *env);
|
||||||
void print_parsed_cmd(t_cmd *cmd);//debug
|
void print_parsed_cmd(t_cmd *cmd);//debug
|
||||||
int get_cmd_count(t_token *cmds);
|
int get_cmd_count(t_cmd *cmds);
|
||||||
int first_is_in_type(t_msh *msh);
|
int first_is_in_type(t_msh *msh);
|
||||||
int contains_newline(char *str);
|
int contains_newline(char *str);
|
||||||
int check_var_name(char *name);
|
int check_var_name(char *name);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* 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 #+# #+# */
|
||||||
/* Updated: 2024/03/28 13:26:17 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 18:44:30 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -58,9 +58,9 @@ void get_out_type(t_msh *msh, t_token *cmds)
|
|||||||
msh->out_type = ARG;
|
msh->out_type = ARG;
|
||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
cur_cmd = cmds;
|
cur_cmd = cmds;
|
||||||
if (cmds->type && msh->cmds == cmds)
|
if (cmds->type && msh->tokens == cmds)
|
||||||
{
|
{
|
||||||
while (msh->cmds->type != ARG && msh->cmds->next->next)
|
while (msh->cmds->cmd_type != ARG && msh->cmds->next->next)
|
||||||
msh->cmds = msh->cmds->next->next;
|
msh->cmds = msh->cmds->next->next;
|
||||||
}
|
}
|
||||||
while (cur_cmd && cur_cmd->next && (cur_cmd->type == ARG
|
while (cur_cmd && cur_cmd->next && (cur_cmd->type == ARG
|
||||||
|
@ -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/03/28 13:56:58 by tomoron ### ########.fr */
|
/* Updated: 2024/03/30 18:45:27 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ void free_msh(t_msh *msh)
|
|||||||
free_env(msh->env);
|
free_env(msh->env);
|
||||||
free(msh->pids);
|
free(msh->pids);
|
||||||
free(msh->fds);
|
free(msh->fds);
|
||||||
free_token(msh->cmds);
|
free_token(msh->tokens);
|
||||||
set_echoctl(msh->echoctl);
|
set_echoctl(msh->echoctl);
|
||||||
free(msh);
|
free(msh);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user