diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-22 23:48:09 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-22 23:48:09 +0200 |
commit | 0bb60bc035d22d11c490d243fa7bc0292577c371 (patch) | |
tree | fbde024a63c2262ef37e43a6ef54632c45afb71f /src | |
parent | Implementing redirections (diff) | |
download | 42-minishell-0bb60bc035d22d11c490d243fa7bc0292577c371.tar.gz 42-minishell-0bb60bc035d22d11c490d243fa7bc0292577c371.tar.bz2 42-minishell-0bb60bc035d22d11c490d243fa7bc0292577c371.tar.xz 42-minishell-0bb60bc035d22d11c490d243fa7bc0292577c371.tar.zst 42-minishell-0bb60bc035d22d11c490d243fa7bc0292577c371.zip |
Gathering rdrpath successfully
Diffstat (limited to '')
-rw-r--r-- | src/ft_p_lcom.c | 64 | ||||
-rw-r--r-- | src/ft_p_lcom.h | 2 | ||||
-rw-r--r-- | src/ft_s_lcom.c | 5 |
3 files changed, 63 insertions, 8 deletions
diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index ec30f43..9a4ebad 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -11,36 +11,87 @@ /* ************************************************************************** */ #include <libft.h> +#include <stdlib.h> #include <stdint.h> #include "ft_s_lcom.h" #include "ft_s_struct.h" -void - ft_check_redir_file() +/* void */ +/* ft_check_redir_file() */ +/* { */ +/* } */ + +static void + ft_rdr_err_check(char *ptr, + t_lcom **link) +{ + if ((*link)->redir == -1 && ft_ischarset(">", *(ptr + 1))) + { + /* TODO: syntax err */ + } + else if ((*link)->redir == 1 && ft_ischarset("<", *(ptr + 1))) + { + } + else if ((*link)->redir == 1 && ft_ischarset("<>", *(ptr + 1))) + { + } +} + +static int8_t + ft_get_rdrpath(char *ptr, + t_lcom **link) { + char *p_rdrpath; + + ptr += ((*link)->redir == 2) ? (2) : (1); + if (!((*link)->rdrpath = + (char*)malloc((ft_strlen(ptr) + 1) * sizeof(char)))) + { + return (-1); + } + p_rdrpath = (*link)->rdrpath; + while (*ptr) + { + if (*ptr != ' ') + { + *p_rdrpath = *ptr; + p_rdrpath++; + } + ptr++; + } + *(p_rdrpath) = '\0'; + return (0); } -void +int8_t ft_get_redir(const char word[], t_lcom **link) { char *ptr; - ptr = word; + ptr = (char *)word; while (*ptr) { if (*ptr == '<') { - *link->redir = -1; + (*link)->redir = -1; break ; } if (*ptr == '>') { - *link->redir = (*(ptr + 1) == '>') ? (2) : (1); + (*link)->redir = (*(ptr + 1) == '>') ? (2) : (1); break ; } ptr++; + /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */ } + if ((*link)->redir != 0) + { + ft_rdr_err_check(ptr, link); + if (ft_get_rdrpath(ptr, link) != 0) + return (-1); + } + return (0); } int8_t @@ -62,6 +113,7 @@ int8_t return (-1); } ft_lcom_add_back(&msh->curr, link); + ft_printf("%s\n", msh->curr->rdrpath); i++; } ft_delwords(words); diff --git a/src/ft_p_lcom.h b/src/ft_p_lcom.h index 4cbce6a..f3386e6 100644 --- a/src/ft_p_lcom.h +++ b/src/ft_p_lcom.h @@ -16,7 +16,7 @@ #include <stdint.h> #include "ft_s_struct.h" -void ft_get_redir(const char word[], +int8_t ft_get_redir(const char word[], t_lcom **link); int8_t ft_p_lcom(const char line[], const uint64_t count, diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c index 6661b1e..f469edb 100644 --- a/src/ft_s_lcom.c +++ b/src/ft_s_lcom.c @@ -87,6 +87,8 @@ void ft_memdel((void*)&tmp->com); if (tmp->args) ft_delwords(tmp->args); + if (tmp->redir != 0) + ft_memdel((void*)&tmp->rdrpath); ft_memdel((void*)&tmp); tmp = renext; } @@ -106,7 +108,8 @@ t_lcom link->args = NULL; link->rdrpath = NULL; /* TODO: redirections here */ - ft_get_redir(&link); + if (ft_get_redir(word, &link) != 0) + return (NULL); if (!(words = ft_split(word, ' '))) return (NULL); if (ft_fill_lcom(words, &link) < 0) |