diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-14 15:24:12 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-14 15:24:12 +0200 |
commit | 294adc19078fa8d196ee1d787ec24619f9976178 (patch) | |
tree | 9446807d7ee909046f1cb9f2bd1c7711bbe0b857 /src | |
parent | Removed bloat (diff) | |
download | 42-minishell-294adc19078fa8d196ee1d787ec24619f9976178.tar.gz 42-minishell-294adc19078fa8d196ee1d787ec24619f9976178.tar.bz2 42-minishell-294adc19078fa8d196ee1d787ec24619f9976178.tar.xz 42-minishell-294adc19078fa8d196ee1d787ec24619f9976178.tar.zst 42-minishell-294adc19078fa8d196ee1d787ec24619f9976178.zip |
I must split
Diffstat (limited to '')
-rw-r--r-- | src/p_lcom.c | 12 | ||||
-rw-r--r-- | src/p_split.c | 34 | ||||
-rw-r--r-- | src/p_split.h | 18 | ||||
-rw-r--r-- | src/s_line.c | 8 | ||||
-rw-r--r-- | src/s_struct.h | 11 |
5 files changed, 70 insertions, 13 deletions
diff --git a/src/p_lcom.c b/src/p_lcom.c index 339ab17..e65dd3e 100644 --- a/src/p_lcom.c +++ b/src/p_lcom.c @@ -19,6 +19,7 @@ #include "d_define.h" #include "f_fail.h" +#include "p_split.h" #include "s_line.h" #include "s_lpipes.h" #include "s_struct.h" @@ -124,22 +125,23 @@ int8_t int8_t p_lcom(const char line[], - const uint64_t count, - t_msh *msh) + const uint64_t count, + t_msh *msh) { /* TODO: norme */ uint64_t i; t_line *link; char **words; + char *ptr; t_bool next; i = 0; - if (!(words = ft_split(line, ';'))) + if ((words = p_split_line(line)) == NULL) return (-1); - while (i <= count && words[i]) + while (i <= count && words[i] != NULL) { next = FALSE; - if (ft_strchr(words[i], '|')) + if ((ptr = ft_strchr(words[i], '|')) != NULL) { if ((link = s_line_new(NULL, msh)) == NULL) return (-1); diff --git a/src/p_split.c b/src/p_split.c new file mode 100644 index 0000000..a53eec9 --- /dev/null +++ b/src/p_split.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> + +static char + **p_split_to_semis(const char line[]) +{ + char **words; + + if ((words = ft_split(line, ';')) == NULL) + return (NULL); + return (words); +} + +char + **p_split_line(const char line[]) +{ + char **words; + + if ((words = p_split_to_semis(line)) == NULL) + return (NULL); + return (words); +} diff --git a/src/p_split.h b/src/p_split.h new file mode 100644 index 0000000..648e01c --- /dev/null +++ b/src/p_split.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_split.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef P_SPLIT_H +#define P_SPLIT_H + +char **p_split_line(const char line[]); + +#endif diff --git a/src/s_line.c b/src/s_line.c index 5fe9a96..b47b453 100644 --- a/src/s_line.c +++ b/src/s_line.c @@ -57,13 +57,6 @@ void { s_com_destroy(&tmp->com); } - /* ft_memdel((void*)&tmp->com); */ - /* if (tmp->argv) */ - /* ft_delwords(tmp->argv); */ - /* if (tmp->redir != 0) */ - /* ft_memdel((void*)&tmp->rdrpath); */ - /* if (tmp->env_fork != NULL) */ - /* ft_delwords(tmp->env_fork); */ ft_memdel((void*)&tmp); tmp = renext; } @@ -78,6 +71,7 @@ t_line if ((link = (t_line*)malloc(sizeof(t_line))) == NULL) return (NULL); + link->nextif = 0; link->com = NULL; link->pipes = NULL; link->next = NULL; diff --git a/src/s_struct.h b/src/s_struct.h index e03bbf2..f5d2a23 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -19,7 +19,7 @@ /* ** redir(int8_t) index -** -------------------- +** ------------------- ** -1: < ** 1: > ** 2: >> @@ -49,8 +49,17 @@ struct s_lpipes struct s_lpipes *next; }; +/* +** nextif(uint8_t) index +** --------------------- +** 0: ; +** 1: && +** 2: || +*/ + typedef struct s_line { + uint8_t nextif; struct s_com *com; struct s_lpipes *pipes; struct s_line *next; |