fix: empty input segfault
This commit is contained in:
parent
99fdd578e9
commit
56eead9241
BIN
.infile.c.swp
BIN
.infile.c.swp
Binary file not shown.
Binary file not shown.
4
cmds.c
4
cmds.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:17:26 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 14:17:26 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/15 17:53:59 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/15 21:21:42 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ t_list **ft_parse_cmds(char *line)
|
|||||||
cmds = malloc(sizeof(t_list *));
|
cmds = malloc(sizeof(t_list *));
|
||||||
outfile = ft_outfile(line);
|
outfile = ft_outfile(line);
|
||||||
infile = ft_infile(line);
|
infile = ft_infile(line);
|
||||||
if (infile == -2)
|
if (infile == -2 || outfile == -2)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (ft_syntatic_verif(line) == 1)
|
if (ft_syntatic_verif(line) == 1)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
4
infile.c
4
infile.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 17:52:10 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 17:52:10 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/15 20:47:19 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/15 21:22:24 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ static int ft_infile_is_valid(const char *line)
|
|||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
if (tab[0] == NULL)
|
||||||
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (tab[i + 1] != NULL)
|
while (tab[i + 1] != NULL)
|
||||||
i++;
|
i++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 18:01:07 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 18:01:07 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/15 20:48:39 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/15 21:22:51 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,6 +24,8 @@ static int ft_outfile_is_valid(const char *line)
|
|||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
if (tab[0] == NULL)
|
||||||
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (tab[i + 1] != NULL)
|
while (tab[i + 1] != NULL)
|
||||||
i++;
|
i++;
|
||||||
|
68
syntatics.c
68
syntatics.c
@ -1,5 +1,6 @@
|
|||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
static int ft_quote_verif(const char *str)
|
static int ft_quote_verif(const char *str)
|
||||||
{
|
{
|
||||||
@ -12,7 +13,33 @@ static int ft_quote_verif(const char *str)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_multipipe(const char *str)
|
static int ft_pipe_is_alone(const char *str)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int check;
|
||||||
|
|
||||||
|
check = 0;
|
||||||
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (str[i] != '|')
|
||||||
|
check = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (check == 0)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: Pipe must be followed and ");
|
||||||
|
ft_eprintf("preced by a command or redirection\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
check = 0;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_special_char_dub(const char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t y;
|
size_t y;
|
||||||
@ -20,39 +47,42 @@ static int ft_multipipe(const char *str)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] != '\0')
|
while (str[i] != '\0')
|
||||||
{
|
{
|
||||||
y = 0;
|
if (ft_is_in_quote(str, i))
|
||||||
while (str[i + y] == '|' && !ft_is_in_quote(str, i))
|
continue ;
|
||||||
|
if (ft_is_in("|<>", str[i]))
|
||||||
{
|
{
|
||||||
if (y > 0)
|
y = 0;
|
||||||
|
while (str[i] == str[i + y])
|
||||||
|
y++;
|
||||||
|
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|
||||||
|
|| (y > 1 && str[i] == '|'))
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: Multiple pipes is not supported\n");
|
ft_eprintf("minishell: to many %c in a row", str, str[i]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
y++;
|
i = i + y;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_pipe_is_alone(const char *str)
|
int ft_empty_verif(const char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
i = ft_strlen(str) - 1;
|
i = 0;
|
||||||
while (str[i] != '|' && i > 0)
|
while (str[i] == ' ')
|
||||||
{
|
i++;
|
||||||
if (str[i] != ' ')
|
if (str[i] == '\0')
|
||||||
return (0);
|
ft_eprintf("minishell: %s: command not found \n", str);
|
||||||
i--;
|
return (str[i] == '\0');
|
||||||
}
|
|
||||||
if (i == 0)
|
|
||||||
return (0);
|
|
||||||
ft_eprintf("minishell: Pipe must be followed by a command or redirection\n");
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_syntatic_verif(const char *str)
|
int ft_syntatic_verif(const char *str)
|
||||||
{
|
{
|
||||||
return (ft_quote_verif(str) || ft_multipipe(str) || ft_pipe_is_alone(str));
|
return (ft_quote_verif(str)
|
||||||
|
|| ft_pipe_is_alone(str)
|
||||||
|
|| ft_empty_verif(str)
|
||||||
|
|| ft_special_char_dub(str));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user