diff --git a/a.out b/a.out new file mode 100755 index 0000000..14774e7 Binary files /dev/null and b/a.out differ diff --git a/ft_printf_include_libft/libft/Makefile b/ft_printf_include_libft/libft/Makefile index ae4009b..cde56b0 100644 --- a/ft_printf_include_libft/libft/Makefile +++ b/ft_printf_include_libft/libft/Makefile @@ -9,7 +9,8 @@ SRCS = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \ ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_strtrim.c ft_putchar.c\ ft_lstadd_back.c ft_lstadd_front.c ft_lstclear.c \ ft_lstdelone.c ft_lstiter.c ft_lstlast.c \ - ft_lstmap.c ft_lstnew.c ft_lstsize.c + ft_lstmap.c ft_lstnew.c ft_lstsize.c\ + get_next_line.c get_next_line_utils.c SRC_DIR = ./src/ OBJ_DIR = ./obj/ diff --git a/get_next_line/get_next_line.h b/ft_printf_include_libft/libft/includes/get_next_line.h similarity index 86% rename from get_next_line/get_next_line.h rename to ft_printf_include_libft/libft/includes/get_next_line.h index 2b5f359..2043542 100644 --- a/get_next_line/get_next_line.h +++ b/ft_printf_include_libft/libft/includes/get_next_line.h @@ -6,7 +6,7 @@ /* By: mdenys +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/13 21:55:13 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:22:55 by mdenys ### ########.fr */ +/* Updated: 2021/01/11 20:30:02 by mdenys ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int get_next_line(int fd, char **line); int ft_rn(char *str); -size_t ft_strlen(const char *s); -char *ft_strjoin(const char *s1, const char *s2); +size_t ft_strlen_custom(const char *s); +char *ft_strjoin_custom(const char *s1, const char *s2); #endif diff --git a/get_next_line/get_next_line.c b/ft_printf_include_libft/libft/src/get_next_line.c similarity index 91% rename from get_next_line/get_next_line.c rename to ft_printf_include_libft/libft/src/get_next_line.c index e08dd42..bcd6581 100644 --- a/get_next_line/get_next_line.c +++ b/ft_printf_include_libft/libft/src/get_next_line.c @@ -6,7 +6,7 @@ /* By: mdenys +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/12 13:47:35 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:54:27 by mdenys ### ########.fr */ +/* Updated: 2021/01/11 20:32:35 by mdenys ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ char *check_reminder(char *reminder) free(reminder); return (0); } - if (!(rtn = malloc(sizeof(char) * ((ft_strlen(reminder) - i) + 1)))) + if (!(rtn = malloc(sizeof(char) * ((ft_strlen_custom(reminder) - i) + 1)))) return (0); i++; while (reminder[i]) @@ -81,7 +81,7 @@ int get_next_line(int fd, char **line) return (-1); } buff[r_d] = '\0'; - reminder = ft_strjoin(reminder, buff); + reminder = ft_strjoin_custom(reminder, buff); } free(buff); *line = gnl(reminder); diff --git a/get_next_line/get_next_line_utils.c b/ft_printf_include_libft/libft/src/get_next_line_utils.c similarity index 79% rename from get_next_line/get_next_line_utils.c rename to ft_printf_include_libft/libft/src/get_next_line_utils.c index 8965d91..0b0070a 100644 --- a/get_next_line/get_next_line_utils.c +++ b/ft_printf_include_libft/libft/src/get_next_line_utils.c @@ -6,13 +6,13 @@ /* By: mdenys +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/14 10:50:53 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:56:51 by mdenys ### ########.fr */ +/* Updated: 2021/01/11 20:34:13 by mdenys ### ########.fr */ /* */ /* ************************************************************************** */ #include "get_next_line.h" -size_t ft_strlen(const char *s) +size_t ft_strlen_custom_custom(const char *s) { int i; @@ -24,7 +24,7 @@ size_t ft_strlen(const char *s) return (i); } -void *ft_memmove(void *dst, const void *src, size_t len) +void *ft_memmove_custom(void *dst, const void *src, size_t len) { char *d; char *s; @@ -44,7 +44,7 @@ void *ft_memmove(void *dst, const void *src, size_t len) return (dst); } -char *ft_strjoin(char const *s1, char const *s2) +char *ft_strjoin_custom(char const *s1, char const *s2) { size_t s1_len; size_t s2_len; @@ -53,14 +53,14 @@ char *ft_strjoin(char const *s1, char const *s2) if (!s1 && !s2) return (0); - s1_len = ft_strlen((char *)s1); - s2_len = ft_strlen((char *)s2); + s1_len = ft_strlen_custom((char *)s1); + s2_len = ft_strlen_custom((char *)s2); stot_len = s1_len + s2_len + 1; rtn = malloc(sizeof(char) * stot_len); if (!rtn) return (0); - ft_memmove(rtn, s1, s1_len); - ft_memmove(rtn + s1_len, s2, s2_len); + ft_memmove_custom(rtn, s1, s1_len); + ft_memmove_custom(rtn + s1_len, s2, s2_len); rtn[stot_len - 1] = '\0'; free((char *)s1); return (rtn); diff --git a/get_next_line/get_next_line_bonus.c b/get_next_line/get_next_line_bonus.c deleted file mode 100644 index 813f361..0000000 --- a/get_next_line/get_next_line_bonus.c +++ /dev/null @@ -1,122 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mdenys +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/11/12 13:47:35 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:55:45 by mdenys ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line_bonus.h" - -char *check_reminder(char *reminder) -{ - char *rtn; - int i; - int j; - - i = 0; - j = 0; - if (!reminder) - return (0); - while (reminder[i] && reminder[i] != '\n') - i++; - if (!reminder[i]) - { - free(reminder); - return (0); - } - if (!(rtn = malloc(sizeof(char) * ((ft_strlen(reminder) - i) + 1)))) - return (0); - i++; - while (reminder[i]) - rtn[j++] = reminder[i++]; - rtn[j] = '\0'; - free(reminder); - return (rtn); -} - -char *gnl(char *str) -{ - int i; - char *rtn; - - i = 0; - if (!str) - return (0); - while (str[i] && str[i] != '\n') - i++; - if (!(rtn = malloc(sizeof(char) * (i + 1)))) - return (0); - i = 0; - while (str[i] && str[i] != '\n') - { - rtn[i] = str[i]; - i++; - } - rtn[i] = '\0'; - return (rtn); -} - -int get_line(int fd, char **line, char **reminder) -{ - char *buff; - int r_d; - - r_d = 1; - if (fd < 0 || !line || BUFFER_SIZE <= 0) - return (-1); - if (!(buff = malloc(sizeof(char) * (BUFFER_SIZE + 1)))) - return (-1); - while (!ft_rn(*reminder) && r_d != 0) - { - if ((r_d = read(fd, buff, BUFFER_SIZE)) == -1) - { - free(buff); - return (-1); - } - buff[r_d] = '\0'; - *reminder = ft_strjoin(*reminder, buff); - } - free(buff); - *line = gnl(*reminder); - *reminder = check_reminder(*reminder); - if (r_d == 0) - return (0); - return (1); -} - -t_netnext_line *new_linked_list_el(const int fd) -{ - t_netnext_line *new; - - new = (t_netnext_line *)malloc(sizeof(t_netnext_line)); - new->fd = fd; - new->reminder = NULL; - new->next = NULL; - return (new); -} - -int get_next_line(int fd, char **line) -{ - static t_netnext_line *head; - t_netnext_line *temp; - - if (fd < 0) - return (-1); - if (fd == 0) - return (0); - if (head == NULL) - head = new_linked_list_el(fd); - temp = head; - while (temp->fd != fd) - { - if (temp->next == NULL) - temp->next = new_linked_list_el(fd); - temp = temp->next; - } - return (get_line(fd, line, &temp->reminder)); -} diff --git a/get_next_line/get_next_line_bonus.h b/get_next_line/get_next_line_bonus.h deleted file mode 100644 index a4b796a..0000000 --- a/get_next_line/get_next_line_bonus.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_bonus.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mdenys +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/11/13 21:55:13 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:58:39 by mdenys ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef GET_NEXT_LINE_BONUS_H -# define GET_NEXT_LINE_BONUS_H - -# include -# include - -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 5000 -# endif - -typedef struct s_netnext_line -{ - int fd; - char *reminder; - struct s_netnext_line *next; -} t_netnext_line; - -int get_next_line(int fd, char **line); -int ft_rn(char *str); -size_t ft_strlen(const char *s); -char *ft_strjoin(const char *s1, const char *s2); - -#endif diff --git a/get_next_line/get_next_line_utils_bonus.c b/get_next_line/get_next_line_utils_bonus.c deleted file mode 100644 index 8d282bc..0000000 --- a/get_next_line/get_next_line_utils_bonus.c +++ /dev/null @@ -1,83 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_utils_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mdenys +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/11/14 10:50:53 by mdenys #+# #+# */ -/* Updated: 2020/11/17 23:56:22 by mdenys ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line_bonus.h" - -size_t ft_strlen(const char *s) -{ - int i; - - i = 0; - if (!s) - return (0); - while (s[i] != '\0') - i++; - return (i); -} - -void *ft_memmove(void *dst, const void *src, size_t len) -{ - char *d; - char *s; - - d = (char *)dst; - s = (char *)src; - if (dst == src) - return (dst); - if (s < d) - { - while (len--) - *(d + len) = *(s + len); - return (dst); - } - while (len--) - *d++ = *s++; - return (dst); -} - -char *ft_strjoin(char const *s1, char const *s2) -{ - size_t s1_len; - size_t s2_len; - size_t stot_len; - char *rtn; - - if (!s1 && !s2) - return (0); - s1_len = ft_strlen((char *)s1); - s2_len = ft_strlen((char *)s2); - stot_len = s1_len + s2_len + 1; - rtn = malloc(sizeof(char) * stot_len); - if (!rtn) - return (0); - ft_memmove(rtn, s1, s1_len); - ft_memmove(rtn + s1_len, s2, s2_len); - rtn[stot_len - 1] = '\0'; - free((char *)s1); - return (rtn); -} - -int ft_rn(char *str) -{ - int i; - - i = 0; - if (!str) - return (0); - while (str[i]) - { - if (str[i] == '\n') - return (1); - i++; - } - return (0); -} diff --git a/main.c b/main.c new file mode 100644 index 0000000..e0918dd --- /dev/null +++ b/main.c @@ -0,0 +1,9 @@ +#include "ft_printf_include_libft/ft_printf.h" +#include "ft_printf_include_libft/libft/includes/libft.h" +#include "ft_printf_include_libft/libft/includes/get_next_line.h" + +int main() +{ + ft_printf("test\n"); + ft_printf("%d,\n", ft_strlen("test")); +}