| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* ft_take_args.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2018/01/04 20:23:47 by bchanot #+# #+# */
- /* Updated: 2018/10/14 04:25:02 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "libft.h"
- static char **ft_take_arg_begin2(size_t size, int ac, char **av)
- {
- t_bool check;
- size_t index;
- char **args;
- int i;
- i = -1;
- index = 0;
- check = false;
- if (!(args = (char **)ft_memalloc(sizeof(char *) * (size + 1))))
- return (NULL);
- while (++i < ac)
- {
- if (check)
- args[index++] = ft_strdup(av[i]);
- else if (av[i][0] != '-')
- {
- args[index++] = ft_strdup(av[i]);
- check = true;
- }
- else if ((av[i][0] == '-' && av[i][1] && av[i][1] == '-' &&
- !av[i][2]))
- check = true;
- }
- args[index] = 0;
- return (args);
- }
- char **ft_take_args_begin(int ac, char **av)
- {
- t_bool check;
- size_t index;
- int i;
- i = -1;
- check = false;
- index = 0;
- if (ac < 1)
- return (NULL);
- while (++i < ac)
- {
- if (check)
- index++;
- else if (av[i][0] != '-')
- {
- check = true;
- index++;
- }
- if (av[i][0] == '-' && av[i][1] && av[i][1] == '-' &&
- !av[i][2])
- check = true;
- }
- return (index > 0 ? ft_take_arg_begin2(index, ac, av) : NULL);
- }
|