summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--TODO.org3
-rw-r--r--src/p_redirs.c18
-rw-r--r--src/p_redirs.h2
-rw-r--r--src/s_com.c2
4 files changed, 12 insertions, 13 deletions
diff --git a/TODO.org b/TODO.org
index 2ba9dd8..863b1f8 100644
--- a/TODO.org
+++ b/TODO.org
@@ -16,7 +16,8 @@
** DONE [#A] Don't fuck with '$vars'
** DONE [#A] <>>
CLOSED: [2020-09-26 Sat 18:41]
-** TODO [#A] Subst ~ after >
+** DONE [#A] Subst ~ after >
+ CLOSED: [2020-09-26 Sat 19:43]
** TODO [#A] msh ~> qwewqrqrqwrqwrqr ($? and output vs bash)
** TODO [#A] pipes don't split "qweqwreq | qweqweqe"
** DONE [#A] SEGV on pipes
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;
}
diff --git a/src/p_redirs.h b/src/p_redirs.h
index 57294e3..67e8ab1 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, t_msh *msh);
#endif
diff --git a/src/s_com.c b/src/s_com.c
index 527829d..4f06c84 100644
--- a/src/s_com.c
+++ b/src/s_com.c
@@ -109,7 +109,7 @@ t_com
com->rdr = NULL;
nword[0] = C_NUL;
ft_strlcpy(nword, word, ARG_MAX);
- if (p_redirs(nword, &com) != 0)
+ if (p_redirs(nword, &com, msh) != 0)
return (NULL);
if (msh->alias != NULL)
{