Compare commits

...

3 Commits

Author SHA1 Message Date
Camille Chauvet
41bbe2bc0b fix: quote closed verif 2023-03-30 15:43:57 +02:00
Camille Chauvet
3374d21cad Merge branch 'master' of git.chauvet.pro:starnakin/42_minishell 2023-03-30 15:21:54 +02:00
Camille Chauvet
6f3b1ab918 fix: execve failed 2023-03-30 14:30:13 +02:00
3 changed files with 24 additions and 26 deletions

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */ /* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
/* Updated: 2023/03/29 18:53:35 by cchauvet ### ########.fr */ /* Updated: 2023/03/30 14:03:07 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,7 +58,6 @@ static bool ft_executor(t_cmd *cmd, char **env, int fd)
ft_closer(cmd->fd_in); ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out); ft_closer(cmd->fd_out);
execve(cmd->executable, cmd->args, env); execve(cmd->executable, cmd->args, env);
ft_eprintf("minishell: permission denied: %s\n", cmd->executable);
return (1); return (1);
} }
return (0); return (0);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */ /* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/03/30 12:45:18 by cchauvet ### ########.fr */ /* Updated: 2023/03/30 15:42:13 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -86,7 +86,7 @@ static int ft_empty_verif(const char *str)
size_t i; size_t i;
i = 0; i = 0;
while (str[i] == ' ') while (str[i] == ' ' || str[i] == '\"' || str[i] == '\'')
i++; i++;
return (str[i] == '\0'); return (str[i] == '\0');
} }

View File

@ -3,39 +3,38 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */ /* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */ /* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */ /* Updated: 2023/03/30 15:40:06 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "utils.h" #include "utils.h"
#include <sys/types.h>
int ft_is_in_quote(const char *str, size_t n) int ft_is_in_quote(const char *str, size_t n)
{ {
ssize_t i; size_t i;
ssize_t start;
i = -1; start = -1;
while (str[++i] != '\0' && i < (ssize_t) n) i = 0;
while (str[i] != '\0')
{ {
if (str[i] == '\'') if (i == n)
break ;
if (str[i] == '\"' || str[i] == '\'')
{ {
i++; if (start == -1)
while (str[i] != '\'' && str[i] != '\0') start = i;
{ else if (str[i] == str[start])
if (i == (ssize_t) n) start = -1;
return (1);
i++;
}
}
if (str[i] == '"')
{
while (str[++i] != '"' && str[i] != '\0')
if (i == (ssize_t) n)
return (2);
} }
i++;
} }
return (0); if (start == -1)
return ((str[i] == '\'') + (str[i] == '\"') * 2);
if (str[start] == '\'')
return (1);
return (2);
} }