diff options
Diffstat (limited to 'src/m_argv.c')
-rw-r--r-- | src/m_argv.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/m_argv.c b/src/m_argv.c index 6a79bd7..1e23bae 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -12,6 +12,8 @@ #include <libft.h> #include <stdint.h> +#include <fcntl.h> +#include <unistd.h> #include "d_define.h" #include "m_comm.h" @@ -20,16 +22,16 @@ uint8_t m_argv(int argc, - char *const argv[], - t_msh *msh) + char *const argv[], + t_msh *msh) { - /* TODO: better argv handling */ + int32_t fd; + if (argc == 1) { - msh->ret = m_loop(msh); - return (msh->ret); + msh->ret = m_loop(STDIN_FILENO, msh); } - if (!ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3)) + else if (argc > 1 && ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3) == 0) { if (*(argv + 2) == NULL) { @@ -39,5 +41,12 @@ uint8_t } msh->ret = m_comm(*(argv + 2), msh); } + else + { + if ((fd = open(*(argv + 1), O_RDONLY)) < 0) + f_open_file(msh); + msh->ret = m_loop(fd, msh); + close(fd); + } return (msh->ret); } |