quote fix in syntax

This commit is contained in:
gazhonsepaskwa
2025-02-18 11:38:04 +01:00
parent 588db5280f
commit c7aabe7938
3 changed files with 19 additions and 12 deletions

View File

@@ -27,7 +27,7 @@ int is_redir(t_node *cpy);
int is_basic_word(t_node *cpy);
int syntax_err_mess(char *token_base, int selected);
int check_unclosed(char *c, t_node *node);
int check_unclosed_quote(char *c, t_node *node);
bool check_unclosed_quote(char *c, t_node *node);
int last_tok_redir(t_node *lst);
int last_tok_subsh(t_node *lst);

View File

@@ -59,9 +59,9 @@ int unclosed(t_node *head)
{
if (check_unclosed("()", head) != 0)
return (syntax_err_mess("()", check_unclosed("()", head)));
if (check_unclosed_quote("\"", head) != 0)
if (check_unclosed_quote("\"", head))
return (syntax_err_mess("\"\"", 1));
if (check_unclosed_quote("'", head) != 0)
if (check_unclosed_quote("'", head))
return (syntax_err_mess("'", 1));
return (0);
}

View File

@@ -55,23 +55,30 @@ int check_unclosed(char *c, t_node *node)
return (0);
}
int check_unclosed_quote(char *c, t_node *node)
bool check_unclosed_quote(char *c, t_node *node)
{
t_node *cpy;
int count;
int len;
int i;
bool closed;
bool in_other_quote;
closed = true;
in_other_quote = false;
cpy = node;
count = 0;
while (cpy)
{
len = ft_strlen(cpy->val);
if (len > 0 && cpy->val[0] == c[0])
i = 0;
while(cpy->val[i])
{
if (len == 1 || cpy->val[len - 1] != c[0])
count++;
if ((cpy->val[i] == '"' || cpy->val[i] == '\'') && cpy->val[i] != c[0] && closed)
in_other_quote = !in_other_quote;
if (cpy->val[i] == c[0] && !in_other_quote)
closed = !closed;
i++;
}
cpy = cpy->next;
}
return (count % 2);
if (!closed)
return (true);
return (false);
}