Compare commits

..

No commits in common. "2a0846fbf0c0ea03f1d284b0b2d37d9d8005949d" and "8a6a0012dc903afdedeb9f469e972975994d9fe1" have entirely different histories.

33 changed files with 79 additions and 364 deletions

0
bozo
View File

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:41:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTINS_H #ifndef BUILTINS_H
# define BUILTINS_H # define BUILTINS_H
# include "../libftx/libft/list.h" # include "../libftx/libft/list.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:41:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTINS_PRIVATE_H #ifndef BUILTINS_PRIVATE_H
# define BUILTINS_PRIVATE_H # define BUILTINS_PRIVATE_H
# include <limits.h> # include <limits.h>

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
/* Updated: 2023/03/28 15:53:52 by cchauvet ### ########.fr */ /* Updated: 2023/03/13 16:50:40 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,8 +46,7 @@ int echo(int fd, char **strs)
{ {
while (is_space(*strs[i])) while (is_space(*strs[i]))
strs[i]++; strs[i]++;
if (check_start_write == 1 if (check_start_write == 1 || check_argument(strs[i], &check_backslash_n))
|| check_argument(strs[i], &check_backslash_n))
{ {
check_start_write = 1; check_start_write = 1;
ft_putstr_fd(strs[i], fd); ft_putstr_fd(strs[i], fd);
@ -59,3 +58,9 @@ int echo(int fd, char **strs)
write(fd, "\n", 1); write(fd, "\n", 1);
return (0); return (0);
} }
/*int main(int argc, char *argv[])
{
echo(1, argv + 1);
return (0);
}*/

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:47:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CMD_H #ifndef CMD_H
# define CMD_H # define CMD_H
# include <stdbool.h> # include <stdbool.h>

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:50:24 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CMD_PRIVATE_H #ifndef CMD_PRIVATE_H
# define CMD_PRIVATE_H # define CMD_PRIVATE_H
# include <sys/types.h> # include <sys/types.h>

View File

@ -1,19 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:42:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./data_private.h" #include "./data_private.h"
#include "data.h" #include "data.h"
t_data *ft_get_data(void) t_data *ft_get_data()
{ {
static t_data data; static t_data data;

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:43:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_H #ifndef DATA_H
# define DATA_H # define DATA_H
# include "../libftx/libft/list.h" # include "../libftx/libft/list.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:21 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:42:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_PRIVATE_H #ifndef DATA_PRIVATE_H
# define DATA_PRIVATE_H # define DATA_PRIVATE_H
# include "../libftx/libftx.h" # include "../libftx/libftx.h"

12
env/env.h vendored
View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:42:01 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:42:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_H #ifndef ENV_H
# define ENV_H # define ENV_H
# include <stdbool.h> # include <stdbool.h>

7
env/env_fill.c vendored
View File

@ -6,11 +6,12 @@
/* 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/27 16:42:27 by cchauvet ### ########.fr */ /* Updated: 2023/02/20 15:39:28 by starnakin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "./env_private.h" #include "./env_private.h"
#include "env.h"
static char *ft_getkey(const char *str) static char *ft_getkey(const char *str)
{ {
@ -96,12 +97,12 @@ char *ft_env_filler(t_data *data, const char *str)
return (NULL); return (NULL);
temp = ft_strreplace(out, value, i, key_len + i); temp = ft_strreplace(out, value, i, key_len + i);
i = i + ft_strlen(value); i = i + ft_strlen(value);
ft_freer_ultimate(2, value, out); free(out);
free(value);
if (temp == NULL) if (temp == NULL)
return (NULL); return (NULL);
out = temp; out = temp;
} }
if (out[i] != '\0')
i++; i++;
} }
return (out); return (out);

12
env/env_private.h vendored
View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:40:24 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:40:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_PRIVATE_H #ifndef ENV_PRIVATE_H
# define ENV_PRIVATE_H # define ENV_PRIVATE_H
# include "./env.h" # include "./env.h"

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/28 15:46:43 by cchauvet ### ########.fr */ /* Updated: 2023/02/28 14:56:05 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
else if (ft_strcmp(cmd->executable, "env") == 0) else if (ft_strcmp(cmd->executable, "env") == 0)
return_code = print_env(data->env, cmd->fd_out[0]); return_code = print_env(data->env, cmd->fd_out[0]);
else if (ft_strcmp(cmd->executable, "export") == 0) else if (ft_strcmp(cmd->executable, "export") == 0)
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]); return_code = (ft_export(data->env,cmd->args + 1, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "cd") == 0) else if (ft_strcmp(cmd->executable, "cd") == 0)
return_code = (move_folder(cmd->args + 1, cmd->fd_out[0])); return_code = (move_folder(cmd->args + 1, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "unset") == 0) else if (ft_strcmp(cmd->executable, "unset") == 0)

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:46:52 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:46:53 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXECUTION_H #ifndef EXECUTION_H
# define EXECUTION_H # define EXECUTION_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:45:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXECUTION_PRIVATE_H #ifndef EXECUTION_PRIVATE_H
# define EXECUTION_PRIVATE_H # define EXECUTION_PRIVATE_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,7 +1,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* format.c :+: :+: :+: */ /* spacer.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:44:56 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:44:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FORMAT_H #ifndef FORMAT_H
# define FORMAT_H # define FORMAT_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:44:59 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:45:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FORMAT_PRIVATE_H #ifndef FORMAT_PRIVATE_H
# define FORMAT_PRIVATE_H # define FORMAT_PRIVATE_H
# include "../libftx/libftx.h" # include "../libftx/libftx.h"

0
in
View File

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:25 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:43:26 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h" #include "extra.h"
void ft_swap(void *a, void *b) void ft_swap(void *a, void *b)

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:43:53 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:43:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIST_H #ifndef LIST_H
# define LIST_H # define LIST_H

6
main.c
View File

@ -6,7 +6,7 @@
/* 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/28 15:39:53 by cchauvet ### ########.fr */ /* Updated: 2023/03/28 14:35:13 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/wait.h> #include <sys/wait.h>
static char *ft_get_user_input(void) static char *ft_get_user_input()
{ {
char *line; char *line;
char *prompt; char *prompt;
@ -62,7 +62,7 @@ static void ft_cmds_waiter(t_data *data)
{ {
if (WTERMSIG(exit_status) == SIGKILL) if (WTERMSIG(exit_status) == SIGKILL)
data->exit_code = 131; data->exit_code = 131;
else else //(WTERMSIG(exit_status) == SIGINT)
data->exit_code = 130; data->exit_code = 130;
} }
else else

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:37 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./parse_private.h" #include "./parse_private.h"
static int ft_args_parse(char *cmd_str, t_cmd *cmd) static int ft_args_parse(char *cmd_str, t_cmd *cmd)
@ -42,11 +30,19 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
ft_closer(cmd->fd_in); ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out); ft_closer(cmd->fd_out);
} }
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0], else if (ft_strcmp(cmd->args[0], "env") == 0)
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0) own = 1;
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0], else if (ft_strcmp(cmd->args[0], "export") == 0)
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0) own = 1;
|| (ft_strcmp(cmd->args[0], "cd") == 0)) else if (ft_strcmp(cmd->args[0], "echo") == 0)
own = 1;
else if (ft_strcmp(cmd->args[0], "unset") == 0)
own = 1;
else if (ft_strcmp(cmd->args[0], "exit") == 0)
own = 1;
else if (ft_strcmp(cmd->args[0], "pwd") == 0)
own = 1;
else if (ft_strcmp(cmd->args[0], "cd") == 0)
own = 1; own = 1;
else else
{ {
@ -59,23 +55,10 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
return (0); return (0);
} }
int ft_cmd_adder(t_data *data, t_cmd *cmd)
{
t_list *element;
element = ft_lstnew(cmd);
if (element == NULL)
{
ft_cmddel(cmd);
return (1);
}
ft_lstadd_back(data->cmds, element);
return (0);
}
int ft_cmd_parser(t_data *data, char *cmd_str) int ft_cmd_parser(t_data *data, char *cmd_str)
{ {
t_cmd *cmd; t_cmd *cmd;
t_list *element;
cmd = ft_calloc(sizeof(t_cmd), 1); cmd = ft_calloc(sizeof(t_cmd), 1);
if (cmd == NULL) if (cmd == NULL)
@ -98,28 +81,37 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
ft_cmddel(cmd); ft_cmddel(cmd);
return (1); return (1);
} }
return (ft_cmd_adder(data, cmd)); element = ft_lstnew(cmd);
if (element == NULL)
{
ft_cmddel(cmd);
return (1);
}
ft_lstadd_back(data->cmds, element);
return (0);
} }
int ft_cmds_parser(t_data *data, const char *line) int ft_cmds_parser(t_data *data, const char *line)
{ {
char **tab; char **tab;
ssize_t i; size_t i;
tab = ft_split_quoted(line, '|'); tab = ft_split_quoted(line, '|');
if (tab == NULL) if (tab == NULL)
{ {
ft_freer_tab_ultimate(1, tab);
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("minishell: malloc failed\n");
return (1); return (1);
} }
i = -1; i = 0;
while (tab[++i] != NULL) while (tab[i] != NULL)
{ {
if (ft_cmd_parser(data, tab[i])) if (ft_cmd_parser(data, tab[i]))
{ {
ft_freer_tab_ultimate(1, tab); ft_freer_tab_ultimate(1, tab);
return (1); return (1);
} }
i++;
} }
if (*data->cmds != NULL) if (*data->cmds != NULL)
{ {

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:38 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_H #ifndef PARSE_H
# define PARSE_H # define PARSE_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:44 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:45 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_PRIVATE_H #ifndef PARSE_PRIVATE_H
# define PARSE_PRIVATE_H # define PARSE_PRIVATE_H
# include "../redirection/redirection.h" # include "../redirection/redirection.h"

View File

@ -6,13 +6,13 @@
/* 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/28 15:47:25 by cchauvet ### ########.fr */ /* Updated: 2023/02/17 16:21:02 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "./redirection_private.h" #include "./redirection_private.h"
int *ft_get_heredoc(void) int *ft_get_heredoc()
{ {
static int heredoc = -1; static int heredoc = -1;

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:49:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "redirection_private.h" #include "redirection_private.h"
int ft_replace_file(t_data *data, char **tab) int ft_replace_file(t_data *data, char **tab)
@ -56,8 +44,7 @@ void ft_remove_redirection(char *cmd_str)
i++; i++;
while (cmd_str[i] == ' ') while (cmd_str[i] == ' ')
i++; i++;
while (cmd_str[i] != '\0' && (cmd_str[i] != ' ' while (cmd_str[i] != '\0' && (cmd_str[i] != ' ' || ft_is_in_quote(cmd_str, i)))
|| ft_is_in_quote(cmd_str, i)))
i++; i++;
stop = i - start; stop = i - start;
if (start != -1) if (start != -1)
@ -92,16 +79,14 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
else if(ft_strcmp(tab[i], ">") == 0) else if(ft_strcmp(tab[i], ">") == 0)
{ {
if (ft_file_is_writable(data, tab[i + 1])) if (ft_file_is_writable(data, tab[i + 1]))
cmd->fd_out[0] = open(tab[i + 1], cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_TRUNC | O_CREAT, 0644);
O_WRONLY | O_TRUNC | O_CREAT, 0644);
else else
return (1); return (1);
} }
else if(ft_strcmp(tab[i], ">>") == 0) else if(ft_strcmp(tab[i], ">>") == 0)
{ {
if (ft_file_is_appendable(data, tab[i + 1])) if (ft_file_is_appendable(data, tab[i + 1]))
cmd->fd_out[0] = open(tab[i + 1], cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_APPEND | O_CREAT, 0644);
O_WRONLY | O_APPEND | O_CREAT, 0644);
else else
return (1); return (1);
} }

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:19 by cchauvet #+# #+# */
/* Updated: 2023/03/27 13:44:20 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDIRECTION_H #ifndef REDIRECTION_H
# define REDIRECTION_H # define REDIRECTION_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,17 +1,5 @@
/* ************************************************************************** */ #ifndef REDIRECTIONS_PRIVATE
/* */ # define REDIRECTIONS_PRIVATE
/* ::: :::::::: */
/* redirection_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:44:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDIRECTION_PRIVATE_H
# define REDIRECTION_PRIVATE_H
# include <sys/stat.h> # include <sys/stat.h>
# include <fcntl.h> # include <fcntl.h>
# include <stddef.h> # include <stddef.h>

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:42:54 by cchauvet #+# #+# */
/* Updated: 2023/03/28 15:42:55 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SYNTAX_H #ifndef SYNTAX_H
# define SYNTAX_H # define SYNTAX_H
# include "../data/data.h" # include "../data/data.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 "./utils.h"
#include <stdio.h> #include <stdio.h>
@ -17,10 +5,12 @@ void ft_closer(int fds[2])
{ {
if (fds[0] > 2) if (fds[0] > 2)
{ {
//dprintf(2, "close(%d)\n", fds[0]);
close(fds[0]); close(fds[0]);
} }
if (fds[1] > 2) if (fds[1] > 2)
{ {
//dprintf(2, "close(%d)\n", fds[1]);
close(fds[1]); close(fds[1]);
} }
} }

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 "./utils.h"
#include <unistd.h> #include <unistd.h>
@ -38,11 +26,14 @@ char *ft_get_executable_with_path(t_data *data, const char *name)
return (path); return (path);
} }
static char **ft_get_paths(t_data *data, const char *name) char *ft_get_executable_without_path(t_data *data, const char *name)
{ {
char *paths;
char **tab; char **tab;
char *paths;
char *path;
size_t i;
path = NULL;
paths = get_value_by_key("PATH", data->env); paths = get_value_by_key("PATH", data->env);
if (paths == NULL) if (paths == NULL)
{ {
@ -56,23 +47,10 @@ static char **ft_get_paths(t_data *data, const char *name)
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("minishell: malloc failed\n");
return (NULL); 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; i = 0;
while (paths[i] != NULL) while (tab[i] != NULL)
{ {
path = ft_strmerger(3, paths[i], "/", name); path = ft_strmerger(3, tab[i], "/", name);
if (path == NULL) if (path == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("minishell: malloc failed\n");
@ -84,7 +62,7 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
path = NULL; path = NULL;
i++; i++;
} }
ft_freer_tab_ultimate(1, paths); ft_freer_tab_ultimate(1, tab);
if (path == NULL) if (path == NULL)
{ {
data->exit_code = 127; data->exit_code = 127;

View File

@ -6,36 +6,40 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */ /* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */ /* Updated: 2023/02/21 23:08:10 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;
i = -1; i = 0;
while (str[++i] != '\0' && i < (ssize_t) n) while (str[i] != '\0' && i < n)
{ {
if (str[i] == '\'') if (str[i] == '\'')
{ {
i++; i++;
while (str[i] != '\'' && str[i] != '\0') while (str[i] != '\'' && str[i] != '\0')
{ {
if (i == (ssize_t) n) if (i == n)
return (1); return (1);
i++; i++;
} }
} }
if (str[i] == '"') if (str[i] == '"')
{ {
while (str[++i] != '"' && str[i] != '\0') i++;
if (i == (ssize_t) n) while (str[i] != '"' && str[i] != '\0')
{
if (i == n)
return (2); return (2);
i++;
} }
} }
i++;
}
return (0); return (0);
} }