fix quelques trucs
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/04/23 19:56:00 by tomoron ### ########.fr */
|
/* Updated: 2024/04/29 21:47:25 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
int cmd_is_forkable_builtin(char *cmd_token)
|
int cmd_is_forkable_builtin(char *cmd_token)
|
||||||
{
|
{
|
||||||
if (!ft_strcmp(cmd_token, "echo") || !ft_strcmp(cmd_token, "ret")
|
if (!ft_strcmp(cmd_token, "echo") || !ft_strcmp(cmd_token, "env")
|
||||||
|| !ft_strcmp(cmd_token, "env") || !ft_strcmp(cmd_token, "exit")
|
|| !ft_strcmp(cmd_token, "exit") || !ft_strcmp(cmd_token, "pwd")
|
||||||
|| !ft_strcmp(cmd_token, "pwd") || !ft_strcmp(cmd_token, "cd")
|
|| !ft_strcmp(cmd_token, "cd") || !ft_strcmp(cmd_token, "export")
|
||||||
|| !ft_strcmp(cmd_token, "export") || !ft_strcmp(cmd_token, "unset"))
|
|| !ft_strcmp(cmd_token, "unset"))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -48,8 +48,6 @@ int exec_builtin(t_msh *msh)
|
|||||||
return (0);
|
return (0);
|
||||||
if (!ft_strcmp(msh->tokens->value, "echo"))
|
if (!ft_strcmp(msh->tokens->value, "echo"))
|
||||||
g_return_code = echo(msh->tokens->next);
|
g_return_code = echo(msh->tokens->next);
|
||||||
else if (!ft_strcmp(msh->tokens->value, "ret"))
|
|
||||||
g_return_code = ft_atoi(msh->tokens->next->value);
|
|
||||||
else if (!ft_strcmp(msh->tokens->value, "env"))
|
else if (!ft_strcmp(msh->tokens->value, "env"))
|
||||||
g_return_code = print_env(msh->env);
|
g_return_code = print_env(msh->env);
|
||||||
else if (!ft_strcmp(msh->tokens->value, "exit"))
|
else if (!ft_strcmp(msh->tokens->value, "exit"))
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/29 21:42:38 by tomoron ### ########.fr */
|
/* Updated: 2024/04/29 22:11:06 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -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/26 15:26:41 by tomoron ### ########.fr */
|
/* Updated: 2024/04/29 22:06:15 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -75,6 +75,7 @@ void exec_command(t_msh *msh, int i, int cmd_count)
|
|||||||
get_redirections(msh, msh->cmds);
|
get_redirections(msh, msh->cmds);
|
||||||
if (msh->in_fd != -2)
|
if (msh->in_fd != -2)
|
||||||
{
|
{
|
||||||
|
msh->last_return_code = g_return_code;
|
||||||
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])
|
||||||
@ -121,8 +122,8 @@ void exec_commands(t_msh *msh)
|
|||||||
|
|
||||||
if (!msh->tokens && !is_parenthesis(msh->cmds))
|
if (!msh->tokens && !is_parenthesis(msh->cmds))
|
||||||
{
|
{
|
||||||
g_return_code = 0;
|
|
||||||
get_redirections(msh, msh->cmds);
|
get_redirections(msh, msh->cmds);
|
||||||
|
g_return_code = (msh->in_fd == -1 || msh->out_fd == -1);
|
||||||
if (msh->in_fd > 2)
|
if (msh->in_fd > 2)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
if (msh->out_fd > 2)
|
if (msh->out_fd > 2)
|
||||||
|
@ -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/04/26 10:49:17 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/29 21:54:57 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
|||||||
else if (cur_cmd)
|
else if (cur_cmd)
|
||||||
*exit_code = (unsigned char)ft_atoi(cur_cmd->value);
|
*exit_code = (unsigned char)ft_atoi(cur_cmd->value);
|
||||||
else
|
else
|
||||||
*exit_code = g_return_code;
|
*exit_code = msh->last_return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exit_bt(t_msh *msh)
|
int exit_bt(t_msh *msh)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/25 18:53:51 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/29 22:11:22 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ int print_env(t_env *env)
|
|||||||
{
|
{
|
||||||
while (env)
|
while (env)
|
||||||
{
|
{
|
||||||
|
if (*env->value)
|
||||||
ft_printf("%s=%s\n", env->name, env->value);
|
ft_printf("%s=%s\n", env->name, env->value);
|
||||||
env = env->next;
|
env = env->next;
|
||||||
}
|
}
|
||||||
|
@ -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/29 11:12:35 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/29 21:50:52 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ typedef struct s_msh
|
|||||||
int in_fd;
|
int in_fd;
|
||||||
int echoctl;
|
int echoctl;
|
||||||
int out_fd;
|
int out_fd;
|
||||||
|
int last_return_code;
|
||||||
int locked_return_code;
|
int locked_return_code;
|
||||||
char *here_doc_filename;
|
char *here_doc_filename;
|
||||||
} t_msh;
|
} t_msh;
|
||||||
|
3
todo
3
todo
@ -1,6 +1,3 @@
|
|||||||
- cat filenotfound -> exit # (exit avec le status 0 et pas 1)
|
|
||||||
- < filenotfound # (status code pas a 1)
|
|
||||||
- export aaa -> env # (variable aaa qui s'affiche)
|
|
||||||
- .. # (pas de command not found)
|
- .. # (pas de command not found)
|
||||||
- cat Makefile | commandnotfound | cat
|
- cat Makefile | commandnotfound | cat
|
||||||
- cat < Makefile | rev | cat -e | rev | cat
|
- cat < Makefile | rev | cat -e | rev | cat
|
||||||
|
Reference in New Issue
Block a user