diff --git a/.nfs00000000098c816100000162 b/.nfs00000000098c816100000162 new file mode 100755 index 0000000..ec49366 Binary files /dev/null and b/.nfs00000000098c816100000162 differ diff --git a/builtins/builtins_private.h b/builtins/builtins_private.h index a29128c..4c0f98e 100644 --- a/builtins/builtins_private.h +++ b/builtins/builtins_private.h @@ -4,5 +4,7 @@ # include "../libftx/libftx.h" # include "../env/env.h" # include "../utils/utils.h" + char *get_pwd(int fd); + #endif diff --git a/data/data.h b/data/data.h index f20c87f..11404c9 100644 --- a/data/data.h +++ b/data/data.h @@ -10,5 +10,6 @@ typedef struct s_data int child_pid; } t_data; -t_data *ft_get_data(); +t_data *ft_get_data(void); + #endif diff --git a/env/env_fill.c b/env/env_fill.c index be85e83..eb64c42 100644 --- a/env/env_fill.c +++ b/env/env_fill.c @@ -22,6 +22,8 @@ static char *ft_getkey(const char *str) key = ft_strdup("$"); else if (ft_strncmp(str, "$?", 2) == 0) key = ft_strdup("?"); + if (str[1] == '\0') + key = ft_strdup(""); else { i = 1; @@ -42,12 +44,14 @@ static char *ft_getvalue(t_data *data, char *key) value = ft_itoa(data->exit_code); else if (ft_strcmp(key, "$") == 0) value = ft_strdup("PID"); + else if (key[0] == '\0') + value = ft_strdup("$"); else { value = get_value_by_key(key, data->env); if (value == NULL) value = ft_strdup(""); - else + else value = ft_strdup(value); } if (value == NULL) @@ -55,7 +59,8 @@ static char *ft_getvalue(t_data *data, char *key) return (value); } -static char *ft_getvalue_by_str(t_data *data, const char *str, size_t *key_len) +static char *ft_getvalue_by_str(t_data *data, const char *str, + size_t *key_len) { char *key; char *value; diff --git a/parse/parse.c b/parse/parse.c index be1dd7c..9f4a6a9 100644 --- a/parse/parse.c +++ b/parse/parse.c @@ -115,10 +115,8 @@ int ft_cmds_parser(t_data *data, const char *line) } if (*data->cmds != NULL) { - if (((t_cmd *) (*data->cmds)->content)->fd_in[0] == -1) - ((t_cmd *) (*data->cmds)->content)->fd_in[0] = 0; - if (((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] == -1) - (((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] = 1); + ft_add_fd(((t_cmd *)(*data->cmds)->content)->fd_in, 0); + ft_add_fd(((t_cmd *)(ft_lstlast(*data->cmds))->content)->fd_out, 1); } ft_freer_tab_ultimate(1, tab); return (0); diff --git a/redirection/redirection.h b/redirection/redirection.h index cb5bb30..66f32fa 100644 --- a/redirection/redirection.h +++ b/redirection/redirection.h @@ -4,6 +4,6 @@ # include "../cmd/cmd.h" int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str); -int *ft_get_heredoc(); +int *ft_get_heredoc(void); #endif diff --git a/utils/ft_get_executable.c b/utils/ft_get_executable.c index 2ad3c54..e1b7979 100644 --- a/utils/ft_get_executable.c +++ b/utils/ft_get_executable.c @@ -54,10 +54,10 @@ char *ft_get_executable_without_path(t_data *data, const char *name) if (path == NULL) { ft_eprintf("minishell: malloc failed\n"); - break; + break ; } if (access(path, X_OK) == 0) - break; + break ; free(path); path = NULL; i++; @@ -74,7 +74,7 @@ char *ft_get_executable_without_path(t_data *data, const char *name) char *ft_get_executable(t_data *data, const char *name) { char *path; - + if (name[0] == '.' || name[0] == '/') path = ft_get_executable_with_path(data, name); else diff --git a/utils/utils.h b/utils/utils.h index 88f8725..d1a23aa 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -29,8 +29,7 @@ void ft_strshift(char *str, int shift); char *ft_quote_remover(char *str); int ft_atoi_check(const char *nptr); char *ft_get_executable(t_data *data, const char *name); -void ft_closer(int fds[2]); -void ft_add_fd(int fds[2], int fd); - +void ft_closer(int fds[2]); +void ft_add_fd(int fds[2], int fd); #endif