summaryrefslogtreecommitdiffstats
path: root/src/p_redirs.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-26 19:43:38 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-26 19:43:38 +0200
commitcd0db603de6660c4f9388a5f69e36996788ed625 (patch)
tree91eaa42a7c52635bbeed65e20bade9ab12380b50 /src/p_redirs.c
parentIn progress (diff)
download42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.gz
42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.bz2
42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.xz
42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.zst
42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.zip
Fixed qwe>~/qweqwe
Diffstat (limited to 'src/p_redirs.c')
-rw-r--r--src/p_redirs.c18
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;
}