1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-13 16:08:45 +02:00

🔨」 fix: fixed quote unclosed

This commit is contained in:
2024-07-16 16:20:23 +02:00
parent bf60c02fd3
commit e0987139dd
6 changed files with 53 additions and 34 deletions

View File

@ -6,39 +6,36 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */
/* Updated: 2024/07/15 18:16:52 by adjoly ### ########.fr */
/* Updated: 2024/07/16 16:15:41 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "error_msg.h"
#include "tokenizer.h"
#include <stdio.h>
size_t count_quote(char *readline, t_quote type)
bool watch_quote(char *rl)
{
char *tmp;
size_t count;
tmp = readline;
count = 0;
tmp = rl;
while (*tmp)
{
if (*tmp == type)
count += search_for_next_quote(tmp, type) - tmp;
if (__is_quote(*tmp) != FALSE)
{
tmp = search_for_next_quote(tmp + 1, __is_quote(*tmp));
if (!tmp)
return (true);
}
tmp++;
}
return (count);
return (false);
}
bool check_quote(char *readline)
{
size_t count;
count = count_quote(readline, DOUBLE);
if (count % 2)
return (send_error_parsing("double quote not closed"));
count = count_quote(readline, SINGLE);
if (count % 2)
return (send_error_parsing("single quote not closed"));
if (watch_quote(readline))
return (send_error_parsing("quote not closed"));
return (false);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */
/* Updated: 2024/07/06 14:52:02 by adjoly ### ########.fr */
/* Updated: 2024/07/16 15:55:00 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,10 +17,17 @@
char *search_for_next_quote(char *s, t_quote quote_type)
{
char *tmp;
t_quote o_quote;
tmp = s;
while (*tmp && __is_quote(*tmp) != quote_type)
if (quote_type == DOUBLE)
o_quote = SINGLE;
else if (quote_type == SINGLE)
o_quote = DOUBLE;
while (*tmp && __is_quote(*tmp) != quote_type && __is_quote(*tmp) != o_quote)
tmp++;
if (__is_quote(*tmp) != quote_type)
return (NULL);
return (tmp);
}