diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-15 19:59:41 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-15 19:59:41 +0200 |
commit | ca2e36781039eb7e9901ccde395600e7af87ff4f (patch) | |
tree | 8a9d85433e943fbbd079bc55700e048a54d9bf24 /src/m_loop.c | |
parent | type builtin fix (diff) | |
download | 42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.gz 42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.bz2 42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.xz 42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.tar.zst 42-minishell-ca2e36781039eb7e9901ccde395600e7af87ff4f.zip |
Huge fixes and stack stuff
Diffstat (limited to 'src/m_loop.c')
-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); |