This commit is contained in:
gazhonsepaskwa
2025-02-08 16:23:44 +01:00
parent 2d7667db48
commit e4e994f833
3 changed files with 28 additions and 6 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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);