From a9182eee769cec9d81f11b19844428da28667022 Mon Sep 17 00:00:00 2001
From: JozanLeClerc <bousset.rudy@gmail.com>
Date: Fri, 24 Jan 2020 16:54:01 +0100
Subject: ft_split redone

---
 libft/Makefile            |   2 +-
 libft/src/ft_split.c      |  80 +++++++++++++++++-------------------
 libft/src/ft_split_redo.c | 101 ----------------------------------------------
 src/ft_get_tex.c          |   7 ++++
 4 files changed, 44 insertions(+), 146 deletions(-)
 delete mode 100644 libft/src/ft_split_redo.c

diff --git a/libft/Makefile b/libft/Makefile
index 04035b9..051fcd7 100644
--- a/libft/Makefile
+++ b/libft/Makefile
@@ -58,7 +58,7 @@ SRCS_NAME	+= ft_strdup.c
 SRCS_NAME	+= ft_substr.c
 SRCS_NAME	+= ft_strjoin.c
 SRCS_NAME	+= ft_strtrim.c
-SRCS_NAME	+= ft_split_redo.c
+SRCS_NAME	+= ft_split.c
 SRCS_NAME	+= ft_itoa.c
 SRCS_NAME	+= ft_itoa_base.c
 SRCS_NAME	+= ft_uitoa.c
diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c
index f0cac95..1d33dda 100644
--- a/libft/src/ft_split.c
+++ b/libft/src/ft_split.c
@@ -1,31 +1,10 @@
-/* ************************************************************************** */
-/*                                                          LE - /            */
-/*                                                              /             */
-/*   ft_split.c                                       .::    .:/ .      .::   */
-/*                                                 +:+:+   +:    +:  +:+:+    */
-/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */
-/*                                                 #+#   #+    #+    #+#      */
-/*   Created: 2019/10/12 19:24:20 by rbousset     #+#   ##    ##    #+#       */
-/*   Updated: 2019/10/13 08:37:16 by rbousset    ###    #+. /#+    ###.fr     */
-/*                                                         /                  */
-/*                                                        /                   */
-/* ************************************************************************** */
-
 #include <libft.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <inttypes.h>
 
-static uint8_t
-	ft_check(int c, char sep)
-{
-	if (c == sep)
-		return (1);
-	return (0);
-}
-
 static size_t
-	ft_strlen_plus(const char *str, char c)
+ft_count_words(const char *s, char c)
 {
 	size_t	i;
 	size_t	count;
@@ -34,11 +13,11 @@ static size_t
 	i = 0;
 	count = 0;
 	ibool = 1;
-	while (str[i])
+	while (s[i])
 	{
-		while (ft_check(str[i], c) && str[i])
+		while (s[i] == c && s[i])
 			i++;
-		while (!ft_check(str[i], c) && str[i])
+		while (s[i] != c && s[i])
 		{
 			if (ibool == 1)
 				count++;
@@ -51,59 +30,72 @@ static size_t
 }
 
 static size_t
-	ft_strlen_again(const char *str, char c)
+ft_splitlen(const char *str, char c)
 {
 	size_t	i;
 
 	i = 0;
-	while (!ft_check(str[i], c) && str[i])
+	while (str[i] != c && str[i])
 		i++;
 	return (i);
 }
 
 static char
-	*ft_strdup_plus(const char *src, char c)
+	*ft_splitdup(const char *str, char c)
 {
+	char	*word;
 	size_t	i;
-	size_t	slen;
-	char	*nstr;
 
 	i = 0;
-	slen = ft_strlen_again(src, c) + 1;
-	if (!(nstr = (char*)ft_calloc(slen, sizeof(char))))
+	if (!(word = (char*)malloc((ft_splitlen(str, c) + 1) * sizeof(char))))
 		return (NULL);
-	while (!ft_check(src[i], c) && src[i])
+	while (str[i] != c && str[i])
 	{
-		nstr[i] = src[i];
+		word[i] = str[i];
 		i++;
 	}
-	nstr[i] = '\0';
-	return (nstr);
+	word[i] = '\0';
+	return (word);
+}
+
+static void
+ft_splitfree(char **best_split, size_t j)
+{
+	while (j > 0)
+	{
+		free(best_split[j]);
+		j--;
+	}
+	free(best_split);
 }
 
 char
 	**ft_split(const char *s, char c)
 {
+	char	**best_split;
 	size_t	i;
 	size_t	j;
-	char	**best_split;
 
 	i = 0;
 	j = 0;
-	if (!(best_split = (char **)ft_calloc(ft_strlen_plus(s, c) + 1,
-						sizeof(char *))))
+	if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
+										* sizeof(char *))))
 		return (NULL);
 	while (s[i])
 	{
-		while (ft_check(s[i], c) && s[i])
+		while (s[i] == c && s[i])
 			i++;
-		while (!ft_check(s[i], c) && s[i])
+		while (s[i] != c && s[i])
 		{
-			best_split[j] = ft_strdup_plus(&s[i], c);
-			i += ft_strlen_again(&s[i], c);
+			if (!(best_split[j] = ft_splitdup(s + i, c)))
+			{
+				ft_splitfree(best_split, j);
+				return (NULL);
+			}
+			i += ft_splitlen(s + i, c);
 			j++;
 		}
 	}
-	best_split[j] = 0;
+	best_split[j] = NULL;
 	return (best_split);
 }
diff --git a/libft/src/ft_split_redo.c b/libft/src/ft_split_redo.c
deleted file mode 100644
index 1d33dda..0000000
--- a/libft/src/ft_split_redo.c
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <libft.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-static size_t
-ft_count_words(const char *s, char c)
-{
-	size_t	i;
-	size_t	count;
-	uint8_t	ibool;
-
-	i = 0;
-	count = 0;
-	ibool = 1;
-	while (s[i])
-	{
-		while (s[i] == c && s[i])
-			i++;
-		while (s[i] != c && s[i])
-		{
-			if (ibool == 1)
-				count++;
-			ibool = 0;
-			i++;
-		}
-		ibool = 1;
-	}
-	return (count);
-}
-
-static size_t
-ft_splitlen(const char *str, char c)
-{
-	size_t	i;
-
-	i = 0;
-	while (str[i] != c && str[i])
-		i++;
-	return (i);
-}
-
-static char
-	*ft_splitdup(const char *str, char c)
-{
-	char	*word;
-	size_t	i;
-
-	i = 0;
-	if (!(word = (char*)malloc((ft_splitlen(str, c) + 1) * sizeof(char))))
-		return (NULL);
-	while (str[i] != c && str[i])
-	{
-		word[i] = str[i];
-		i++;
-	}
-	word[i] = '\0';
-	return (word);
-}
-
-static void
-ft_splitfree(char **best_split, size_t j)
-{
-	while (j > 0)
-	{
-		free(best_split[j]);
-		j--;
-	}
-	free(best_split);
-}
-
-char
-	**ft_split(const char *s, char c)
-{
-	char	**best_split;
-	size_t	i;
-	size_t	j;
-
-	i = 0;
-	j = 0;
-	if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
-										* sizeof(char *))))
-		return (NULL);
-	while (s[i])
-	{
-		while (s[i] == c && s[i])
-			i++;
-		while (s[i] != c && s[i])
-		{
-			if (!(best_split[j] = ft_splitdup(s + i, c)))
-			{
-				ft_splitfree(best_split, j);
-				return (NULL);
-			}
-			i += ft_splitlen(s + i, c);
-			j++;
-		}
-	}
-	best_split[j] = NULL;
-	return (best_split);
-}
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c
index e69de29..d38e494 100644
--- a/src/ft_get_tex.c
+++ b/src/ft_get_tex.c
@@ -0,0 +1,7 @@
+#include <libft.h>
+#include <cub3d.h>
+
+int
+ft_get_tex(int fd, t_cub *clist)
+{
+}
-- 
cgit v1.2.3