diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-01 18:28:12 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-01 18:28:12 +0200 |
commit | 70e3b4133b89e4e77a67139ccaa37322e2507e49 (patch) | |
tree | f288fbaad300075c16b6a5385d860b142fa59ba9 /src/p_args.c | |
parent | Cool (diff) | |
download | 42-minishell-70e3b4133b89e4e77a67139ccaa37322e2507e49.tar.gz 42-minishell-70e3b4133b89e4e77a67139ccaa37322e2507e49.tar.bz2 42-minishell-70e3b4133b89e4e77a67139ccaa37322e2507e49.tar.xz 42-minishell-70e3b4133b89e4e77a67139ccaa37322e2507e49.tar.zst 42-minishell-70e3b4133b89e4e77a67139ccaa37322e2507e49.zip |
Added quotes multiline
Diffstat (limited to 'src/p_args.c')
-rw-r--r-- | src/p_args.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/src/p_args.c b/src/p_args.c index d8ca029..1cab59d 100644 --- a/src/p_args.c +++ b/src/p_args.c @@ -14,6 +14,8 @@ #include <stdint.h> #include <stdlib.h> +#include "d_define.h" + /* ================= */ /* TODO: DELETE THIS */ /* ================= */ @@ -35,14 +37,80 @@ p_print(char *words[]) /* TODO: DELETE ABOVE */ /* ================== */ +static void + p_skip_delim(char *ptr, char c) +{ + ptr++; + while (*ptr != C_NULL && *ptr != c) + { + ptr++; + if (*ptr == c && *(ptr - 1) == C_BACKSLASH) + ptr++; + } + if (*ptr != C_NULL) + ptr++; +} + +static uint16_t + p_count_args(char *ptr, uint16_t argc) +{ + if (*ptr == C_NULL) + return (argc); + while (*ptr != C_NULL && ft_iswhitespace(*ptr) == TRUE) + ptr++; + if (*ptr != C_SQUOTE && *ptr != C_DQUOTE) + { + while (*ptr != C_NULL && ft_iswhitespace(*ptr) == FALSE) + { + ptr++; + if ((*ptr == C_SQUOTE || *ptr == C_DQUOTE) && + *(ptr - 1) != C_BACKSLASH) + { + ptr++; + return (p_count_args(ptr, argc)); + } + } + } + else if (*ptr == C_SQUOTE) + { + p_skip_delim(ptr, C_SQUOTE); + } + else if (*ptr == C_DQUOTE) + { + p_skip_delim(ptr, C_DQUOTE); + } + return (p_count_args(ptr, argc + 1)); +} + +static char + **p_split_words_no_rdr(const char word[]) +{ + char **words; + char *ptr; + uint16_t argc; + + ptr = (char*)word; + argc = p_count_args(ptr, 0); + ft_printf("%hu\n", argc); + exit(0); + if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL) + return (NULL); + words[argc] = 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); if (redir == 0) { + if ((words = p_split_words_no_rdr(word)) == NULL) + return (NULL); p_print(words); return (words); } |