summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-20 17:43:29 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-20 17:43:29 +0200
commit6f3fe87d2589b8911d6ac0cdce80466f87a85ad3 (patch)
tree2667969809ad70a4fb216ef6563ee9e7d46d3322
parentUnfinished work (diff)
download42-minishell-6f3fe87d2589b8911d6ac0cdce80466f87a85ad3.tar.gz
42-minishell-6f3fe87d2589b8911d6ac0cdce80466f87a85ad3.tar.bz2
42-minishell-6f3fe87d2589b8911d6ac0cdce80466f87a85ad3.tar.xz
42-minishell-6f3fe87d2589b8911d6ac0cdce80466f87a85ad3.tar.zst
42-minishell-6f3fe87d2589b8911d6ac0cdce80466f87a85ad3.zip
in progress
Diffstat (limited to '')
-rw-r--r--src/p_redirs.c36
-rw-r--r--src/p_redirs.h2
2 files changed, 32 insertions, 6 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index 0be5c99..46d0397 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -19,18 +19,45 @@
#include "s_struct.h"
#include "u_parse.h"
-static int8_t p_get_redir(char word[], char *ptr, t_com **com)
+static int32_t p_get_fd(char word, char *ptr)
+{
+ char digit[255];
+ char *tmp;
+
+ tmp = ptr;
+ while ((tmp - word) > 0 && ft_isdigit(*tmp) == TRUE)
+ tmp--;
+ if ((tmp - word) != 0 && ft_iswhitespace(*tmp) == FALSE)
+ {
+ return (0);
+ }
+ else
+ {
+ while (tmp != ptr)
+ {
+ digit[tmp - word] = *tmp;
+ tmp++;
+ }
+ digit[tmp - word] = C_NUL;
+ }
+ return (ft_atoi(digit));
+}
+
+static int8_t p_get_redir(char word[], char *ptr, t_com *com)
{
struct s_lredir *rdr;
+ const int32_t fd = p_get_fd(word, ptr);
+ int8_t redir;
- (void)word;
- (void)ptr;
+ redir = (*ptr == '>') ? (1) : (-1);
+ redir = (redir == 1 && *(ptr + 1) == '>') ? (2) : (redir);
+ redir = (redir == -1 && *(ptr + 1) == '<') ? (-2) : (redir);
(void)com;
(void)rdr;
return (0);
}
-int8_t p_redirs(char word[], t_com **com)
+int8_t p_redirs(char word[], t_com *com)
{
struct s_com *com_ptr;
char *ptr;
@@ -54,4 +81,3 @@ int8_t p_redirs(char word[], t_com **com)
}
return (0);
}
-
diff --git a/src/p_redirs.h b/src/p_redirs.h
index 493c44a..eac5324 100644
--- a/src/p_redirs.h
+++ b/src/p_redirs.h
@@ -17,6 +17,6 @@
#include "s_struct.h"
-int8_t p_redirs(char word[], t_com **com);
+int8_t p_redirs(char word[], t_com *com);
#endif