diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/b_cd.c | 12 | ||||
| -rw-r--r-- | src/b_export.c | 6 | ||||
| -rw-r--r-- | src/b_export_next.c | 14 | ||||
| -rw-r--r-- | src/b_pwd.c | 2 | ||||
| -rw-r--r-- | src/b_type.c | 3 | ||||
| -rw-r--r-- | src/b_unset.c | 4 | ||||
| -rw-r--r-- | src/e_externs.c | 2 | ||||
| -rw-r--r-- | src/e_externs_next.c | 8 | ||||
| -rw-r--r-- | src/e_externs_pipes.c | 4 | ||||
| -rw-r--r-- | src/f_alloc.c | 14 | ||||
| -rw-r--r-- | src/f_alloc.h | 4 | ||||
| -rw-r--r-- | src/m_funptr.c | 2 | ||||
| -rw-r--r-- | src/p_lcom_next.c | 50 | ||||
| -rw-r--r-- | src/p_line.c | 3 | ||||
| -rw-r--r-- | src/s_lcom.c | 3 | ||||
| -rw-r--r-- | src/s_lvars.c | 6 | ||||
| -rw-r--r-- | src/s_struct.h | 1 | ||||
| -rw-r--r-- | src/u_utils.c | 4 | ||||
| -rw-r--r-- | src/u_vars.c | 16 | 
19 files changed, 91 insertions, 67 deletions
| @@ -30,16 +30,14 @@ static void  {  	if (!(*path = ft_strdup(*args)))  	{ -		s_destroy(msh); -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  	if (!ft_strncmp("~/", *path, 2) || !ft_strncmp("~", *path, 2))  	{  		if (!(*path = ft_strsubst(*path,  			"~", u_get_var_value("$HOME", msh))))  		{ -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  	}  } @@ -54,7 +52,7 @@ static void  	if ((pwd = u_get_var_value("$PWD", msh)) == NULL)  	{  		if ((pwd = ft_strdup(msh->cwd)) == NULL) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  	}  	if ((tmp = u_get_var_value("$OLDPWD", msh)) == NULL)  	{ @@ -114,7 +112,7 @@ static void  	if (path[0] != '/')  		ft_memcpy(repath, msh->cwd, ft_strlen(msh->cwd));  	if ((splited = ft_split(path, '/')) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	b_fill_repath(repath, splited);  	repath[0] = (repath[0] == '\0') ? '/' : repath[0];  	ft_delwords(splited); @@ -127,7 +125,7 @@ static void  	}  	ft_memdel((void*)&msh->cwd);  	if ((msh->cwd = ft_strdup(repath)) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  }  uint8_t diff --git a/src/b_export.c b/src/b_export.c index 0b5dbf6..62dc64b 100644 --- a/src/b_export.c +++ b/src/b_export.c @@ -67,16 +67,16 @@ void  	while (msh->envp[i] != NULL)  		i++;  	if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*)))) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	i = 0;  	while (msh->envp[i] != NULL)  	{  		if (!(nenvp[i] = ft_strdup(msh->envp[i]))) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  		i++;  	}  	if (!(nenvp[i] = ft_strdup(var))) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	nenvp[i + 1] = 0;  	ft_delwords(msh->envp);  	lvars_delone(&msh->vars, varname); diff --git a/src/b_export_next.c b/src/b_export_next.c index 7b70047..90a4820 100644 --- a/src/b_export_next.c +++ b/src/b_export_next.c @@ -28,17 +28,17 @@ static char  	char	**var;  	if ((var = (char**)malloc(3 * sizeof(char*))) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	len = 0;  	while (arg[len] != '=' && arg[len] != '\0')  		len++;  	len += 1;  	if ((var[FT_VAR_NAME] = (char*)malloc((len + 1) * sizeof(char))) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	var[FT_VAR_NAME][0] = '$';  	ft_strlcpy(var[FT_VAR_NAME] + 1, arg, len);  	if ((var[FT_VAR_VAL] = ft_strdup(arg + len)) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	var[FT_VAR_NULL] = NULL;  	return (var);  } @@ -75,16 +75,16 @@ static void  	while (msh->envp[i] != NULL)  		i++;  	if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*)))) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	i = 0;  	while (msh->envp[i] != NULL)  	{  		if (!(nenvp[i] = ft_strdup(msh->envp[i]))) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  		i++;  	}  	if (!(nenvp[i] = ft_strdup(arg))) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	nenvp[i + 1] = 0;  	ft_delwords(msh->envp);  	msh->envp = nenvp; @@ -103,7 +103,7 @@ void  	{  		ft_memdel((void*)&msh->envp[env_i]);  		if ((msh->envp[env_i] = ft_strdup(arg)) == NULL) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  	}  	else if ((varval = u_get_cstm_vr(var[FT_VAR_NAME], msh)) != NULL)  	{ diff --git a/src/b_pwd.c b/src/b_pwd.c index 5e4209e..e3da005 100644 --- a/src/b_pwd.c +++ b/src/b_pwd.c @@ -34,7 +34,7 @@ uint8_t  		return (0);  	}  	if ((cwd = ft_strdup(msh->cwd)) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	ft_printf("%s\n", cwd);  	ft_memdel((void*)&cwd);  	return (0); diff --git a/src/b_type.c b/src/b_type.c index 00bad1a..16791c9 100644 --- a/src/b_type.c +++ b/src/b_type.c @@ -56,8 +56,7 @@ static char  		{  			if (!(fullpath = ft_strdup(com)))  			{ -				lcom_clear(&msh->curr); -				f_fail_alloc(msh); +				f_alloc_and_destroy_msh(msh);  			}  			return (fullpath);  		} diff --git a/src/b_unset.c b/src/b_unset.c index c45d5ee..00fab78 100644 --- a/src/b_unset.c +++ b/src/b_unset.c @@ -58,7 +58,7 @@ static void  	while (msh->envp[i] != NULL)  		i++;  	if (!(nenvp = (char**)malloc(i * sizeof(char*)))) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	i = 0;  	skipped = 0;  	while (msh->envp[i] != NULL) @@ -71,7 +71,7 @@ static void  			skipped = 1;  		}  		if (!(nenvp[i - skipped] = ft_strdup(msh->envp[i]))) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  		i++;  	}  	nenvp[i - 1] = 0; diff --git a/src/e_externs.c b/src/e_externs.c index 32596c3..7593c3d 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -43,6 +43,8 @@ static void  	if ((pid = fork()) == 0)  	{ +		/* if (ptr->env_fork != NULL) */ +		/* 	e_export_env_fork(ptr->env_fork, msh); */  		e_extern_child(fullpath, ptr, msh);  	}  	else if (pid < 0) diff --git a/src/e_externs_next.c b/src/e_externs_next.c index bbd9d81..5d7deaf 100644 --- a/src/e_externs_next.c +++ b/src/e_externs_next.c @@ -32,9 +32,7 @@ static char  	if (!(fullpath = (char*)malloc((path_len + name_len + 2) * sizeof(char))))  	{ -		lcom_clear(&msh->curr); -		s_destroy(msh); -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  	(void)ft_memcpy(fullpath, p_path, path_len);  	*(fullpath + (path_len)) = '/'; @@ -96,9 +94,7 @@ char  	{  		if (!(envpath = ft_split(envline, ':')))  		{ -			lcom_clear(&msh->curr); -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  		return (envpath);  	} diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index a5ee696..c9f677f 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -122,7 +122,7 @@ void  	rptr = ptr;  	pipes = e_get_pipes_count(head);  	if (!(fullpath = (char **)malloc((pipes + 2) * sizeof(char *)))) -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	fullpath[pipes + 1] = NULL;  	i = 0;  	while (rptr != NULL) @@ -130,7 +130,7 @@ void  		if (ft_ischarset("/.", rptr->one->com[0]))  		{  			if (!(fullpath[i] = ft_strdup(rptr->one->com))) -				f_fail_alloc(msh); +				f_alloc_and_destroy_msh(msh);  		}  		else if ((envpath = get_env_path(msh)) != NULL)  		{ diff --git a/src/f_alloc.c b/src/f_alloc.c index bfa75c3..62b7008 100644 --- a/src/f_alloc.c +++ b/src/f_alloc.c @@ -21,16 +21,20 @@  #include "s_struct.h"  void -	f_fail_alloc(t_msh *msh) +	f_alloc_and_destroy_msh(t_msh *msh)  { -	ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno)); +	char	tmp[255]; + +	lcom_clear(&msh->curr); +	ft_strlcpy(tmp, msh->shname, ft_strlen(msh->shname) + 1); +	s_destroy(msh); +	ft_dprintf(STDERR_FILENO, "%s: %s\n", tmp, strerror(errno));  	exit(FT_RET_ALLOC);  }  void -	f_fail_alloc_and_destroy(t_msh *msh) +	f_alloc_and_clear_lcom(t_msh *msh)  {  	lcom_clear(&msh->curr); -	s_destroy(msh); -	f_fail_alloc(msh); +	ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno));  } diff --git a/src/f_alloc.h b/src/f_alloc.h index 34a5e7d..d309802 100644 --- a/src/f_alloc.h +++ b/src/f_alloc.h @@ -15,7 +15,7 @@  #include "s_struct.h" -void	f_fail_alloc(t_msh *msh); -void	f_fail_alloc_and_destroy(t_msh *msh); +void	f_alloc_and_destroy_msh(t_msh *msh); +void	f_alloc_and_clear_lcom(t_msh *msh);  #endif diff --git a/src/m_funptr.c b/src/m_funptr.c index 3bd0969..2fdf4d1 100644 --- a/src/m_funptr.c +++ b/src/m_funptr.c @@ -32,6 +32,6 @@ void  	msh->bu_ptr[7] = b_type;  	if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))  	{ -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  } diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index 997878e..e461d55 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -157,8 +157,7 @@ static char  	if (!(rewords = (char**)malloc((j + 1) * sizeof(char*))))  	{  		ft_delwords(words); -		s_destroy(msh); -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  	k = i;  	while (i - k < j) @@ -166,8 +165,7 @@ static char  		if (!(rewords[i - k] = ft_strdup(words[i])))  		{  			ft_delwords(words); -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  		i++;  	} @@ -177,6 +175,37 @@ static char  	return (rewords);  } +static void +	p_add_to_env_fork(int64_t i, +					char *words[], +					t_lcom *ptr, +					t_msh *msh) +{ +	int64_t	j; + +	(void)msh; +	(void)words; +	j = 0; +	if ((ptr->env_fork = (char**)malloc((i + 1) * sizeof(char*))) == NULL) +	{ +		ft_delwords(words); +		f_alloc_and_destroy_msh(msh); +	} +	while(j < i) +	{ +		if ((ptr->env_fork[j] = ft_strdup(words[j])) == NULL) +			f_alloc_and_destroy_msh(msh); +		j++; +	} +	ptr->env_fork[j] = NULL; +	/* TODO: delete this */ +	i = 0; +	while (ptr->env_fork[i] != NULL) { +		ft_printf("[%s]\n", ptr->env_fork[i]); +	} +	ft_printf("[%s]\n", ptr->env_fork[i]); +} +  char  	**p_check_args_equals(char *words[],  						t_msh *msh) @@ -187,18 +216,25 @@ char  	int64_t	i;  	i = 0; -	reg = TRUE; -	isvar = TRUE; +	reg = FALSE; +	isvar = FALSE;  	while (words[i])  	{  		ptr = words[i];  		while (*ptr != '\0' && *ptr != '=')  			ptr++; -		if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0])) +		if (*ptr == '=') +		{ +			reg = TRUE; +			isvar = TRUE; +		} +		if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0]) == 1)  		{  			reg = FALSE;  			if (i == 0)  				isvar = FALSE; +			if (isvar == TRUE) +				p_add_to_env_fork(i, words, msh->curr, msh);  			break ;  		}  		i++; diff --git a/src/p_line.c b/src/p_line.c index aafc900..a9a918c 100644 --- a/src/p_line.c +++ b/src/p_line.c @@ -44,7 +44,6 @@ void  	}  	if (p_lcom(line, count, msh) < 0)  	{ -		s_destroy(msh); -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  } diff --git a/src/s_lcom.c b/src/s_lcom.c index f1ef2a4..7ef64b3 100644 --- a/src/s_lcom.c +++ b/src/s_lcom.c @@ -97,6 +97,8 @@ void  			ft_delwords(tmp->argv);  		if (tmp->redir != 0)  			ft_memdel((void*)&tmp->rdrpath); +		if (tmp->env_fork != NULL) +			ft_delwords(tmp->env_fork);  		ft_memdel((void*)&tmp);  		tmp = renext;  	} @@ -119,6 +121,7 @@ t_lcom  	link->rdrfd = 0;  	link->rdrpath = NULL;  	link->pipes = NULL; +	link->env_fork = NULL;  	if (!word)  	{  		link->next = NULL; diff --git a/src/s_lvars.c b/src/s_lvars.c index d9b7159..9369f84 100644 --- a/src/s_lvars.c +++ b/src/s_lvars.c @@ -40,12 +40,6 @@ void  		ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno));  		exit(FT_RET_ALLOC);  	} -	/* TODO: delete this */ -	tmp = *lvars; -	while (tmp) { -		ft_printf("[%s]: [%s]\n", tmp->name, tmp->val); -		tmp = tmp->next; -	}  }  void diff --git a/src/s_struct.h b/src/s_struct.h index 0c5acf0..c2caf92 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -42,6 +42,7 @@ typedef struct		s_lcom  	int8_t			redir;  	int32_t			rdrfd;  	char			*rdrpath; +	char			**env_fork;  	struct s_lpipes	*pipes;  	struct s_lcom	*next;  }					t_lcom; diff --git a/src/u_utils.c b/src/u_utils.c index a485fb3..5e31060 100644 --- a/src/u_utils.c +++ b/src/u_utils.c @@ -27,14 +27,14 @@ char  	while (msh->envp[i] != NULL)  		i++;  	if ((vars = (char**)malloc((i + 1) * sizeof(char*))) == NULL) -		f_fail_alloc_and_destroy(msh); +		f_alloc_and_destroy_msh(msh);  	i = 0;  	while (msh->envp[i] != NULL)  	{  		if ((vars[i] =  			(char*)malloc((ft_strclen(msh->envp[i], '=') + 1)  			* sizeof(char))) == NULL) -			f_fail_alloc_and_destroy(msh); +			f_alloc_and_destroy_msh(msh);  		ft_strlcpy(vars[i], msh->envp[i], ft_strclen(msh->envp[i], '=') + 1);  		i++;  	} diff --git a/src/u_vars.c b/src/u_vars.c index e949cc9..ebdba25 100644 --- a/src/u_vars.c +++ b/src/u_vars.c @@ -29,9 +29,7 @@ static char  	if (!(varval = ft_strdup(p_env)))  	{ -		lcom_clear(&msh->curr); -		s_destroy(msh); -		f_fail_alloc(msh); +		f_alloc_and_destroy_msh(msh);  	}  	return (varval);  } @@ -76,9 +74,7 @@ static char  	{  		if ((varval = ft_uitoa(msh->ret)) == NULL)  		{ -			lcom_clear(&msh->curr); -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  		return (varval);  	} @@ -86,9 +82,7 @@ static char  	{  		if ((varval = ft_strdup(msh->shname)) == NULL)  		{ -			lcom_clear(&msh->curr); -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  		return (varval);  	} @@ -112,9 +106,7 @@ char  	{  		if (!(varval = ft_strdup(ptr->val)))  		{ -			lcom_clear(&msh->curr); -			s_destroy(msh); -			f_fail_alloc(msh); +			f_alloc_and_destroy_msh(msh);  		}  		return (varval);  	} | 
