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