minishell/srcs/main.c
Tanguy MAZE 852248636f Restart from scratch
branched out on dev
removed all previous source files
started test on new env2lst function
2019-09-19 18:00:54 +02:00

69 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */
/* Updated: 2019/09/19 17:59:58 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void lstdelenvelem(void *content, size_t size)
{
size = 0;
ft_strdel(&(((char**)content)[1]));
ft_strdel(&(((char**)content)[0]));
ft_memdel(&content);
}
t_list *env2lst(char** env)
{
t_list *ret;
t_list *new;
int i;
i = 0;
ret = NULL;
while (env[i])
{
if ((new = (t_list*)ft_memalloc(sizeof(t_list))) == NULL
|| (new->content = ft_strsplit(env[i], '=')) == NULL
|| ft_lstaddend(&ret, new) == NULL)
{
ft_lstdel(&ret, &lstdelenvelem);
return (NULL);
}
i++;
}
return (ret);
}
int main(void)
{
extern char **environ;
t_list *env;
char *cmd;
env = NULL;
if ((env = env2lst(environ)) == NULL)
return (2);
while (1)
{
cmd = NULL;
ft_printf("%s$>%s ", FT_COLOR_GREEN, FT_RESET);
if (ft_getline(&cmd) >= 0)
{
ft_printf("%s\n", cmd);
}
ft_strdel(&cmd);
break;
}
ft_lstdel(&env, &lstdelenvelem);
return (0);
}