summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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