diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-12 20:43:30 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-12 20:43:30 +0200 |
commit | ff116f01c3680d0e5d8c32dd9978ed05a37f800c (patch) | |
tree | 73765e5ac7ea4ec8af461f44f6d8288fdad6fd82 /src/p_lcom.c | |
parent | Lots of stuff to do (diff) | |
download | 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.gz 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.bz2 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.xz 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.zst 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.zip |
FeelsCleanMan
Diffstat (limited to 'src/p_lcom.c')
-rw-r--r-- | src/p_lcom.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/p_lcom.c b/src/p_lcom.c index 2dbd505..339ab17 100644 --- a/src/p_lcom.c +++ b/src/p_lcom.c @@ -19,23 +19,23 @@ #include "d_define.h" #include "f_fail.h" -#include "s_lcom.h" +#include "s_line.h" #include "s_lpipes.h" #include "s_struct.h" static void rdr_err_check(char *ptr, - t_lcom **link) + t_com **com) { - if ((*link)->redir == -1 && ft_ischarset("><", *(ptr + 1))) + if ((*com)->redir == -1 && ft_ischarset("><", *(ptr + 1))) { /* TODO: syntax err */ } - else if ((*link)->redir == 1 && ft_ischarset("<", *(ptr + 1))) + else if ((*com)->redir == 1 && ft_ischarset("<", *(ptr + 1))) { /* TODO: syntax err */ } - else if ((*link)->redir == 2 && ft_ischarset("<>", *(ptr + 1))) + else if ((*com)->redir == 2 && ft_ischarset("<>", *(ptr + 1))) { /* TODO: syntax err */ } @@ -43,17 +43,17 @@ static void static int8_t get_rdrpath(char *ptr, - t_lcom **link) + t_com **com) { char *p_rdrpath; - ptr += ((*link)->redir == 2) ? (2) : (1); - if (!((*link)->rdrpath = + ptr += ((*com)->redir == 2) ? (2) : (1); + if (!((*com)->rdrpath = (char*)malloc((ft_strlen(ptr) + 1) * sizeof(char)))) { return (-1); } - p_rdrpath = (*link)->rdrpath; + p_rdrpath = (*com)->rdrpath; while (*ptr) { if (*ptr != ' ') @@ -69,24 +69,24 @@ static int8_t static void get_rdrfd(const char *ptr, - t_lcom **link) + t_com **com) { while (ft_isdigit(*ptr)) { ptr--; } if (*ptr != ' ') - (*link)->rdrfd = STDOUT_FILENO; + (*com)->rdrfd = STDOUT_FILENO; else { ptr += 1; - (*link)->rdrfd = ft_atoi(ptr); + (*com)->rdrfd = ft_atoi(ptr); } } int8_t get_redir(const char word[], - t_lcom **link) + t_com **com) { /* TODO: norme */ char *ptr; @@ -96,12 +96,12 @@ int8_t { if (*ptr == '<') { - (*link)->redir = -1; + (*com)->redir = -1; break ; } if (*ptr == '>') { - (*link)->redir = (*(ptr + 1) == '>') ? (2) : (1); + (*com)->redir = (*(ptr + 1) == '>') ? (2) : (1); break ; } ptr++; @@ -109,14 +109,14 @@ int8_t /* hint: bash only handles the last one */ /* TODO: handle "msh ~> cat < Makefile >qwe" | gl hf */ } - if ((*link)->redir > 0) + if ((*com)->redir > 0) { if (ft_isdigit(*(ptr - 1))) - get_rdrfd(ptr - 1, link); + get_rdrfd(ptr - 1, com); else - (*link)->rdrfd = STDOUT_FILENO; - rdr_err_check(ptr, link); - if (get_rdrpath(ptr, link) != 0) + (*com)->rdrfd = STDOUT_FILENO; + rdr_err_check(ptr, com); + if (get_rdrpath(ptr, com) != 0) return (-1); } return (0); @@ -129,7 +129,7 @@ int8_t { /* TODO: norme */ uint64_t i; - t_lcom *link; + t_line *link; char **words; t_bool next; @@ -141,15 +141,15 @@ int8_t next = FALSE; if (ft_strchr(words[i], '|')) { - if (!(link = lcom_new(NULL, msh))) + if ((link = s_line_new(NULL, msh)) == NULL) return (-1); - if (!(split_pipes(words[i], link, msh))) + if ((split_pipes(words[i], link, msh)) == NULL) return (-1); next = TRUE; } - if (next == FALSE && !(link = lcom_new(words[i], msh))) + if (next == FALSE && (link = s_line_new(words[i], msh)) == NULL) return (-1); - lcom_add_back(&msh->curr, link); + s_line_add_back(&msh->curr, link); i++; } ft_delwords(words); |