Compare commits
No commits in common. "6498031d59c2416388d0c989bf511ed0db693446" and "a9df16029581c6ffa7ea081789e9a5eb01090716" have entirely different histories.
6498031d59
...
a9df160295
4
Makefile
4
Makefile
@ -23,9 +23,7 @@ SRCS = ${BUILTINS_SRC} \
|
|||||||
./redirection/heredoc.c \
|
./redirection/heredoc.c \
|
||||||
./redirection/file.c \
|
./redirection/file.c \
|
||||||
./redirection/redirection.c \
|
./redirection/redirection.c \
|
||||||
./redirection/check.c \
|
./parse/parse.c
|
||||||
./parse/parse.c \
|
|
||||||
./signal/signal.c
|
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
29
env/env_fill.c
vendored
29
env/env_fill.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 19:06:44 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/27 16:42:27 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ static char *ft_getkey(const char *str)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = 1;
|
i = 1;
|
||||||
while (str[i] != '\0' && !ft_is_in("$?\'\" ", str[i]))
|
while (str[i] != '\0' && !ft_is_in("$?\'\"", str[i]))
|
||||||
i++;
|
i++;
|
||||||
key = ft_strndup(str + 1, i - 1);
|
key = ft_strndup(str + 1, i - 1);
|
||||||
}
|
}
|
||||||
@ -73,25 +73,12 @@ static char *ft_getvalue_by_str(t_data *data, const char *str,
|
|||||||
return (value);
|
return (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_str_formator(t_data *data, char *str, size_t *i)
|
|
||||||
{
|
|
||||||
char *value;
|
|
||||||
size_t key_len;
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
value = ft_getvalue_by_str(data, str + *i, &key_len);
|
|
||||||
if (value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
out = ft_strreplace(str, value, *i, key_len + *i);
|
|
||||||
*i = *i + ft_strlen(value);
|
|
||||||
free(value);
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_env_filler(t_data *data, const char *str)
|
char *ft_env_filler(t_data *data, const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
char *temp;
|
char *temp;
|
||||||
|
char *value;
|
||||||
|
size_t key_len;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
@ -104,10 +91,14 @@ char *ft_env_filler(t_data *data, const char *str)
|
|||||||
i++;
|
i++;
|
||||||
while (out[i] == '$')
|
while (out[i] == '$')
|
||||||
{
|
{
|
||||||
temp = ft_str_formator(data, out, &i);
|
value = ft_getvalue_by_str(data, out + i, &key_len);
|
||||||
|
if (value == NULL)
|
||||||
|
return (NULL);
|
||||||
|
temp = ft_strreplace(out, value, i, key_len + i);
|
||||||
|
i = i + ft_strlen(value);
|
||||||
|
ft_freer_ultimate(2, value, out);
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
free(out);
|
|
||||||
out = temp;
|
out = temp;
|
||||||
}
|
}
|
||||||
if (out[i] != '\0')
|
if (out[i] != '\0')
|
||||||
|
@ -6,16 +6,17 @@
|
|||||||
/* 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/28 15:46:43 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "execution_private.h"
|
#include "execution_private.h"
|
||||||
|
|
||||||
static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||||
{
|
{
|
||||||
int return_code;
|
int return_code;
|
||||||
|
|
||||||
|
return_code = -1;
|
||||||
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
||||||
return_code = pwd(cmd->fd_out[0]);
|
return_code = pwd(cmd->fd_out[0]);
|
||||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||||
@ -28,7 +29,7 @@ static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
|||||||
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
||||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
||||||
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
||||||
else
|
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
||||||
{
|
{
|
||||||
return_code = ft_exit(cmd->args + 1);
|
return_code = ft_exit(cmd->args + 1);
|
||||||
if (return_code >= 0)
|
if (return_code >= 0)
|
||||||
@ -71,7 +72,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
|||||||
|
|
||||||
if (cmd->own_cmd == 1)
|
if (cmd->own_cmd == 1)
|
||||||
{
|
{
|
||||||
exit_code = ft_execute_own_cmd(data, cmd);
|
exit_code = ft_own_cmd(data, cmd);
|
||||||
ft_closer(cmd->fd_in);
|
ft_closer(cmd->fd_in);
|
||||||
ft_closer(cmd->fd_out);
|
ft_closer(cmd->fd_out);
|
||||||
if (exit_code == -1)
|
if (exit_code == -1)
|
||||||
@ -103,6 +104,7 @@ int ft_cmds_executor(t_data *data)
|
|||||||
{
|
{
|
||||||
content = current->content;
|
content = current->content;
|
||||||
fds[0] = -1;
|
fds[0] = -1;
|
||||||
|
fds[1] = -1;
|
||||||
if (current->next != NULL)
|
if (current->next != NULL)
|
||||||
{
|
{
|
||||||
if (pipe(fds) == -1)
|
if (pipe(fds) == -1)
|
||||||
@ -110,9 +112,7 @@ int ft_cmds_executor(t_data *data)
|
|||||||
ft_add_fd(content->fd_out, fds[1]);
|
ft_add_fd(content->fd_out, fds[1]);
|
||||||
ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]);
|
ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]);
|
||||||
}
|
}
|
||||||
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
|
if (ft_cmd_executor(data, content, fds[0]))
|
||||||
ft_mega_closer(content->fd_in, content->fd_out);
|
|
||||||
else if (ft_cmd_executor(data, content, fds[0]))
|
|
||||||
return (1);
|
return (1);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:55:22 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:45:54 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,7 @@
|
|||||||
# include "../cmd/cmd.h"
|
# include "../cmd/cmd.h"
|
||||||
# include "../env/env.h"
|
# include "../env/env.h"
|
||||||
# include "../builtins/builtins.h"
|
# include "../builtins/builtins.h"
|
||||||
# include "../utils/utils.h"
|
|
||||||
|
|
||||||
|
void ft_closer(int fds[2]);
|
||||||
|
void ft_add_fd(int fds[2], int fd);
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,30 +6,16 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 16:53:15 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/16 16:26:15 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./format_private.h"
|
#include "./format_private.h"
|
||||||
|
|
||||||
static int ft_replace(char **str, size_t i)
|
|
||||||
{
|
|
||||||
char *temp;
|
|
||||||
|
|
||||||
temp = ft_strreplace(*str, " ", i, i);
|
|
||||||
free(*str);
|
|
||||||
if (temp == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
*str = temp;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *ft_spacer_after(const char *str)
|
static char *ft_spacer_after(const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
|
char *temp;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
@ -46,7 +32,10 @@ static char *ft_spacer_after(const char *str)
|
|||||||
{
|
{
|
||||||
while (out[i] == out[i - 1])
|
while (out[i] == out[i - 1])
|
||||||
i++;
|
i++;
|
||||||
if (ft_replace(&out, i))
|
temp = ft_strreplace(out, " ", i, i);
|
||||||
|
free(out);
|
||||||
|
out = temp;
|
||||||
|
if (out == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (out[i] != '\0')
|
if (out[i] != '\0')
|
||||||
@ -58,13 +47,14 @@ static char *ft_spacer_after(const char *str)
|
|||||||
static char *ft_spacer_before(const char *str)
|
static char *ft_spacer_before(const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
ssize_t i;
|
char *temp;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i = -1;
|
i = 0;
|
||||||
while (out[++i] != '\0')
|
while (out[i + 1] != '\0')
|
||||||
{
|
{
|
||||||
while (ft_is_in_quote(out, i))
|
while (ft_is_in_quote(out, i))
|
||||||
i++;
|
i++;
|
||||||
@ -76,9 +66,13 @@ static char *ft_spacer_before(const char *str)
|
|||||||
i++;
|
i++;
|
||||||
while (out[i] == out[i + 1])
|
while (out[i] == out[i + 1])
|
||||||
i++;
|
i++;
|
||||||
if (ft_replace(&out, i + 1))
|
temp = ft_strreplace(out, " ", i + 1, i + 1);
|
||||||
|
free(out);
|
||||||
|
out = temp;
|
||||||
|
if (out == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
77
main.c
77
main.c
@ -6,14 +6,19 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:48:50 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:39:53 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "data/data.h"
|
#include "data/data.h"
|
||||||
#include "env/env.h"
|
#include "execution/execution.h"
|
||||||
|
#include "libftx/libft/libft.h"
|
||||||
|
#include "libftx/libft/list.h"
|
||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
static char *ft_get_user_input(void)
|
static char *ft_get_user_input(void)
|
||||||
{
|
{
|
||||||
@ -50,8 +55,7 @@ static void ft_cmds_waiter(t_data *data)
|
|||||||
while (current != NULL)
|
while (current != NULL)
|
||||||
{
|
{
|
||||||
content = current->content;
|
content = current->content;
|
||||||
if (content->own_cmd == 0 && content->pid != -1
|
if (content->own_cmd == 0 && content->pid != -1)
|
||||||
&& content->fd_in[0] != -2 && content->fd_out[0] != -2)
|
|
||||||
{
|
{
|
||||||
waitpid(content->pid, &exit_status, 0);
|
waitpid(content->pid, &exit_status, 0);
|
||||||
if (WIFSIGNALED(exit_status))
|
if (WIFSIGNALED(exit_status))
|
||||||
@ -91,25 +95,53 @@ static int ft_minishell(t_data *data, char *line)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_init_data(t_data *data, char **env)
|
void ft_ctrlc(int num)
|
||||||
{
|
{
|
||||||
data->exit_code = 0;
|
t_data *data;
|
||||||
|
|
||||||
|
if (num == SIGQUIT)
|
||||||
|
return ;
|
||||||
|
data = ft_get_data();
|
||||||
|
data->exit_code = 130;
|
||||||
|
if (*ft_get_heredoc() != -1)
|
||||||
|
{
|
||||||
|
close(*ft_get_heredoc());
|
||||||
|
*ft_get_heredoc() = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (data->child_pid > 1)
|
||||||
|
{
|
||||||
data->child_pid = 0;
|
data->child_pid = 0;
|
||||||
data->cmds = malloc(sizeof(t_cmd *));
|
ft_putchar_fd('\n', 1);
|
||||||
if (data->cmds == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
*data->cmds = NULL;
|
else
|
||||||
data->env = init_env(env);
|
|
||||||
if (data->env == NULL)
|
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
rl_replace_line("", 0);
|
||||||
free(data->cmds);
|
rl_on_new_line();
|
||||||
return (1);
|
ft_putchar_fd('\n', 1);
|
||||||
|
rl_redisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_quit(int num)
|
||||||
|
{
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
(void) num;
|
||||||
|
data = ft_get_data();
|
||||||
|
data->exit_code = 131;
|
||||||
|
if (data->child_pid > 1)
|
||||||
|
{
|
||||||
|
ft_printf("Quit (core dumped)\n");
|
||||||
|
data->child_pid = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rl_replace_line("", 0);
|
||||||
|
rl_redisplay();
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av, char **env)
|
int main(int ac, char **av, char **env)
|
||||||
@ -122,7 +154,14 @@ int main(int ac, char **av, char **env)
|
|||||||
signal(SIGINT, ft_ctrlc);
|
signal(SIGINT, ft_ctrlc);
|
||||||
signal(SIGQUIT, ft_quit);
|
signal(SIGQUIT, ft_quit);
|
||||||
data = ft_get_data();
|
data = ft_get_data();
|
||||||
if (ft_init_data(data, env))
|
data->exit_code = 0;
|
||||||
|
data->child_pid = 0;
|
||||||
|
data->cmds = malloc(sizeof(t_cmd *));
|
||||||
|
if (data->cmds == NULL)
|
||||||
|
return (1);
|
||||||
|
*data->cmds = NULL;
|
||||||
|
data->env = init_env(env);
|
||||||
|
if (data->env == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
line = ft_get_user_input();
|
line = ft_get_user_input();
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 16:03:54 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/09 14:59:49 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,7 +23,6 @@
|
|||||||
# include "./libftx/libftx.h"
|
# include "./libftx/libftx.h"
|
||||||
# include "./utils/utils.h"
|
# include "./utils/utils.h"
|
||||||
# include "./data/data.h"
|
# include "./data/data.h"
|
||||||
# include "./signal/signal.h"
|
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* check.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/03/29 18:43:20 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "./redirection_private.h"
|
|
||||||
|
|
||||||
static void ft_check_heredoc(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(redirection_identifier, "<<") == 0)
|
|
||||||
cmd->fd_in[0] = ft_heredoc(data, redirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_check_infile(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(redirection_identifier, "<") == 0)
|
|
||||||
{
|
|
||||||
if (ft_file_is_readable(data, redirection))
|
|
||||||
cmd->fd_in[0] = open(redirection, O_RDONLY);
|
|
||||||
else
|
|
||||||
cmd->fd_in[0] = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_check_outfile(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(redirection_identifier, ">") == 0)
|
|
||||||
{
|
|
||||||
if (ft_file_is_writable(data, redirection))
|
|
||||||
cmd->fd_out[0] = open(redirection,
|
|
||||||
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
|
||||||
else
|
|
||||||
cmd->fd_out[0] = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_check_outfile_append(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(redirection_identifier, ">>") == 0)
|
|
||||||
{
|
|
||||||
if (ft_file_is_writable(data, redirection))
|
|
||||||
cmd->fd_out[0] = open(redirection,
|
|
||||||
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
|
||||||
else
|
|
||||||
cmd->fd_out[0] = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_check_redirection(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection)
|
|
||||||
{
|
|
||||||
ft_check_heredoc(data, cmd, redirection_identifier, redirection);
|
|
||||||
ft_check_infile(data, cmd, redirection_identifier, redirection);
|
|
||||||
ft_check_outfile(data, cmd, redirection_identifier, redirection);
|
|
||||||
ft_check_outfile_append(data, cmd, redirection_identifier, redirection);
|
|
||||||
}
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 16:37:05 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:47:25 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,62 +19,38 @@ int *ft_get_heredoc(void)
|
|||||||
return (&heredoc);
|
return (&heredoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_format_and_write(t_data *data, const char *str, int fd)
|
|
||||||
{
|
|
||||||
char *line_clean;
|
|
||||||
|
|
||||||
line_clean = ft_env_filler(data, str);
|
|
||||||
if (line_clean == NULL)
|
|
||||||
return (1);
|
|
||||||
ft_putendl_fd(line_clean, fd);
|
|
||||||
free(line_clean);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_heredoc2(t_data *data, char *stop, char *line, int fds[2])
|
|
||||||
{
|
|
||||||
line[ft_strlen(line) - 1] = '\0';
|
|
||||||
if (ft_strcmp(line, stop) == 0)
|
|
||||||
{
|
|
||||||
free(line);
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
if (ft_format_and_write(data, line, fds[1]))
|
|
||||||
{
|
|
||||||
ft_closer(fds);
|
|
||||||
free(line);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
free(line);
|
|
||||||
ft_printf("> ");
|
|
||||||
line = get_next_line(*ft_get_heredoc());
|
|
||||||
if (line == NULL && *ft_get_heredoc() == -1)
|
|
||||||
{
|
|
||||||
ft_closer(fds);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_heredoc(t_data *data, char *stop)
|
int ft_heredoc(t_data *data, char *stop)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
char *line_clean;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
int return_code;
|
|
||||||
|
|
||||||
if (pipe(fds) == -1)
|
if (pipe(fds) == -1)
|
||||||
return (-1);
|
return (-2);
|
||||||
*ft_get_heredoc() = dup(0);
|
*ft_get_heredoc() = dup(0);
|
||||||
ft_printf("> ");
|
ft_printf("> ");
|
||||||
line = get_next_line(*ft_get_heredoc());
|
line = get_next_line(*ft_get_heredoc());
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
return_code = ft_heredoc2(data, stop, line, fds);
|
line[ft_strlen(line) - 1] = '\0';
|
||||||
if (return_code == 2)
|
if (ft_strcmp(line, stop) == 0)
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
break ;
|
break ;
|
||||||
else if (return_code)
|
}
|
||||||
|
line_clean = ft_env_filler(data, line);
|
||||||
|
free(line);
|
||||||
|
ft_putendl_fd(line_clean, fds[1]);
|
||||||
|
free(line_clean);
|
||||||
|
ft_printf("> ");
|
||||||
|
line = get_next_line(*ft_get_heredoc());
|
||||||
|
if (line == NULL && *ft_get_heredoc() == -1)
|
||||||
|
{
|
||||||
|
close(fds[0]);
|
||||||
|
close(fds[1]);
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
*ft_get_heredoc() = -1;
|
*ft_get_heredoc() = -1;
|
||||||
return (fds[0]);
|
return (fds[0]);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 17:58:57 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:49:58 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -35,21 +35,11 @@ int ft_replace_file(t_data *data, char **tab)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_skip(char *str, size_t *i, ssize_t *start)
|
void ft_remove_redirection(char *cmd_str)
|
||||||
{
|
|
||||||
while (str[*i] == str[*start])
|
|
||||||
(*i)++;
|
|
||||||
while (str[*i] == ' ')
|
|
||||||
(*i)++;
|
|
||||||
while (str[*i] != '\0' && (str[*i] != ' '
|
|
||||||
|| ft_is_in_quote(str, *i)))
|
|
||||||
(*i)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_remove_redirection(char *cmd_str)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
ssize_t start;
|
ssize_t start;
|
||||||
|
ssize_t stop;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (cmd_str[i] != '\0')
|
while (cmd_str[i] != '\0')
|
||||||
@ -60,12 +50,19 @@ static void ft_remove_redirection(char *cmd_str)
|
|||||||
i++;
|
i++;
|
||||||
if (ft_is_in("<>", cmd_str[i]))
|
if (ft_is_in("<>", cmd_str[i]))
|
||||||
start = i;
|
start = i;
|
||||||
else
|
if (start == -1)
|
||||||
continue ;
|
continue ;
|
||||||
ft_skip(cmd_str, &i, &start);
|
while (cmd_str[i] == cmd_str[start])
|
||||||
|
i++;
|
||||||
|
while (cmd_str[i] == ' ')
|
||||||
|
i++;
|
||||||
|
while (cmd_str[i] != '\0' && (cmd_str[i] != ' '
|
||||||
|
|| ft_is_in_quote(cmd_str, i)))
|
||||||
|
i++;
|
||||||
|
stop = i - start;
|
||||||
if (start != -1)
|
if (start != -1)
|
||||||
{
|
{
|
||||||
ft_strshift(cmd_str + start, -1 * (i - start));
|
ft_strshift(cmd_str + start, -1 * stop);
|
||||||
i = start;
|
i = start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +76,35 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
|
|||||||
while (tab[i + 1] != NULL)
|
while (tab[i + 1] != NULL)
|
||||||
{
|
{
|
||||||
ft_quote_remover(tab[i + 1]);
|
ft_quote_remover(tab[i + 1]);
|
||||||
if (ft_check_redirection(data, cmd, tab[i], tab[i + 1]) == 2)
|
if (ft_strcmp(tab[i], "<<") == 0)
|
||||||
|
{
|
||||||
|
cmd->fd_in[0] = ft_heredoc(data, tab[i + 1]);
|
||||||
|
if (cmd->fd_in[0] == -2)
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
|
else if (ft_strcmp(tab[i], "<") == 0)
|
||||||
|
{
|
||||||
|
if (ft_file_is_readable(data, tab[i + 1]))
|
||||||
|
cmd->fd_in[0] = open(tab[i + 1], O_RDONLY);
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else if (ft_strcmp(tab[i], ">") == 0)
|
||||||
|
{
|
||||||
|
if (ft_file_is_writable(data, tab[i + 1]))
|
||||||
|
cmd->fd_out[0] = open(tab[i + 1],
|
||||||
|
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else if (ft_strcmp(tab[i], ">>") == 0)
|
||||||
|
{
|
||||||
|
if (ft_file_is_appendable(data, tab[i + 1]))
|
||||||
|
cmd->fd_out[0] = open(tab[i + 1],
|
||||||
|
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:21:45 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:44:38 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
int ft_file_is_readable(t_data *data, const char *path);
|
int ft_file_is_readable(t_data *data, const char *path);
|
||||||
int ft_file_is_writable(t_data *data, const char *path);
|
int ft_file_is_writable(t_data *data, const char *path);
|
||||||
void ft_check_redirection(t_data *data, t_cmd *cmd,
|
|
||||||
char *redirection_identifier, char *redirection);
|
|
||||||
int ft_file_is_appendable(t_data *data, const char *path);
|
int ft_file_is_appendable(t_data *data, const char *path);
|
||||||
int ft_heredoc(t_data *data, char *stop);
|
int ft_heredoc(t_data *data, char *stop);
|
||||||
|
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* signal.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/03/28 16:09:37 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "signal_private.h"
|
|
||||||
|
|
||||||
static void ft_new_line(void)
|
|
||||||
{
|
|
||||||
rl_replace_line("", 0);
|
|
||||||
rl_on_new_line();
|
|
||||||
ft_putchar_fd('\n', 1);
|
|
||||||
rl_redisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_ctrlc(int num)
|
|
||||||
{
|
|
||||||
t_data *data;
|
|
||||||
|
|
||||||
if (num == SIGQUIT)
|
|
||||||
return ;
|
|
||||||
data = ft_get_data();
|
|
||||||
data->exit_code = 130;
|
|
||||||
if (*ft_get_heredoc() != -1)
|
|
||||||
{
|
|
||||||
close(*ft_get_heredoc());
|
|
||||||
*ft_get_heredoc() = -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (data->child_pid > 1)
|
|
||||||
{
|
|
||||||
data->child_pid = 0;
|
|
||||||
ft_putchar_fd('\n', 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_new_line();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_quit(int num)
|
|
||||||
{
|
|
||||||
t_data *data;
|
|
||||||
|
|
||||||
(void) num;
|
|
||||||
data = ft_get_data();
|
|
||||||
data->exit_code = 131;
|
|
||||||
if (data->child_pid > 1)
|
|
||||||
{
|
|
||||||
ft_printf("Quit (core dumped)\n");
|
|
||||||
data->child_pid = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rl_replace_line("", 0);
|
|
||||||
rl_redisplay();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* signal.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/03/28 16:03:11 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef SIGNAL_H
|
|
||||||
# define SIGNAL_H
|
|
||||||
|
|
||||||
void ft_quit(int num);
|
|
||||||
void ft_ctrlc(int num);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* signal_private.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/03/28 15:59:42 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/03/28 16:04:46 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef SIGNAL_PRIVATE_H
|
|
||||||
# define SIGNAL_PRIVATE_H
|
|
||||||
# include <signal.h>
|
|
||||||
# include <readline/readline.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include "../libftx/libftx.h"
|
|
||||||
# include "../data/data.h"
|
|
||||||
# include "../redirection/redirection.h"
|
|
||||||
#endif
|
|
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* syntax.c :+: :+: :+: */
|
/* syntatics.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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/28 16:37:29 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/21 23:40:20 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,14 +26,16 @@ static int ft_quote_verif(const char *str)
|
|||||||
|
|
||||||
static int ft_pipe_is_alone(const char *str)
|
static int ft_pipe_is_alone(const char *str)
|
||||||
{
|
{
|
||||||
ssize_t i;
|
size_t i;
|
||||||
int check;
|
int check;
|
||||||
|
|
||||||
check = 0;
|
check = 0;
|
||||||
i = -1;
|
i = 0;
|
||||||
while (str[++i] != '\0')
|
while (str[i] != '\0')
|
||||||
{
|
{
|
||||||
while (str[i] == ' ' || ft_is_in_quote(str, i))
|
while (str[i] == ' ')
|
||||||
|
i++;
|
||||||
|
while (ft_is_in_quote(str, i))
|
||||||
i++;
|
i++;
|
||||||
if (str[i] == '\0')
|
if (str[i] == '\0')
|
||||||
break ;
|
break ;
|
||||||
@ -42,13 +44,20 @@ static int ft_pipe_is_alone(const char *str)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (check == 0)
|
if (check == 0)
|
||||||
break ;
|
{
|
||||||
|
ft_eprintf("minishell: Pipe must be followed and ");
|
||||||
|
ft_eprintf("preced by a command or redirection\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
check = 0;
|
check = 0;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (check == 0)
|
if (check == 0)
|
||||||
ft_eprintf("minishell: Pipe must be followed and ",
|
{
|
||||||
"preced by a command or redirection\n");
|
ft_eprintf("minishell: Pipe must be followed and ");
|
||||||
|
ft_eprintf("preced by a command or redirection\n");
|
||||||
|
}
|
||||||
return (check == 0);
|
return (check == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:51:58 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/27 14:14:17 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,12 +25,6 @@ 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)
|
void ft_add_fd(int fds[2], int fd)
|
||||||
{
|
{
|
||||||
if (fds[0] == -1)
|
if (fds[0] == -1)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 16:34:37 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/27 13:39:50 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -59,23 +59,6 @@ static char **ft_get_paths(t_data *data, const char *name)
|
|||||||
return (tab);
|
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)
|
static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||||
{
|
{
|
||||||
char **paths;
|
char **paths;
|
||||||
@ -89,9 +72,16 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (paths[i] != NULL)
|
while (paths[i] != NULL)
|
||||||
{
|
{
|
||||||
path = ft_file_is_executable(paths[i], name);
|
path = ft_strmerger(3, paths[i], "/", name);
|
||||||
if (path != NULL)
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
break ;
|
break ;
|
||||||
|
}
|
||||||
|
if (access(path, X_OK) == 0)
|
||||||
|
break ;
|
||||||
|
free(path);
|
||||||
|
path = NULL;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
ft_freer_tab_ultimate(1, paths);
|
ft_freer_tab_ultimate(1, paths);
|
||||||
|
@ -6,20 +6,12 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "utils.h"
|
#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)
|
char *ft_quote_remover(char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -40,7 +32,10 @@ char *ft_quote_remover(char *str)
|
|||||||
}
|
}
|
||||||
if (stop != -1)
|
if (stop != -1)
|
||||||
{
|
{
|
||||||
ft_remove_quote_and_reset(str, &start, &stop);
|
ft_strshift(str + start, -1);
|
||||||
|
ft_strshift(str + stop - 1, -1);
|
||||||
|
start = -1;
|
||||||
|
stop = -1;
|
||||||
i = i - 1;
|
i = i - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:52:32 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/16 16:13:47 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,7 +30,6 @@ char *ft_quote_remover(char *str);
|
|||||||
int ft_atoi_check(const char *nptr);
|
int ft_atoi_check(const char *nptr);
|
||||||
char *ft_get_executable(t_data *data, const char *name);
|
char *ft_get_executable(t_data *data, const char *name);
|
||||||
void ft_closer(int fds[2]);
|
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);
|
void ft_add_fd(int fds[2], int fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user