diff options
Diffstat (limited to '')
-rw-r--r-- | src/m_loop.c | 29 |
1 files changed, 29 insertions, 0 deletions
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); |