clean: norm part2 (FINAL)
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/27 14:14:17 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 18:51:58 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,6 +25,12 @@ void ft_closer(int fds[2])
|
||||
}
|
||||
}
|
||||
|
||||
void ft_mega_closer(int fds1[2], int fds2[2])
|
||||
{
|
||||
ft_closer(fds1);
|
||||
ft_closer(fds2);
|
||||
}
|
||||
|
||||
void ft_add_fd(int fds[2], int fd)
|
||||
{
|
||||
if (fds[0] == -1)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/27 13:39:50 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/28 16:34:37 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -59,6 +59,23 @@ static char **ft_get_paths(t_data *data, const char *name)
|
||||
return (tab);
|
||||
}
|
||||
|
||||
static char *ft_file_is_executable(const char *path, const char *name)
|
||||
{
|
||||
char *out;
|
||||
|
||||
out = ft_strmerger(3, path, "/", name);
|
||||
if (out == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
free(out);
|
||||
return (NULL);
|
||||
}
|
||||
if (access(out, X_OK) == 0)
|
||||
return (out);
|
||||
free(out);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
{
|
||||
char **paths;
|
||||
@ -72,16 +89,9 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
i = 0;
|
||||
while (paths[i] != NULL)
|
||||
{
|
||||
path = ft_strmerger(3, paths[i], "/", name);
|
||||
if (path == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
path = ft_file_is_executable(paths[i], name);
|
||||
if (path != NULL)
|
||||
break ;
|
||||
}
|
||||
if (access(path, X_OK) == 0)
|
||||
break ;
|
||||
free(path);
|
||||
path = NULL;
|
||||
i++;
|
||||
}
|
||||
ft_freer_tab_ultimate(1, paths);
|
||||
|
@ -6,12 +6,20 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static void ft_remove_quote_and_reset(char *str, ssize_t *start, ssize_t *stop)
|
||||
{
|
||||
ft_strshift(str + *start, -1);
|
||||
ft_strshift(str + *stop - 1, -1);
|
||||
*start = -1;
|
||||
*stop = -1;
|
||||
}
|
||||
|
||||
char *ft_quote_remover(char *str)
|
||||
{
|
||||
size_t i;
|
||||
@ -32,10 +40,7 @@ char *ft_quote_remover(char *str)
|
||||
}
|
||||
if (stop != -1)
|
||||
{
|
||||
ft_strshift(str + start, -1);
|
||||
ft_strshift(str + stop - 1, -1);
|
||||
start = -1;
|
||||
stop = -1;
|
||||
ft_remove_quote_and_reset(str, &start, &stop);
|
||||
i = i - 1;
|
||||
}
|
||||
else
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/16 16:13:47 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 18:52:32 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,6 +30,7 @@ char *ft_quote_remover(char *str);
|
||||
int ft_atoi_check(const char *nptr);
|
||||
char *ft_get_executable(t_data *data, const char *name);
|
||||
void ft_closer(int fds[2]);
|
||||
void ft_mega_closer(int fds1[2], int fds2[2]);
|
||||
void ft_add_fd(int fds[2], int fd);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user