2023-02-06 14:41:10 -05:00
|
|
|
#include "libftx/libftx.h"
|
|
|
|
#include "minishell.h"
|
2023-02-15 15:31:49 -05:00
|
|
|
#include "utils/utils.h"
|
2023-02-06 14:41:10 -05:00
|
|
|
|
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-15 15:31:49 -05:00
|
|
|
static int ft_pipe_is_alone(const char *str)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
|
|
|
size_t i;
|
2023-02-15 15:31:49 -05:00
|
|
|
int check;
|
2023-02-06 14:41:10 -05:00
|
|
|
|
2023-02-15 15:31:49 -05:00
|
|
|
check = 0;
|
2023-02-06 14:41:10 -05:00
|
|
|
i = 0;
|
|
|
|
while (str[i] != '\0')
|
|
|
|
{
|
2023-02-15 15:31:49 -05:00
|
|
|
if (str[i] != '|')
|
|
|
|
check = 1;
|
|
|
|
else
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
2023-02-15 15:31:49 -05:00
|
|
|
if (check == 0)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
2023-02-15 15:31:49 -05:00
|
|
|
ft_eprintf("minishell: Pipe must be followed and ");
|
|
|
|
ft_eprintf("preced by a command or redirection\n");
|
2023-02-06 14:41:10 -05:00
|
|
|
return (1);
|
|
|
|
}
|
2023-02-15 15:31:49 -05:00
|
|
|
check = 0;
|
2023-02-06 14:41:10 -05:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2023-02-15 15:31:49 -05:00
|
|
|
static int ft_special_char_dub(const char *str)
|
2023-02-09 12:47:05 -05:00
|
|
|
{
|
|
|
|
size_t i;
|
2023-02-15 15:31:49 -05:00
|
|
|
size_t y;
|
2023-02-09 12:47:05 -05:00
|
|
|
|
2023-02-15 15:31:49 -05:00
|
|
|
i = 0;
|
|
|
|
while (str[i] != '\0')
|
2023-02-09 12:47:05 -05:00
|
|
|
{
|
2023-02-16 07:53:49 -05:00
|
|
|
while (ft_is_in_quote(str, i))
|
|
|
|
i++;
|
2023-02-15 15:31:49 -05:00
|
|
|
if (ft_is_in("|<>", str[i]))
|
|
|
|
{
|
|
|
|
y = 0;
|
|
|
|
while (str[i] == str[i + y])
|
|
|
|
y++;
|
|
|
|
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|
|
|
|
|| (y > 1 && str[i] == '|'))
|
|
|
|
{
|
|
|
|
ft_eprintf("minishell: to many %c in a row", str, str[i]);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
i = i + y;
|
|
|
|
}
|
|
|
|
i++;
|
2023-02-09 12:47:05 -05:00
|
|
|
}
|
2023-02-15 15:31:49 -05:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_empty_verif(const char *str)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (str[i] == ' ')
|
|
|
|
i++;
|
|
|
|
if (str[i] == '\0')
|
|
|
|
ft_eprintf("minishell: %s: command not found \n", str);
|
|
|
|
return (str[i] == '\0');
|
2023-02-09 12:47:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int ft_syntatic_verif(const char *str)
|
2023-02-06 14:41:10 -05:00
|
|
|
{
|
2023-02-15 15:31:49 -05:00
|
|
|
return (ft_quote_verif(str)
|
|
|
|
|| ft_pipe_is_alone(str)
|
|
|
|
|| ft_empty_verif(str)
|
|
|
|
|| ft_special_char_dub(str));
|
2023-02-06 14:41:10 -05:00
|
|
|
}
|