summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 16:26:01 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-22 16:26:01 +0200
commit37040d7917928f5666717dc9b238a3246d470fbe (patch)
tree32f66d443db46959cc77aba5897b29a84377351d
parentWork to do (diff)
download42-minishell-37040d7917928f5666717dc9b238a3246d470fbe.tar.gz
42-minishell-37040d7917928f5666717dc9b238a3246d470fbe.tar.bz2
42-minishell-37040d7917928f5666717dc9b238a3246d470fbe.tar.xz
42-minishell-37040d7917928f5666717dc9b238a3246d470fbe.tar.zst
42-minishell-37040d7917928f5666717dc9b238a3246d470fbe.zip
Fix
-rw-r--r--src/m_loop.c19
-rw-r--r--src/p_lblock.c12
-rw-r--r--src/p_lblock.h2
3 files changed, 14 insertions, 19 deletions
diff --git a/src/m_loop.c b/src/m_loop.c
index b111577..718b23e 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -25,6 +25,7 @@
#include "e_line.h"
#include "m_loop_multis.h"
#include "m_prompt.h"
+#include "p_lblock.h"
#include "p_line.h"
#include "s_com.h"
#include "s_lpipes.h"
@@ -33,26 +34,28 @@
#include "u_parse.h"
#include "u_vars.h"
-static void m_parse_and_run_line(char line[], t_msh *msh)
+static void m_parse_and_run_line(char line[], uint8_t previf, t_msh *msh)
{
t_line_block *ptr;
- uint8_t previf;
p_line(line, msh);
- previf = 0;
ptr = msh->curr;
while (ptr != NULL)
{
if ((previf == 0) || (previf == 1 && msh->ret == 0)
|| (previf == 2 && msh->ret != 0))
{
- if ((msh->com = s_com_new(ptr->lblock, msh)) == NULL)
+ if (p_find_good_pipe(ptr->lblock) == TRUE
+ && (s_split_pipes(ptr->lblock, msh)) == NULL)
+ break ;
+ else if ((msh->com = s_com_new(ptr->lblock, msh)) == NULL)
break ;
e_line(msh);
- s_com_destroy(&msh->com);
+ if (msh->com != NULL)
+ s_com_destroy(&msh->com);
+ if (msh->pipes != NULL)
+ s_lpipes_clear(&msh->pipes);
}
- else if (msh->pipes != NULL)
- s_lpipes_clear(&msh->pipes);
previf = ptr->nextif;
ptr = ptr->next;
}
@@ -141,7 +144,7 @@ uint8_t m_loop(int32_t fd, t_msh *msh)
line = m_check_multis(fd, line, msh);
if (fd == STDIN_FILENO)
m_handle_hist(hist, line, msh);
- m_parse_and_run_line(line, msh);
+ m_parse_and_run_line(line, 0, msh);
}
else
ft_memdel((void*)&line);
diff --git a/src/p_lblock.c b/src/p_lblock.c
index 36f2e12..82d1b44 100644
--- a/src/p_lblock.c
+++ b/src/p_lblock.c
@@ -42,7 +42,7 @@ static uint8_t p_get_nextif(char *words[], size_t i)
return (nextif);
}
-static t_bool p_find_good_pipe(const char word[])
+t_bool p_find_good_pipe(const char word[])
{
char *ptr;
t_quote_mode mode;
@@ -76,16 +76,6 @@ static int8_t p_loop(char *words[], t_msh *msh)
while (words[i] != NULL)
{
nextif = p_get_nextif(words, i);
- if (p_find_good_pipe(words[i]) == TRUE)
- {
- if ((link = s_line_new(NULL, 0)) == NULL)
- return (-1);
- s_line_add_back(&msh->curr, link);
- if ((s_split_pipes(words[i], msh)) == NULL)
- return (-1);
- i++;
- continue ;
- }
if ((link = s_line_new(words[i], nextif)) == NULL)
return (-1);
s_line_add_back(&msh->curr, link);
diff --git a/src/p_lblock.h b/src/p_lblock.h
index 2f6ba37..9f92beb 100644
--- a/src/p_lblock.h
+++ b/src/p_lblock.h
@@ -13,10 +13,12 @@
#ifndef P_LBLOCK_H
# define P_LBLOCK_H
+# include <libft.h>
# include <stdint.h>
# include "s_struct.h"
+t_bool p_find_good_pipe(const char word[]);
int8_t p_line_block(const char line[], t_msh *msh);
#endif