summaryrefslogtreecommitdiffstats
path: root/src/p_split.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-09 16:17:52 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-09 16:17:52 +0200
commitc68b7637d42fac3986857685980e7a7090f5a5aa (patch)
tree85d78b0a187695a7fab0124ae6c02ae12d223e91 /src/p_split.c
parentIn progress (diff)
download42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.gz
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.bz2
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.xz
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.zst
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.zip
In progress
Diffstat (limited to 'src/p_split.c')
-rw-r--r--src/p_split.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/p_split.c b/src/p_split.c
index 7e2260d..25f1cc7 100644
--- a/src/p_split.c
+++ b/src/p_split.c
@@ -14,7 +14,9 @@
#include <stdlib.h>
#include <limits.h>
+#include "f_fail.h"
#include "d_define.h"
+#include "s_struct.h"
#include "u_parse.h"
#include "u_utils.h"
@@ -156,16 +158,31 @@ typedef struct s_split
} t_split;
static void
- p_meet_splitter(char *ptr, char line[], t_split sp, t_quote_mode mode)
+ p_meet_splitter(char *ptr,
+ const char line[],
+ t_split *sp,
+ t_quote_mode mode)
{
- const char c = *ptr;
-
- if (c == C_SEMIC && *ptr + 1 != C_SEMIC && *ptr + 1 != C_NUL &&
+ if (mode == Q_NONE && *ptr == C_SEMIC && *(ptr + 1) != C_SEMIC &&
u_is_not_escaped(line, ptr) == TRUE)
{
- sp.pos[sp.count] = (ptr - line);
- sp.nextif[sp.count] = 0;
- sp.count += 1;
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 0;
+ sp->count += 1;
+ }
+ else if (mode == Q_NONE && *ptr == C_AMP && *(ptr + 1) == C_AMP &&
+ (*ptr + 2) != C_PIPE && u_is_not_escaped(line, ptr) == TRUE)
+ {
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 1;
+ sp->count += 1;
+ }
+ else if (mode == Q_NONE && *ptr == C_PIPE && *(ptr + 1) == C_PIPE &&
+ *(ptr + 2) != C_PIPE && u_is_not_escaped(line, ptr) == TRUE)
+ {
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 2;
+ sp->count += 1;
}
}
@@ -180,27 +197,28 @@ static t_split
sp.nextif[0] = 0;
sp.count = 0;
mode = Q_NONE;
- ptr = line;
+ ptr = (char*)line;
while (*ptr != C_NUL)
{
if (*ptr == C_SQUOTE)
- mode = u_meet_squote(ptr, line, mode);
+ mode = u_meet_squote(line, ptr, mode);
else if (*ptr == C_DQUOTE)
- mode = u_meet_dquote(ptr, line, mode);
+ mode = u_meet_dquote(line, ptr, mode);
else if (*ptr == C_SEMIC || *ptr == C_AMP || *ptr == C_PIPE)
- p_meet_splitter(ptr, line, sp, mode);
+ p_meet_splitter(ptr, line, &sp, mode);
ptr++;
}
return (sp);
}
char
- **p_split_line(const char line[])
+ **p_split_line(char line[])
{
t_split sp;
char **words;
words = NULL;
sp = p_fill_sp(line);
+ ft_memdel((void*)&line);
return (words);
}