Restart from scratch

branched out on dev
removed all previous source files
started test on new env2lst function
This commit is contained in:
Tanguy MAZE
2019-09-19 18:00:54 +02:00
parent 5247e0d8e6
commit 852248636f
13 changed files with 128 additions and 942 deletions

View File

@@ -5,103 +5,64 @@
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:09:55 by tmaze #+# #+# */
/* Updated: 2019/02/01 10:18:41 by tmaze ### ########.fr */
/* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */
/* Updated: 2019/09/19 17:59:58 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int main(void)
void lstdelenvelem(void *content, size_t size)
{
int ret;
char *cmd;
char **tab_cmd;
t_list *lst_env;
extern char **environ;
size = 0;
ft_strdel(&(((char**)content)[1]));
ft_strdel(&(((char**)content)[0]));
ft_memdel(&content);
}
if ((lst_env = ft_envtolst(environ)) == NULL)
ft_putendl("Error envtolst");
if (lst_env == NULL)
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)
{
ret = 0;
ft_putstr(FT_COLOR_GREEN);
ft_putstr("$> ");
ft_putstr(FT_RESET);
ret = get_next_line(1, &cmd);
if (cmd != NULL && ft_strlen(cmd) != 0)
cmd = NULL;
ft_printf("%s$>%s ", FT_COLOR_GREEN, FT_RESET);
if (ft_getline(&cmd) >= 0)
{
if (ret == -1)
{
ft_lstdel(&lst_env, &ft_lstdelenvelem);
ft_strdel(&cmd);
return (2);
}
if (ft_strcmp("exit", cmd) == 0)
{
ft_lstdel(&lst_env, &ft_lstdelenvelem);
ft_strdel(&cmd);
return (0);
}
else if ((tab_cmd = ft_strsplit(cmd, ' ')) == NULL)
{
ft_lstdel(&lst_env, &ft_lstdelenvelem);
ft_strdel(&cmd);
ft_putendl("error split");
return (2);
}
ft_strdel(&cmd);
ft_putnbr(exec_cmd(tab_cmd, &lst_env));
ft_putchar('\n');
ft_del_words_tables(&tab_cmd);
ft_printf("%s\n", cmd);
}
ft_strdel(&cmd);
break;
}
ft_lstdel(&lst_env, &ft_lstdelenvelem);
ft_lstdel(&env, &lstdelenvelem);
return (0);
}
/*
** char *cmd;
** char **tab_cmd;
** t_list *lst_env;
** int ret;
** extern char **environ;
**
** if ((lst_env = ft_envtolst(environ)) == NULL)
** ft_putendl("Error envtolst");
** if (lst_env == NULL)
** return (2);
** while (1)
** {
** ret = 0;
** ft_putstr(FT_COLOR_GREEN);
** ft_putstr("$> ");
** ft_putstr(FT_RESET);
** ret = get_next_line(1, &cmd);
** if (ret == -1)
** {
** ft_lstdel(&lst_env, &ft_lstdelenvelem);
** ft_strdel(&cmd);
** return (2);
** }
** if (ft_strcmp("exit", cmd) == 0)
** {
** ft_lstdel(&lst_env, &ft_lstdelenvelem);
** ft_strdel(&cmd);
** return (0);
** }
** else if ((tab_cmd = ft_strsplit(cmd, ' ')) == NULL)
** {
** ft_lstdel(&lst_env, &ft_lstdelenvelem);
** ft_strdel(&cmd);
** ft_putendl("error split");
** return (2);
** }
** exec_cmd(tab_cmd, lst_env);
** }
** ft_lstdel(&lst_env, &ft_lstdelenvelem);
** return (0);
*/