summaryrefslogtreecommitdiffstats
path: root/src/p_args.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 19:26:46 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-02 19:26:46 +0200
commitd2fba05b0b14ad91f4115790cae82d8627bee2d7 (patch)
treebb0916716627b841ff3c1ed70cc1970b89ce9a9c /src/p_args.c
parentIn progress (diff)
download42-minishell-d2fba05b0b14ad91f4115790cae82d8627bee2d7.tar.gz
42-minishell-d2fba05b0b14ad91f4115790cae82d8627bee2d7.tar.bz2
42-minishell-d2fba05b0b14ad91f4115790cae82d8627bee2d7.tar.xz
42-minishell-d2fba05b0b14ad91f4115790cae82d8627bee2d7.tar.zst
42-minishell-d2fba05b0b14ad91f4115790cae82d8627bee2d7.zip
Normed p_args
Diffstat (limited to 'src/p_args.c')
-rw-r--r--src/p_args.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/p_args.c b/src/p_args.c
index 6431cfc..d005947 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -53,15 +53,14 @@ static char *p_skip_whitespace(char *ptr)
** TODO: quotes parse error
*/
-static uint16_t p_count_args(const char word[], size_t start[])
+static uint16_t p_count_args(const char word[],
+ size_t start[],
+ uint16_t count,
+ t_quote_mode mode)
{
char *ptr;
- t_quote_mode mode;
- uint16_t count;
ptr = (char *)word;
- mode = Q_NONE;
- count = 1;
ptr = p_skip_whitespace(ptr);
start[0] = (ptr - word);
while (*ptr != C_NUL)
@@ -77,8 +76,7 @@ static uint16_t p_count_args(const char word[], size_t start[])
{
ptr = p_skip_whitespace(ptr);
start[count] = (ptr - word);
- if (*ptr != C_NUL)
- count += 1;
+ count += (*ptr != C_NUL) ? (1) : (0);
ptr -= 1;
}
ptr++;
@@ -88,13 +86,13 @@ static uint16_t p_count_args(const char word[], size_t start[])
char **p_split_args(char word[])
{
- char **words;
size_t start[512];
+ char **words;
uint16_t argc;
uint16_t to_del;
words = NULL;
- argc = p_count_args(word, start);
+ argc = p_count_args(word, start, 1, Q_NONE);
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
words[argc] = NULL;