diff options
Diffstat (limited to 'src/p_redirs.c')
-rw-r--r-- | src/p_redirs.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c index d83ebfd..581ac48 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -43,7 +43,7 @@ static void p_append_redir(const char path[], static size_t p_get_path(char path[], char *ptr, const char word[], - int8_t redir) + t_msh *msh) { char home[PATH_MAX]; size_t pos[2]; @@ -51,8 +51,8 @@ static size_t p_get_path(char path[], size_t len; hlen = 0; - redir = (redir < 0) ? (-redir) : (redir); - ptr += redir; + while (ft_ischarset("<>", *ptr) == TRUE) + ptr++; while (*ptr != C_NUL && ft_iswhitespace(*ptr) == TRUE) ptr++; if (*ptr == C_TILDE && u_get_var_value(home, "$HOME", PATH_MAX, msh) == 0) @@ -62,15 +62,13 @@ static size_t p_get_path(char path[], ptr++; } pos[0] = (ptr - word); - while (*ptr != C_NUL && - ft_iswhitespace(*ptr) == FALSE && + while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE && u_is_not_escaped(word, ptr) == TRUE) ptr++; pos[1] = (ptr - word); len = (pos[1] - pos[0]); len = ((hlen + len + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len); ft_strlcpy(path + hlen, word + pos[0], len + 1); - ft_printf("%s\n", path); return (pos[1]); } @@ -97,7 +95,7 @@ static int32_t p_get_fd(const char word[], char *ptr) return (ft_atoi(digit)); } -static int8_t p_get_redir(char word[], char *ptr, t_com *com) +static int8_t p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh) { char path[PATH_MAX]; size_t pos[2]; @@ -115,14 +113,14 @@ 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); - pos[1] = p_get_path(path, ptr, word, redir); + pos[1] = p_get_path(path, ptr, word, msh); (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); } -int8_t p_redirs(char word[], t_com **com) +int8_t p_redirs(char word[], t_com **com, t_msh *msh) { char *ptr; t_quote_mode mode; @@ -137,7 +135,7 @@ int8_t p_redirs(char word[], t_com **com) mode = u_meet_squote(word, ptr, mode); else if (mode == Q_NONE && (*ptr == '<' || *ptr == '>') == 1) { - if (p_get_redir(word, ptr, *com) != 0) + if (p_get_redir(word, ptr, *com, msh) != 0) return (1); ptr = word; } |