diff options
Diffstat (limited to '')
-rw-r--r-- | src/p_args_next.c | 44 |
1 files changed, 34 insertions, 10 deletions
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 <libft.h> #include <stdint.h> -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); } |