summaryrefslogtreecommitdiffstats
path: root/src/p_args.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-04 22:02:44 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-04 22:02:44 +0200
commit0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1 (patch)
tree129b3fbce4992e902e87358becf59e9be4be2851 /src/p_args.c
parentNext time (diff)
download42-minishell-0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1.tar.gz
42-minishell-0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1.tar.bz2
42-minishell-0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1.tar.xz
42-minishell-0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1.tar.zst
42-minishell-0e9cfacaf15bb0f4d8a7bd72bae56010d263b2c1.zip
Time to escape chars
Diffstat (limited to 'src/p_args.c')
-rw-r--r--src/p_args.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/p_args.c b/src/p_args.c
index 72182fd..c25fc40 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -63,7 +63,7 @@ static char
return (ptr);
}
-static uint16_t
+static int32_t
p_skip_clean_arg(const char *head,
char **ptr,
uint16_t argc,
@@ -72,11 +72,18 @@ static uint16_t
while (*(*ptr) != C_NULL && ft_iswhitespace(*(*ptr)) == FALSE)
{
(*ptr)++;
- if ((*(*ptr) == C_SQUOTE || *(*ptr) == C_DQUOTE) && *(*(ptr - 1)) != '\\')
+ if ((*(*ptr) == C_SQUOTE || *(*ptr) == C_DQUOTE) &&
+ *(*ptr - 1) != C_BACKSLASH)
{
- (*ptr)++;
+ (*ptr) += 1;
return (p_count_args(head, *ptr, argc, start));
}
+ if (ft_iswhitespace(*(*ptr)) == TRUE && *(*ptr - 1) == C_BACKSLASH &&
+ *(*ptr - 2) != C_BACKSLASH)
+ {
+ (*ptr) += 1;
+ return (-1);
+ }
}
return (0);
}
@@ -84,7 +91,7 @@ static uint16_t
uint16_t
p_count_args(const char *head, char *ptr, uint16_t argc, size_t start[])
{
- static uint16_t preset = 512;
+ static int32_t preset = -1;
if (*ptr == C_NULL)
return (argc);
@@ -95,7 +102,8 @@ uint16_t
preset = argc;
if (*ptr != C_SQUOTE && *ptr != C_DQUOTE && *ptr != C_NULL)
{
- p_skip_clean_arg(head, &ptr, argc, start);
+ if (p_skip_clean_arg(head, &ptr, argc, start) == -1)
+ argc -= 1;
}
else if (*ptr == C_SQUOTE || *ptr == C_DQUOTE)
{
@@ -114,15 +122,15 @@ uint16_t
static char
**p_split_words_no_rdr(const char word[])
{
- char **words;
- char *ptr;
- size_t start[512];
- uint16_t argc;
- uint16_t to_del;
+ char **words;
+ char *ptr;
+ size_t start[512];
+ uint16_t argc;
+ uint16_t to_del;
ptr = (char*)word;
argc = p_count_args(word, ptr, 0, start);
- ft_printf("%hu\n", argc);
+ ft_printf("argc: %hu\n", argc);
if ((words = (char**)malloc((argc + 1) * sizeof(char*))) == NULL)
return (NULL);
words[argc] = NULL;
@@ -131,6 +139,8 @@ static char
p_del_alloced_words(words, to_del);
return (NULL);
}
+ p_print(words);
+ p_escape_chars(words);
p_args_quotes(words);
return (words);
}