summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 20:11:29 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 20:11:29 +0200
commit02debd1b5d39f2a0722fb73e8b4541b5ce986fb7 (patch)
tree14a7367ac49fb19b4b8e3783d35b1c6a1b7266a0 /src
parentNormed p_args_next (diff)
download42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.gz
42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.bz2
42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.xz
42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.zst
42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.zip
Normed p_lblock
Diffstat (limited to '')
-rw-r--r--src/p_lblock.c63
-rw-r--r--src/p_lblock.h8
2 files changed, 46 insertions, 25 deletions
diff --git a/src/p_lblock.c b/src/p_lblock.c
index a9b7144..b0a5c6a 100644
--- a/src/p_lblock.c
+++ b/src/p_lblock.c
@@ -24,43 +24,64 @@
#include "s_lpipes.h"
#include "s_struct.h"
-int8_t p_line_block(const char line[], t_msh *msh)
+static uint8_t p_get_nextif(char *words[], size_t i)
{
- /* TODO: norme */
- uint64_t i;
- t_line_block *link;
- char **words;
- char *ptr;
uint8_t nextif;
- t_bool next;
- i = 0;
nextif = 0;
- if ((words = p_split_line((char*)line)) == NULL)
- return (-1);
+ if (words[i][ft_strlen(words[i]) - 1] == '0')
+ nextif = 0;
+ else if (words[i][ft_strlen(words[i]) - 1] == '1')
+ nextif = 1;
+ else
+ nextif = 2;
+ words[i][ft_strlen(words[i]) - 1] = '\0';
+ return (nextif);
+}
+
+static int8_t p_loop(char *words[], t_msh *msh)
+{
+ t_line_block *link;
+ size_t i;
+ uint8_t nextif;
+
+ i = 0;
while (words[i] != NULL)
{
- if (words[i][ft_strlen(words[i]) - 1] == '0')
- nextif = 0;
- else if (words[i][ft_strlen(words[i]) - 1] == '1')
- nextif = 1;
- else
- nextif = 2;
- words[i][ft_strlen(words[i]) - 1] = '\0';
- next = FALSE;
- if ((ptr = ft_strchr(words[i], '|')) != NULL)
+ nextif = p_get_nextif(words, i);
+ if (ft_strchr(words[i], '|') != NULL)
{
if ((link = s_line_new(NULL, 0)) == NULL)
return (-1);
if ((s_split_pipes(words[i], msh)) == NULL)
return (-1);
- next = TRUE;
+ s_line_add_back(&msh->curr, link);
+ i++;
+ continue ;
}
- if (next == FALSE && (link = s_line_new(words[i], nextif)) == NULL)
+ if ((link = s_line_new(words[i], nextif)) == NULL)
return (-1);
s_line_add_back(&msh->curr, link);
i++;
}
+ return (0);
+}
+
+/*
+** TOOD: ft_strchr('|'): danger /!\ rewrite this shit
+*/
+
+int8_t p_line_block(const char line[], t_msh *msh)
+{
+ char **words;
+
+ if ((words = p_split_line((char*)line)) == NULL)
+ return (-1);
+ if (p_loop(words, msh) != 0)
+ {
+ ft_delwords(words);
+ return (-1);
+ }
ft_delwords(words);
return (0);
}
diff --git a/src/p_lblock.h b/src/p_lblock.h
index b5052f3..88a8b1e 100644
--- a/src/p_lblock.h
+++ b/src/p_lblock.h
@@ -10,12 +10,12 @@
/* */
/* ************************************************************************** */
-#ifndef P_LCOM_H
-#define P_LCOM_H
+#ifndef FT_P_LCOM_H
+# define FT_P_LCOM_H
-#include <stdint.h>
+# include <stdint.h>
-#include "s_struct.h"
+# include "s_struct.h"
int8_t p_line_block(const char line[], t_msh *msh);