feature: added execution of commands from path

This commit is contained in:
Tanguy MAZE
2019-09-27 17:00:03 +02:00
parent aa8e971688
commit 58459bc0c1
5 changed files with 209 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */
/* Updated: 2019/09/26 16:48:37 by tmaze ### ########.fr */
/* Updated: 2019/09/27 16:21:14 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -68,3 +68,51 @@ t_env *lstaddend(t_env **alst, t_env *new)
return (*alst);
}
t_env *lstgetelem(char *key, t_env *env)
{
t_env *it;
it = env;
while (it && !ft_strequ(it->key, key))
it = it->next;
return (it);
}
char **lsttotab(t_env *env)
{
t_env *it;
char *new;
char **ret;
size_t size;
int i;
i = 0;
ret = NULL;
it = env;
while (it)
{
i++;
it = it->next;
}
if ((ret = (char**)ft_memalloc(sizeof(char*) * (i + 1))) == NULL)
return (NULL);
while (i >= 0)
ret[i--] = NULL;
it = env;
i = 0;
while (it)
{
size = ft_strlen(it->key) + ft_strlen(it->val) + 1;
if ((new = ft_strnew(size)) == NULL)
{
ft_del_words_tables(&ret);
break ;
}
ft_strlcpy(new, it->key, size);
ft_strlcat(new, "=", size);
ft_strlcat(new, it->val, size);
ret[i++] = new;
it = it->next;
}
return (ret);
}