summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/p_args.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/p_args.c b/src/p_args.c
index f3e7403..ee2b937 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -93,6 +93,14 @@ static t_bool
return (FALSE);
}
+static char
+ *p_skip_whitespace(char *ptr)
+{
+ while (*ptr != C_NULL && ft_iswhitespace(*ptr))
+ ptr++;
+ return (ptr);
+}
+
static uint16_t
p_count_args(const char word[], size_t start[])
{
@@ -100,10 +108,11 @@ static uint16_t
t_quote_mode mode;
uint16_t count;
- (void)start;
ptr = (char *)word;
mode = Q_NONE;
- count = 0;
+ count = 1;
+ ptr = p_skip_whitespace(ptr);
+ start[0] = (ptr - word);
while (*ptr != C_NULL)
{
if (*ptr == C_DQUOTE)
@@ -114,10 +123,9 @@ static uint16_t
p_meet_whitespace((char*)word, ptr, mode) == TRUE)
{
count += 1;
- while (*ptr != C_NULL && ft_iswhitespace(*ptr))
- ptr++;
+ ptr = p_skip_whitespace(ptr);
+ start[count - 1] = (ptr - word);
ptr -= 1;
- ft_printf("[%s]\n", ptr);
}
ptr++;
}
@@ -135,7 +143,6 @@ static char
argc = p_count_args(word, start);
ft_printf("argc: %hu\n", argc);
- exit(0);
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
words[argc] = NULL;