summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--src/p_args.c21
-rw-r--r--src/p_args_next.c36
-rw-r--r--src/p_args_next.h20
4 files changed, 76 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index bf8bb0c..94e77ee 100644
--- a/Makefile
+++ b/Makefile
@@ -62,6 +62,7 @@ SRCS_NAME += s_line
SRCS_NAME += s_lvars
SRCS_NAME += s_lpipes
SRCS_NAME += p_args
+SRCS_NAME += p_args_next
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 f14b467..6a15cb8 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include "d_define.h"
+#include "p_args_next.h"
/* ================= */
/* TODO: DELETE THIS */
@@ -86,6 +87,17 @@ static uint16_t
else if (*ptr == C_NULL)
return (argc);
return (p_count_args(ptr, argc + 1));
+ /* TODO: quotes parse error */
+}
+
+static void
+ p_del_alloced_words(char *words[], uint16_t to_del, uint16_t i)
+{
+ while (i > to_del)
+ {
+ ft_memdel((void*)&words[i]);
+ i--;
+ }
}
static char
@@ -94,6 +106,7 @@ static char
char **words;
char *ptr;
uint16_t argc;
+ uint16_t to_del;
ptr = (char*)word;
argc = p_count_args(ptr, 0);
@@ -102,14 +115,18 @@ static char
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
words[argc] = NULL;
+ if ((to_del = p_dup_words(words, word, argc)) != 0)
+ {
+ p_del_alloced_words(words, to_del, argc);
+ return (NULL);
+ }
return (words);
}
-
char
**p_split_args(const char word[], int8_t redir)
{
- char **words;
+ char **words;
words = NULL;
ft_printf("word at start: [%s]\n", word);
diff --git a/src/p_args_next.c b/src/p_args_next.c
new file mode 100644
index 0000000..d371ba0
--- /dev/null
+++ b/src/p_args_next.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_args_next.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>
+
+static char
+ p_give_me_an_arg(const char word[])
+{
+ char str[4096];
+
+ str[0] = '\0';
+ return (str);
+}
+
+uint16_t
+ p_dup_words(char *words[], const char word[], uint16_t i)
+{
+ while (i > 0)
+ {
+ if ((words[i] = ft_strdup(p_give_me_an_arg(word))) == NULL)
+ return (i);
+ i--;
+ }
+ return (0);
+}
+
diff --git a/src/p_args_next.h b/src/p_args_next.h
new file mode 100644
index 0000000..46998b7
--- /dev/null
+++ b/src/p_args_next.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_args_next.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_NEXT_H
+#define P_ARGS_NEXT_H
+
+#include <stdint.h>
+
+uint16_t p_dup_words(char *words[], const char word[], uint16_t i);
+
+#endif