diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-25 17:35:48 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-25 17:35:48 +0200 |
commit | c293dfa39ef25e37d889206cf5bc47d91e330869 (patch) | |
tree | 9f6984e7f45e5e61827c79cf77c097f701bb7749 | |
parent | Stupid bash rule (diff) | |
download | 42-minishell-c293dfa39ef25e37d889206cf5bc47d91e330869.tar.gz 42-minishell-c293dfa39ef25e37d889206cf5bc47d91e330869.tar.bz2 42-minishell-c293dfa39ef25e37d889206cf5bc47d91e330869.tar.xz 42-minishell-c293dfa39ef25e37d889206cf5bc47d91e330869.tar.zst 42-minishell-c293dfa39ef25e37d889206cf5bc47d91e330869.zip |
Now handles -c option
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/ft_d_define.h | 4 | ||||
-rw-r--r-- | src/ft_m_argv.c | 17 | ||||
-rw-r--r-- | src/ft_m_comm.c | 38 | ||||
-rw-r--r-- | src/ft_m_comm.h | 23 | ||||
-rw-r--r-- | src/ft_m_loop.c | 6 | ||||
-rw-r--r-- | src/ft_m_loop.h | 1 |
7 files changed, 78 insertions, 12 deletions
@@ -30,6 +30,7 @@ SRCS_NAME += ft_e_lcom.c SRCS_NAME += ft_f_fail.c SRCS_NAME += ft_f_redir.c SRCS_NAME += ft_m_argv.c +SRCS_NAME += ft_m_comm.c SRCS_NAME += ft_m_funptr.c SRCS_NAME += ft_m_loop.c SRCS_NAME += ft_m_prompt.c diff --git a/src/ft_d_define.h b/src/ft_d_define.h index acb1a29..89e1106 100644 --- a/src/ft_d_define.h +++ b/src/ft_d_define.h @@ -29,8 +29,8 @@ ** ====== OPTIONS ====== */ -#define FT_INTERACT "-i" -#define FT_COMMAND "-c" +#define FT_OPT_INTERACT "-i" +#define FT_OPT_COMMAND "-c" /* ** ====== FAIL MSG ====== diff --git a/src/ft_m_argv.c b/src/ft_m_argv.c index a4da580..389fbe7 100644 --- a/src/ft_m_argv.c +++ b/src/ft_m_argv.c @@ -14,6 +14,7 @@ #include <stdint.h> #include "ft_d_define.h" +#include "ft_m_comm.h" #include "ft_m_loop.h" #include "ft_s_struct.h" @@ -22,19 +23,21 @@ uint8_t const char *argv[], t_msh *msh) { - int32_t i; - - (void)argv; + /* TODO: better argv handling */ if (argc == 1) { msh->ret = ft_m_loop(msh); return (msh->ret); } - i = 1; - while (i < argc) + if (!ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3)) { - /* if (ft_strncmp(*(argv + i), )) */ - i++; + if (*(argv + 2) == NULL) + { + ft_dprintf(2, "%s: %s: option requires an argument", + msh->shname, FT_OPT_COMMAND); + return (2); + } + msh->ret = ft_m_comm(*(argv + 2), msh); } return (msh->ret); } diff --git a/src/ft_m_comm.c b/src/ft_m_comm.c new file mode 100644 index 0000000..5fca253 --- /dev/null +++ b/src/ft_m_comm.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_m_comm.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdint.h> + +#include "ft_d_enum.h" +#include "ft_e_lcom.h" +#include "ft_m_prompt.h" +#include "ft_p_line.h" +#include "ft_s_lcom.h" + +uint8_t + ft_m_comm(const char line[], + t_msh *msh) +{ + if (line[0] != '\0') + { + ft_p_line((char*)line, msh); + ft_e_lcom(msh); + ft_lcom_clear(&msh->curr); + } + else + { + ft_memdel((void*)&line); + } + return (msh->ret); +} + diff --git a/src/ft_m_comm.h b/src/ft_m_comm.h new file mode 100644 index 0000000..5b22f3a --- /dev/null +++ b/src/ft_m_comm.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_m_comm.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_M_COMM_H +#define FT_M_COMM_H + +#include <stdint.h> + +#include "ft_s_struct.h" + +uint8_t ft_m_comm(const char line[], + t_msh *msh); + +#endif diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index d902d93..7f805a2 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -14,9 +14,7 @@ #include <stdint.h> #include <unistd.h> -#include "ft_d_enum.h" #include "ft_e_lcom.h" -#include "ft_m_loop.h" #include "ft_m_prompt.h" #include "ft_p_line.h" #include "ft_s_lcom.h" @@ -38,6 +36,8 @@ uint8_t ft_memdel((void*)&line); ft_e_lcom(msh); ft_lcom_clear(&msh->curr); + /* TODO: segv on ';' terminated lines "msh ~> echo qwe;" */ + /* TODO: (null): Bad address on "msh ~> echo a > asd; cat < asd" but not on "msh ~> echo a > asd; cat asd" */ /* TODO: GNL 25 leak on "msh ~> exit" */ /* TODO: "msh ~> some command \": re GNL into ft_nrealloc */ /* TODO: the chad pipes | */ @@ -48,5 +48,5 @@ uint8_t ft_memdel((void*)&line); } } - return (FT_RET_FINE); + return (msh->ret); } diff --git a/src/ft_m_loop.h b/src/ft_m_loop.h index b7a6b12..4dd1873 100644 --- a/src/ft_m_loop.h +++ b/src/ft_m_loop.h @@ -14,6 +14,7 @@ #define FT_M_LOOP #include <stdint.h> + #include "ft_s_struct.h" uint8_t ft_m_loop(t_msh *msh); |