summaryrefslogtreecommitdiffstats
path: root/src/p_args.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 19:22:12 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 19:22:12 +0200
commit665fbd28fb608364f2cc251e04fcceedbd774e93 (patch)
tree0d7e185f88007033361de0cf5aaf6772f681be01 /src/p_args.c
parentNormed m_prompt (diff)
download42-minishell-665fbd28fb608364f2cc251e04fcceedbd774e93.tar.gz
42-minishell-665fbd28fb608364f2cc251e04fcceedbd774e93.tar.bz2
42-minishell-665fbd28fb608364f2cc251e04fcceedbd774e93.tar.xz
42-minishell-665fbd28fb608364f2cc251e04fcceedbd774e93.tar.zst
42-minishell-665fbd28fb608364f2cc251e04fcceedbd774e93.zip
In progress
Diffstat (limited to 'src/p_args.c')
-rw-r--r--src/p_args.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/p_args.c b/src/p_args.c
index fc676a1..6431cfc 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -21,8 +21,7 @@
#include "u_parse.h"
#include "u_utils.h"
-static void
- p_meet_bs(char *ptr, t_quote_mode mode)
+static void p_meet_bs(char *ptr, t_quote_mode mode)
{
if (mode != Q_SINGLE)
{
@@ -34,8 +33,7 @@ static void
}
}
-static t_bool
- p_meet_whitespace(char *head, char *ptr, t_quote_mode mode)
+static t_bool p_meet_whitespace(char *head, char *ptr, t_quote_mode mode)
{
if (mode == Q_NONE && u_is_not_escaped(head, ptr) == TRUE)
{
@@ -44,16 +42,18 @@ static t_bool
return (FALSE);
}
-static char
- *p_skip_whitespace(char *ptr)
+static char *p_skip_whitespace(char *ptr)
{
while (*ptr != C_NUL && ft_iswhitespace(*ptr))
ptr++;
return (ptr);
}
-static uint16_t
- p_count_args(const char word[], size_t start[])
+/*
+** TODO: quotes parse error
+*/
+
+static uint16_t p_count_args(const char word[], size_t start[])
{
char *ptr;
t_quote_mode mode;
@@ -72,8 +72,8 @@ static uint16_t
mode = u_meet_dquote(word, ptr, mode);
else if (*ptr == C_SQUOTE)
mode = u_meet_squote(word, ptr, mode);
- if (ft_iswhitespace(*ptr) == TRUE &&
- p_meet_whitespace((char*)word, ptr, mode) == TRUE)
+ if (ft_iswhitespace(*ptr) == TRUE
+ && p_meet_whitespace((char*)word, ptr, mode) == TRUE)
{
ptr = p_skip_whitespace(ptr);
start[count] = (ptr - word);
@@ -84,17 +84,16 @@ static uint16_t
ptr++;
}
return (count);
- /* TODO: quotes parse error */
}
-static char
- **p_split_words(const char word[])
+char **p_split_args(char word[])
{
- char **words;
+ char **words;
size_t start[512];
uint16_t argc;
uint16_t to_del;
+ words = NULL;
argc = p_count_args(word, start);
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
@@ -107,14 +106,3 @@ static char
p_args_escape_chars_and_quotes(words);
return (words);
}
-
-char
- **p_split_args(char word[])
-{
- char **words;
-
- words = NULL;
- if ((words = p_split_words(word)) == NULL)
- return (NULL);
- return (words);
-}