summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--src/p_lcom.c12
-rw-r--r--src/p_split.c34
-rw-r--r--src/p_split.h18
-rw-r--r--src/s_line.c8
-rw-r--r--src/s_struct.h11
6 files changed, 71 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 13b2d47..5d2aa3f 100644
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,7 @@ SRCS_NAME += s_lpipes
SRCS_NAME += p_line
SRCS_NAME += p_lcom
SRCS_NAME += p_lcom_next
+SRCS_NAME += p_split
SRCS_NAME += u_utils
SRCS_NAME += u_vars
SRCS_NAME += u_vars_next
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;