summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/p_redirs.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c
index 2c9faa3..3f9e866 100644
--- a/src/p_redirs.c
+++ b/src/p_redirs.c
@@ -18,9 +18,45 @@
#include "d_define.h"
#include "s_lredir.h"
#include "s_struct.h"
+#include "u_utils.h"
#include "u_parse.h"
-static int32_t p_get_fd(char word[], char *ptr)
+static void p_append_redir(const char path[],
+ int32_t fd,
+ int8_t redir,
+ t_com *com)
+{
+ struct s_lredir *rdr;
+}
+
+static size_t p_get_path(char path[],
+ char *ptr,
+ const char word[],
+ int8_t redir)
+{
+ size_t pos[2];
+ size_t end;
+
+ pos[0] = 0;
+ pos[1] = 0;
+ redir = (redir < 0) ? (-redir) : (redir);
+ ptr += redir;
+ while (*ptr != C_NUL && ft_iswhitespace(*ptr) == TRUE)
+ ptr++;
+ pos[0] = (ptr - word);
+ while (*ptr != C_NUL &&
+ ft_iswhitespace(*ptr) == FALSE &&
+ u_is_not_escaped(word, ptr) == TRUE)
+ ptr++;
+ pos[1] = (ptr - word);
+ end = pos[1];
+ while (pos[1] - pos[0] > PATH_MAX)
+ end--;
+ ft_strlcpy(path, word + pos[0], end);
+ return (pos[1]);
+}
+
+static int32_t p_get_fd(const char word[], char *ptr)
{
char digit[255];
char *tmp;
@@ -45,12 +81,13 @@ static int32_t p_get_fd(char word[], char *ptr)
static int8_t p_get_redir(char word[], char *ptr, t_com *com)
{
- struct s_lredir *rdr;
- /* char path[PATH_MAX]; */
+ char path[PATH_MAX];
size_t pos[2];
int32_t fd;
int8_t redir;
+ pos[0] = 0;
+ pos[1] = 0;
if ((fd = p_get_fd(word, ptr)) < 0)
fd = 0;
redir = (*ptr == '>') ? (1) : (-1);
@@ -60,10 +97,10 @@ static int8_t p_get_redir(char word[], char *ptr, t_com *com)
pos[0] = (ptr - word);
else
pos[0] = (ptr - word) - ft_intlen(fd);
- /* p_get_path(path, ptr, word); */
- /* ft_printf("fd: %d redir: %hhd path: [%s]\n", fd, redir, path); */
- (void)com;
- (void)rdr;
+ pos[1] = p_get_path(path, ptr, word, redir);
+ (void)ft_memmove(word + pos[0],
+ word + pos[1], (ft_strlen(word + pos[1]) + 1) * sizeof(char));
+ p_append_redir(path, fd, redir, com);
return (0);
}