Commit 51010a74 authored by abenoit's avatar abenoit
Browse files

few minor fixes and read from file removed

parent 4cc3921f
......@@ -19,6 +19,8 @@ int ft_exit(char **args, t_xe *xe)
}
else
{
if (ft_putstr_fd("exit\n", STDOUT_FILENO) != WRITE_SUCCESS)
return (WRITE_ERR);
xe->stat_loc = 2;
return (EXIT_NAN);
}
......
......@@ -69,7 +69,7 @@ int clean_and_exit(int err_code, t_xe *xe)
if (err_code == ARG_ERR)
{
if (ft_putstr_fd("Minishell takes no argument", STDERR_FILENO) != WRITE_SUCCESS) // takes no argument?
if (ft_putstr_fd("Minishell takes no argument\n", STDERR_FILENO) != WRITE_SUCCESS) // takes no argument?
ft_error(WRITE_ERR, xe); // possible?
}
if (err_code < FT_EXIT)
......
......@@ -66,20 +66,6 @@ int exec_env_init(t_xe *xe, char **env_source)
return (SUCCESS);
}
int read_from_file(t_xe *xe, char *file)
{
int fd;
int flags;
flags = O_RDONLY;
fd = open(file, flags);
if (fd == ERROR)
return (-1); // another error code
dup2(fd, STDIN_FILENO);
xe->backup_stdin = dup(STDIN_FILENO);
return (SUCCESS);
}
int main(int argc, char **argv, char **env_source)
{
int ret;
......@@ -91,18 +77,8 @@ int main(int argc, char **argv, char **env_source)
if (xe == NULL)
return (error_and_exit(MALLOC_ERR, xe));
ft_bzero(xe, sizeof(t_xe));
if (argc > 2)
if (argc > 1)
ret = ARG_ERR;
else if (argc == 2)
{
//signal_handler(); ?
ret = exec_env_init(xe, env_source);
ret = read_from_file(xe, argv[1]);
if (ret != SUCCESS) // needed?
return (error_and_exit(ret, xe)); // needed?
while (ret == SUCCESS)
ret = main_loop(xe);
}
else // merge with else if (argc == 2) ?
{
signal_handler(); // err?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment