|
|
@ -12,21 +12,21 @@ |
|
|
|
|
|
|
|
#include "minishell.h" |
|
|
|
|
|
|
|
int command_call(char *argv[]) |
|
|
|
int command_call(t_command *cmd) |
|
|
|
{ |
|
|
|
if (ft_strncmp(argv[0], "echo", 5) == 0) |
|
|
|
return (ft_echo(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "pwd", 4) == 0) |
|
|
|
return (ft_pwd(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "cd", 3) == 0) |
|
|
|
return (ft_cd(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "export", 7) == 0) |
|
|
|
return (ft_export(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "unset", 6) == 0) |
|
|
|
return (ft_unset(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "env", 4) == 0) |
|
|
|
return (ft_env(argv)); |
|
|
|
else if (ft_strncmp(argv[0], "exit", 5) == 0) |
|
|
|
if (ft_strncmp(cmd->argv[0], "echo", 5) == 0) |
|
|
|
return (ft_echo(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "pwd", 4) == 0) |
|
|
|
return (ft_pwd(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "cd", 3) == 0) |
|
|
|
return (ft_cd(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "export", 7) == 0) |
|
|
|
return (ft_export(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "unset", 6) == 0) |
|
|
|
return (ft_unset(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "env", 4) == 0) |
|
|
|
return (ft_env(cmd)); |
|
|
|
else if (ft_strncmp(cmd->argv[0], "exit", 5) == 0) |
|
|
|
return (close_minishell(0)); |
|
|
|
else |
|
|
|
{ |
|
|
@ -35,25 +35,25 @@ int command_call(char *argv[]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void exe(char *argv[], char *const envp[]) |
|
|
|
void exe(t_command *cmd) |
|
|
|
{ |
|
|
|
char **path_dirs; |
|
|
|
char *path; |
|
|
|
size_t path_length; |
|
|
|
|
|
|
|
if (ft_strchr(argv[0], '/')) |
|
|
|
execve(argv[0], argv, envp); |
|
|
|
if (ft_strchr(cmd->argv[0], '/')) |
|
|
|
execve(cmd->argv[0], cmd->argv, *cmd->envp); |
|
|
|
else |
|
|
|
{ |
|
|
|
path_dirs = ft_split(getenv("PATH"), ':'); |
|
|
|
while (path_dirs) |
|
|
|
{ |
|
|
|
path_length = ft_strlen(*path_dirs) + ft_strlen(argv[0]) + 2; |
|
|
|
path_length = ft_strlen(*path_dirs) + ft_strlen(cmd->argv[0]) + 2; |
|
|
|
path = ft_calloc(path_length, sizeof(char)); |
|
|
|
ft_memcpy(path, *path_dirs, ft_strlen(*path_dirs)); |
|
|
|
ft_memcpy(path + ft_strlen(*path_dirs),"/", 1); |
|
|
|
ft_memcpy(path + ft_strlen(*path_dirs) + 1, argv[0], ft_strlen(argv[0])); |
|
|
|
execve(path, argv, envp); |
|
|
|
ft_memcpy(path + ft_strlen(*path_dirs) + 1, cmd->argv[0], ft_strlen(cmd->argv[0])); |
|
|
|
execve(path, cmd->argv, *cmd->envp); |
|
|
|
path_dirs++; |
|
|
|
} |
|
|
|
} |
|
|
|