From f8bb8b120e6d8a207d1e34d139ecbb30653f36d6 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 25 Apr 2020 15:41:44 +0200 Subject: Nice redirs --- src/ft_p_lcom.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/ft_p_lcom.c') diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index 7a19bd6..ee2ec89 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -16,6 +16,8 @@ #include #include #include + +#include "ft_f_fail.h" #include "ft_s_lcom.h" #include "ft_s_struct.h" @@ -29,9 +31,11 @@ static void } else if ((*link)->redir == 1 && ft_ischarset("<", *(ptr + 1))) { + /* TODO: syntax err */ } else if ((*link)->redir == 2 && ft_ischarset("<>", *(ptr + 1))) { + /* TODO: syntax err */ } } @@ -61,10 +65,28 @@ static int8_t return (0); } +static void + ft_get_rdrfd(const char *ptr, + t_lcom **link) +{ + while (ft_isdigit(*ptr)) + { + ptr--; + } + if (*ptr != ' ') + (*link)->rdrfd = STDOUT_FILENO; + else + { + ptr += 1; + (*link)->rdrfd = ft_atoi(ptr); + } +} + int8_t ft_get_redir(const char word[], t_lcom **link) { + /* TODO: norme */ char *ptr; ptr = (char *)word; @@ -84,8 +106,12 @@ int8_t /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */ /* hint: bash only handles the last onke */ } - if ((*link)->redir != 0) + if ((*link)->redir > 0) { + if (ft_isdigit(*(ptr - 1))) + ft_get_rdrfd(ptr - 1, link); + else + (*link)->rdrfd = STDOUT_FILENO; ft_rdr_err_check(ptr, link); if (ft_get_rdrpath(ptr, link) != 0) return (-1); -- cgit v1.2.3