WIP added libft & creating useable shell
This commit is contained in:
66
srcs/main.c
Normal file
66
srcs/main.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/18 13:09:55 by tmaze #+# #+# */
|
||||
/* Updated: 2018/11/23 11:28:26 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *cmd;
|
||||
char **myenv;
|
||||
char **tab_cmd;
|
||||
int ret;
|
||||
extern char **environ;
|
||||
|
||||
if ((myenv = ft_memalloc(sizeof(environ))) == NULL)
|
||||
{
|
||||
ft_putendl("error alloc");
|
||||
return (2);
|
||||
}
|
||||
ft_memcpy((void*)myenv, (void*)environ, sizeof(environ));
|
||||
while (1)
|
||||
{
|
||||
ret = 0;
|
||||
ft_putstr(FT_COLOR_BLUE);
|
||||
ft_putstr("$> ");
|
||||
ft_putstr(FT_RESET);
|
||||
while (ret == 0)
|
||||
ret = get_next_line(0, &cmd);
|
||||
if (ft_strcmp("exit", cmd) == 0)
|
||||
{
|
||||
ft_memdel((void*)&myenv);
|
||||
ft_strdel(&cmd);
|
||||
return (0);
|
||||
}
|
||||
else if ((tab_cmd = ft_strsplit(cmd, ' ')) == NULL)
|
||||
{
|
||||
ft_memdel((void*)&myenv);
|
||||
ft_strdel(&cmd);
|
||||
ft_putendl("error split");
|
||||
return (2);
|
||||
}
|
||||
if ((ret = fork()) == 0)
|
||||
{
|
||||
execve(cmd, tab_cmd, environ);
|
||||
ft_putstr("Error: ");
|
||||
ft_putendl(cmd);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
waitpid(ret, NULL, 0);
|
||||
ft_strdel(&cmd);
|
||||
ft_del_words_tables(&tab_cmd);
|
||||
}
|
||||
}
|
||||
ft_strdel((void*)&myenv);
|
||||
return (3);
|
||||
}
|
Reference in New Issue
Block a user