diff --git a/includes/parser/tokenizer.h b/includes/parser/tokenizer.h index 67a4ff1..5ab016c 100644 --- a/includes/parser/tokenizer.h +++ b/includes/parser/tokenizer.h @@ -56,12 +56,13 @@ void free_linked_list(t_node *stack); t_token get_token(char *str); t_pres get_pressision(char *s, t_token token, t_token last_token, t_pres last_pres); int create_node_after(t_node *elem, char *val); -char *copy_meta_xor(char *val, int *copied, int rev); int is_meta(char c); int is_sticked(char *val); int trim_nodes(t_node *head); void debug_linked_list(t_node *head, char *msg); int find_quote_node(t_node *head, char q); int syntax_error(t_node *head); +char *copy_meta(char *val, int *copied); +char *copy_unmeta(char *val, int *copied); #endif diff --git a/srcs/parsing/tokenizer/tokenizer.c b/srcs/parsing/tokenizer/tokenizer.c index 1c849bc..a338d1e 100644 --- a/srcs/parsing/tokenizer/tokenizer.c +++ b/srcs/parsing/tokenizer/tokenizer.c @@ -66,9 +66,9 @@ static int unstick_nodes(t_node *head) if (is_sticked(it->val)) { if (is_meta(it->val[0])) - first_str = copy_meta_xor(it->val, &copied, 0); + first_str = copy_meta(it->val, &copied); else - first_str = copy_meta_xor(it->val, &copied, 1); + first_str = copy_unmeta(it->val, &copied); second_str = ft_substr(it->val, copied, ft_strlen(it->val) - copied); ft_free(&it->val); @@ -153,6 +153,9 @@ t_node *tokenize(char *str) if (!head) return (NULL); debug_token_list(head, "tokenize_base"); + if (!trim_nodes(head)) + return (NULL); + debug_token_list(head, "trim_nodes"); if (!unstick_nodes(head)) return (NULL); debug_token_list(head, "unstick_nodes"); @@ -164,7 +167,7 @@ t_node *tokenize(char *str) debug_token_list(head, "trim_nodes"); set_token(head); del_void_nodes(&head); - debug_token_list(head, "del_void_nodes"); + debug_token_list(head, "tokenizer"); if (syntax_error(head)) return (NULL); return (head); diff --git a/srcs/parsing/tokenizer/unstick_node_utils.c b/srcs/parsing/tokenizer/unstick_node_utils.c index a7668c5..ba6c8f6 100644 --- a/srcs/parsing/tokenizer/unstick_node_utils.c +++ b/srcs/parsing/tokenizer/unstick_node_utils.c @@ -12,7 +12,7 @@ #include "../../../includes/minishell.h" -char *copy_meta_xor(char *val, int *copied, int rev) +char *copy_meta(char *val, int *copied) { int i; int j; @@ -21,7 +21,25 @@ char *copy_meta_xor(char *val, int *copied, int rev) i = 0; ref = val[0]; - while ((is_meta(val[i]) && val[i] == ref) ^ rev) + while (val[i] && ((is_meta(val[i]) && val[i] == ref))) + i++; + *copied = i; + out = malloc(i + 1); + j = -1; + while (++j < i) + out[j] = val[j]; + out[i] = 0; + return (out); +} + +char *copy_unmeta(char *val, int *copied) +{ + int i; + int j; + char *out; + + i = 0; + while (val[i] && !is_meta(val[i])) i++; *copied = i; out = malloc(i + 1);