summaryrefslogtreecommitdiffstats
path: root/src/ft_p_lcom.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-25 15:41:44 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-25 15:41:44 +0200
commitf8bb8b120e6d8a207d1e34d139ecbb30653f36d6 (patch)
treefa9827b6f179035328fabfafee1e014ba31195a3 /src/ft_p_lcom.c
parentstrerror is nice actually (diff)
download42-minishell-f8bb8b120e6d8a207d1e34d139ecbb30653f36d6.tar.gz
42-minishell-f8bb8b120e6d8a207d1e34d139ecbb30653f36d6.tar.bz2
42-minishell-f8bb8b120e6d8a207d1e34d139ecbb30653f36d6.tar.xz
42-minishell-f8bb8b120e6d8a207d1e34d139ecbb30653f36d6.tar.zst
42-minishell-f8bb8b120e6d8a207d1e34d139ecbb30653f36d6.zip
Nice redirs
Diffstat (limited to '')
-rw-r--r--src/ft_p_lcom.c28
1 files changed, 27 insertions, 1 deletions
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 <fcntl.h>
#include <unistd.h>
#include <errno.h>
+
+#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);