clean: norm part 1

This commit is contained in:
Camille Chauvet
2023-03-28 15:55:08 +02:00
parent 9787d71b85
commit 2a0846fbf0
32 changed files with 360 additions and 74 deletions

View File

@ -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;

View File

@ -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)
@ -76,17 +89,19 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
else
return (1);
}
else if(ft_strcmp(tab[i], ">") == 0)
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)
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);
}

View File

@ -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"

View File

@ -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>