summaryrefslogtreecommitdiffstats
path: root/src/m_argv.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 18:00:23 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 18:00:23 +0200
commit56ccad6b85a5f3f17eebaf4ba511e07ba760b050 (patch)
treeb7073ccf7712baf52ee5c7792130029495249d3f /src/m_argv.c
parentNow deletes comments (diff)
download42-minishell-56ccad6b85a5f3f17eebaf4ba511e07ba760b050.tar.gz
42-minishell-56ccad6b85a5f3f17eebaf4ba511e07ba760b050.tar.bz2
42-minishell-56ccad6b85a5f3f17eebaf4ba511e07ba760b050.tar.xz
42-minishell-56ccad6b85a5f3f17eebaf4ba511e07ba760b050.tar.zst
42-minishell-56ccad6b85a5f3f17eebaf4ba511e07ba760b050.zip
Can read scripts, but need to handle fails
Diffstat (limited to 'src/m_argv.c')
-rw-r--r--src/m_argv.c21
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);
}