summaryrefslogtreecommitdiffstats
path: root/src/m_loop.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-24 18:05:34 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-24 18:05:34 +0200
commitf10e352f8740009d1a93f90160fda7aeabf2a2dc (patch)
treed8c98fdad9cb985d05e63d0999c4c252c233b8c8 /src/m_loop.c
parentTODO update (diff)
download42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.gz
42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.bz2
42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.xz
42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.zst
42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.zip
Counter | and counter \
Diffstat (limited to 'src/m_loop.c')
-rw-r--r--src/m_loop.c79
1 files changed, 8 insertions, 71 deletions
diff --git a/src/m_loop.c b/src/m_loop.c
index 2521204..e174f30 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -16,67 +16,16 @@
#include <unistd.h>
#include "e_line.h"
+#include "m_loop_next.h"
#include "m_prompt.h"
#include "p_line.h"
#include "s_line.h"
-
-static char
- *strjoin_m(char *s1,
- char *s2,
- uint8_t mode)
-{
- size_t i;
- size_t j;
- size_t size1;
- size_t size2;
- char *dst;
-
- i = -1;
- j = -1;
- size1 = ft_strlen(s1);
- size2 = ft_strlen(s2) + 1;
- if (!(dst = (char*)malloc((size1 + size2 + 2) * sizeof(char))))
- return (NULL);
- while (++i < size1)
- dst[i] = s1[i];
- (mode == 0) ? dst[i++] = '\n' : 0;
- while (++j < size2)
- dst[i + j] = s2[j];
- dst[i + j] = '\0';
- (mode == 0) ? ft_memdel((void*)&s1) : ft_memdel((void*)&s2);
- return (dst);
-}
-
-void
- m_loop_cont(t_msh *msh,
- char *line,
- char *quote,
- int8_t gnl)
+static void
+ m_parse_and_run_line(char *line, t_msh *msh)
{
- char *prog;
- char *buf;
- char *fin;
-
- if (!(prog = ft_calloc(ft_strlen(line) + 1, sizeof(char))) ||
- !(buf = ft_strdup(line + (quote - line) + 1)))
- return ;
- ft_memcpy(prog, line, (quote - line));
- while (gnl > 0 && ((!(quote = ft_strrchr(buf, '\"'))) &&
- (!(quote = ft_strrchr(buf, '\'')))))
- {
- m_prompt_psx(2, msh);
- gnl = get_next_line(STDIN_FILENO, &line);
- buf = strjoin_m(buf, line, 0);
- ft_memdel((void*)&line);
- }
- fin = ft_strtrim(buf, "\"'");
- ft_memdel((void*)&buf);
- fin = (ft_strrchr(fin, '\'')) ? ft_strsubst(fin, "\'", "") : fin;
- fin = strjoin_m(prog, fin, 1);
- p_line(fin, msh);
- ft_memdel((void*)&prog);
- ft_memdel((void*)&fin);
+ p_line(line, msh);
+ ft_memdel((void*)&line);
e_line(msh);
s_line_clear(&msh->curr);
}
@@ -85,7 +34,6 @@ uint8_t
m_loop(int32_t fd, t_msh *msh)
{
char *line;
- char *quote;
int8_t gnl;
gnl = 1;
@@ -96,21 +44,10 @@ uint8_t
gnl = get_next_line(fd, &line);
if (line[0] != '\0')
{
- if (!(quote = ft_strchr(line, '\'')) && !(quote = ft_strchr(line, '\"')))
- {
- p_line(line, msh);
- ft_memdel((void*)&line);
- e_line(msh);
- s_line_clear(&msh->curr);
- }
- else
- {
- m_loop_cont(msh, line, quote, 1);
- if (line != NULL)
- ft_memdel((void*)&line);
- }
+ line = m_check_multi_backslash(fd, line, msh);
+ line = m_check_multi_pipe(fd, line, msh);
+ m_parse_and_run_line(line, msh);
/* TODO: (null): Bad address on "msh ~> echo a > asd; cat < asd" but not on "msh ~> echo a > asd; cat asd" */
- /* TODO: GNL 25 leak on "msh ~> exit" | gl hf */
/* TODO: "msh ~> some command \": re GNL into ft_nrealloc */
/* TODO: a histfile would be nice */
}