From 4dd10e6f4de22446ea84d7b194d2a18cb6e43c6c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 18:50:11 +0200 Subject: Names --- src/p_lblock_next.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 src/p_lblock_next.c (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c new file mode 100644 index 0000000..16d8aac --- /dev/null +++ b/src/p_lblock_next.c @@ -0,0 +1,223 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_line_next.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +#include "d_define.h" +#include "s_destroy.h" +#include "f_fail.h" +#include "s_struct.h" +#include "u_utils.h" +#include "u_vars.h" +#include "u_vars_next.h" + +/* TODO: norme */ + +static char + *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) +{ + char tmp[4096]; + char varval[4096]; + char *ptr; + size_t varlen; + + ptr = word; + varlen = i + 1; + while (ptr[varlen] != C_NUL && + ft_ischarset("$=\\/@%^*+{}[]<>,.-", ptr[varlen]) == FALSE && + ft_iswhitespace(ptr[varlen]) == FALSE) + varlen += 1; + ft_strlcpy(tmp, ptr + i, varlen + 1 - i); + u_get_var_value(varval, tmp, 4096, msh); + ft_strlcpy(tmp, ptr + varlen, varlen); + word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1); + ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); + ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); + *(p) = word + (i + ft_strlen(varval) - 1); + return (word); +} + +char + *p_subst_vars(char word[], t_msh *msh) +{ + char *ptr; + + ptr = word; + while (*ptr != C_NUL) + { + if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) + { + if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) == NULL) + { + return (NULL); + } + } + ptr++; + } + return (word); +} + +char + **p_subst_home(char *words[], + t_msh *msh) +{ + char path[PATH_MAX]; + char **ptr; + + u_get_var_value(path, "$HOME", PATH_MAX, msh); + if (path[0] == C_NUL) + return (words); + ptr = words; + while (*ptr != NULL) + { + if (*ptr[0] == '~') + { + *ptr = ft_strsubst(*ptr, "~", path); + } + ptr++; + } + return (words); +} + +static void + p_register_word(char word[], + t_msh *msh) +{ + char name[255]; + char val[255]; + char *ptr; + size_t i; + + name[0] = '$'; + ptr = word; + i = 1; + while (*ptr != '=' && *ptr != '\0') + { + name[i] = *ptr; + i++; + ptr++; + } + name[i] = '\0'; + ptr++; + i = 0; + while (*ptr != '\0') + { + val[i] = *ptr; + i++; + ptr++; + } + val[i] = '\0'; + u_subst_var_value(name, val, msh); +} + +static char + **p_add_to_variables_and_delete(char *words[], + t_bool reg, + int64_t i, + t_msh *msh) +{ + int64_t j; + int64_t k; + char **rewords; + + j = 0; + if (reg == TRUE) + { + while (words[j] && j < i) + { + p_register_word(words[j], msh); + j++; + } + } + j = 0; + while (words[i + j] != NULL) + j++; + if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) + { + ft_delwords(words); + f_alloc_and_destroy_msh(msh); + } + k = i; + while (i - k < j) + { + if ((rewords[i - k] = ft_strdup(words[i])) == NULL) + { + ft_delwords(words); + f_alloc_and_destroy_msh(msh); + } + i++; + } + rewords[i - k] = 0; + ft_delwords(words); + i++; + return (rewords); +} + +static void + p_add_to_env_fork(int64_t i, + char *words[], + t_msh *msh) +{ + int64_t j; + + j = 0; + while(j < i) + { + ft_strlcpy(msh->env_fork_tmp[j], words[j], ft_strlen(words[j]) + 1); + j++; + } + msh->env_fork_tmp[j][0] = '\0'; +} + +char + **p_check_args_equals(char *words[], + t_msh *msh) +{ + char *ptr; + t_bool reg; + t_bool isvar; + int64_t i; + + i = 0; + reg = FALSE; + isvar = FALSE; + while (words[i]) + { + ptr = words[i]; + while (*ptr != '\0' && *ptr != '=') + ptr++; + if (*ptr == '=') + { + reg = TRUE; + isvar = TRUE; + } + if (*ptr == '\0' || words[i][0] == '=' || + ft_isdigit(words[i][0]) == TRUE) + { + reg = FALSE; + if (i == 0) + isvar = FALSE; + if (isvar == TRUE) + p_add_to_env_fork(i, words, msh); + else + msh->env_fork_tmp[0][0] = '\0'; + break ; + } + i++; + } + if (isvar == TRUE) + return (p_add_to_variables_and_delete(words, reg, i, msh)); + return (words); +} -- cgit v1.2.3 From d742075e1af0c063ef9677f157263c0d45253f73 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 19:32:40 +0200 Subject: Rework in progress --- src/p_lblock_next.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 16d8aac..5777a3c 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* p_line_next.c :+: :+: :+: */ +/* p_lblock_next.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -- cgit v1.2.3 From bea195a2e8d8e26af7511a65af4c8641cb4d1c4f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 17:28:06 +0200 Subject: Even better parse --- src/p_lblock_next.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 5777a3c..56a789d 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -59,7 +59,8 @@ char { if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) { - if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) == NULL) + if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) + == NULL) { return (NULL); } @@ -70,8 +71,7 @@ char } char - **p_subst_home(char *words[], - t_msh *msh) + **p_subst_home(char *words[], t_msh *msh) { char path[PATH_MAX]; char **ptr; @@ -92,8 +92,7 @@ char } static void - p_register_word(char word[], - t_msh *msh) + p_register_word(char word[], t_msh *msh) { char name[255]; char val[255]; @@ -182,8 +181,7 @@ static void } char - **p_check_args_equals(char *words[], - t_msh *msh) + **p_check_args_equals(char *words[], t_msh *msh) { char *ptr; t_bool reg; -- cgit v1.2.3 From f165808b1cb551cd86655268b8dfa4fb7dcd5eb7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 18:13:47 +0200 Subject: FIX --- src/p_lblock_next.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 56a789d..8b22f7c 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -28,8 +28,8 @@ static char *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) { - char tmp[4096]; - char varval[4096]; + char tmp[ARG_MAX]; + char varval[ARG_MAX]; char *ptr; size_t varlen; @@ -42,7 +42,9 @@ static char ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, 4096, msh); ft_strlcpy(tmp, ptr + varlen, varlen); - word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1); + if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + + ft_strlen(tmp) + 1)) == NULL) + return (NULL); ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); *(p) = word + (i + ft_strlen(varval) - 1); @@ -143,7 +145,7 @@ static char j = 0; while (words[i + j] != NULL) j++; - if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) + if ((rewords = (char**)malloc((j + 1) * sizeof(char*))) == NULL) { ft_delwords(words); f_alloc_and_destroy_msh(msh); -- cgit v1.2.3 From 20b9a703186d7bf06936467ae3e8108cfbee43dd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 19:28:08 +0200 Subject: I was born an idiot I swear --- src/p_lblock_next.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 8b22f7c..21cd4a7 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -25,6 +25,24 @@ /* TODO: norme */ +static char + *p_double_them_bs(char varval[]) +{ + char *ptr; + + ptr = varval; + while (*ptr != C_NUL) + { + if (*ptr == C_BACKS) + { + ptr = ft_memmove(ptr + 1, ptr, ft_strlen(ptr) + 1); + varval[ptr - varval] = C_BACKS; + } + ptr++; + } + return (varval); +} + static char *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) { @@ -32,6 +50,7 @@ static char char varval[ARG_MAX]; char *ptr; size_t varlen; + int32_t count; ptr = word; varlen = i + 1; @@ -40,13 +59,15 @@ static char ft_iswhitespace(ptr[varlen]) == FALSE) varlen += 1; ft_strlcpy(tmp, ptr + i, varlen + 1 - i); - u_get_var_value(varval, tmp, 4096, msh); + u_get_var_value(varval, tmp, ARG_MAX, msh); + p_double_them_bs(varval); ft_strlcpy(tmp, ptr + varlen, varlen); if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1)) == NULL) return (NULL); ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); + count = 0; *(p) = word + (i + ft_strlen(varval) - 1); return (word); } -- cgit v1.2.3 From 6f756ee6112c723cfe0f8ece2d530b249aa47e00 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 15:05:31 +0200 Subject: Fix --- src/p_lblock_next.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 21cd4a7..e342f4a 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -61,7 +61,7 @@ static char ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - ft_strlcpy(tmp, ptr + varlen, varlen); + ft_strlcpy(tmp, ptr + varlen, varlen + 1); if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1)) == NULL) return (NULL); @@ -150,9 +150,9 @@ static char int64_t i, t_msh *msh) { + char **rewords; int64_t j; int64_t k; - char **rewords; j = 0; if (reg == TRUE) -- cgit v1.2.3 From a0f1c28e809f036ebb06d9c017aceef032139316 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 15:15:22 +0200 Subject: Huge fix --- src/p_lblock_next.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index e342f4a..e5e46dc 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -61,7 +61,7 @@ static char ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - ft_strlcpy(tmp, ptr + varlen, varlen + 1); + ft_strlcpy(tmp, ptr + varlen, ft_strlen(ptr + varlen) + 1); if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1)) == NULL) return (NULL); @@ -69,6 +69,7 @@ static char ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); count = 0; *(p) = word + (i + ft_strlen(varval) - 1); + ft_printf("[%s]\n", word); return (word); } -- cgit v1.2.3 From a1120710a40fd1ac8fae1d68da9c3fe3fb407da2 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 15:27:54 +0200 Subject: TODO update --- src/p_lblock_next.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index e5e46dc..8d89cf3 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -69,7 +69,6 @@ static char ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); count = 0; *(p) = word + (i + ft_strlen(varval) - 1); - ft_printf("[%s]\n", word); return (word); } -- cgit v1.2.3 From b2ffd2aeb4a91501ae7931cb43a9679b01eb0351 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 16:25:51 +0200 Subject: Nice fix --- src/p_lblock_next.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 8d89cf3..a5314f2 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -19,6 +19,7 @@ #include "s_destroy.h" #include "f_fail.h" #include "s_struct.h" +#include "u_parse.h" #include "u_utils.h" #include "u_vars.h" #include "u_vars_next.h" @@ -43,14 +44,13 @@ static char return (varval); } -static char - *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) +static void + p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) { char tmp[ARG_MAX]; char varval[ARG_MAX]; char *ptr; size_t varlen; - int32_t count; ptr = word; varlen = i + 1; @@ -61,32 +61,29 @@ static char ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - ft_strlcpy(tmp, ptr + varlen, ft_strlen(ptr + varlen) + 1); - if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) + - ft_strlen(tmp) + 1)) == NULL) - return (NULL); - ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); - ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); - count = 0; + (void)ft_memmove(ptr + (i + ft_strlen(tmp)), ptr + varlen, (ft_strlen(ptr + varlen) + 1) * sizeof(char)); + (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char)); *(p) = word + (i + ft_strlen(varval) - 1); - return (word); } char *p_subst_vars(char word[], t_msh *msh) { - char *ptr; + char *ptr; + t_quote_mode mode; + mode = Q_NONE; ptr = word; while (*ptr != C_NUL) { - if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(word, ptr, mode); + else if (*ptr == C_SQUOTE) + mode = u_meet_squote(word, ptr, mode); + if ((mode == Q_NONE || mode == Q_DOUBLE) && *ptr == C_DOLLAR && + u_is_not_escaped(word, ptr) == TRUE) { - if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) - == NULL) - { - return (NULL); - } + p_subst_this_var(&ptr, (ptr - word), word, msh); } ptr++; } -- cgit v1.2.3 From be1403ef70e51442df459b1ef89f547cbc9af4ca Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 19:32:47 +0200 Subject: This shit is killing me --- src/p_lblock_next.c | 108 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 37 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index a5314f2..adfa043 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -19,6 +19,7 @@ #include "s_destroy.h" #include "f_fail.h" #include "s_struct.h" +#include "u_alias.h" #include "u_parse.h" #include "u_utils.h" #include "u_vars.h" @@ -66,8 +67,8 @@ static void *(p) = word + (i + ft_strlen(varval) - 1); } -char - *p_subst_vars(char word[], t_msh *msh) +void + p_subst_vars(char word[], t_msh *msh) { char *ptr; t_quote_mode mode; @@ -87,7 +88,25 @@ char } ptr++; } - return (word); +} + +void + p_subst_alias(char word[], t_msh *msh) +{ + /* char subst[ARG_MAX]; */ + char *ptr; + + ptr = word; + (void)msh; + ft_printf("[%s]\n", ptr); + /* while (*ptr != C_NUL) */ + /* { */ + /* ptr++; */ + /* } */ + /* if (u_get_alias_value(subst, ?, ARG_MAX, msh) == 0) */ + /* { */ + /* /\* copy *\/ */ + /* } */ } char @@ -200,42 +219,57 @@ static void msh->env_fork_tmp[j][0] = '\0'; } -char - **p_check_args_equals(char *words[], t_msh *msh) +void + p_check_args_equals(char word[], t_msh *msh) { - char *ptr; - t_bool reg; - t_bool isvar; - int64_t i; + char *ptr; + t_quote_mode mode; - i = 0; - reg = FALSE; - isvar = FALSE; - while (words[i]) + mode = Q_NONE; + ptr = word; + while (*ptr != C_NUL) { - ptr = words[i]; - while (*ptr != '\0' && *ptr != '=') - ptr++; - if (*ptr == '=') - { - reg = TRUE; - isvar = TRUE; - } - if (*ptr == '\0' || words[i][0] == '=' || - ft_isdigit(words[i][0]) == TRUE) - { - reg = FALSE; - if (i == 0) - isvar = FALSE; - if (isvar == TRUE) - p_add_to_env_fork(i, words, msh); - else - msh->env_fork_tmp[0][0] = '\0'; - break ; - } - i++; + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(word, ptr, mode); + else if (*ptr == C_SQUOTE) + mode = u_meet_squote(word, ptr, mode); + else if (mode == Q_NONE && *ptr == C_EQUALS) + u_meet_equals(); + ptr++; } - if (isvar == TRUE) - return (p_add_to_variables_and_delete(words, reg, i, msh)); - return (words); + /* char *ptr; */ + /* t_bool reg; */ + /* t_bool isvar; */ + /* int64_t i; */ + + /* i = 0; */ + /* reg = FALSE; */ + /* isvar = FALSE; */ + /* while (words[i]) */ + /* { */ + /* ptr = words[i]; */ + /* while (*ptr != '\0' && *ptr != '=') */ + /* ptr++; */ + /* if (*ptr == '=') */ + /* { */ + /* reg = TRUE; */ + /* isvar = TRUE; */ + /* } */ + /* if (*ptr == '\0' || words[i][0] == '=' || */ + /* ft_isdigit(words[i][0]) == TRUE) */ + /* { */ + /* reg = FALSE; */ + /* if (i == 0) */ + /* isvar = FALSE; */ + /* if (isvar == TRUE) */ + /* p_add_to_env_fork(i, words, msh); */ + /* else */ + /* msh->env_fork_tmp[0][0] = '\0'; */ + /* break ; */ + /* } */ + /* i++; */ + /* } */ + /* if (isvar == TRUE) */ + /* return (p_add_to_variables_and_delete(words, reg, i, msh)); */ + /* return (words); */ } -- cgit v1.2.3 From 2a5b43429d411bf5b2a71e32b6a8e11a896786b6 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 19:55:23 +0200 Subject: qwe --- src/p_lblock_next.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index adfa043..6f5f00d 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -234,7 +234,6 @@ void else if (*ptr == C_SQUOTE) mode = u_meet_squote(word, ptr, mode); else if (mode == Q_NONE && *ptr == C_EQUALS) - u_meet_equals(); ptr++; } /* char *ptr; */ -- cgit v1.2.3 From ff845bada3fe6898a228c10422f0561e2a532622 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 21:18:27 +0200 Subject: Fuck this --- src/p_lblock_next.c | 96 +++++++++++++++++++---------------------------------- 1 file changed, 35 insertions(+), 61 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 6f5f00d..10c4d84 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -93,20 +93,8 @@ void void p_subst_alias(char word[], t_msh *msh) { - /* char subst[ARG_MAX]; */ - char *ptr; - - ptr = word; + (void)word; (void)msh; - ft_printf("[%s]\n", ptr); - /* while (*ptr != C_NUL) */ - /* { */ - /* ptr++; */ - /* } */ - /* if (u_get_alias_value(subst, ?, ARG_MAX, msh) == 0) */ - /* { */ - /* /\* copy *\/ */ - /* } */ } char @@ -219,56 +207,42 @@ static void msh->env_fork_tmp[j][0] = '\0'; } -void - p_check_args_equals(char word[], t_msh *msh) +char + **p_check_args_equals(char *words[], t_msh *msh) { - char *ptr; - t_quote_mode mode; + char *ptr; + t_bool reg; + t_bool isvar; + int64_t i; - mode = Q_NONE; - ptr = word; - while (*ptr != C_NUL) + i = 0; + reg = FALSE; + isvar = FALSE; + while (words[i]) { - if (*ptr == C_DQUOTE) - mode = u_meet_dquote(word, ptr, mode); - else if (*ptr == C_SQUOTE) - mode = u_meet_squote(word, ptr, mode); - else if (mode == Q_NONE && *ptr == C_EQUALS) - ptr++; + ptr = words[i]; + while (*ptr != '\0' && *ptr != '=') + ptr++; + if (*ptr == '=') + { + reg = TRUE; + isvar = TRUE; + } + if (*ptr == '\0' || words[i][0] == '=' || + ft_isdigit(words[i][0]) == TRUE) + { + reg = FALSE; + if (i == 0) + isvar = FALSE; + if (isvar == TRUE) + p_add_to_env_fork(i, words, msh); + else + msh->env_fork_tmp[0][0] = '\0'; + break ; + } + i++; } - /* char *ptr; */ - /* t_bool reg; */ - /* t_bool isvar; */ - /* int64_t i; */ - - /* i = 0; */ - /* reg = FALSE; */ - /* isvar = FALSE; */ - /* while (words[i]) */ - /* { */ - /* ptr = words[i]; */ - /* while (*ptr != '\0' && *ptr != '=') */ - /* ptr++; */ - /* if (*ptr == '=') */ - /* { */ - /* reg = TRUE; */ - /* isvar = TRUE; */ - /* } */ - /* if (*ptr == '\0' || words[i][0] == '=' || */ - /* ft_isdigit(words[i][0]) == TRUE) */ - /* { */ - /* reg = FALSE; */ - /* if (i == 0) */ - /* isvar = FALSE; */ - /* if (isvar == TRUE) */ - /* p_add_to_env_fork(i, words, msh); */ - /* else */ - /* msh->env_fork_tmp[0][0] = '\0'; */ - /* break ; */ - /* } */ - /* i++; */ - /* } */ - /* if (isvar == TRUE) */ - /* return (p_add_to_variables_and_delete(words, reg, i, msh)); */ - /* return (words); */ + if (isvar == TRUE) + return (p_add_to_variables_and_delete(words, reg, i, msh)); + return (words); } -- cgit v1.2.3 From 064c1e22c83f24c112bc2e3e3ce4427f8ff9e4c7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 21:22:42 +0200 Subject: Format --- src/p_lblock_next.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 10c4d84..0a982a5 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -62,7 +62,9 @@ static void ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - (void)ft_memmove(ptr + (i + ft_strlen(tmp)), ptr + varlen, (ft_strlen(ptr + varlen) + 1) * sizeof(char)); + (void)ft_memmove(ptr + (i + ft_strlen(tmp)), + ptr + varlen, + (ft_strlen(ptr + varlen) + 1) * sizeof(char)); (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char)); *(p) = word + (i + ft_strlen(varval) - 1); } -- cgit v1.2.3 From 291cabef51915c280c26e567d864b6ea3fc56dbd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 06:32:26 +0200 Subject: In progress --- src/p_lblock_next.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 0a982a5..036d6b5 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -92,11 +92,35 @@ void } } +static char + *p_skip_whitespace(char *ptr) +{ + while (*ptr != C_NUL && ft_iswhitespace(*ptr)) + ptr++; + return (ptr); +} + void p_subst_alias(char word[], t_msh *msh) { - (void)word; + char *ptr; + size_t first; + t_quote_mode mode; + (void)msh; + mode = Q_NONE; + ptr = word; + p_skip_whitespace(ptr); + first = 1; + while (*ptr != C_NUL) + { + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(word, ptr, mode); + if (*ptr == C_SQUOTE) + mode = u_meet_squote(word, ptr, mode); + if (ft_iswhitespace(*ptr) == TRUE && p_meet_whitespace((char*)word, ptr, mode) == TRUE) + ptr++; + } } char -- cgit v1.2.3 From 8b15c7b0f233238a53088d8c095bd5af7f7592e7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 14:51:23 +0200 Subject: how tf will I norm this --- src/p_lblock_next.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 036d6b5..8b755da 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -100,27 +100,65 @@ static char return (ptr); } +static t_bool + p_meet_whitespace(char *head, char *ptr, t_quote_mode mode) +{ + if (mode == Q_NONE && u_is_not_escaped(head, ptr) == TRUE) + { + return (TRUE); + } + return (FALSE); +} + void p_subst_alias(char word[], t_msh *msh) { char *ptr; - size_t first; + char tmp[255]; + size_t locat[2]; + t_bool good; t_quote_mode mode; (void)msh; mode = Q_NONE; ptr = word; - p_skip_whitespace(ptr); - first = 1; + ptr = p_skip_whitespace(ptr); + good = TRUE; + locat[0] = (ptr - word); + locat[1] = (ptr - word); while (*ptr != C_NUL) { if (*ptr == C_DQUOTE) mode = u_meet_dquote(word, ptr, mode); if (*ptr == C_SQUOTE) mode = u_meet_squote(word, ptr, mode); - if (ft_iswhitespace(*ptr) == TRUE && p_meet_whitespace((char*)word, ptr, mode) == TRUE) + if (mode == Q_NONE && *ptr == C_EQUALS) + good = FALSE; + if (ft_iswhitespace(*ptr) == TRUE && + p_meet_whitespace((char*)word, ptr, mode) == TRUE) + { + locat[1] = (ptr - word); + if (good == TRUE) + break ; + else + { + ptr = p_skip_whitespace(ptr); + locat[0] = (ptr - word); + ptr -= 1; + good = TRUE; + } + } ptr++; } + if (*ptr == C_NUL && good == TRUE) + locat[1] = (ptr - word); + if (good == TRUE) + { + ft_strlcpy(tmp, + word + locat[0], + ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); + ft_printf("(%s)\n", tmp); + } } char -- cgit v1.2.3 From 477ea057edf32486e944ef4e33023e9ab6636e07 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 15:07:22 +0200 Subject: Aliases work, fucker --- src/p_lblock_next.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 8b755da..707acc0 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -113,13 +113,13 @@ static t_bool void p_subst_alias(char word[], t_msh *msh) { - char *ptr; + char value[ARG_MAX]; char tmp[255]; size_t locat[2]; + char *ptr; t_bool good; t_quote_mode mode; - (void)msh; mode = Q_NONE; ptr = word; ptr = p_skip_whitespace(ptr); @@ -157,7 +157,14 @@ void ft_strlcpy(tmp, word + locat[0], ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); - ft_printf("(%s)\n", tmp); + if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0) + return ; + (void)ft_memmove(word + (locat[0] + ft_strlen(value)), + word + locat[1], + ft_strlen(word + locat[1]) + 1 * sizeof(char)); + (void)ft_memmove(word + locat[0], + value, + ft_strlen(value) * sizeof(char)); } } -- cgit v1.2.3 From 81900e8ff106bbd9602f6589fc54e4530f5cc3dd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 15:57:51 +0200 Subject: Fix --- src/p_lblock_next.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 707acc0..3fa0ea5 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -62,9 +62,9 @@ static void ft_strlcpy(tmp, ptr + i, varlen + 1 - i); u_get_var_value(varval, tmp, ARG_MAX, msh); p_double_them_bs(varval); - (void)ft_memmove(ptr + (i + ft_strlen(tmp)), + ft_strlcpy(ptr + (i + ft_strlen(varval)), ptr + varlen, - (ft_strlen(ptr + varlen) + 1) * sizeof(char)); + ft_strlen(ptr + varlen) + 1); (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char)); *(p) = word + (i + ft_strlen(varval) - 1); } -- cgit v1.2.3 From 949f93b57b6411b07eb12110e0db37cdf393db0c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 16:33:02 +0200 Subject: Fuck --- src/p_lblock_next.c | 55 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 3fa0ea5..0c1c1f4 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -110,16 +110,30 @@ static t_bool return (FALSE); } -void - p_subst_alias(char word[], t_msh *msh) +size_t + p_subst_alias(char word[], t_bool reset, t_msh *msh) { + static size_t used[4096]; + static size_t i = 0; char value[ARG_MAX]; char tmp[255]; size_t locat[2]; + size_t j; + size_t usedcmp; char *ptr; t_bool good; t_quote_mode mode; + if (reset == TRUE) + { + i = 0; + while (i < 4096) + { + used[i] = 0; + i++; + } + i = 0; + } mode = Q_NONE; ptr = word; ptr = p_skip_whitespace(ptr); @@ -157,15 +171,36 @@ void ft_strlcpy(tmp, word + locat[0], ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); - if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0) - return ; - (void)ft_memmove(word + (locat[0] + ft_strlen(value)), - word + locat[1], - ft_strlen(word + locat[1]) + 1 * sizeof(char)); - (void)ft_memmove(word + locat[0], - value, - ft_strlen(value) * sizeof(char)); + if ((usedcmp = u_get_alias_value(value, tmp, ARG_MAX, msh)) != 0) + { + j = 0; + good = TRUE; + while (j < i) + { + if (used[j] == usedcmp) + good = FALSE; + j++; + } + if (good == TRUE) + { + (void)ft_memmove(word + (locat[0] + ft_strlen(value)), + word + locat[1], + ft_strlen(word + locat[1]) + 1 * sizeof(char)); + (void)ft_memmove(word + locat[0], + value, + ft_strlen(value) * sizeof(char)); + used[i] = usedcmp; + i++; + return (usedcmp); + } + } + /* ptr = value; */ + /* save = value; */ + /* while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE) */ + /* ptr++; */ + /* ft_strlcpy(tmp, save, (ptr - save) + 1); */ } + return (0); } char -- cgit v1.2.3 From f7eb7d0c123e71f8b3998199a690b5d57aa96e1f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 17:25:26 +0200 Subject: In progress --- src/p_lblock_next.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/p_lblock_next.c') diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 0c1c1f4..02ecbb2 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -194,11 +194,6 @@ size_t return (usedcmp); } } - /* ptr = value; */ - /* save = value; */ - /* while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE) */ - /* ptr++; */ - /* ft_strlcpy(tmp, save, (ptr - save) + 1); */ } return (0); } -- cgit v1.2.3