fix: empty line, leaks, pipe

This commit is contained in:
Camille Chauvet 2023-02-16 16:29:46 +01:00
parent f20038e37b
commit e48ee8b693
8 changed files with 38 additions and 9 deletions

BIN
.fill_env.c.swp Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c
OBJS = ${SRCS:.c=.o}

3
env.c
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/16 15:18:48 by cchauvet ### ########.fr */
/* Updated: 2023/02/16 16:24:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -113,6 +113,7 @@ void env_del(void *ptr)
content = ptr;
free(content->key);
free(content->value);
free(content);
}
char *get_key(char *str)

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/02/16 15:17:07 by cchauvet ### ########.fr */
/* Updated: 2023/02/16 16:12:26 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
/* Updated: 2023/02/16 14:53:16 by cchauvet ### ########.fr */
/* Updated: 2023/02/16 16:26:15 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -101,6 +101,8 @@ char *ft_normalizer(char *str)
char *out;
char *temp;
if (ft_str_is_empty(str))
return (ft_strdup(" "));
temp = ft_spacer_after(str);
if (temp == NULL)
return (NULL);
@ -109,6 +111,7 @@ char *ft_normalizer(char *str)
if (out == NULL)
return (NULL);
ft_space_simplifier(out);
if (out[ft_strlen(out) - 1] == ' ')
out[ft_strlen(out) - 1] = '\0';
return (out);
}

View File

@ -24,7 +24,9 @@ static int ft_pipe_is_alone(const char *str)
{
while (str[i] == ' ')
i++;
if (str[i] != '|' && str[i] != '\0')
if (str[i] == '\0')
break ;
if (str[i] != '|')
check = 1;
else
{
@ -89,7 +91,7 @@ int ft_empty_verif(const char *str)
int ft_syntatic_verif(const char *str)
{
return (ft_quote_verif(str)
|| ft_pipe_is_alone(str)
|| ft_empty_verif(str)
|| ft_pipe_is_alone(str)
|| ft_special_char_dub(str));
}

23
utils/ft_str_is_empty.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_empty.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 16:12:46 by cchauvet #+# #+# */
/* Updated: 2023/02/16 16:13:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_str_is_empty(const char *str)
{
size_t i;
i = 0;
while (str[i] == ' ')
i++;
return (str[i] == '\0');
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
/* Updated: 2023/02/16 15:15:05 by cchauvet ### ########.fr */
/* Updated: 2023/02/16 16:13:47 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop);
ssize_t ft_strnchr(const char *str, char c);
char *ft_getstr(const char *str, size_t n);
void ft_printn(const char *str, size_t n);
int ft_str_is_empty(const char *str);
char **ft_split_quoted(const char *s, char c);
void ft_strshift(char *str, int shift);
char *ft_quote_remover(char *str);