diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-03 16:09:12 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-03 16:09:12 +0200 | 
| commit | f3f724dd7f434f2731f63d03a925b0e24983b484 (patch) | |
| tree | 59d4d65e4adfe9608680d2480935c4ba936c57c8 /src | |
| parent | Shit in progress (diff) | |
| download | 42-minishell-f3f724dd7f434f2731f63d03a925b0e24983b484.tar.gz 42-minishell-f3f724dd7f434f2731f63d03a925b0e24983b484.tar.bz2 42-minishell-f3f724dd7f434f2731f63d03a925b0e24983b484.tar.xz 42-minishell-f3f724dd7f434f2731f63d03a925b0e24983b484.tar.zst 42-minishell-f3f724dd7f434f2731f63d03a925b0e24983b484.zip | |
how tf do i use tok
Diffstat (limited to '')
| -rw-r--r-- | src/p_args.c | 21 | ||||
| -rw-r--r-- | src/p_args_next.c | 36 | ||||
| -rw-r--r-- | src/p_args_next.h | 20 | 
3 files changed, 75 insertions, 2 deletions
| diff --git a/src/p_args.c b/src/p_args.c index f14b467..6a15cb8 100644 --- a/src/p_args.c +++ b/src/p_args.c @@ -15,6 +15,7 @@  #include <stdlib.h>  #include "d_define.h" +#include "p_args_next.h"  /* ================= */  /* TODO: DELETE THIS */ @@ -86,6 +87,17 @@ static uint16_t  	else if (*ptr == C_NULL)  		return (argc);  	return (p_count_args(ptr, argc + 1)); +	/* TODO: quotes parse error */ +} + +static void +	p_del_alloced_words(char *words[], uint16_t to_del, uint16_t i) +{ +	while (i > to_del) +	{ +		ft_memdel((void*)&words[i]); +		i--; +	}  }  static char @@ -94,6 +106,7 @@ static char  	char		**words;  	char		*ptr;  	uint16_t	argc; +	uint16_t	to_del;  	ptr = (char*)word;  	argc = p_count_args(ptr, 0); @@ -102,14 +115,18 @@ static char  	if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)  		return (NULL);  	words[argc] = NULL; +	if ((to_del = p_dup_words(words, word, argc)) != 0) +	{ +		p_del_alloced_words(words, to_del, argc); +		return (NULL); +	}  	return (words);  } -  char  	**p_split_args(const char word[], int8_t redir)  { -	char			**words; +	char	**words;  	words = NULL;  	ft_printf("word at start: [%s]\n", word); 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 <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> + +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); +} + diff --git a/src/p_args_next.h b/src/p_args_next.h new file mode 100644 index 0000000..46998b7 --- /dev/null +++ b/src/p_args_next.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   p_args_next.h                                      :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   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   */ +/*                                                                            */ +/* ************************************************************************** */ + +#ifndef P_ARGS_NEXT_H +#define P_ARGS_NEXT_H + +#include <stdint.h> + +uint16_t	p_dup_words(char *words[], const char word[], uint16_t i); + +#endif | 
