From 3a09e7ae69c3eb1fc3d1f8dfa25f7376ca066e86 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 27 Aug 2020 15:33:35 +0200 Subject: Freed leaks --- src/m_loop.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index e174f30..c25188e 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -36,6 +36,7 @@ uint8_t char *line; int8_t gnl; + msh->fd = fd; gnl = 1; while (gnl > 0) { -- cgit v1.2.3 From 8a1352d62c0dd66ecdd5807e83c16a00fb864635 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 27 Aug 2020 17:47:04 +0200 Subject: Histfile is BAV --- src/m_loop.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index c25188e..a5e2723 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "e_line.h" @@ -20,9 +21,10 @@ #include "m_prompt.h" #include "p_line.h" #include "s_line.h" +#include "u_vars.h" static void - m_parse_and_run_line(char *line, t_msh *msh) + m_parse_and_run_line(char line[], t_msh *msh) { p_line(line, msh); ft_memdel((void*)&line); @@ -30,11 +32,48 @@ static void s_line_clear(&msh->curr); } +void + m_dump_hist(t_msh *msh) +{ + int32_t fd; + char *histfile_path; + + if (ft_strlen(msh->hist) > 0 && + (histfile_path = u_get_var_value("$HISTFILE", msh)) != NULL) + { + if ((fd = open(histfile_path, + O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) + { + write(fd, msh->hist, ft_strlen(msh->hist)); + close(fd); + } + ft_memdel((void*)&histfile_path); + } +} + +static void + m_handle_hist(char line[], t_msh *msh) +{ + static uint16_t hist_i = 0; + + if (hist_i == 0) + msh->hist[0] = '\0'; + ft_strlcpy(msh->hist + ft_strlen(msh->hist), line, 4096); + msh->hist[ft_strlen(msh->hist) + 1] = '\0'; + msh->hist[ft_strlen(msh->hist)] = '\n'; + hist_i += 1; + if (hist_i == 255) + { + m_dump_hist(msh); + hist_i = 0; + } +} + uint8_t m_loop(int32_t fd, t_msh *msh) { - char *line; - int8_t gnl; + char *line; + int8_t gnl; msh->fd = fd; gnl = 1; @@ -47,6 +86,8 @@ uint8_t { line = m_check_multi_backslash(fd, line, msh); line = m_check_multi_pipe(fd, line, msh); + if (fd == STDIN_FILENO) + m_handle_hist(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: "msh ~> some command \": re GNL into ft_nrealloc */ @@ -57,5 +98,7 @@ uint8_t ft_memdel((void*)&line); } } + if (fd == STDIN_FILENO) + m_dump_hist(msh); return (msh->ret); } -- cgit v1.2.3 From 6f4b096ba1cff30c1c33dd887aa70740be7990c7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 28 Aug 2020 14:46:35 +0200 Subject: Multiline added for && --- src/m_loop.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index a5e2723..1faa2cf 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -86,17 +86,14 @@ uint8_t { line = m_check_multi_backslash(fd, line, msh); line = m_check_multi_pipe(fd, line, msh); + line = m_check_multi_and(fd, line, msh); if (fd == STDIN_FILENO) m_handle_hist(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: "msh ~> some command \": re GNL into ft_nrealloc */ - /* TODO: a histfile would be nice */ } else - { ft_memdel((void*)&line); - } } if (fd == STDIN_FILENO) m_dump_hist(msh); -- cgit v1.2.3 From 70e3b4133b89e4e77a67139ccaa37322e2507e49 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 1 Sep 2020 18:28:12 +0200 Subject: Added quotes multiline --- src/m_loop.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 1faa2cf..17668a5 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -87,6 +87,7 @@ uint8_t line = m_check_multi_backslash(fd, line, msh); line = m_check_multi_pipe(fd, line, msh); line = m_check_multi_and(fd, line, msh); + line = m_check_multi_quotes(fd, line, msh); if (fd == STDIN_FILENO) m_handle_hist(line, msh); m_parse_and_run_line(line, msh); -- cgit v1.2.3 From 4543c3ba3222d47780ad3e091cfe6f3098cc2bca Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 6 Sep 2020 21:56:20 +0200 Subject: Stacked --- src/m_loop.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 17668a5..d5a3ceb 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -15,7 +15,9 @@ #include #include #include +#include +#include "d_define.h" #include "e_line.h" #include "m_loop_next.h" #include "m_prompt.h" @@ -36,18 +38,20 @@ void m_dump_hist(t_msh *msh) { int32_t fd; - char *histfile_path; + char histfile[PATH_MAX]; - if (ft_strlen(msh->hist) > 0 && - (histfile_path = u_get_var_value("$HISTFILE", msh)) != NULL) + if (ft_strlen(msh->hist) > 0) { - if ((fd = open(histfile_path, - O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) + u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh); + if (histfile[0] != C_NUL) { - write(fd, msh->hist, ft_strlen(msh->hist)); - close(fd); + if ((fd = open(histfile, + O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) + { + ft_dprintf(fd, "%s", msh->hist); + close(fd); + } } - ft_memdel((void*)&histfile_path); } } -- cgit v1.2.3 From 6805673bff96379c03ba32e681f8fb40aad52adc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 6 Sep 2020 22:12:15 +0200 Subject: Improvement --- src/m_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index d5a3ceb..0a810a0 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -40,7 +40,7 @@ void int32_t fd; char histfile[PATH_MAX]; - if (ft_strlen(msh->hist) > 0) + if (msh->hist[0] != C_NUL && ft_strlen(msh->hist) > 0) { u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh); if (histfile[0] != C_NUL) -- cgit v1.2.3 From d0038f19a7cb23749588b72c9febcf114d9d31e9 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 18:31:51 +0200 Subject: static hist, words fix --- src/m_loop.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 0a810a0..7dc19e0 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -35,12 +35,12 @@ static void } void - m_dump_hist(t_msh *msh) + m_dump_hist(char hist[], t_msh *msh) { - int32_t fd; char histfile[PATH_MAX]; + int32_t fd; - if (msh->hist[0] != C_NUL && ft_strlen(msh->hist) > 0) + if (hist[0] != C_NUL && ft_strlen(hist) > 0) { u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh); if (histfile[0] != C_NUL) @@ -48,7 +48,7 @@ void if ((fd = open(histfile, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) { - ft_dprintf(fd, "%s", msh->hist); + ft_dprintf(fd, "%s", hist); close(fd); } } @@ -56,19 +56,19 @@ void } static void - m_handle_hist(char line[], t_msh *msh) + m_handle_hist(char hist[], char line[], t_msh *msh) { static uint16_t hist_i = 0; if (hist_i == 0) - msh->hist[0] = '\0'; - ft_strlcpy(msh->hist + ft_strlen(msh->hist), line, 4096); - msh->hist[ft_strlen(msh->hist) + 1] = '\0'; - msh->hist[ft_strlen(msh->hist)] = '\n'; + hist[0] = '\0'; + ft_strlcpy(hist + ft_strlen(hist), line, 4096); + hist[ft_strlen(hist) + 1] = '\0'; + hist[ft_strlen(hist)] = '\n'; hist_i += 1; - if (hist_i == 255) + if (hist_i == 254) { - m_dump_hist(msh); + m_dump_hist(hist, msh); hist_i = 0; } } @@ -76,8 +76,9 @@ static void uint8_t m_loop(int32_t fd, t_msh *msh) { - char *line; - int8_t gnl; + static char hist[255 * 4096]; + char *line; + int8_t gnl; msh->fd = fd; gnl = 1; @@ -93,7 +94,7 @@ uint8_t line = m_check_multi_and(fd, line, msh); line = m_check_multi_quotes(fd, line, msh); if (fd == STDIN_FILENO) - m_handle_hist(line, msh); + m_handle_hist(hist, 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" */ } @@ -101,6 +102,6 @@ uint8_t ft_memdel((void*)&line); } if (fd == STDIN_FILENO) - m_dump_hist(msh); + m_dump_hist(hist, msh); return (msh->ret); } -- cgit v1.2.3 From 4dd10e6f4de22446ea84d7b194d2a18cb6e43c6c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 18:50:11 +0200 Subject: Names --- src/m_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 7dc19e0..9d00f2b 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -87,7 +87,7 @@ uint8_t if (fd == STDIN_FILENO) m_prompt_psx(1, msh); gnl = get_next_line(fd, &line); - if (line[0] != '\0') + if (line[0] != C_NUL) { line = m_check_multi_backslash(fd, line, msh); line = m_check_multi_pipe(fd, line, msh); -- cgit v1.2.3 From d742075e1af0c063ef9677f157263c0d45253f73 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 19:32:40 +0200 Subject: Rework in progress --- src/m_loop.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/m_loop.c') 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); } -- cgit v1.2.3 From 332a55e859e8b213a9680b06022e4812d190951f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 19:37:19 +0200 Subject: Pretty bav --- src/m_loop.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 9ecea98..b3c06d0 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -39,11 +39,10 @@ static void 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) + if ((msh->com = s_com_new(ptr->lblock, msh)) == NULL) break ; e_line(msh); } -- cgit v1.2.3 From c68b7637d42fac3986857685980e7a7090f5a5aa Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 9 Sep 2020 16:17:52 +0200 Subject: In progress --- src/m_loop.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index b3c06d0..5641686 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -34,7 +34,6 @@ static void uint8_t previf; p_line(line, msh); - ft_memdel((void*)&line); previf = 0; ptr = msh->curr; while (ptr != NULL) -- cgit v1.2.3 From 42aa32df3f63d4dd1213b0683ab7110d788defef Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 9 Sep 2020 18:29:25 +0200 Subject: The more memory the better LOL --- src/m_loop.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 5641686..50357eb 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -44,6 +44,7 @@ static void if ((msh->com = s_com_new(ptr->lblock, msh)) == NULL) break ; e_line(msh); + s_com_destroy(&msh->com); } else if (msh->pipes != NULL) s_lpipes_clear(&msh->pipes); -- cgit v1.2.3 From cf39c418a49808eb63cf4e1b5e2e363455f2da84 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 17:58:05 +0200 Subject: alias utils prepared --- src/m_loop.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 50357eb..bd4fb1c 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -26,6 +26,7 @@ #include "s_lpipes.h" #include "s_line.h" #include "u_vars.h" +#include "u_alias.h" static void m_parse_and_run_line(char line[], t_msh *msh) -- cgit v1.2.3 From 32fb33b2dea95c00dc37efd14d34c799b23d09cf Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 18:07:48 +0200 Subject: In progress --- src/m_loop.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index bd4fb1c..50357eb 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -26,7 +26,6 @@ #include "s_lpipes.h" #include "s_line.h" #include "u_vars.h" -#include "u_alias.h" static void m_parse_and_run_line(char line[], t_msh *msh) -- cgit v1.2.3 From ca2e36781039eb7e9901ccde395600e7af87ff4f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 15 Sep 2020 19:59:41 +0200 Subject: Huge fixes and stack stuff --- src/m_loop.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/m_loop.c') diff --git a/src/m_loop.c b/src/m_loop.c index 50357eb..41c9e36 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -25,6 +25,8 @@ #include "s_com.h" #include "s_lpipes.h" #include "s_line.h" +#include "u_utils.h" +#include "u_parse.h" #include "u_vars.h" static void @@ -93,6 +95,32 @@ static void } } +static void m_delete_comments(char line[]) +{ + char *ptr; + t_quote_mode mode; + + ptr = line; + mode = Q_NONE; + while (*ptr != C_NUL) + { + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(line, ptr, mode); + else if (*ptr == C_SQUOTE) + mode = u_meet_squote(line, ptr, mode); + else if (mode == Q_NONE && *ptr == C_SHARP + && u_is_not_escaped(line, ptr) == TRUE) + { + if (ptr - line == 0) + *ptr = C_NUL; + else if (ptr - line > 0 && ft_iswhitespace(*(ptr - 1)) == TRUE + && u_is_not_escaped(line, ptr - 1) == TRUE) + *ptr = C_NUL; + } + ptr++; + } +} + uint8_t m_loop(int32_t fd, t_msh *msh) { @@ -107,6 +135,7 @@ uint8_t if (fd == STDIN_FILENO) m_prompt_psx(1, msh); gnl = get_next_line(fd, &line); + m_delete_comments(line); if (line[0] != C_NUL) { line = m_check_multi_backslash(fd, line, msh); -- cgit v1.2.3