diff options
author | joe <rbousset@42lyon.fr> | 2020-11-30 17:34:00 +0100 |
---|---|---|
committer | joe <rbousset@42lyon.fr> | 2020-11-30 17:34:00 +0100 |
commit | 75bad8f18024e8b4dbb9700329cfb888ae1e3dc3 (patch) | |
tree | b8fe22aa34e578191d165ed2486b272e66e65f5e /src | |
parent | get normed (diff) | |
download | 42-minishell-75bad8f18024e8b4dbb9700329cfb888ae1e3dc3.tar.gz 42-minishell-75bad8f18024e8b4dbb9700329cfb888ae1e3dc3.tar.bz2 42-minishell-75bad8f18024e8b4dbb9700329cfb888ae1e3dc3.tar.xz 42-minishell-75bad8f18024e8b4dbb9700329cfb888ae1e3dc3.tar.zst 42-minishell-75bad8f18024e8b4dbb9700329cfb888ae1e3dc3.zip |
In progress
Diffstat (limited to 'src')
-rw-r--r-- | src/c_init.c | 3 | ||||
-rw-r--r-- | src/c_init.h | 5 | ||||
-rw-r--r-- | src/s_init_next.c | 46 |
3 files changed, 40 insertions, 14 deletions
diff --git a/src/c_init.c b/src/c_init.c index 2ba73f5..5e09031 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -88,6 +88,9 @@ static short return (c_end_key(ft_strlen(line), tcaps->plen, tcaps)); else if ((*((unsigned int *)buf)) == CTRL_L) return (c_ctrl_l(line, tcaps, msh)); + else if (((*((unsigned int *)buf)) == UP_K) || + ((*((unsigned int *)buf)) == CTRL_P)) + return (ft_dprintf(0, "qweqwe\n")); else if ((*((unsigned int *)buf)) == CTRL_D && line[0] == '\0') { diff --git a/src/c_init.h b/src/c_init.h index f563df2..a41202d 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -18,8 +18,10 @@ # include "s_struct.h" -# define LEFT_K 0x445b1b +# define UP_K 0x415b1b +# define DOWN_K 0x425b1b # define RIGHT_K 0x435b1b +# define LEFT_K 0x445b1b # define HOME_K 0x485b1b # define END_K 0x465b1b # define DEL_K 0x7f @@ -32,6 +34,7 @@ # define CTRL_E 0x05 # define CTRL_F 0x06 # define CTRL_L 0x0c +# define CTRL_P 0x10 typedef struct s_caps { diff --git a/src/s_init_next.c b/src/s_init_next.c index 4521ce1..d506d9d 100644 --- a/src/s_init_next.c +++ b/src/s_init_next.c @@ -10,16 +10,17 @@ /* */ /* ************************************************************************** */ -#include <libft.h> -#include <stdlib.h> -#include <unistd.h> #include <dirent.h> #include <errno.h> +#include <libft.h> #ifdef __linux__ # include <linux/limits.h> #else # include <limits.h> #endif +#include <paths.h> +#include <stdlib.h> +#include <unistd.h> #include "b_export_next.h" #include "f_fail.h" @@ -27,7 +28,7 @@ #include "u_vars.h" #include "u_vars_next.h" -void s_inc_shlvl(t_msh *msh) +void s_inc_shlvl(t_msh *msh) { char fmt[8]; char tmp[255]; @@ -52,7 +53,7 @@ void s_inc_shlvl(t_msh *msh) } } -char **s_dupenv_del(char **nenvp, unsigned long i) +char **s_dupenv_del(char **nenvp, unsigned long i) { while (i > 0) { @@ -63,20 +64,37 @@ char **s_dupenv_del(char **nenvp, unsigned long i) return (NULL); } -char **s_dupenv(char *const envp[]) +static char s_cpy_path(char **ptr, char *nenvp[], size_t *i) +{ + char tmp[255]; + + if (*ptr != NULL) + return (0); + if (*ptr == NULL) + { + ft_sprintf(tmp, "PATH=%s", _PATH_STDPATH); + if ((nenvp[*i] = ft_strdup(tmp)) == NULL) + return (1); + *(i) += 1; + } + return (0); +} + +char **s_dupenv(char *const envp[]) { - unsigned long i; - char **nenvp; + size_t i; + char **nenvp; + char **ptr; + ptr = (char**)envp; + while (*ptr != NULL && ft_strncmp(*ptr, "PATH=", 5) != 0) + ptr++; i = 0; while (envp[i] != NULL) - { i++; - } + i += (*ptr == NULL) ? (1) : (0); if ((nenvp = (char**)malloc((i + 1) * sizeof(char*))) == NULL) - { return (NULL); - } i = 0; while (envp[i] != NULL) { @@ -84,11 +102,13 @@ char **s_dupenv(char *const envp[]) return (s_dupenv_del(nenvp, i)); i++; } + if (s_cpy_path(ptr, nenvp, &i) == 1) + return (s_dupenv_del(nenvp, i)); nenvp[i] = NULL; return (nenvp); } -void s_set_cwd(char cwd[], t_msh *msh) +void s_set_cwd(char cwd[], t_msh *msh) { char fmt[PATH_MAX]; DIR *dir; |