summaryrefslogtreecommitdiffstats
path: root/src/m_loop_next.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-05 14:48:49 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-05 14:48:49 +0200
commit3976118a6e9acd035d20ef79d92632ecb962814e (patch)
treefdcf1e85b2e4c492c9955299f6e0a2e24d5272c8 /src/m_loop_next.c
parentThis is all wrong (diff)
download42-minishell-3976118a6e9acd035d20ef79d92632ecb962814e.tar.gz
42-minishell-3976118a6e9acd035d20ef79d92632ecb962814e.tar.bz2
42-minishell-3976118a6e9acd035d20ef79d92632ecb962814e.tar.xz
42-minishell-3976118a6e9acd035d20ef79d92632ecb962814e.tar.zst
42-minishell-3976118a6e9acd035d20ef79d92632ecb962814e.zip
Rewrite in progress
Diffstat (limited to '')
-rw-r--r--src/m_loop_next.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/m_loop_next.c b/src/m_loop_next.c
index 1163a49..75c00ac 100644
--- a/src/m_loop_next.c
+++ b/src/m_loop_next.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include "d_define.h"
+#include "m_loop_next.h"
#include "m_prompt.h"
#include "s_struct.h"
@@ -141,38 +142,39 @@ char
return (line);
}
-static void
- m_set_q_arr(size_t q[], char line[])
+static t_bool
+ m_check_missing_quotes(char line[])
{
- char *ptr;
-
- q[0] = 0;
- q[1] = 0;
- ptr = line;
- while (*ptr != C_NULL)
+ char *p;
+ uint8_t mode;
+ t_bool ret;
+
+ ret = FALSE;
+ p = line;
+ mode = M_NO_MODE;
+ while (*p != C_NULL)
{
- if (*ptr == C_SQUOTE)
- {
- q[0] += 1;
- }
- else if (*ptr == C_DQUOTE)
+ if (*p == C_SQUOTE || *p == C_DQUOTE)
{
- if (*(ptr - 1) != C_BACKSLASH)
- q[1] += 1;
- else if (*(ptr - 2) == C_BACKSLASH)
- q[1] += 1;
+ 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);
}
- ptr++;
+ p++;
}
+ return (ret);
}
char
*m_check_multi_quotes(int32_t fd, char line[], t_msh *msh)
{
- size_t q[2];
+ t_bool reparse;
- m_set_q_arr(q, line);
- if (q[0] % 2 == 1 || q[1] % 2 == 1)
+ reparse = FALSE;
+ reparse = m_check_missing_quotes(line);
+ if (reparse == TRUE)
{
line = m_counter_line_quotes(fd, 2, line, msh);
line = m_check_multi_backslash(fd, line, msh);