summaryrefslogtreecommitdiffstats
path: root/src/m_loop_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/m_loop_next.c')
-rw-r--r--src/m_loop_next.c73
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