env modifiable

This commit is contained in:
2024-02-18 16:37:22 +01:00
parent 86d96fc099
commit 1396ee52af
2 changed files with 13 additions and 13 deletions

View File

@ -6,13 +6,13 @@
/* 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/02/18 16:22:58 by tomoron ### ########.fr */ /* Updated: 2024/02/18 16:36:29 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int exec_builtin(t_cmd *parsed_cmd, t_env *env, t_alias **aliases) int exec_builtin(t_cmd *parsed_cmd, t_env **env, t_alias **aliases)
{ {
if (!ft_strcmp(parsed_cmd->token, "echo")) if (!ft_strcmp(parsed_cmd->token, "echo"))
@ -20,9 +20,9 @@ int exec_builtin(t_cmd *parsed_cmd, t_env *env, t_alias **aliases)
else if (!ft_strcmp(parsed_cmd->token, "ret")) else if (!ft_strcmp(parsed_cmd->token, "ret"))
g_return_code = ft_atoi(parsed_cmd->next->token); g_return_code = ft_atoi(parsed_cmd->next->token);
else if (!ft_strcmp(parsed_cmd->token, "env")) else if (!ft_strcmp(parsed_cmd->token, "env"))
g_return_code = print_env(env); g_return_code = print_env(*env);
else if (!ft_strcmp(parsed_cmd->token, "exit")) else if (!ft_strcmp(parsed_cmd->token, "exit"))
exit_bt(parsed_cmd, env, *aliases); exit_bt(parsed_cmd, *env, *aliases);
else if (!ft_strcmp(parsed_cmd->token, "pwd")) else if (!ft_strcmp(parsed_cmd->token, "pwd"))
g_return_code = pwd(); g_return_code = pwd();
else if (!ft_strcmp(parsed_cmd->token, "cd")) else if (!ft_strcmp(parsed_cmd->token, "cd"))
@ -134,7 +134,7 @@ void get_cmd_path(t_cmd *cmd, t_env *env)
} }
} }
void exec_command(t_cmd *parsed_cmd, t_env *env, t_alias **aliases) void exec_command(t_cmd *parsed_cmd, t_env **env, t_alias **aliases)
{ {
t_cmd *cur_cmd; t_cmd *cur_cmd;
int args_count; int args_count;
@ -147,9 +147,9 @@ void exec_command(t_cmd *parsed_cmd, t_env *env, t_alias **aliases)
args_count = get_args_count(parsed_cmd); args_count = get_args_count(parsed_cmd);
cmd_args = ft_calloc(args_count + 1, sizeof(char *)); cmd_args = ft_calloc(args_count + 1, sizeof(char *));
if (!cmd_args) if (!cmd_args)
ft_exit(parsed_cmd, env, 1); ft_exit(parsed_cmd, *env, 1);
i = 0; i = 0;
get_cmd_path(parsed_cmd, env); get_cmd_path(parsed_cmd, *env);
while (i < args_count) while (i < args_count)
{ {
cmd_args[i] = cur_cmd->token; cmd_args[i] = cur_cmd->token;
@ -161,19 +161,19 @@ void exec_command(t_cmd *parsed_cmd, t_env *env, t_alias **aliases)
if (pid == -1) if (pid == -1)
{ {
perror("fork"); perror("fork");
ft_exit(parsed_cmd, env, 1); ft_exit(parsed_cmd, *env, 1);
} }
if (pid == 0) if (pid == 0)
{ {
if (parsed_cmd->token) if (parsed_cmd->token)
execve(parsed_cmd->token, cmd_args, env_to_char_tab(env)); execve(parsed_cmd->token, cmd_args, env_to_char_tab(*env));
ft_exit(parsed_cmd, env, 1); ft_exit(parsed_cmd, *env, 1);
} }
else else
{ {
rl_redisplay(); rl_redisplay();
if (waitpid(pid, 0, 0) < 0) if (waitpid(pid, 0, 0) < 0)
ft_exit(parsed_cmd, env, 1); ft_exit(parsed_cmd, *env, 1);
} }
//if (cur_cmd->type == PIPE) //if (cur_cmd->type == PIPE)
// exec_command(cur_cmd->next, env); // exec_command(cur_cmd->next, env);

View File

@ -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/02/18 16:26:27 by tomoron ### ########.fr */ /* Updated: 2024/02/18 16:31:58 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -56,7 +56,7 @@ extern int g_return_code;
t_cmd *cmd_add_back(t_cmd *res, char *token, t_token_type type); t_cmd *cmd_add_back(t_cmd *res, char *token, t_token_type type);
void free_cmd(t_cmd *cmd); void free_cmd(t_cmd *cmd);
void exec_command(t_cmd *cmd, t_env *env, t_alias **alias); void exec_command(t_cmd *cmd, t_env **env, t_alias **alias);
int echo(t_cmd *args); int echo(t_cmd *args);
void exit_bt(t_cmd *args, t_env *env, t_alias *aliases); void exit_bt(t_cmd *args, t_env *env, t_alias *aliases);
t_env *env_add_back(t_env *env, char *name, char *value); t_env *env_add_back(t_env *env, char *name, char *value);