From e9e6664be08910fd0621402c1b2519535c37aef7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 14:42:51 +0200 Subject: 'msh ~> ;' bug fix --- src/ft_p_lcom.c | 2 +- src/ft_p_line.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index 9a7a1b8..9a678e6 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -132,7 +132,7 @@ int8_t i = 0; if (!(words = ft_split(line, ';'))) return (-1); - while (i <= count) + while (i <= count && words[i]) { if (!(link = ft_lcom_new(words[i], msh))) { diff --git a/src/ft_p_line.c b/src/ft_p_line.c index b1ba6b2..b827503 100644 --- a/src/ft_p_line.c +++ b/src/ft_p_line.c @@ -41,6 +41,7 @@ void { count -= 1; } + ft_printf("%lu\n", count); if (ft_p_lcom(line, count, msh) < 0) { ft_s_destroy(msh); -- cgit v1.2.3 From c8e857173d2879e9a55085384fe5978370a11c57 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 15:39:14 +0200 Subject: Variables fixed --- libft/src/ft_substr.c | 7 +------ src/ft_p_lcom_next.c | 3 +-- src/ft_p_line.c | 1 - 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/libft/src/ft_substr.c b/libft/src/ft_substr.c index 6d94368..947a305 100644 --- a/libft/src/ft_substr.c +++ b/libft/src/ft_substr.c @@ -23,11 +23,6 @@ char i = 0; if (!(nstr = (char*)malloc((len + 1) * sizeof(char)))) return (NULL); - while (s[start + i] && i < len) - { - nstr[i] = s[start + i]; - i++; - } - nstr[i] = '\0'; + ft_strlcpy(nstr, s + start, len + 1); return (nstr); } diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index 272931d..c4666f4 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -39,9 +39,8 @@ char varlen = i + 1; while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') varlen += 1; - if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen))) + if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) return (NULL); - ft_printf("a\n"); varval = ft_subst_var_value(s_varname, msh); *p_words = ft_strsubst(*p_words, s_varname, varval); ft_memdel((void*)&s_varname); diff --git a/src/ft_p_line.c b/src/ft_p_line.c index b827503..b1ba6b2 100644 --- a/src/ft_p_line.c +++ b/src/ft_p_line.c @@ -41,7 +41,6 @@ void { count -= 1; } - ft_printf("%lu\n", count); if (ft_p_lcom(line, count, msh) < 0) { ft_s_destroy(msh); -- cgit v1.2.3 From bcc9a58fe387e02f8aeb140df7d11e9cd627220a Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 15:46:27 +0200 Subject: Normed --- src/ft_p_lcom_next.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index c4666f4..53292ff 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -17,34 +17,43 @@ #include "ft_s_struct.h" #include "ft_u_vars.h" +static int8_t + ft_subst_those_vars(int64_t i, + char **p_words, + t_msh *msh) +{ + size_t varlen; + char *s_varname; + char *varval; + + varval = NULL; + s_varname = NULL; + varlen = i + 1; + while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') + varlen += 1; + if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) + return (-1); + varval = ft_subst_var_value(s_varname, msh); + *p_words = ft_strsubst(*p_words, s_varname, varval); + ft_memdel((void*)&s_varname); + ft_memdel((void*)&varval); + return (0); +} + char **ft_subst_vars(char *words[], t_msh *msh) { - /* TODO: norme */ char **p_words; - char *s_varname; - char *varval; int64_t i; - size_t varlen; p_words = words; - varlen = 0; - varval = NULL; - s_varname = NULL; while (*p_words) { while ((i = ft_strlchr(*p_words, '$')) != -1) { - varlen = i + 1; - while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') - varlen += 1; - if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) + if (ft_subst_those_vars(i, p_words, msh) != 0) return (NULL); - varval = ft_subst_var_value(s_varname, msh); - *p_words = ft_strsubst(*p_words, s_varname, varval); - ft_memdel((void*)&s_varname); - ft_memdel((void*)&varval); } p_words += 1; } -- cgit v1.2.3 From f17ede577f807b76b41ca04934186e1d43cc711a Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 15:52:09 +0200 Subject: More norme --- src/ft_p_lcom_next.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index 53292ff..07fadbe 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -60,11 +60,11 @@ char return (words); } + char **ft_subst_args(const char word[], int8_t redir) { - /* TODO: norme */ char **words; char *subst; size_t i; @@ -78,11 +78,8 @@ char i = 0; while (word[i] && !ft_ischarset("<>", word[i])) i++; - if (redir > 0) - { - while (ft_isdigit(word[i])) - i--; - } + while (redir > 0 && ft_isdigit(word[i])) + i--; if (!(subst = ft_substr(word, 0, i))) return (NULL); if (!(words = ft_split(subst, ' '))) -- cgit v1.2.3 From d71625e4dd34e88058520246377277b8914525a8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 15:52:54 +0200 Subject: TODO update --- src/minishell.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/minishell.c b/src/minishell.c index f5216a8..b5c07ed 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -30,6 +30,7 @@ int int32_t ret; /* TODO: increment $SHLVL */ + /* TODO: also set $SHELL */ /* TODO: handle general variables | $var */ if (!(msh = ft_init_msh(argv, envp))) { -- cgit v1.2.3 From 205be3d43b7a543784466c8fb6839e8e02d0af56 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 15:54:25 +0200 Subject: TODO update --- src/ft_b_echo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c index fdac868..bca20ac 100644 --- a/src/ft_b_echo.c +++ b/src/ft_b_echo.c @@ -16,8 +16,7 @@ #include "ft_s_struct.h" #include "ft_u_utils.h" -/* TODO: norme, echo $variables (variables are subst when parsing the line), */ -/* echo "quoted text", echo 'quoted text', */ +/* TODO: echo "quoted text", echo 'quoted text', */ /* echo kill\nbackslash\nbut\nnot\nn, echo "quoted\nnew\nlines" */ /* Might need to go full buffer */ -- cgit v1.2.3 From 47d2d539c74386eceb05dee7cd07adf43688014f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 16:16:13 +0200 Subject: Fixed relative pathn exec --- src/ft_e_externs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ft_e_externs.c b/src/ft_e_externs.c index 4cdcc3c..07bd9e1 100644 --- a/src/ft_e_externs.c +++ b/src/ft_e_externs.c @@ -70,7 +70,8 @@ void if (ft_ischarset("/.", ptr->com[0])) { - /* TODO: ft_get_physical_path(ptr->com); */ + ft_exec_path(ptr->com, ptr, msh); + return ; } else if ((envpath = ft_get_env_path(msh)) != NULL) { -- cgit v1.2.3 From aa8af198bbe1ea7ba0db60f07b1880d181447336 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 16:41:06 +0200 Subject: Finished and normed type --- src/ft_b_type.c | 72 ++++++++++++++++++++++++++++++++++++++----------- src/ft_e_externs_next.c | 1 - 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/ft_b_type.c b/src/ft_b_type.c index f6601d8..4338b32 100644 --- a/src/ft_b_type.c +++ b/src/ft_b_type.c @@ -12,13 +12,37 @@ #include #include +#include +#include +#include +#include "ft_f_fail.h" +#include "ft_s_lcom.h" #include "ft_s_struct.h" #include "ft_e_externs_next.h" #include "ft_u_utils.h" +static int8_t + ft_absolute_path_exists(char com[]) +{ + int32_t fd; + DIR *dir; + + if ((dir = opendir(com)) != NULL) + { + closedir(dir); + return (0); + } + if ((fd = open(com, O_RDONLY)) != -1) + { + close(fd); + return (1); + } + return (0); +} + static char - *ft_type_get_path(char *com, + *ft_type_get_path(char com[], t_msh *msh) { char **envpath; @@ -28,7 +52,16 @@ static char fullpath = NULL; if (ft_ischarset("/.", com[0])) { - /* TODO: ft_get_absolute_path(ptr->com); */ + if (ft_absolute_path_exists(com)) + { + if (!(fullpath = ft_strdup(com))) + { + ft_lcom_clear(&msh->curr); + ft_fail_alloc(msh); + } + return (fullpath); + } + return (NULL); } else if ((envpath = ft_get_env_path(msh)) != NULL) { @@ -38,19 +71,37 @@ static char return (fullpath); } +static uint8_t + ft_chk_nonbuilt(char **ptr, + t_msh *msh) +{ + char *fullpath; + int32_t ret; + + ret = 0; + fullpath = ft_type_get_path(*ptr, msh); + if (fullpath) + ft_printf("%s is %s\n", *ptr, fullpath); + else + { + ft_printf("minishell: type: %s: not found\n", *ptr); + ret = 1; + } + ft_memdel((void*)&fullpath); + return (ret); +} + uint8_t ft_b_type(char *args[], t_msh *msh) { - /* TODO: norme */ char **ptr; char **p_bu; - char *fullpath; int32_t ret; ptr = args; if (!*ptr) - return (1); + return (0); ret = 0; while (*ptr) { @@ -61,18 +112,9 @@ uint8_t ft_printf("%s is a shell builtin\n", *ptr); else { - fullpath = ft_type_get_path(*ptr, msh); - if (fullpath) - ft_printf("%s is %s\n", *ptr, fullpath); - else - { - ft_printf("minishell: type: %s: not found\n", *ptr); - ret = 1; - } - ft_memdel((void*)&fullpath); + ret = ft_chk_nonbuilt(ptr, msh); } ptr++; } - /* TODO: finish type */ return (ret); } diff --git a/src/ft_e_externs_next.c b/src/ft_e_externs_next.c index ab5f150..36bf5e6 100644 --- a/src/ft_e_externs_next.c +++ b/src/ft_e_externs_next.c @@ -53,7 +53,6 @@ char char *fullpath; DIR *dir; - (void)com; p_path = envpath; while (*p_path) { -- cgit v1.2.3