2023-02-06 14:41:10 -05:00
|
|
|
#include "libftx/libftx.h"
|
|
|
|
#include "minishell.h"
|
|
|
|
|
2023-02-09 12:47:05 -05:00
|
|
|
static int ft_quote_verif(const char *str)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
|
|
|
if (ft_is_in_quote(str, ft_strlen(str)))
|
|
|
|
{
|
|
|
|
ft_eprintf("minishell: Quote is note closed");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2023-02-09 12:47:05 -05:00
|
|
|
static int ft_multipipe(const char *str)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t y;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (str[i] != '\0')
|
|
|
|
{
|
|
|
|
y = 0;
|
2023-02-09 12:47:05 -05:00
|
|
|
while (str[i + y] == '|' && !ft_is_in_quote(str, i))
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
2023-02-09 12:47:05 -05:00
|
|
|
if (y > 0)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
|
|
|
ft_eprintf("minishell: Multiple pipes is not supported\n");
|
|
|
|
return (1);
|
|
|
|
}
|
2023-02-09 12:47:05 -05:00
|
|
|
y++;
|
2023-02-06 14:41:10 -05:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2023-02-09 12:47:05 -05:00
|
|
|
static int ft_pipe_is_alone(const char *str)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
i = ft_strlen(str) - 1;
|
|
|
|
while (str[i] != '|' && i > 0)
|
|
|
|
{
|
|
|
|
if (str[i] != ' ')
|
|
|
|
return (0);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
ft_eprintf("minishell: Pipe must be followed by a command or redirection\n");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_syntatic_verif(const char *str)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
2023-02-09 12:47:05 -05:00
|
|
|
return (ft_quote_verif(str) || ft_multipipe(str) || ft_pipe_is_alone(str));
|
2023-02-06 14:41:10 -05:00
|
|
|
}
|