long time no see =)

added fully test realpath function
removed zombie strsplitstr2 function
This commit is contained in:
Tanguy MAZE 2019-01-29 18:20:52 +01:00
parent 19d3e23b74
commit 4b44c49fc6
4 changed files with 82 additions and 73 deletions

View File

@ -6,12 +6,12 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ # # By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# # # Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
# Updated: 2018/11/26 12:40:27 by tmaze ### ########.fr # # Updated: 2019/01/29 18:19:09 by tmaze ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#
CC = gcc CC = gcc
CCFLAGS = -Wall -Werror -Wextra -g CCFLAGS = -Wall -Werror -Wextra
CCSTD = CCSTD =
NAME = libft.a NAME = libft.a
@ -19,7 +19,7 @@ NAME = libft.a
SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c ft_strcmp.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c \ SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c ft_strcmp.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c \
ft_memalloc.c ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c\ ft_memalloc.c ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c\
ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c \ ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c \
ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c ft_strsplitstr2.c ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c ft_realpath.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
INCLS = -I. INCLS = -I.

77
ft_realpath.c Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realpath.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/27 14:42:35 by tmaze #+# #+# */
/* Updated: 2019/01/29 18:16:22 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_tabtopath(char **tab_path)
{
size_t total_size;
size_t i;
char *ret;
i = 0;
total_size = 0;
while (tab_path[i])
total_size += ft_strlen(tab_path[i++]);
total_size = (total_size == 0) ? 1 : total_size;
if ((ret = ft_strnew(total_size + i)) == NULL)
return (NULL);
i = 0;
ft_strcat(ret, "/");
while (tab_path[i])
{
if (i > 0)
ft_strcat(ret, "/");
ft_strcat(ret, tab_path[i++]);
}
return (ret);
}
void ft_reducepath(char ***tab)
{
size_t i;
size_t j;
int strcmp;
i = 0;
while ((*tab)[i])
{
if ((strcmp = ft_strcmp((*tab)[i], "..")) == 0
|| ft_strcmp((*tab)[i], ".") == 0)
{
ft_strdel(&((*tab)[i]));
if ((j = i) == i && strcmp == 0 && i != 0)
ft_strdel(&((*tab)[i - 1]));
while ((*tab)[++j])
(*tab)[j - ((strcmp == 0 && i != 0) ? 2 : 1)] = (*tab)[j];
if (strcmp == 0 && i != 0)
(*tab)[j - 2] = NULL;
(*tab)[j - 1] = NULL;
if (strcmp == 0 && i != 0)
i--;
}
else
i++;
}
}
char *ft_realpath(char *r_path, char **a_path)
{
char **tab_path;
if ((tab_path = ft_strsplit(r_path, '/')) == NULL)
return (NULL);
ft_reducepath(&tab_path);
*a_path = ft_tabtopath(tab_path);
ft_del_words_tables(&tab_path);
return (*a_path);
}

View File

@ -1,68 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplitstr2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/26 11:33:06 by tmaze #+# #+# */
/* Updated: 2018/11/26 12:42:46 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int isin(char c, char *str)
{
size_t i;
i = 0;
while (str[i])
if (c == str[i++])
return (1);
return (0);
}
static void ft_cntdelstr(void* content, size_t content_size)
{
ft_strdel((char**)content);
content_size = 0;
}
t_list *ft_strsplitstr2(char *str, char *split)
{
size_t i;
size_t j;
char *token;
t_list *lst;
t_list *new;
lst = NULL;
i = 0;
j = 0;
while (str[i])
{
if (isin(str[i], split))
{
if ((token = ft_strnew(i - j + 1)) == NULL)
{
ft_lstdel(&lst, &ft_cntdelstr);
return (NULL);
}
token[i + j + 1] = '\0';
ft_strsub(str, j, i);
if ((new = ft_lstnew((void*)token, ft_strlen(token))) == NULL)
{
ft_strdel(&token);
ft_lstdel(&lst, &ft_cntdelstr);
return (NULL);
}
ft_lstaddend(&lst, new);
while ((isin(str[i], split)))
i++;
j = i;
}
i++;
}
return (lst);
}

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */ /* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
/* Updated: 2018/11/26 12:36:58 by tmaze ### ########.fr */ /* Updated: 2019/01/29 18:18:28 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -174,6 +174,6 @@ void ft_lstaddsort(t_list **lst, t_list *new,
int ft_round(float x, float ind); int ft_round(float x, float ind);
t_list *ft_strsplitstr2(char *str, char *split); char *ft_realpath(char *r_path, char **a_path);
#endif #endif