diff --git a/srcs/builtins.c b/srcs/builtins.c index ecdd52e..2c3d435 100755 --- a/srcs/builtins.c +++ b/srcs/builtins.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ -/* Updated: 2024/04/23 10:56:19 by marde-vr ### ########.fr */ +/* Updated: 2024/04/23 12:50:19 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,11 +33,8 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token) g_return_code = cd(msh->tokens); else if (!ft_strcmp(cmd_token, "exit")) g_return_code = exit_bt(msh); - else if (!ft_strcmp(cmd_token, "export") && (msh->out_type == PIPE - || msh->out_type == RED_O || msh->out_type == RED_O_APP)) - ft_printf_fd(2, "print the thing into the pipe\n"); - else if (!ft_strcmp(cmd_token, "export")) - g_return_code = ft_export(msh->tokens, msh->env); + else if (!ft_strcmp(cmd_token, "export") && msh->out_type != PIPE) + g_return_code = ft_export(msh, msh->tokens, msh->env); else if (!ft_strcmp(cmd_token, "unset")) g_return_code = ft_unset(msh); else @@ -61,11 +58,9 @@ int exec_builtin(t_msh *msh) g_return_code = pwd(); else if (!ft_strcmp(msh->tokens->value, "cd")) return (1); - else if (!ft_strcmp(msh->tokens->value, "export") && (msh->out_type == PIPE - || msh->out_type == RED_O || msh->out_type == RED_O_APP)) - ft_printf_fd(2, "catch the printed stuff and put it write it into file\n"); + else if (!ft_strcmp(msh->tokens->value, "export") && msh->out_type == PIPE) + g_return_code = ft_export(msh, msh->tokens, msh->env); else if (!ft_strcmp(msh->tokens->value, "export")) - //g_return_code = ft_export(msh->tokens, msh->env); return (1); else if (!ft_strcmp(msh->tokens->value, "unset")) return (1); diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 786e72a..5c12202 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/22 19:55:41 by marde-vr ### ########.fr */ +/* Updated: 2024/04/23 13:21:32 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -136,6 +136,13 @@ int get_cmd_count(t_cmd *cmds) return (nb); } +int is_parentethis(t_cmd *cmd) +{ + if(!cmd) + return(0); + return(cmd->cmd_type == PAREN || (cmd->cmd_type == PIPE && cmd->next->cmd_type == PAREN)); +} + void print_signaled(int status) { int signal; diff --git a/srcs/export.c b/srcs/export.c index a88fcb0..5ce4201 100755 --- a/srcs/export.c +++ b/srcs/export.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ -/* Updated: 2024/04/22 23:02:44 by tomoron ### ########.fr */ +/* Updated: 2024/04/23 12:49:46 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,20 +53,22 @@ void sort_env(t_env *env) } } -void print_env_declare(t_env *env_orig) +void print_env_declare(t_msh *msh, t_env *env_orig) { t_env *env; env = dup_env(env_orig); sort_env(env); + if(!msh->out_fd) + msh->out_fd = 1; while (env) { if (strcmp(env->name, "_")) { if (env->value && *(env->value)) - printf("declare -x %s=\"%s\"\n", env->name, env->value); + ft_printf_fd(msh->out_fd, "declare -x %s=\"%s\"\n", env->name, env->value); else - printf("declare -x %s\n", env->name); + ft_printf_fd(msh->out_fd, "declare -x %s\n", env->name); } env = env->next; } @@ -115,7 +117,7 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append) return (env_add_back(env, name, value)); } -int ft_export(t_token *cmd, t_env *env) +int ft_export(t_msh *msh, t_token *cmd, t_env *env) { char *arg; char *name; @@ -124,7 +126,7 @@ int ft_export(t_token *cmd, t_env *env) int append; if (cmd && !cmd->next) - print_env_declare(env); + print_env_declare(msh, env); if (cmd && cmd->next && !cmd->next->next) { arg = cmd->next->value; diff --git a/srcs/minishell.h b/srcs/minishell.h index 4de4bc2..d9a4c87 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/22 19:30:03 by marde-vr ### ########.fr */ +/* Updated: 2024/04/23 12:37:16 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -141,7 +141,7 @@ int set_echoctl(int value); int is_output_type(t_cmd *cmd); int print_env(t_env *env); t_cmd *free_cmd(t_cmd *cmd); -int ft_export(t_token *cmd, t_env *env); +int ft_export(t_msh *msh, t_token *cmd, t_env *env); int is_input_type(t_cmd *cmd); void free_env(t_env *env); int ft_unset(t_msh *msh); diff --git a/todo_list b/todo_list index 5f5096f..67fc9e8 100644 --- a/todo_list +++ b/todo_list @@ -1,3 +1 @@ pipe with parenthesis - -redirections d'output des builtins