clean: norm part 1
This commit is contained in:
14
utils/fd.c
14
utils/fd.c
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@ -5,12 +17,10 @@ void ft_closer(int fds[2])
|
||||
{
|
||||
if (fds[0] > 2)
|
||||
{
|
||||
//dprintf(2, "close(%d)\n", fds[0]);
|
||||
close(fds[0]);
|
||||
}
|
||||
if (fds[1] > 2)
|
||||
{
|
||||
//dprintf(2, "close(%d)\n", fds[1]);
|
||||
close(fds[1]);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_get_executable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./utils.h"
|
||||
#include <unistd.h>
|
||||
|
||||
@ -26,14 +38,11 @@ char *ft_get_executable_with_path(t_data *data, const char *name)
|
||||
return (path);
|
||||
}
|
||||
|
||||
char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
static char **ft_get_paths(t_data *data, const char *name)
|
||||
{
|
||||
char **tab;
|
||||
char *paths;
|
||||
char *path;
|
||||
size_t i;
|
||||
char **tab;
|
||||
|
||||
path = NULL;
|
||||
paths = get_value_by_key("PATH", data->env);
|
||||
if (paths == NULL)
|
||||
{
|
||||
@ -47,10 +56,23 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (NULL);
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
{
|
||||
char **paths;
|
||||
char *path;
|
||||
size_t i;
|
||||
|
||||
paths = ft_get_paths(data, name);
|
||||
if (paths == NULL)
|
||||
return (NULL);
|
||||
path = NULL;
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
while (paths[i] != NULL)
|
||||
{
|
||||
path = ft_strmerger(3, tab[i], "/", name);
|
||||
path = ft_strmerger(3, paths[i], "/", name);
|
||||
if (path == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
@ -62,7 +84,7 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
path = NULL;
|
||||
i++;
|
||||
}
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
ft_freer_tab_ultimate(1, paths);
|
||||
if (path == NULL)
|
||||
{
|
||||
data->exit_code = 127;
|
||||
|
@ -6,40 +6,36 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 23:08:10 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "utils.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
int ft_is_in_quote(const char *str, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
ssize_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' && i < n)
|
||||
i = -1;
|
||||
while (str[++i] != '\0' && i < (ssize_t) n)
|
||||
{
|
||||
if (str[i] == '\'')
|
||||
{
|
||||
i++;
|
||||
while (str[i] != '\'' && str[i] != '\0')
|
||||
{
|
||||
if (i == n)
|
||||
if (i == (ssize_t) n)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (str[i] == '"')
|
||||
{
|
||||
i++;
|
||||
while (str[i] != '"' && str[i] != '\0')
|
||||
{
|
||||
if (i == n)
|
||||
while (str[++i] != '"' && str[i] != '\0')
|
||||
if (i == (ssize_t) n)
|
||||
return (2);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user