diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-05 15:34:41 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-05 15:34:41 +0200 |
commit | 8895d8b4d33d3c8a0242178b6d78178e055b11c7 (patch) | |
tree | 3bbfb159a4c99ff831028c50a2c9609890ec8f36 /src | |
parent | Rewrite in progress (diff) | |
download | 42-minishell-8895d8b4d33d3c8a0242178b6d78178e055b11c7.tar.gz 42-minishell-8895d8b4d33d3c8a0242178b6d78178e055b11c7.tar.bz2 42-minishell-8895d8b4d33d3c8a0242178b6d78178e055b11c7.tar.xz 42-minishell-8895d8b4d33d3c8a0242178b6d78178e055b11c7.tar.zst 42-minishell-8895d8b4d33d3c8a0242178b6d78178e055b11c7.zip |
Good relining
Diffstat (limited to 'src')
-rw-r--r-- | src/m_loop_next.c | 73 |
1 files changed, 60 insertions, 13 deletions
diff --git a/src/m_loop_next.c b/src/m_loop_next.c index 75c00ac..f1d1f0b 100644 --- a/src/m_loop_next.c +++ b/src/m_loop_next.c @@ -143,28 +143,75 @@ char } static t_bool + m_check_dquote(char **ptr, char line[]) +{ + if (((*ptr - line) == 0) || + ((*ptr - line) == 1 && *(*ptr - 1) == C_BS) || + ((*ptr - line) > 1 && *(*ptr - 1) == C_BS && *(*ptr - 2) != C_BS)) + { + return (FALSE); + } + else + { + return (TRUE); + } +} + +static t_bool + m_find_next_quote(char **ptr, char line[], uint8_t mode) +{ + char c; + + if (mode == M_NO_MODE) + return (FALSE); + c = (mode == M_SQ_MODE) ? (C_SQUOTE) : (C_DQUOTE); + (*ptr) += 1; + while (**ptr != C_NULL) + { + if (**ptr == c && c == C_DQUOTE) + { + if (m_check_dquote(ptr, line) == FALSE) + { + (*ptr)++; + if (**ptr == C_NULL) + break ; + } + else + return (FALSE); + } + else if (**ptr == c && c == C_SQUOTE) + return (FALSE); + (*ptr)++; + } + return (TRUE); +} + +static t_bool m_check_missing_quotes(char line[]) { - char *p; + char *ptr; uint8_t mode; - t_bool ret; - ret = FALSE; - p = line; + ptr = line; mode = M_NO_MODE; - while (*p != C_NULL) + while (*ptr != C_NULL) { - if (*p == C_SQUOTE || *p == C_DQUOTE) + if (*ptr == C_SQUOTE || *ptr == C_DQUOTE) { - if (((p - line) == 0) || - ((p - line) == 1 && *(p - 1) != C_BS) || - ((p - line) > 1 && *(p - 1) == C_BS && - *(p - 2) == C_BS)) - mode = (*p == C_SQUOTE) ? (M_SQ_MODE) : (M_DQ_MODE); + if (((ptr - line) == 0) || + ((ptr - line) >= 1 && *(ptr - 1) != C_BS) || + ((ptr - line) > 1 && *(ptr - 1) == C_BS && *(ptr - 2) == C_BS)) + { + mode = (*ptr == C_SQUOTE) ? (M_SQ_MODE) : (M_DQ_MODE); + if (m_find_next_quote(&ptr, line, mode) == FALSE) + mode = M_NO_MODE; + else + return (TRUE); + } } - p++; + ptr++; } - return (ret); + return (FALSE); } char |