diff options
Diffstat (limited to '')
-rw-r--r-- | src/p_args_next.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/p_args_next.c b/src/p_args_next.c new file mode 100644 index 0000000..ea8dd81 --- /dev/null +++ b/src/p_args_next.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_args_next.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdint.h> +#include <limits.h> + +#include "d_define.h" +#include "p_args.h" +#include "p_args_len.h" + +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); + 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[], + const uint16_t argc, + const size_t start[]) +{ + char tmp[ARG_MAX]; + uint16_t i; + + i = 0; + while (i < argc) + { + if ((words[i] = ft_strdup( + p_give_me_an_arg(tmp, word, i, start) + )) == NULL) + return (i); + i++; + } + return (i); +} |