diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/p_redirs.c | 37 | ||||
-rw-r--r-- | src/p_redirs.h | 2 | ||||
-rw-r--r-- | src/s_com.c | 8 |
3 files changed, 29 insertions, 18 deletions
diff --git a/src/p_redirs.c b/src/p_redirs.c index 46d0397..2c9faa3 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -13,32 +13,32 @@ #include <libft.h> #include <stdint.h> #include <stddef.h> +#include <limits.h> #include "d_define.h" #include "s_lredir.h" #include "s_struct.h" #include "u_parse.h" -static int32_t p_get_fd(char word, char *ptr) +static int32_t p_get_fd(char word[], char *ptr) { char digit[255]; char *tmp; + if (*ptr == '<' || (ptr - word) == 1) + return (0); tmp = ptr; + tmp -= 1; + if (ft_isdigit(*tmp) == FALSE) + return (0); while ((tmp - word) > 0 && ft_isdigit(*tmp) == TRUE) tmp--; - if ((tmp - word) != 0 && ft_iswhitespace(*tmp) == FALSE) - { + if ((tmp - word) > 0 && ft_iswhitespace(*tmp) == FALSE) return (0); - } else { - while (tmp != ptr) - { - digit[tmp - word] = *tmp; - tmp++; - } - digit[tmp - word] = C_NUL; + tmp += ((tmp - word) > 0) ? (1) : (0); + ft_strlcpy(digit, word + (tmp - word), (ptr - tmp) + 1); } return (ft_atoi(digit)); } @@ -46,20 +46,29 @@ 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; - const int32_t fd = p_get_fd(word, ptr); + /* char path[PATH_MAX]; */ + size_t pos[2]; + int32_t fd; int8_t redir; + if ((fd = p_get_fd(word, ptr)) < 0) + fd = 0; redir = (*ptr == '>') ? (1) : (-1); redir = (redir == 1 && *(ptr + 1) == '>') ? (2) : (redir); redir = (redir == -1 && *(ptr + 1) == '<') ? (-2) : (redir); + if (fd == 0) + 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; 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; t_quote_mode mode; @@ -73,7 +82,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) != 0) return (1); ptr = word; } diff --git a/src/p_redirs.h b/src/p_redirs.h index d82c2e8..57294e3 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 diff --git a/src/s_com.c b/src/s_com.c index 8c41040..45a6304 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -30,7 +30,6 @@ static int8_t uint64_t i; uint64_t j; - i = 0; if (words[0] != NULL) { if (((*com)->bin = (char*)malloc((ft_strlen(words[0]) + 1) * @@ -40,6 +39,9 @@ static int8_t } else return (0); + i = 0; + while (words[i] != NULL) + i++; if (((*com)->argv = (char**)malloc((i + 1) * sizeof(char*))) == NULL) return (-1); j = 0; @@ -106,11 +108,11 @@ t_com com->bin = NULL; com->rdr = NULL; nword[0] = C_NUL; - ft_printf("BEFORE: [%s]\n", nword); ft_strlcpy(nword, word, ARG_MAX); - ft_printf("AFTER: [%s]\n", nword); + ft_printf("BEFORE: [%s]\n", nword); if (p_redirs(nword, &com) != 0) return (NULL); + ft_printf("AFTER: [%s]\n", nword); if (msh->alias != NULL) { ret = p_subst_alias(nword, TRUE, msh); |