clean: norm part 1
This commit is contained in:
parent
9787d71b85
commit
2a0846fbf0
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define BUILTINS_H
|
||||
# include "../libftx/libft/list.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define BUILTINS_PRIVATE_H
|
||||
# include <limits.h>
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/13 16:50:40 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/03/28 15:53:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -46,7 +46,8 @@ int echo(int fd, char **strs)
|
||||
{
|
||||
while (is_space(*strs[i]))
|
||||
strs[i]++;
|
||||
if (check_start_write == 1 || check_argument(strs[i], &check_backslash_n))
|
||||
if (check_start_write == 1
|
||||
|| check_argument(strs[i], &check_backslash_n))
|
||||
{
|
||||
check_start_write = 1;
|
||||
ft_putstr_fd(strs[i], fd);
|
||||
@ -58,9 +59,3 @@ int echo(int fd, char **strs)
|
||||
write(fd, "\n", 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*int main(int argc, char *argv[])
|
||||
{
|
||||
echo(1, argv + 1);
|
||||
return (0);
|
||||
}*/
|
||||
|
12
cmd/cmd.h
12
cmd/cmd.h
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define CMD_H
|
||||
# include <stdbool.h>
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define CMD_PRIVATE_H
|
||||
# include <sys/types.h>
|
||||
|
14
data/data.c
14
data/data.c
@ -1,7 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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.h"
|
||||
|
||||
t_data *ft_get_data()
|
||||
t_data *ft_get_data(void)
|
||||
{
|
||||
static t_data data;
|
||||
|
||||
|
12
data/data.h
12
data/data.h
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define DATA_H
|
||||
# include "../libftx/libft/list.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define DATA_PRIVATE_H
|
||||
# include "../libftx/libftx.h"
|
||||
|
12
env/env.h
vendored
12
env/env.h
vendored
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define ENV_H
|
||||
# include <stdbool.h>
|
||||
|
12
env/env_private.h
vendored
12
env/env_private.h
vendored
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define ENV_PRIVATE_H
|
||||
# include "./env.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/28 14:56:05 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/03/28 15:46:43 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,7 +22,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||
return_code = print_env(data->env, cmd->fd_out[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)
|
||||
return_code = (move_folder(cmd->args + 1, cmd->fd_out[0]));
|
||||
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define EXECUTION_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define EXECUTION_PRIVATE_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* spacer.c :+: :+: :+: */
|
||||
/* format.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define FORMAT_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define FORMAT_PRIVATE_H
|
||||
# include "../libftx/libftx.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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"
|
||||
|
||||
void ft_swap(void *a, void *b)
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define LIST_H
|
||||
|
||||
|
6
main.c
6
main.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 14:35:13 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/28 15:39:53 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static char *ft_get_user_input()
|
||||
static char *ft_get_user_input(void)
|
||||
{
|
||||
char *line;
|
||||
char *prompt;
|
||||
@ -62,7 +62,7 @@ static void ft_cmds_waiter(t_data *data)
|
||||
{
|
||||
if (WTERMSIG(exit_status) == SIGKILL)
|
||||
data->exit_code = 131;
|
||||
else //(WTERMSIG(exit_status) == SIGINT)
|
||||
else
|
||||
data->exit_code = 130;
|
||||
}
|
||||
else
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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"
|
||||
|
||||
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
||||
@ -30,19 +42,11 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
}
|
||||
else if (ft_strcmp(cmd->args[0], "env") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "export") == 0)
|
||||
own = 1;
|
||||
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)
|
||||
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0],
|
||||
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0)
|
||||
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0],
|
||||
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0)
|
||||
|| (ft_strcmp(cmd->args[0], "cd") == 0))
|
||||
own = 1;
|
||||
else
|
||||
{
|
||||
@ -55,10 +59,23 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
||||
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)
|
||||
{
|
||||
t_cmd *cmd;
|
||||
t_list *element;
|
||||
|
||||
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||
if (cmd == NULL)
|
||||
@ -81,37 +98,28 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
|
||||
ft_cmddel(cmd);
|
||||
return (1);
|
||||
}
|
||||
element = ft_lstnew(cmd);
|
||||
if (element == NULL)
|
||||
{
|
||||
ft_cmddel(cmd);
|
||||
return (1);
|
||||
}
|
||||
ft_lstadd_back(data->cmds, element);
|
||||
return (0);
|
||||
return (ft_cmd_adder(data, cmd));
|
||||
}
|
||||
|
||||
int ft_cmds_parser(t_data *data, const char *line)
|
||||
{
|
||||
char **tab;
|
||||
size_t i;
|
||||
ssize_t i;
|
||||
|
||||
tab = ft_split_quoted(line, '|');
|
||||
if (tab == NULL)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
i = -1;
|
||||
while (tab[++i] != NULL)
|
||||
{
|
||||
if (ft_cmd_parser(data, tab[i]))
|
||||
{
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
return (1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (*data->cmds != NULL)
|
||||
{
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define PARSE_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define PARSE_PRIVATE_H
|
||||
# include "../redirection/redirection.h"
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/17 16:21:02 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/28 15:47:25 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./redirection_private.h"
|
||||
|
||||
int *ft_get_heredoc()
|
||||
int *ft_get_heredoc(void)
|
||||
{
|
||||
static int heredoc = -1;
|
||||
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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"
|
||||
|
||||
int ft_replace_file(t_data *data, char **tab)
|
||||
@ -44,7 +56,8 @@ void ft_remove_redirection(char *cmd_str)
|
||||
i++;
|
||||
while (cmd_str[i] == ' ')
|
||||
i++;
|
||||
while (cmd_str[i] != '\0' && (cmd_str[i] != ' ' || ft_is_in_quote(cmd_str, i)))
|
||||
while (cmd_str[i] != '\0' && (cmd_str[i] != ' '
|
||||
|| ft_is_in_quote(cmd_str, i)))
|
||||
i++;
|
||||
stop = i - start;
|
||||
if (start != -1)
|
||||
@ -79,14 +92,16 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
|
||||
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);
|
||||
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);
|
||||
cmd->fd_out[0] = open(tab[i + 1],
|
||||
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define REDIRECTION_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,5 +1,17 @@
|
||||
#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 <fcntl.h>
|
||||
# include <stddef.h>
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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
|
||||
# define SYNTAX_H
|
||||
# include "../data/data.h"
|
||||
|
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);
|
||||
}
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
return (tab);
|
||||
}
|
||||
|
||||
static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||
{
|
||||
path = ft_strmerger(3, tab[i], "/", name);
|
||||
char **paths;
|
||||
char *path;
|
||||
size_t i;
|
||||
|
||||
paths = ft_get_paths(data, name);
|
||||
if (paths == NULL)
|
||||
return (NULL);
|
||||
path = NULL;
|
||||
i = 0;
|
||||
while (paths[i] != NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user