summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/p_args.c7
-rw-r--r--src/p_args_next.c38
2 files changed, 43 insertions, 2 deletions
diff --git a/src/p_args.c b/src/p_args.c
index 572b965..953fa17 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -43,6 +43,8 @@ static char
*p_skip_delim(char *ptr, char c)
{
ptr++;
+ if (*ptr == c)
+ return (++ptr);
while (*ptr != C_NULL && *ptr != c)
{
ptr++;
@@ -83,7 +85,9 @@ static uint16_t
else if (*ptr == C_SQUOTE || *ptr == C_DQUOTE)
{
ptr = p_skip_delim(ptr, *ptr);
- if (ft_iswhitespace(*ptr) == FALSE)
+ if (*ptr == C_NULL)
+ return (argc += 1);
+ else if (ft_iswhitespace(*ptr) == FALSE)
return (p_count_args(head, ptr, argc, start));
}
else if (*ptr == C_NULL)
@@ -116,6 +120,7 @@ static char
ptr = (char*)word;
argc = p_count_args(word, ptr, 0, start);
+ ft_printf("%hu\n", argc);
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
words[argc] = NULL;
diff --git a/src/p_args_next.c b/src/p_args_next.c
index 5967963..28410cd 100644
--- a/src/p_args_next.c
+++ b/src/p_args_next.c
@@ -13,15 +13,51 @@
#include <libft.h>
#include <stdint.h>
+#include "d_define.h"
#include "p_args.h"
static size_t
+ p_skip_delim_size(const char word[], char c, size_t end)
+{
+ end++;
+ if (word[end] == c)
+ return (end + 1);
+ while (word[end] != C_NULL && word[end] != c)
+ {
+ end++;
+ if (word[end] == c && c == C_DQUOTE)
+ {
+ if (word[end - 1] == C_BACKSLASH)
+ {
+ if (word[end - 2] != C_BACKSLASH)
+ end++;
+ }
+ }
+ }
+ if (word[end] != C_NULL)
+ {
+ end++;
+ }
+ return (end);
+}
+
+static size_t
p_arg_len(const char word[], const size_t start)
{
size_t end;
- (void)word;
end = start;
+ if (word[start] != C_SQUOTE &&
+ word[start] != C_DQUOTE &&
+ word[start] != C_NULL)
+ {
+ while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE)
+ end++;
+ }
+ else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE)
+ {
+ end = p_skip_delim_size(word, word[end], end);
+ }
return (end);
}