WIP adding env exec capabilities

This commit is contained in:
Tanguy MAZE 2019-01-31 17:58:05 +01:00
parent f04da8b91f
commit 25bfd0c946
3 changed files with 75 additions and 7 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */
/* Updated: 2019/01/29 18:23:45 by tmaze ### ########.fr */
/* Updated: 2019/01/31 17:36:17 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,4 +47,8 @@ int ft_isin(char *str, char c);
char *check_path_slash(char *exec);
char *check_path_dot(char *exec, t_list *env);
void ft_lstdelenvelem(void *content, size_t size);
t_envelem *ft_envtoenvelem(char *env);
#endif

View File

@ -6,19 +6,17 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/14 15:54:45 by tmaze #+# #+# */
/* Updated: 2019/01/13 17:48:51 by tmaze ### ########.fr */
/* Updated: 2019/01/31 17:57:27 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int cmd_env(char **argv, t_list **env)
void put_env(t_list *env)
{
t_list *tmp;
if (argv[1] != NULL)
return (0);
tmp = *env;
tmp = env;
while (tmp)
{
ft_putstr(((t_envelem*)(tmp->content))->key);
@ -26,5 +24,71 @@ int cmd_env(char **argv, t_list **env)
ft_putendl(((t_envelem*)(tmp->content))->val);
tmp = tmp->next;
}
}
t_envelem *envelemdup(t_envelem *elem)
{
t_envelem *ret;
if ((ret = (t_envelem*)ft_memalloc(sizeof(t_envelem))) == NULL)
return (NULL);
if ((ret->key = ft_strdup(elem->key)) == NULL)
ft_memdel(&ret);
if (ret == NULL)
return (0);
if ((ret->val = ft_strdup(elem->val)) == NULL)
{
ft_strdel(&(ret->key));
ft_memdel(&ret);
return (NULL);
}
return (ret);
}
t_list *env_cpy(t_list *env)
{
t_list *ret;
t_list *ind;
t_list *tmp;
t_envelem elem;
ret = NULL;
ind = env;
while (ind)
{
if ((envelem = envelemdup((t_envelem*)ind->val)) == NULL)
ft_lstdel(&ret, &lstdelenvelem);
if (envelem = NULL)
break ;
if ((tmp = ft_lstnew((void*)envelem, sizeof(t_envelem))) == NULL
|| ft_lstaddend(&ret, tmp) == NULL)
{
ft_memdel(&envelem);
ft_lstdel(&ret, &lstdelenvelem);
break ;
}
ft_memdel(&envelem);
ind = ind->next;
}
return (ret);
}
int cmd_env(char **argv, t_list **env)
{
t_list *env_cp;
t_list *new;
t_envelem *envelem;
char tmp;
size_t i;
if (argv[1] == NULL)
put_env(*env);
i = 0;
if ((env_cp = env_cpy(*env)) == NULL)
return (2);
while (argv[++i] && (tmp = ft_strchr(argv[i], '=')))
{
// add each env arg to a char ** and pass it ti ft_envtolst
}
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:09:55 by tmaze #+# #+# */
/* Updated: 2019/01/24 12:54:27 by tmaze ### ########.fr */
/* Updated: 2019/01/31 17:57:41 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */