summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--src/p_args.c43
-rw-r--r--src/p_args.h6
-rw-r--r--src/p_args_next.c14
-rw-r--r--src/p_args_next.h1
-rw-r--r--src/p_args_quotes.c44
-rw-r--r--src/p_args_quotes.h18
7 files changed, 103 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 94e77ee..bf199f6 100644
--- a/Makefile
+++ b/Makefile
@@ -63,6 +63,7 @@ SRCS_NAME += s_lvars
SRCS_NAME += s_lpipes
SRCS_NAME += p_args
SRCS_NAME += p_args_next
+SRCS_NAME += p_args_quotes
SRCS_NAME += p_line
SRCS_NAME += p_lcom
SRCS_NAME += p_lcom_next
diff --git a/src/p_args.c b/src/p_args.c
index 953fa17..a0da592 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -17,6 +17,7 @@
#include "d_define.h"
#include "p_args.h"
#include "p_args_next.h"
+#include "p_args_quotes.h"
/* ================= */
/* TODO: DELETE THIS */
@@ -63,6 +64,24 @@ static char
}
static uint16_t
+ p_skip_clean_arg(const char *head,
+ char **ptr,
+ uint16_t argc,
+ size_t start[])
+{
+ while (*(*ptr) != C_NULL && ft_iswhitespace(*(*ptr)) == FALSE)
+ {
+ (*ptr)++;
+ if ((*(*ptr) == C_SQUOTE || *(*ptr) == C_DQUOTE) && *(*(ptr - 1)) != '\\')
+ {
+ (*ptr)++;
+ return (p_count_args(head, *ptr, argc, start));
+ }
+ }
+ return (0);
+}
+
+uint16_t
p_count_args(const char *head, char *ptr, uint16_t argc, size_t start[])
{
if (*ptr == C_NULL)
@@ -72,15 +91,7 @@ static uint16_t
start[argc] = ptr - head;
if (*ptr != C_SQUOTE && *ptr != C_DQUOTE && *ptr != C_NULL)
{
- while (*ptr != C_NULL && ft_iswhitespace(*ptr) == FALSE)
- {
- ptr++;
- if ((*ptr == C_SQUOTE || *ptr == C_DQUOTE) && *(ptr - 1) != '\\')
- {
- ptr++;
- return (p_count_args(head, ptr, argc, start));
- }
- }
+ p_skip_clean_arg(head, &ptr, argc, start);
}
else if (*ptr == C_SQUOTE || *ptr == C_DQUOTE)
{
@@ -96,19 +107,6 @@ static uint16_t
/* TODO: quotes parse error */
}
-static void
- p_del_alloced_words(char *words[], uint16_t to_del)
-{
- uint16_t i;
-
- i = 0;
- while (i < to_del)
- {
- ft_memdel((void*)&words[i]);
- i++;
- }
-}
-
static char
**p_split_words_no_rdr(const char word[])
{
@@ -129,6 +127,7 @@ static char
p_del_alloced_words(words, to_del);
return (NULL);
}
+ p_args_quotes(words);
return (words);
}
diff --git a/src/p_args.h b/src/p_args.h
index 162723d..27f5729 100644
--- a/src/p_args.h
+++ b/src/p_args.h
@@ -15,6 +15,10 @@
#include <stdint.h>
-char **p_split_args(const char word[], int8_t redir);
+uint16_t p_count_args(const char *head,
+ char *ptr,
+ uint16_t argc,
+ size_t start[]);
+char **p_split_args(const char word[], int8_t redir);
#endif
diff --git a/src/p_args_next.c b/src/p_args_next.c
index 28410cd..4d7f979 100644
--- a/src/p_args_next.c
+++ b/src/p_args_next.c
@@ -71,10 +71,22 @@ static char
ft_strlcpy(tmp,
word + start[i],
(p_arg_len(word, start[i]) - start[i]) + 1);
- /* TODO: remove quotes */
return (tmp);
}
+void
+ p_del_alloced_words(char *words[], uint16_t to_del)
+{
+ uint16_t i;
+
+ i = 0;
+ while (i < to_del)
+ {
+ ft_memdel((void*)&words[i]);
+ i++;
+ }
+}
+
uint16_t
p_dup_words(char *words[],
const char word[],
diff --git a/src/p_args_next.h b/src/p_args_next.h
index e918254..365f228 100644
--- a/src/p_args_next.h
+++ b/src/p_args_next.h
@@ -19,5 +19,6 @@ uint16_t p_dup_words(char *words[],
const char word[],
const uint16_t argc,
const size_t start[]);
+void p_del_alloced_words(char *words[], uint16_t to_del);
#endif
diff --git a/src/p_args_quotes.c b/src/p_args_quotes.c
new file mode 100644
index 0000000..2b47b6b
--- /dev/null
+++ b/src/p_args_quotes.c
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_args_quotes.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdint.h>
+
+#include "d_define.h"
+
+static void
+ p_arg_squotes(char word[])
+{
+ ft_memmove(word, word + 1, ft_strlen(word));
+}
+
+static void
+ p_arg_dquotes(char word[])
+{
+ (void)word;
+}
+
+void
+ p_args_quotes(char *words[])
+{
+ char **ptr;
+
+ ptr = words;
+ while (*ptr != NULL)
+ {
+ if (**ptr == C_SQUOTE)
+ p_arg_squotes(*ptr);
+ else if (**ptr == C_DQUOTE)
+ p_arg_dquotes(*ptr);
+ ptr++;
+ }
+}
diff --git a/src/p_args_quotes.h b/src/p_args_quotes.h
new file mode 100644
index 0000000..b902438
--- /dev/null
+++ b/src/p_args_quotes.h
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_args_quotes.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef P_ARGS_QUOTES_H
+#define P_ARGS_QUOTES_H
+
+void p_args_quotes(char *words[]);
+
+#endif