minishell/srcs/main.c
2019-02-01 16:50:20 +01:00

108 lines
2.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#include "minishell.h"
int main(void)
{
int ret;
char *cmd;
char **tab_cmd;
t_list *lst_env;
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 (cmd != NULL && ft_strlen(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_strdel(&cmd);
}
ft_lstdel(&lst_env, &ft_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);
*/