diff --git a/.fill_env.c.swp b/.env_fill.c.swp similarity index 77% rename from .fill_env.c.swp rename to .env_fill.c.swp index 164f87e..13854eb 100644 Binary files a/.fill_env.c.swp and b/.env_fill.c.swp differ diff --git a/Makefile b/Makefile index 8d576dc..ff84e10 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c -SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c +SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c env_fill.c OBJS = ${SRCS:.c=.o} diff --git a/cmd.c b/cmd.c index e6581ef..cfe007d 100644 --- a/cmd.c +++ b/cmd.c @@ -6,10 +6,11 @@ /* By: cchauvet args = args; diff --git a/cmds.c b/cmds.c index 3f316cb..e05b8eb 100644 --- a/cmds.c +++ b/cmds.c @@ -6,13 +6,14 @@ /* By: cchauvet -static char *ft_get_variable(char **env, char *variable) -{ - size_t i; - - i = 0; - while (env[i] != NULL) - { - if (ft_strncmp(variable, env[i], ft_strlen(variable)) == 0) - return (ft_strchr(env[i], '=') + 1); - i++; - } - return (NULL); -} - -static char *ft_get_executable_path(char *executable_name, char **env) +static char *ft_get_executable_path(char *executable_name, t_list **env) { char *path; char *temp; @@ -33,10 +19,15 @@ static char *ft_get_executable_path(char *executable_name, char **env) ft_eprintf("minishell: malloc failed\n"); return (NULL); } + if (access(path, X_OK) == 0) + { + ft_eprintf("minishell: %s: permission denied\n", path); + return (NULL); + } } else { - tab = ft_split(ft_get_variable(env, "PATH"), ':'); + tab = ft_split(get_value_by_key("PATH", env), ':'); if (tab == NULL) return (NULL); i = 0; @@ -66,10 +57,11 @@ static char *ft_get_executable_path(char *executable_name, char **env) return (path); } -static int ft_excutor(t_cmd *cmd, char **env) +static int ft_excutor(t_cmd *cmd, t_list **env) { int pid; int return_value; + char **tab; if (cmd->fd_in == -1 || cmd->fd_out == -1) return (1); @@ -78,16 +70,21 @@ static int ft_excutor(t_cmd *cmd, char **env) return (1); if (pid == 0) { + //TODO DO THIS + /* tab = t_env2tab(env); */ + /* if (tab == NULL) */ + /* return (1); */ + tab = NULL; dup2(cmd->fd_out, 1); dup2(cmd->fd_in, 0); - execve(cmd->executable, cmd->args, env); + execve(cmd->executable, cmd->args, tab); } else waitpid(pid, &return_value, 0); return (return_value); } -int ft_cmds_executor(t_list **cmds, char **env) +int ft_cmds_executor(t_list **cmds, t_list **env) { t_cmd *content; t_list *current; diff --git a/infile.c b/infile.c index 805ab12..c0e09ce 100644 --- a/infile.c +++ b/infile.c @@ -6,7 +6,7 @@ /* By: cchauvet t_list **init_env(char **env); -int set_value_key(t_list **env, char *key, char *value); -char *get_value_index(int index, t_list **head); -char *get_value_key(char *key, t_list **head); +int set_value_by_key(char *key, char *value, t_list **env); +char *get_value_by_key(char *key, t_list **head); int ft_syntatic_verif(const char *str); int ft_file_is_readable(const char *path); int ft_file_is_writable(const char *path); @@ -35,13 +34,14 @@ int ft_infile(char *line); int ft_outfile(char *line); int ft_heredoc(char *stop); size_t ft_seglen_quoted(const char *str, char c); -int ft_cmds_executor(t_list **cmds, char **env); +int ft_cmds_executor(t_list **cmds, t_list **env); char **ft_split_quoted(const char *s, char c); void ft_cmddel(void *content); void env_del(void *content); -t_list **ft_parse_cmds(char *line); -int ft_cmd_filler(t_list *current, char **args); +t_list **ft_parse_cmds(char *line, t_list **env); +int ft_cmd_filler(t_list *current, char **args, t_list **env); char *ft_normalizer(char *str); +char *ft_env_filler(t_list **env, const char *str); typedef struct s_cmd { diff --git a/outfile.c b/outfile.c index f2e3c6b..ec1a8eb 100644 --- a/outfile.c +++ b/outfile.c @@ -6,7 +6,7 @@ /* By: cchauvet ') + if (fd != 1) + close(fd); if (ft_strcmp(">", tab[i]) == 0) fd = ft_file_is_writable(ft_quote_remover(tab[i + 1])); else if (ft_strcmp(">>", tab[i]) == 0)