summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-08 19:32:40 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-08 19:32:40 +0200
commitd742075e1af0c063ef9677f157263c0d45253f73 (patch)
tree656be50d447b90308647a253e3ba6ba75a751b13
parentUpdate (diff)
download42-minishell-d742075e1af0c063ef9677f157263c0d45253f73.tar.gz
42-minishell-d742075e1af0c063ef9677f157263c0d45253f73.tar.bz2
42-minishell-d742075e1af0c063ef9677f157263c0d45253f73.tar.xz
42-minishell-d742075e1af0c063ef9677f157263c0d45253f73.tar.zst
42-minishell-d742075e1af0c063ef9677f157263c0d45253f73.zip
Rework in progress
Diffstat (limited to '')
-rw-r--r--Makefile4
-rw-r--r--src/e_externs_pipes.c2
-rw-r--r--src/e_line.c45
-rw-r--r--src/e_pipes.c7
-rw-r--r--src/e_pipes.h2
-rw-r--r--src/m_loop.c23
-rw-r--r--src/p_lblock.c12
-rw-r--r--src/p_lblock.h2
-rw-r--r--src/p_lblock_next.c2
-rw-r--r--src/p_lblock_next.h2
-rw-r--r--src/s_com.c4
-rw-r--r--src/s_line.c50
-rw-r--r--src/s_line.h10
-rw-r--r--src/s_lpipes.c6
-rw-r--r--src/s_lpipes.h2
-rw-r--r--src/s_struct.h6
16 files changed, 88 insertions, 91 deletions
diff --git a/Makefile b/Makefile
index 86d9a1f..af4a263 100644
--- a/Makefile
+++ b/Makefile
@@ -66,8 +66,8 @@ SRCS_NAME += p_args_next
SRCS_NAME += p_args_len
SRCS_NAME += p_args_escape
SRCS_NAME += p_line
-SRCS_NAME += p_lcom
-SRCS_NAME += p_lcom_next
+SRCS_NAME += p_lblock
+SRCS_NAME += p_lblock_next
SRCS_NAME += p_split
SRCS_NAME += u_utils
SRCS_NAME += u_vars
diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c
index f6243e5..e6252e4 100644
--- a/src/e_externs_pipes.c
+++ b/src/e_externs_pipes.c
@@ -58,7 +58,7 @@ static void
bu_id = get_builtin_id(ptr->bin, msh);
ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh);
u_eof_fd(msh->fd);
- s_lpipes_clear(&msh->curr->pipes);
+ s_lpipes_clear(&msh->pipes);
s_line_clear(&msh->curr);
s_destroy(msh);
ft_delwords(fullpath);
diff --git a/src/e_line.c b/src/e_line.c
index f47170f..bb97556 100644
--- a/src/e_line.c
+++ b/src/e_line.c
@@ -22,8 +22,7 @@
#include "s_struct.h"
static uint8_t
- get_builtin_id(const char bin[],
- t_msh *msh)
+ e_get_builtin_id(const char bin[], t_msh *msh)
{
uint8_t i;
@@ -36,44 +35,20 @@ static uint8_t
return (i);
}
-static void
- e_line_destroy(t_line *ptr)
-{
- if (ptr->pipes != NULL)
- {
- s_lpipes_clear(&ptr->pipes);
- }
-}
-
void
e_line(t_msh *msh)
{
- t_line *ptr;
uint8_t bu_id;
- uint8_t previf;
- previf = 0;
- ptr = msh->curr;
- while (ptr != NULL)
+ if (msh->pipes != NULL)
+ e_pipes(msh);
+ else if (msh->com != NULL)
{
- if ((previf == 0) || (previf == 1 && msh->ret == 0) ||
- (previf == 2 && msh->ret != 0))
- {
- if (ptr->pipes != NULL)
- e_pipes(ptr, msh);
- else if (ptr->com != NULL)
- {
- if (ptr->com->bin != NULL &&
- (bu_id = get_builtin_id(ptr->com->bin, msh))
- < FT_BUILTINS_COUNT)
- e_builtin(ptr->com, bu_id, msh);
- else if (ptr->com->bin != NULL)
- e_extern(ptr->com, msh);
- }
- }
- else
- e_line_destroy(ptr);
- previf = ptr->nextif;
- ptr = ptr->next;
+ if (msh->com->bin != NULL &&
+ (bu_id = e_get_builtin_id(msh->com->bin, msh))
+ < FT_BUILTINS_COUNT)
+ e_builtin(msh->com, bu_id, msh);
+ else if (msh->com->bin != NULL)
+ e_extern(msh->com, msh);
}
}
diff --git a/src/e_pipes.c b/src/e_pipes.c
index 6fdc149..a1807d1 100644
--- a/src/e_pipes.c
+++ b/src/e_pipes.c
@@ -35,14 +35,13 @@
/* } */
void
- e_pipes(t_line *ptr,
- t_msh *msh)
+ e_pipes(t_msh *msh)
{
/* uint8_t bu_id; */
/* if ((bu_id = get_builtin_id(ptr->pipes->one->com, msh)) */
/* < FT_BUILTINS_COUNT) */
/* e_builtin(ptr->pipes->one, bu_id, msh); */
- e_externs_pipes(ptr->pipes, msh);
- s_lpipes_clear(&ptr->pipes);
+ e_externs_pipes(msh->pipes, msh);
+ s_lpipes_clear(&msh->pipes);
}
diff --git a/src/e_pipes.h b/src/e_pipes.h
index 5bc073a..2f6c550 100644
--- a/src/e_pipes.h
+++ b/src/e_pipes.h
@@ -15,6 +15,6 @@
#include "s_struct.h"
-void e_pipes(t_line *ptr, t_msh *msh);
+void e_pipes(t_msh *msh);
#endif
diff --git a/src/m_loop.c b/src/m_loop.c
index 9d00f2b..9ecea98 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -22,15 +22,36 @@
#include "m_loop_next.h"
#include "m_prompt.h"
#include "p_line.h"
+#include "s_com.h"
+#include "s_lpipes.h"
#include "s_line.h"
#include "u_vars.h"
static void
m_parse_and_run_line(char line[], t_msh *msh)
{
+ t_line_block *ptr;
+ uint8_t previf;
+
p_line(line, msh);
ft_memdel((void*)&line);
- e_line(msh);
+ previf = 0;
+ ptr = msh->curr;
+ while (ptr != NULL)
+ {
+ ft_printf("[%s]\n", ptr->lblock);
+ if ((previf == 0) || (previf == 1 && msh->ret == 0) ||
+ (previf == 2 && msh->ret != 0))
+ {
+ if ((msh->com = s_com_new(msh->curr->lblock, msh)) == NULL)
+ break ;
+ e_line(msh);
+ }
+ else if (msh->pipes != NULL)
+ s_lpipes_clear(&msh->pipes);
+ previf = ptr->nextif;
+ ptr = ptr->next;
+ }
s_line_clear(&msh->curr);
}
diff --git a/src/p_lblock.c b/src/p_lblock.c
index 5be1c9d..856a546 100644
--- a/src/p_lblock.c
+++ b/src/p_lblock.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* p_lcom.c :+: :+: :+: */
+/* p_lblock.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -125,13 +125,14 @@ int8_t
{
/* TODO: norme */
uint64_t i;
- t_line *link;
+ t_line_block *link;
char **words;
char *ptr;
uint8_t nextif;
t_bool next;
i = 0;
+ nextif = 0;
if ((words = p_split_line(line)) == NULL)
return (-1);
while (words[i] != NULL)
@@ -146,15 +147,14 @@ int8_t
next = FALSE;
if ((ptr = ft_strchr(words[i], '|')) != NULL)
{
- if ((link = s_line_new(NULL, msh)) == NULL)
+ if ((link = s_line_new(NULL, 0)) == NULL)
return (-1);
- if ((s_split_pipes(words[i], link, msh)) == NULL)
+ if ((s_split_pipes(words[i], msh)) == NULL)
return (-1);
next = TRUE;
}
- if (next == FALSE && (link = s_line_new(words[i], msh)) == NULL)
+ if (next == FALSE && (link = s_line_new(words[i], nextif)) == NULL)
return (-1);
- link->nextif = nextif;
s_line_add_back(&msh->curr, link);
i++;
}
diff --git a/src/p_lblock.h b/src/p_lblock.h
index 6d4a023..3979e31 100644
--- a/src/p_lblock.h
+++ b/src/p_lblock.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* p_lcom.h :+: :+: :+: */
+/* p_lblock.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 16d8aac..5777a3c 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* p_line_next.c :+: :+: :+: */
+/* p_lblock_next.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
diff --git a/src/p_lblock_next.h b/src/p_lblock_next.h
index 8fbbb99..5fa9f45 100644
--- a/src/p_lblock_next.h
+++ b/src/p_lblock_next.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* p_line_next.h :+: :+: :+: */
+/* p_lblock_next.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
diff --git a/src/s_com.c b/src/s_com.c
index ac23f35..5bdb36a 100644
--- a/src/s_com.c
+++ b/src/s_com.c
@@ -15,8 +15,8 @@
#include "f_fail.h"
#include "p_args.h"
-#include "p_lcom.h"
-#include "p_lcom_next.h"
+#include "p_lblock.h"
+#include "p_lblock_next.h"
#include "s_struct.h"
static int8_t
diff --git a/src/s_line.c b/src/s_line.c
index ae0ec07..b198fff 100644
--- a/src/s_line.c
+++ b/src/s_line.c
@@ -14,26 +14,30 @@
#include <stdlib.h>
#include <stdint.h>
+#include "d_define.h"
#include "p_line.h"
#include "s_com.h"
#include "s_struct.h"
-t_line
- *s_line_last(t_line *line)
+t_line_block
+ *s_line_last(t_line_block *line)
{
while (line->next != NULL)
+ {
line = line->next;
+ }
return (line);
}
void
- s_line_add_back(t_line **aline,
- t_line *new)
+ s_line_add_back(t_line_block **aline, t_line_block *new)
{
- t_line *tmp;
+ t_line_block *tmp;
- if (!*aline)
+ if (*aline == NULL)
+ {
*aline = new;
+ }
else
{
tmp = s_line_last(*aline);
@@ -42,45 +46,43 @@ void
}
void
- s_line_clear(t_line **line)
+ s_line_clear(t_line_block **line)
{
- t_line *tmp;
- t_line *renext;
+ t_line_block *tmp;
+ t_line_block *renext;
- if (!line)
+ if (line == NULL)
+ {
return ;
+ }
tmp = *line;
while (tmp != NULL)
{
renext = tmp->next;
- if (tmp->com != NULL)
- {
- s_com_destroy(&tmp->com);
- }
ft_memdel((void*)&tmp);
tmp = renext;
}
*line = NULL;
}
-t_line
- *s_line_new(const char word[],
- t_msh *msh)
+t_line_block
+ *s_line_new(const char word[], uint8_t nextif)
{
- t_line *link;
+ t_line_block *link;
- if ((link = (t_line*)malloc(sizeof(t_line))) == NULL)
+ if ((link = (t_line_block*)malloc(sizeof(t_line_block))) == NULL)
return (NULL);
- link->nextif = 0;
- link->com = NULL;
- link->pipes = NULL;
+ link->lblock[0] = C_NUL;
+ link->nextif = nextif;
link->next = NULL;
if (word == NULL)
{
link->next = NULL;
return (link);
}
- if ((link->com = s_com_new(word, msh)) == NULL)
- return (NULL);
+ else
+ {
+ ft_strlcpy(link->lblock, word, 4096);
+ }
return (link);
}
diff --git a/src/s_line.h b/src/s_line.h
index cd2211b..b46643f 100644
--- a/src/s_line.h
+++ b/src/s_line.h
@@ -13,11 +13,13 @@
#ifndef S_LCOM_H
#define S_LCOM_H
+#include <stdint.h>
+
#include "s_struct.h"
-void s_line_add_back(t_line **aline, t_line *new);
-void s_line_clear(t_line **line);
-t_line *s_line_new(const char word[], t_msh *msh);
-t_line *s_line_last(t_line *line);
+void s_line_add_back(t_line_block **aline, t_line_block *new);
+void s_line_clear(t_line_block **line);
+t_line_block *s_line_new(const char word[], uint8_t nextif);
+t_line_block *s_line_last(t_line_block *line);
#endif
diff --git a/src/s_lpipes.c b/src/s_lpipes.c
index f6a6845..0c1a6ea 100644
--- a/src/s_lpipes.c
+++ b/src/s_lpipes.c
@@ -79,9 +79,7 @@ struct s_lpipes
}
struct s_lpipes
- *s_split_pipes(const char word[],
- t_line *line,
- t_msh *msh)
+ *s_split_pipes(const char word[], t_msh *msh)
{
struct s_lpipes *lpipes;
char **words;
@@ -96,7 +94,7 @@ struct s_lpipes
{
return (NULL);
}
- s_lpipes_add_back(&line->pipes, lpipes);
+ s_lpipes_add_back(&msh->pipes, lpipes);
i++;
}
ft_delwords(words);
diff --git a/src/s_lpipes.h b/src/s_lpipes.h
index 5b2795a..e2b3f40 100644
--- a/src/s_lpipes.h
+++ b/src/s_lpipes.h
@@ -20,6 +20,6 @@ void s_lpipes_add_back(struct s_lpipes **alpipes,
struct s_lpipes *new);
void s_lpipes_clear(struct s_lpipes **lpipes);
struct s_lpipes *s_lpipes_new(const char pipedword[], t_msh *msh);
-struct s_lpipes *s_split_pipes(const char word[], t_line *line, t_msh *msh);
+struct s_lpipes *s_split_pipes(const char word[], t_msh *msh);
#endif
diff --git a/src/s_struct.h b/src/s_struct.h
index f98f948..f7ea271 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -57,12 +57,12 @@ struct s_lpipes
** 2: ||
*/
-typedef struct s_line
+typedef struct s_line_block
{
- char line[4096];
+ char lblock[4096];
uint8_t nextif;
struct s_line_block *next;
-} t_line;
+} t_line_block;
typedef struct s_msh
{