diff options
| -rw-r--r-- | TODO.org | 2 | ||||
| -rw-r--r-- | libft/src/ft_split.c | 4 | ||||
| -rw-r--r-- | src/e_line.c | 37 | ||||
| -rw-r--r-- | src/p_lcom.c | 12 | ||||
| -rw-r--r-- | src/p_lcom.h | 2 | ||||
| -rw-r--r-- | src/p_line.c | 20 | ||||
| -rw-r--r-- | src/p_split.c | 26 | 
7 files changed, 56 insertions, 47 deletions
| @@ -10,7 +10,7 @@  * Stuff to add  ** DONE [#A] builtins to pipes  ** TODO [#A] Proper ~ subst -** TODO [#B] && || +** DONE [#B] && ||  ** TODO [#B] &  ** TODO [#C] $_  ** TODO [#C] Norm diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c index 3035a00..34cd57a 100644 --- a/libft/src/ft_split.c +++ b/libft/src/ft_split.c @@ -75,10 +75,10 @@ static char  {  	while (j > 0)  	{ -		ft_memdel((void**)&best_split[j]); +		ft_memdel((void*)&best_split[j]);  		j--;  	} -	ft_memdel((void**)best_split); +	ft_memdel((void*)&best_split);  	return (NULL);  } diff --git a/src/e_line.c b/src/e_line.c index 4489926..e584140 100644 --- a/src/e_line.c +++ b/src/e_line.c @@ -18,6 +18,7 @@  #include "e_externs.h"  #include "e_pipes.h"  #include "s_lpipes.h" +#include "s_com.h"  #include "s_struct.h"  static uint8_t @@ -35,27 +36,43 @@ static uint8_t  	return (i);  } +static void +	e_line_destroy(t_line *ptr) +{ +	if (ptr->pipes != NULL) +	{ +		lpipes_clear(&ptr->pipes); +	} +} +  void  	e_line(t_msh *msh)  {  	t_line	*ptr;  	uint8_t	bu_id; +	uint8_t	previf; +	previf = 0;  	ptr = msh->curr;  	while (ptr != NULL)  	{ -		if (ptr->pipes) -		{ -			e_pipes(ptr, msh); -		} -		else if (ptr->com) +		if ((previf == 0) || (previf == 1 && msh->ret == 0) || +			(previf == 2 && msh->ret != 0))  		{ -			if ((bu_id = get_builtin_id(ptr->com->bin, msh)) -				< FT_BUILTINS_COUNT) -				e_builtin(ptr->com, bu_id, msh); -			else -				e_extern(ptr->com, msh); +			if (ptr->pipes) +				e_pipes(ptr, msh); +			else if (ptr->com) +			{ +				if ((bu_id = get_builtin_id(ptr->com->bin, msh)) +					< FT_BUILTINS_COUNT) +					e_builtin(ptr->com, bu_id, msh); +				else +					e_extern(ptr->com, msh); +			}  		} +		else +			e_line_destroy(ptr); +		previf = ptr->nextif;  		ptr = ptr->next;  	}  } diff --git a/src/p_lcom.c b/src/p_lcom.c index e65dd3e..0e849a0 100644 --- a/src/p_lcom.c +++ b/src/p_lcom.c @@ -125,7 +125,6 @@ int8_t  int8_t  	p_lcom(const char line[], -		const uint64_t count,  		t_msh *msh)  {  	/* TODO: norme */ @@ -133,13 +132,21 @@ int8_t  	t_line			*link;  	char			**words;  	char			*ptr; +	uint8_t			nextif;  	t_bool			next;  	i = 0;  	if ((words = p_split_line(line)) == NULL)  		return (-1); -	while (i <= count && words[i] != NULL) +	while (words[i] != NULL)  	{ +		if (words[i][ft_strlen(words[i]) - 1] == ';') +			nextif = 0; +		else if (words[i][ft_strlen(words[i]) - 1] == '&') +			nextif = 1; +		else +			nextif = 2; +		words[i][ft_strlen(words[i]) - 1] = '\0';  		next = FALSE;  		if ((ptr = ft_strchr(words[i], '|')) != NULL)  		{ @@ -151,6 +158,7 @@ int8_t  		}  		if (next == FALSE && (link = s_line_new(words[i], msh)) == NULL)  			return (-1); +		link->nextif = nextif;  		s_line_add_back(&msh->curr, link);  		i++;  	} diff --git a/src/p_lcom.h b/src/p_lcom.h index d84269e..2ff2c7e 100644 --- a/src/p_lcom.h +++ b/src/p_lcom.h @@ -18,6 +18,6 @@  #include "s_struct.h"  int8_t	get_redir(const char word[], t_com **com); -int8_t	p_lcom(const char line[], const uint64_t count, t_msh *msh); +int8_t	p_lcom(const char line[], t_msh *msh);  #endif diff --git a/src/p_line.c b/src/p_line.c index 23a3896..6e02525 100644 --- a/src/p_line.c +++ b/src/p_line.c @@ -24,25 +24,7 @@ void  	p_line(char line[],  		t_msh *msh)  { -	char		*ptr; -	uint64_t	count; - -	count = 0; -	ptr = line; -	while (*ptr != '\0') -	{ - -		if (*ptr == ';') -		{ -			count += 1; -		} -		ptr++; -	} -	if (*(ptr - 1) == ';') -	{ -		count -= 1; -	} -	if (p_lcom(line, count, msh) < 0) +	if (p_lcom(line, msh) < 0)  	{  		f_alloc_and_destroy_msh(msh);  	} diff --git a/src/p_split.c b/src/p_split.c index d834e58..bbe9bf5 100644 --- a/src/p_split.c +++ b/src/p_split.c @@ -70,6 +70,18 @@ static char  }  static char +	**p_split_destroy(char **words, +					size_t i) +{ +	while (i > 0) +	{ +		ft_memdel((void*)&words[i]); +	} +	ft_memdel((void*)&words); +	return (NULL); +} + +static char  	**p_split_to_stuff(const char line[],  					const size_t count)  { @@ -94,7 +106,7 @@ static char  		{  			if ((words[i] = (char*)malloc(((ft_strlen(line_ptr) + 2) *  				sizeof(char)))) == NULL) -				return (NULL); +				return (p_split_destroy(words, i));  			ft_memcpy(words[i], line_ptr, ft_strlen(line_ptr));  			words[i][ft_strlen(line_ptr)] = ';';  			words[i][ft_strlen(line_ptr) + 1] = '\0'; @@ -103,7 +115,7 @@ static char  		{  			if ((words[i] = (char*)malloc(((need_ptr - line_ptr) + 1) *  				sizeof(char))) == NULL) -				return (NULL); +				return (p_split_destroy(words, i));  			ft_memcpy(words[i], line_ptr, (need_ptr - line_ptr) - 1);  			words[i][(need_ptr - line_ptr) - ((c == ';') ? (1) : (2))] = c;  			words[i][(need_ptr - line_ptr) - ((c == ';') ? (0) : (1))] = '\0'; @@ -119,7 +131,6 @@ char  	**p_split_line(const char line[])  {  	char	**words; -	size_t	i;  	size_t	count;  	count = p_count_semi_words(line); @@ -128,14 +139,5 @@ char  	count += 1;  	if ((words = p_split_to_stuff(line, count)) == NULL)  		return (NULL); -	/* TODO: delete this */ -	ft_printf("words[]:\n--------\n"); -	i = 0; -	while (words[i] != NULL) { -		ft_printf("[%s]\n", words[i]); -		i++; -	} -	ft_printf("[%s]\n", words[i]); -	exit(0);  	return (words);  } | 
