From f3f724dd7f434f2731f63d03a925b0e24983b484 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 16:09:12 +0200 Subject: how tf do i use tok --- src/p_args_next.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/p_args_next.c (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c new file mode 100644 index 0000000..d371ba0 --- /dev/null +++ b/src/p_args_next.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_args_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 + +static char + p_give_me_an_arg(const char word[]) +{ + char str[4096]; + + str[0] = '\0'; + return (str); +} + +uint16_t + p_dup_words(char *words[], const char word[], uint16_t i) +{ + while (i > 0) + { + if ((words[i] = ft_strdup(p_give_me_an_arg(word))) == NULL) + return (i); + i--; + } + return (0); +} + -- cgit v1.2.3 From 869498a720e3c54b206f346dea6bf9b7995a7778 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 17:18:41 +0200 Subject: Genius in progress --- src/p_args_next.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index d371ba0..5967963 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -13,24 +13,48 @@ #include #include -static char - p_give_me_an_arg(const char word[]) +#include "p_args.h" + +static size_t + p_arg_len(const char word[], const size_t start) { - char str[4096]; + size_t end; - str[0] = '\0'; - return (str); + (void)word; + end = start; + return (end); +} + +static char + *p_give_me_an_arg(char tmp[], + const char word[], + const uint16_t i, + const size_t start[]) +{ + tmp[0] = '\0'; + ft_strlcpy(tmp, + word + start[i], + (p_arg_len(word, start[i]) - start[i]) + 1); + /* TODO: remove quotes */ + return (tmp); } uint16_t - p_dup_words(char *words[], const char word[], uint16_t i) + p_dup_words(char *words[], + const char word[], + const uint16_t argc, + const size_t start[]) { - while (i > 0) + char tmp[4096]; + uint16_t i; + + i = 0; + while (i < argc) { - if ((words[i] = ft_strdup(p_give_me_an_arg(word))) == NULL) + if ((words[i] = ft_strdup(p_give_me_an_arg(tmp, word, i, start))) == NULL) return (i); - i--; + i++; } - return (0); + return (i); } -- cgit v1.2.3 From 93fd5f480c4fb841945611ed13ca3fa81b376dff Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 18:37:45 +0200 Subject: Better conditions, fuck the norm niggas --- src/p_args_next.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 5967963..28410cd 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -13,15 +13,51 @@ #include #include +#include "d_define.h" #include "p_args.h" +static size_t + p_skip_delim_size(const char word[], char c, size_t end) +{ + end++; + if (word[end] == c) + return (end + 1); + while (word[end] != C_NULL && word[end] != c) + { + end++; + if (word[end] == c && c == C_DQUOTE) + { + if (word[end - 1] == C_BACKSLASH) + { + if (word[end - 2] != C_BACKSLASH) + end++; + } + } + } + if (word[end] != C_NULL) + { + end++; + } + return (end); +} + static size_t p_arg_len(const char word[], const size_t start) { size_t end; - (void)word; end = start; + if (word[start] != C_SQUOTE && + word[start] != C_DQUOTE && + word[start] != C_NULL) + { + while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE) + end++; + } + else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) + { + end = p_skip_delim_size(word, word[end], end); + } return (end); } -- cgit v1.2.3 From 757801bea2d236148e061324716425fc0e6aa686 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 19:09:05 +0200 Subject: In progress --- src/p_args_next.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 28410cd..4d7f979 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -71,10 +71,22 @@ static char ft_strlcpy(tmp, word + start[i], (p_arg_len(word, start[i]) - start[i]) + 1); - /* TODO: remove quotes */ return (tmp); } +void + p_del_alloced_words(char *words[], uint16_t to_del) +{ + uint16_t i; + + i = 0; + while (i < to_del) + { + ft_memdel((void*)&words[i]); + i++; + } +} + uint16_t p_dup_words(char *words[], const char word[], -- cgit v1.2.3 From be81297dfc28503f7c1014aad4efcf52bd13aad1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 19:24:54 +0200 Subject: am good --- src/p_args_next.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 4d7f979..36f6bf1 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -56,7 +56,8 @@ static size_t } else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) { - end = p_skip_delim_size(word, word[end], end); + while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE) + end = p_skip_delim_size(word, word[end], end); } return (end); } -- cgit v1.2.3 From 59172914d2a6831474431c068eea9eca1e710499 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 3 Sep 2020 19:41:05 +0200 Subject: =?UTF-8?q?Pourquoi=20je=20suis=20n=C3=A9=20idiot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/p_args_next.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 36f6bf1..10ca37f 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -27,10 +27,9 @@ static size_t end++; if (word[end] == c && c == C_DQUOTE) { - if (word[end - 1] == C_BACKSLASH) + if (word[end - 1] == C_BACKSLASH && word[end - 2] != C_BACKSLASH) { - if (word[end - 2] != C_BACKSLASH) - end++; + end++; } } } @@ -57,7 +56,16 @@ static size_t else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) { while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE) - end = p_skip_delim_size(word, word[end], end); + { + if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) + end = p_skip_delim_size(word, word[end], end); + else + { + while (word[end] != C_NULL && + ft_iswhitespace(word[end]) == FALSE) + end++; + } + } } return (end); } -- cgit v1.2.3 From 0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 4 Sep 2020 22:02:44 +0200 Subject: Time to escape chars --- src/p_args_next.c | 59 ++++--------------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 10ca37f..77f8ced 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -15,60 +15,7 @@ #include "d_define.h" #include "p_args.h" - -static size_t - p_skip_delim_size(const char word[], char c, size_t end) -{ - end++; - if (word[end] == c) - return (end + 1); - while (word[end] != C_NULL && word[end] != c) - { - end++; - if (word[end] == c && c == C_DQUOTE) - { - if (word[end - 1] == C_BACKSLASH && word[end - 2] != C_BACKSLASH) - { - end++; - } - } - } - if (word[end] != C_NULL) - { - end++; - } - return (end); -} - -static size_t - p_arg_len(const char word[], const size_t start) -{ - size_t end; - - end = start; - if (word[start] != C_SQUOTE && - word[start] != C_DQUOTE && - word[start] != C_NULL) - { - while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE) - end++; - } - else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) - { - while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE) - { - if (word[end] == C_SQUOTE || word[end] == C_DQUOTE) - end = p_skip_delim_size(word, word[end], end); - else - { - while (word[end] != C_NULL && - ft_iswhitespace(word[end]) == FALSE) - end++; - } - } - } - return (end); -} +#include "p_args_len.h" static char *p_give_me_an_arg(char tmp[], @@ -108,7 +55,9 @@ uint16_t i = 0; while (i < argc) { - if ((words[i] = ft_strdup(p_give_me_an_arg(tmp, word, i, start))) == NULL) + if ((words[i] = ft_strdup( + p_give_me_an_arg(tmp, word, i, start) + )) == NULL) return (i); i++; } -- cgit v1.2.3 From d0038f19a7cb23749588b72c9febcf114d9d31e9 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 18:31:51 +0200 Subject: static hist, words fix --- src/p_args_next.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 77f8ced..6fd6b08 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -25,8 +25,8 @@ static char { tmp[0] = '\0'; ft_strlcpy(tmp, - word + start[i], - (p_arg_len(word, start[i]) - start[i]) + 1); + word + start[i], + (p_arg_len(word, start[i]) - start[i]) + 1); return (tmp); } @@ -63,4 +63,3 @@ uint16_t } return (i); } - -- 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_args_next.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/p_args_next.c') diff --git a/src/p_args_next.c b/src/p_args_next.c index 6fd6b08..ea8dd81 100644 --- a/src/p_args_next.c +++ b/src/p_args_next.c @@ -12,6 +12,7 @@ #include #include +#include #include "d_define.h" #include "p_args.h" @@ -49,7 +50,7 @@ uint16_t const uint16_t argc, const size_t start[]) { - char tmp[4096]; + char tmp[ARG_MAX]; uint16_t i; i = 0; -- cgit v1.2.3