added function to transform env entry into list element

This commit is contained in:
Tanguy MAZE
2019-01-08 18:34:22 +01:00
parent 1edfe5167f
commit 2793aed4e5
4 changed files with 44 additions and 7 deletions

View File

@@ -6,13 +6,13 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/27 15:32:29 by tmaze #+# #+# */
/* Updated: 2018/11/28 16:42:22 by tmaze ### ########.fr */
/* Updated: 2019/01/07 18:57:22 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define S_BIN 1
#define S_BIN 2
int exec_cmd(char **argv, char **env)
{

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:09:55 by tmaze #+# #+# */
/* Updated: 2018/11/28 15:10:45 by tmaze ### ########.fr */
/* Updated: 2019/01/08 18:33:40 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -62,6 +62,36 @@ t_list *ft_strtabtolst(char **tab)
return (ret);
}
t_envelem *ft_envtoenvelem(char *env)
{
size_t i;
t_envelem *ret;
i = 0;
if ((ret = (t_envelem*)ft_memalloc(sizeof(t_envelem))) == NULL)
return (NULL);
while (env[i] && env[i] != '=')
i++;
if ((ret->key = (char*)ft_strnew(i)) = NULL)
{
ft_memdel((void**)&ret);
return (NULL);
}
if ((ret->value = (char*)ft_strnew(ft_strlen(ft_strrlen(env) - i - 1))) = NULL)
{
ft_memdel((void**)&ret);
return (NULL);
}
ft_strlcpy(ret->key, env, i);
ft_strlcpy(ret->key, env + i + 1, ft_strrlen(env) - i - 1);
return (&ret);
}
t_list *ft_envtolst(char **env)
{
}
int main(void)
{
char *cmd;
@@ -96,7 +126,7 @@ int main(void)
ft_lstdel(&lst_env, &ft_lstdelstr);
ft_strdel(&cmd);
return (2);
}
}
if (ft_strcmp("exit", cmd) == 0)
{
ft_lstdel(&lst_env, &ft_lstdelstr);