summaryrefslogtreecommitdiffstats
path: root/src/m_loop_next.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/m_loop_next.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/src/m_loop_next.c b/src/m_loop_next.c
index 1a8d867..22eadba 100644
--- a/src/m_loop_next.c
+++ b/src/m_loop_next.c
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <unistd.h>
+#include "d_define.h"
#include "m_prompt.h"
#include "s_struct.h"
@@ -25,7 +26,7 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
get_next_line(fd, &counter_line);
- if (counter_line[0] != 0)
+ if (counter_line[0] != C_NULL)
{
line = ft_nrealloc(line,
ft_strlen(line) + 1,
@@ -46,7 +47,7 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
get_next_line(fd, &counter_line);
- if (counter_line[0] != 0)
+ if (counter_line[0] != C_NULL)
{
line = ft_nrealloc(line,
ft_strlen(line) + 1,
@@ -59,6 +60,30 @@ static char
return (line);
}
+static char
+ *m_counter_line_quotes(int32_t fd, uint8_t psx, char *line, t_msh *msh)
+{
+ char *counter_line;
+
+ if (fd == STDIN_FILENO)
+ m_prompt_psx(psx, msh);
+ get_next_line(fd, &counter_line);
+ if (counter_line[0] != C_NULL)
+ {
+ line = ft_nrealloc(line,
+ ft_strlen(line) + 1,
+ ft_strlen(line) + ft_strlen(counter_line) + 2);
+ line[ft_strlen(line) + 1] = '\0';
+ line[ft_strlen(line)] = '\n';
+ ft_memcpy(line + ft_strlen(line),
+ counter_line,
+ ft_strlen(counter_line) + 1);
+ }
+ ft_memdel((void*)&counter_line);
+ ft_printf("[%s]\n", line);
+ return (line);
+}
+
char
*m_check_multi_backslash(int32_t fd, char line[], t_msh *msh)
{
@@ -80,7 +105,7 @@ char
pipe += 1;
while (*pipe != '\0')
{
- if (ft_isspace(*pipe) == FALSE)
+ if (ft_iswhitespace(*pipe) == FALSE)
{
return (line);
}
@@ -103,7 +128,7 @@ char
and += 1;
while (*and != '\0')
{
- if (ft_isspace(*and) == FALSE)
+ if (ft_iswhitespace(*and) == FALSE)
{
return (line);
}
@@ -116,3 +141,31 @@ char
}
return (line);
}
+
+char
+ *m_check_multi_quotes(int32_t fd, char line[], t_msh *msh)
+{
+ char *ptr;
+ size_t q[2];
+
+ q[0] = 0;
+ q[1] = 0;
+ ptr = line;
+ while (*ptr != C_NULL)
+ {
+ if (*ptr == C_SQUOTE && *(ptr - 1) != C_BACKSLASH)
+ q[0] += 1;
+ else if (*ptr == C_DQUOTE && *(ptr - 1) != C_BACKSLASH)
+ q[1] += 1;
+ ptr++;
+ }
+ if (q[0] % 2 == 1 || q[1] % 2 == 1)
+ {
+ line = m_counter_line_quotes(fd, 2, line, msh);
+ line = m_check_multi_backslash(fd, line, msh);
+ line = m_check_multi_pipe(fd, line, msh);
+ line = m_check_multi_and(fd, line, msh);
+ line = m_check_multi_quotes(fd, line, msh);
+ }
+ return (line);
+}