diff options
Diffstat (limited to '')
| -rw-r--r-- | src/p_split.c | 42 | 
1 files changed, 39 insertions, 3 deletions
| diff --git a/src/p_split.c b/src/p_split.c index 482bc58..d39a4cb 100644 --- a/src/p_split.c +++ b/src/p_split.c @@ -154,7 +154,7 @@ typedef struct	s_split  {  	size_t		pos[ARG_MAX / 2];  	int8_t		nextif[ARG_MAX / 2]; -	int16_t		count; +	uint32_t	count;  }				t_split;  static void @@ -208,15 +208,51 @@ static t_split  			p_meet_splitter(ptr, line, &sp, mode);  		ptr++;  	} +	sp.pos[sp.count] = ptr - line; +	sp.nextif[sp.count] = 0; +	sp.count += 1;  	return (sp);  } +static void +	*p_del_split(char *words[], size_t todel) +{ +	size_t	i; + +	i = 0; +	while (i < todel) +	{ +		ft_memdel((void*)&words[i]); +	} +	ft_memdel((void*)&words); +	return (NULL); +} +  static char -**p_get_words(const char line[], const t_split sp) +	**p_get_words(const char line[], const t_split sp)  {  	char	**words; +	size_t	i; +	size_t	oldpos; +	int8_t	oldif; -	words = NULL; +	if ((words = (char**)malloc((sp.count + 1) * sizeof(char*))) == NULL) +		return (NULL); +	oldpos = 0; +	oldif = -1; +	i = 0; +	while (i < sp.count) +	{ +		if ((words[i] = +			(char*)malloc(((sp.pos[i] - oldpos) + 1) * sizeof(char))) == NULL) +			return ((char**)p_del_split(words, i)); +		ft_strlcpy(words[i], line + oldpos + ((oldif > 0) ? (2) : (oldif) + 1), sp.pos[i] - oldpos); +		ft_printf("[%s]\n", words[i]); +		oldpos = sp.pos[i]; +		oldif = sp.nextif[i]; +		i++; +	} +	words[i] = NULL;  	return (words);  } | 
