From 12841d09c84cacbd042266abc09f127ff612448f Mon Sep 17 00:00:00 2001 From: hysimok Date: Mon, 22 Jun 2020 15:18:25 +0900 Subject: [PATCH] merge libft.a with libftprintf.a --- ft_printf/Libft/Makefile | 53 +++++++++++++++++++ ft_printf/Libft/ft_atoi.c | 37 +++++++++++++ ft_printf/Libft/ft_bzero.c | 28 ++++++++++ ft_printf/Libft/ft_calloc.c | 32 +++++++++++ ft_printf/Libft/ft_isalnum.c | 20 +++++++ ft_printf/Libft/ft_isalpha.c | 20 +++++++ ft_printf/Libft/ft_isascii.c | 20 +++++++ ft_printf/Libft/ft_isdigit.c | 20 +++++++ ft_printf/Libft/ft_isprint.c | 20 +++++++ ft_printf/Libft/ft_itoa.c | 63 ++++++++++++++++++++++ ft_printf/Libft/ft_lstadd_back.c | 28 ++++++++++ ft_printf/Libft/ft_lstadd_front.c | 19 +++++++ ft_printf/Libft/ft_lstclear.c | 30 +++++++++++ ft_printf/Libft/ft_lstdelone.c | 19 +++++++ ft_printf/Libft/ft_lstiter.c | 22 ++++++++ ft_printf/Libft/ft_lstlast.c | 27 ++++++++++ ft_printf/Libft/ft_lstmap.c | 48 +++++++++++++++++ ft_printf/Libft/ft_lstnew.c | 25 +++++++++ ft_printf/Libft/ft_lstsize.c | 32 +++++++++++ ft_printf/Libft/ft_memccpy.c | 32 +++++++++++ ft_printf/Libft/ft_memchr.c | 29 ++++++++++ ft_printf/Libft/ft_memcmp.c | 32 +++++++++++ ft_printf/Libft/ft_memcpy.c | 32 +++++++++++ ft_printf/Libft/ft_memmove.c | 50 ++++++++++++++++++ ft_printf/Libft/ft_memset.c | 28 ++++++++++ ft_printf/Libft/ft_putchar_fd.c | 18 +++++++ ft_printf/Libft/ft_putendl_fd.c | 28 ++++++++++ ft_printf/Libft/ft_putnbr_fd.c | 55 +++++++++++++++++++ ft_printf/Libft/ft_putstr_fd.c | 27 ++++++++++ ft_printf/Libft/ft_split.c | 88 +++++++++++++++++++++++++++++++ ft_printf/Libft/ft_strchr.c | 27 ++++++++++ ft_printf/Libft/ft_strdup.c | 32 +++++++++++ ft_printf/Libft/ft_strjoin.c | 41 ++++++++++++++ ft_printf/Libft/ft_strlcat.c | 40 ++++++++++++++ ft_printf/Libft/ft_strlcpy.c | 33 ++++++++++++ ft_printf/Libft/ft_strlen.c | 25 +++++++++ ft_printf/Libft/ft_strmapi.c | 33 ++++++++++++ ft_printf/Libft/ft_strncmp.c | 34 ++++++++++++ ft_printf/Libft/ft_strnstr.c | 46 ++++++++++++++++ ft_printf/Libft/ft_strrchr.c | 31 +++++++++++ ft_printf/Libft/ft_strtrim.c | 88 +++++++++++++++++++++++++++++++ ft_printf/Libft/ft_substr.c | 35 ++++++++++++ ft_printf/Libft/ft_tolower.c | 21 ++++++++ ft_printf/Libft/ft_toupper.c | 21 ++++++++ ft_printf/Libft/libft.h | 68 ++++++++++++++++++++++++ ft_printf/Makefile | 38 +++++++++++++ ft_printf/ft_printf.c | 20 +++++++ ft_printf/includes/ft_printf.h | 7 +++ ft_printf/run.sh | 1 + 49 files changed, 1623 insertions(+) create mode 100644 ft_printf/Libft/Makefile create mode 100644 ft_printf/Libft/ft_atoi.c create mode 100644 ft_printf/Libft/ft_bzero.c create mode 100644 ft_printf/Libft/ft_calloc.c create mode 100644 ft_printf/Libft/ft_isalnum.c create mode 100644 ft_printf/Libft/ft_isalpha.c create mode 100644 ft_printf/Libft/ft_isascii.c create mode 100644 ft_printf/Libft/ft_isdigit.c create mode 100644 ft_printf/Libft/ft_isprint.c create mode 100644 ft_printf/Libft/ft_itoa.c create mode 100644 ft_printf/Libft/ft_lstadd_back.c create mode 100644 ft_printf/Libft/ft_lstadd_front.c create mode 100644 ft_printf/Libft/ft_lstclear.c create mode 100644 ft_printf/Libft/ft_lstdelone.c create mode 100644 ft_printf/Libft/ft_lstiter.c create mode 100644 ft_printf/Libft/ft_lstlast.c create mode 100644 ft_printf/Libft/ft_lstmap.c create mode 100644 ft_printf/Libft/ft_lstnew.c create mode 100644 ft_printf/Libft/ft_lstsize.c create mode 100644 ft_printf/Libft/ft_memccpy.c create mode 100644 ft_printf/Libft/ft_memchr.c create mode 100644 ft_printf/Libft/ft_memcmp.c create mode 100644 ft_printf/Libft/ft_memcpy.c create mode 100644 ft_printf/Libft/ft_memmove.c create mode 100644 ft_printf/Libft/ft_memset.c create mode 100644 ft_printf/Libft/ft_putchar_fd.c create mode 100644 ft_printf/Libft/ft_putendl_fd.c create mode 100644 ft_printf/Libft/ft_putnbr_fd.c create mode 100644 ft_printf/Libft/ft_putstr_fd.c create mode 100644 ft_printf/Libft/ft_split.c create mode 100644 ft_printf/Libft/ft_strchr.c create mode 100644 ft_printf/Libft/ft_strdup.c create mode 100644 ft_printf/Libft/ft_strjoin.c create mode 100644 ft_printf/Libft/ft_strlcat.c create mode 100644 ft_printf/Libft/ft_strlcpy.c create mode 100644 ft_printf/Libft/ft_strlen.c create mode 100644 ft_printf/Libft/ft_strmapi.c create mode 100644 ft_printf/Libft/ft_strncmp.c create mode 100644 ft_printf/Libft/ft_strnstr.c create mode 100644 ft_printf/Libft/ft_strrchr.c create mode 100644 ft_printf/Libft/ft_strtrim.c create mode 100644 ft_printf/Libft/ft_substr.c create mode 100644 ft_printf/Libft/ft_tolower.c create mode 100644 ft_printf/Libft/ft_toupper.c create mode 100644 ft_printf/Libft/libft.h create mode 100644 ft_printf/Makefile create mode 100644 ft_printf/ft_printf.c create mode 100644 ft_printf/includes/ft_printf.h create mode 100755 ft_printf/run.sh diff --git a/ft_printf/Libft/Makefile b/ft_printf/Libft/Makefile new file mode 100644 index 0000000..ea1cffa --- /dev/null +++ b/ft_printf/Libft/Makefile @@ -0,0 +1,53 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: hysimok +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/02/28 20:00:06 by hjung #+# #+# # +# Updated: 2020/06/22 12:40:19 by hysimok ### ########.fr # +# # +# **************************************************************************** # + +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_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strnstr.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_calloc.c ft_strdup.c\ + ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr.c\ + +OBJS = ft_memset.o ft_bzero.o ft_memcpy.o ft_memccpy.o ft_memmove.o ft_memchr.o ft_memcmp.o\ + ft_strlen.o ft_strlcpy.o ft_strlcat.o ft_strchr.o ft_strrchr.o ft_strnstr.o ft_strncmp.o\ + ft_atoi.o ft_isalpha.o ft_isdigit.o ft_isalnum.o ft_isascii.o ft_isprint.o ft_toupper.o ft_tolower.o\ + ft_calloc.o ft_strdup.o\ + ft_substr.o ft_strjoin.o ft_strtrim.o ft_split.o ft_itoa.o ft_strmapi.o ft_putchar_fd.o ft_putstr_fd.o ft_putendl_fd.o ft_putnbr_fd.o\ + +B_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c +B_OBJS = ft_lstnew.o ft_lstadd_front.o ft_lstsize.o ft_lstlast.o ft_lstadd_back.o ft_lstdelone.o ft_lstclear.o ft_lstiter.o ft_lstmap.o + +CC = gcc +CFLAGS = -Wall -Wextra -Werror + +RM = rm -f + +.c.o: + ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} + +all: $(NAME) + +$(NAME): ${OBJS} + ar rsc $(NAME) ${OBJS} + +bonus: ${OBJS} ${B_OBJS} + ar rsc $(NAME) ${OBJS} ${B_OBJS} + +clean: + ${RM} ${OBJS} ${B_OBJS} + +fclean: clean + ${RM} $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ft_printf/Libft/ft_atoi.c b/ft_printf/Libft/ft_atoi.c new file mode 100644 index 0000000..ad8a996 --- /dev/null +++ b/ft_printf/Libft/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 18:31:33 by hjung #+# #+# */ +/* Updated: 2020/03/03 18:40:32 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_atoi(const char *str) +{ + int cnt_minus; + int res; + + cnt_minus = 1; + res = 0; + while (*str == '\t' || *str == '\n' || *str == '\v' || + *str == '\f' || *str == '\r' || *str == ' ') + str++; + if (*str == '-' || *str == '+') + { + if (*str == '-') + cnt_minus *= (-1); + str++; + } + while (*str >= '0' && *str <= '9') + { + res = (res * 10) + (*str - '0'); + str++; + } + return (res * cnt_minus); +} diff --git a/ft_printf/Libft/ft_bzero.c b/ft_printf/Libft/ft_bzero.c new file mode 100644 index 0000000..858ad4f --- /dev/null +++ b/ft_printf/Libft/ft_bzero.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 19:07:20 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:00:50 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + size_t i; + + i = 0; + if (n != 0) + { + while (i < n) + { + ((char *)s)[i] = '\0'; + i++; + } + } +} diff --git a/ft_printf/Libft/ft_calloc.c b/ft_printf/Libft/ft_calloc.c new file mode 100644 index 0000000..f01ad2e --- /dev/null +++ b/ft_printf/Libft/ft_calloc.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/05 15:42:35 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:01:25 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + size_t total_size; + size_t i; + unsigned char *ptr; + + i = 0; + total_size = count * size; + ptr = (unsigned char *)malloc(total_size); + if (!ptr) + return (void *)(NULL); + while (i < total_size) + { + ptr[i] = '\0'; + i++; + } + return (void *)(ptr); +} diff --git a/ft_printf/Libft/ft_isalnum.c b/ft_printf/Libft/ft_isalnum.c new file mode 100644 index 0000000..55de6b9 --- /dev/null +++ b/ft_printf/Libft/ft_isalnum.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:19:36 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:20:31 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) || ft_isdigit(c)) + return (1); + return (0); +} diff --git a/ft_printf/Libft/ft_isalpha.c b/ft_printf/Libft/ft_isalpha.c new file mode 100644 index 0000000..ad0bb18 --- /dev/null +++ b/ft_printf/Libft/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 18:49:16 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:08:59 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + return (1); + return (0); +} diff --git a/ft_printf/Libft/ft_isascii.c b/ft_printf/Libft/ft_isascii.c new file mode 100644 index 0000000..4fbed23 --- /dev/null +++ b/ft_printf/Libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:21:32 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:23:26 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + return (0); +} diff --git a/ft_printf/Libft/ft_isdigit.c b/ft_printf/Libft/ft_isdigit.c new file mode 100644 index 0000000..5428d5a --- /dev/null +++ b/ft_printf/Libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:11:12 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:14:29 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/ft_printf/Libft/ft_isprint.c b/ft_printf/Libft/ft_isprint.c new file mode 100644 index 0000000..16eb312 --- /dev/null +++ b/ft_printf/Libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:26:16 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:27:48 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c < 127) + return (1); + return (0); +} diff --git a/ft_printf/Libft/ft_itoa.c b/ft_printf/Libft/ft_itoa.c new file mode 100644 index 0000000..592bc3a --- /dev/null +++ b/ft_printf/Libft/ft_itoa.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/08 21:55:36 by hjung #+# #+# */ +/* Updated: 2020/04/06 00:21:50 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_num_len(int n) +{ + int len; + + len = 0; + while (n != 0) + { + n /= 10; + len++; + } + return (len); +} + +char *ft_minus(char *res, int n, int len) +{ + while (n < 0) + { + res[--len] = '0' + ((n % 10) * (-1)); + n /= 10; + } + res[--len] = '-'; + return (res); +} + +char *ft_itoa(int n) +{ + char *res; + int len; + + len = ft_num_len(n) + 2; + res = (char *)malloc(len); + if (!res) + return (NULL); + res[--len] = '\0'; + if (n < 0) + res = ft_minus(res, n, len); + else if (n == 0) + res[--len] = '0'; + else + { + res[--len] = '\0'; + while (n > 0) + { + res[--len] = '0' + (n % 10); + n /= 10; + } + } + return (res); +} diff --git a/ft_printf/Libft/ft_lstadd_back.c b/ft_printf/Libft/ft_lstadd_back.c new file mode 100644 index 0000000..4dedb4c --- /dev/null +++ b/ft_printf/Libft/ft_lstadd_back.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 13:46:34 by hjung #+# #+# */ +/* Updated: 2020/04/14 21:23:18 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *pnode; + + pnode = (*lst); + if (pnode == NULL) + (*lst) = new; + else + { + while (pnode->next != NULL) + pnode = pnode->next; + pnode->next = new; + } +} diff --git a/ft_printf/Libft/ft_lstadd_front.c b/ft_printf/Libft/ft_lstadd_front.c new file mode 100644 index 0000000..868f0b1 --- /dev/null +++ b/ft_printf/Libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 11:19:45 by hjung #+# #+# */ +/* Updated: 2020/03/19 11:53:56 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/ft_printf/Libft/ft_lstclear.c b/ft_printf/Libft/ft_lstclear.c new file mode 100644 index 0000000..89ea85d --- /dev/null +++ b/ft_printf/Libft/ft_lstclear.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 20:19:29 by hjung #+# #+# */ +/* Updated: 2020/04/14 22:17:47 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *delnode; + + delnode = (*lst); + (*lst) = (*lst)->next; + del(delnode->content); + free(delnode); + while (*lst) + { + delnode = (*lst); + (*lst) = (*lst)->next; + del(delnode->content); + free(delnode); + } +} diff --git a/ft_printf/Libft/ft_lstdelone.c b/ft_printf/Libft/ft_lstdelone.c new file mode 100644 index 0000000..abe3f74 --- /dev/null +++ b/ft_printf/Libft/ft_lstdelone.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 15:59:48 by hjung #+# #+# */ +/* Updated: 2020/03/19 20:18:48 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + del(lst->content); + free(lst); +} diff --git a/ft_printf/Libft/ft_lstiter.c b/ft_printf/Libft/ft_lstiter.c new file mode 100644 index 0000000..f80837f --- /dev/null +++ b/ft_printf/Libft/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 21:47:48 by hjung #+# #+# */ +/* Updated: 2020/03/19 21:52:31 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + while (lst) + { + f(lst->content); + lst = lst->next; + } +} diff --git a/ft_printf/Libft/ft_lstlast.c b/ft_printf/Libft/ft_lstlast.c new file mode 100644 index 0000000..df3e0e4 --- /dev/null +++ b/ft_printf/Libft/ft_lstlast.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 11:55:52 by hjung #+# #+# */ +/* Updated: 2020/04/15 13:16:33 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + t_list *cur; + + if (lst == NULL) + return (NULL); + cur = lst; + while (cur->next != NULL) + { + cur = cur->next; + } + return (cur); +} diff --git a/ft_printf/Libft/ft_lstmap.c b/ft_printf/Libft/ft_lstmap.c new file mode 100644 index 0000000..72a94e1 --- /dev/null +++ b/ft_printf/Libft/ft_lstmap.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 21:58:56 by hjung #+# #+# */ +/* Updated: 2020/04/14 21:52:04 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void clearall(t_list *lst, void (*del)(void *)) +{ + while (lst) + { + del(lst->content); + free(lst); + lst = lst->next; + } +} + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *newlist; + t_list *newnode; + t_list *tail; + + newlist = NULL; + while (lst) + { + newnode = ft_lstnew((*f)(lst->content)); + if (!newnode) + { + clearall(newlist, del); + return (NULL); + } + if (newlist == NULL) + newlist = newnode; + else + tail->next = newnode; + tail = newnode; + lst = lst->next; + } + return (newlist); +} diff --git a/ft_printf/Libft/ft_lstnew.c b/ft_printf/Libft/ft_lstnew.c new file mode 100644 index 0000000..5c09c94 --- /dev/null +++ b/ft_printf/Libft/ft_lstnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/18 23:23:14 by hjung #+# #+# */ +/* Updated: 2020/04/14 19:08:12 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *newnode; + + newnode = (t_list *)malloc(sizeof(t_list)); + if (!newnode) + return (NULL); + newnode->content = content; + newnode->next = NULL; + return (newnode); +} diff --git a/ft_printf/Libft/ft_lstsize.c b/ft_printf/Libft/ft_lstsize.c new file mode 100644 index 0000000..9d7f04f --- /dev/null +++ b/ft_printf/Libft/ft_lstsize.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/19 11:41:32 by hjung #+# #+# */ +/* Updated: 2020/04/14 21:19:55 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int cnt; + + cnt = 0; + if (lst == NULL) + return (0); + else + { + while (lst->next != NULL) + { + cnt++; + lst = lst->next; + } + cnt++; + return (cnt); + } +} diff --git a/ft_printf/Libft/ft_memccpy.c b/ft_printf/Libft/ft_memccpy.c new file mode 100644 index 0000000..564b820 --- /dev/null +++ b/ft_printf/Libft/ft_memccpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/29 22:24:21 by hjung #+# #+# */ +/* Updated: 2020/04/15 02:32:22 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memccpy(void *dst, const void *src, int c, size_t n) +{ + size_t i; + unsigned char *s1; + unsigned char *s2; + + s1 = (unsigned char *)dst; + s2 = (unsigned char *)src; + i = 0; + while (i < n) + { + s1[i] = s2[i]; + if (s2[i] == (unsigned char)c) + return (s1 + i + 1); + i++; + } + return (NULL); +} diff --git a/ft_printf/Libft/ft_memchr.c b/ft_printf/Libft/ft_memchr.c new file mode 100644 index 0000000..f2070a9 --- /dev/null +++ b/ft_printf/Libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/01 16:42:41 by hjung #+# #+# */ +/* Updated: 2020/04/05 19:51:34 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + unsigned char *str; + + str = (unsigned char *)s; + i = 0; + while (i < n) + { + if (str[i] == (unsigned char)c) + return (str + i); + i++; + } + return (NULL); +} diff --git a/ft_printf/Libft/ft_memcmp.c b/ft_printf/Libft/ft_memcmp.c new file mode 100644 index 0000000..dad6a2d --- /dev/null +++ b/ft_printf/Libft/ft_memcmp.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/01 17:02:14 by hjung #+# #+# */ +/* Updated: 2020/04/05 19:53:48 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + unsigned char *arr1; + unsigned char *arr2; + + arr1 = (unsigned char *)s1; + arr2 = (unsigned char *)s2; + i = 0; + while (i < n) + { + if (arr1[i] == arr2[i]) + i++; + else + return (arr1[i] - arr2[i]); + } + return (0); +} diff --git a/ft_printf/Libft/ft_memcpy.c b/ft_printf/Libft/ft_memcpy.c new file mode 100644 index 0000000..4f1e548 --- /dev/null +++ b/ft_printf/Libft/ft_memcpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 21:15:10 by hjung #+# #+# */ +/* Updated: 2020/04/15 00:57:51 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + unsigned char *s1; + unsigned char *s2; + + if (dst == NULL && src == NULL) + return (NULL); + s1 = (unsigned char *)dst; + s2 = (unsigned char *)src; + i = 0; + while (i < n) + { + s1[i] = s2[i]; + i++; + } + return (dst); +} diff --git a/ft_printf/Libft/ft_memmove.c b/ft_printf/Libft/ft_memmove.c new file mode 100644 index 0000000..1db3ad2 --- /dev/null +++ b/ft_printf/Libft/ft_memmove.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/01 00:07:18 by hjung #+# #+# */ +/* Updated: 2020/04/15 03:23:29 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_move(unsigned char *dst, unsigned char *src, size_t n) +{ + size_t i; + + i = 0; + if (src < dst) + { + while (i < n) + { + dst[n - i - 1] = src[n - i - 1]; + i++; + } + } + else + { + while (i < n) + { + dst[i] = src[i]; + i++; + } + } + return (dst); +} + +void *ft_memmove(void *dst, const void *src, size_t n) +{ + unsigned char *dst_ptr; + unsigned char *src_ptr; + + if (dst == NULL && src == NULL) + return (NULL); + dst_ptr = (unsigned char *)dst; + src_ptr = (unsigned char *)src; + dst_ptr = ft_move(dst_ptr, src_ptr, n); + return (dst); +} diff --git a/ft_printf/Libft/ft_memset.c b/ft_printf/Libft/ft_memset.c new file mode 100644 index 0000000..8ccb8e9 --- /dev/null +++ b/ft_printf/Libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 02:01:45 by hjung #+# #+# */ +/* Updated: 2020/04/05 19:52:37 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t n) +{ + unsigned char *temp; + size_t i; + + i = 0; + temp = (unsigned char *)b; + while (i != n) + { + *(temp + i) = (unsigned char)c; + i++; + } + return (b); +} diff --git a/ft_printf/Libft/ft_putchar_fd.c b/ft_printf/Libft/ft_putchar_fd.c new file mode 100644 index 0000000..96e1e18 --- /dev/null +++ b/ft_printf/Libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/09 12:43:09 by hjung #+# #+# */ +/* Updated: 2020/03/09 14:34:45 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/ft_printf/Libft/ft_putendl_fd.c b/ft_printf/Libft/ft_putendl_fd.c new file mode 100644 index 0000000..02c4de7 --- /dev/null +++ b/ft_printf/Libft/ft_putendl_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/09 15:21:13 by hjung #+# #+# */ +/* Updated: 2020/04/17 17:20:45 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + if (s == NULL) + return (void)(NULL); + i = 0; + while (s[i] != '\0') + { + ft_putchar_fd(s[i], fd); + i++; + } + write(fd, "\n", 1); +} diff --git a/ft_printf/Libft/ft_putnbr_fd.c b/ft_printf/Libft/ft_putnbr_fd.c new file mode 100644 index 0000000..5f36497 --- /dev/null +++ b/ft_printf/Libft/ft_putnbr_fd.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/09 15:28:20 by hjung #+# #+# */ +/* Updated: 2020/04/06 15:34:57 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void caseofmin(int nb, int fd) +{ + int i; + char arr[11]; + + i = 10; + arr[0] = '-'; + while (i > 0) + { + arr[i] = '0' - (nb % 10); + nb /= 10; + i--; + } + i = 0; + while (i < 11) + { + ft_putchar_fd(arr[i], fd); + i++; + } +} + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + caseofmin(n, fd); + } + else if (n < 0) + { + write(fd, "-", 1); + n *= -1; + ft_putnbr_fd(n, fd); + } + else if (n > 9) + { + ft_putnbr_fd(n / 10, fd); + ft_putchar_fd('0' + n % 10, fd); + } + else + ft_putchar_fd('0' + n, fd); +} diff --git a/ft_printf/Libft/ft_putstr_fd.c b/ft_printf/Libft/ft_putstr_fd.c new file mode 100644 index 0000000..f2368f4 --- /dev/null +++ b/ft_printf/Libft/ft_putstr_fd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/09 14:36:55 by hjung #+# #+# */ +/* Updated: 2020/04/17 17:21:38 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + if (s == NULL) + return (void)(NULL); + i = 0; + while (s[i] != '\0') + { + ft_putchar_fd(s[i], fd); + i++; + } +} diff --git a/ft_printf/Libft/ft_split.c b/ft_printf/Libft/ft_split.c new file mode 100644 index 0000000..01e856e --- /dev/null +++ b/ft_printf/Libft/ft_split.c @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/07 02:12:16 by hjung #+# #+# */ +/* Updated: 2020/04/19 11:25:34 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int w_cnt(const char *str, char c) +{ + int i; + int word_cnt; + + i = 0; + word_cnt = 0; + while (str[i] != '\0') + { + if (((i == 0) && (str[i] != c)) || ((str[i] != c) && (str[i - 1] == c))) + word_cnt++; + i++; + } + return (word_cnt + 1); +} + +int ft_word_len(const char *word, char c) +{ + int i; + + i = 0; + while ((word[i] != c) && (word[i] != '\0')) + i++; + return (i); +} + +int ft_add(const char *str, char c, char *res) +{ + int i; + + i = 0; + while ((str[i] != c) && str[i] != '\0') + { + res[i] = str[i]; + i++; + } + res[i] = '\0'; + return (i); +} + +void ft_increment(char letter, int *i) +{ + if (letter != '\0') + *i += 1; +} + +char **ft_split(char const *s, char c) +{ + char **res; + int i; + int line; + + i = 0; + line = 0; + if (s == 0 || (res = (char **)malloc(sizeof(char *) * w_cnt(s, c))) == NULL) + return (NULL); + while (s[i] != '\0') + { + if (((i == 0) && (s[i] != c)) || ((s[i] != c) && (s[i - 1] == c))) + { + if ((res[line] = (char *)malloc(ft_word_len(&s[i], c) + 1)) == NULL) + { + while (--line >= 0) + free(res[line]); + return (NULL); + } + i += ft_add(&s[i], c, res[line]); + line++; + } + ft_increment(s[i], &i); + } + res[line] = 0; + return (res); +} diff --git a/ft_printf/Libft/ft_strchr.c b/ft_printf/Libft/ft_strchr.c new file mode 100644 index 0000000..911b03e --- /dev/null +++ b/ft_printf/Libft/ft_strchr.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 12:42:20 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:03:51 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i] != (char)c) + { + if (s[i] == '\0') + return (NULL); + i++; + } + return (char *)(s + i); +} diff --git a/ft_printf/Libft/ft_strdup.c b/ft_printf/Libft/ft_strdup.c new file mode 100644 index 0000000..8c8fe3b --- /dev/null +++ b/ft_printf/Libft/ft_strdup.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/05 17:54:36 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:04:11 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *src) +{ + char *box; + int i; + + i = ft_strlen(src); + box = (char *)malloc(i + 1); + if (!box) + return (NULL); + i = 0; + while (src[i] != '\0') + { + box[i] = src[i]; + i++; + } + box[i] = '\0'; + return (box); +} diff --git a/ft_printf/Libft/ft_strjoin.c b/ft_printf/Libft/ft_strjoin.c new file mode 100644 index 0000000..16d8737 --- /dev/null +++ b/ft_printf/Libft/ft_strjoin.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/06 17:14:33 by hjung #+# #+# */ +/* Updated: 2020/04/17 16:41:10 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *res; + int i; + int j; + + if (s1 == NULL || s2 == NULL) + return (NULL); + i = 0; + j = 0; + res = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); + if (!res) + return (NULL); + while (s1[i] != '\0') + { + res[i] = s1[i]; + i++; + } + while (s2[j] != '\0') + { + res[i] = s2[j]; + i++; + j++; + } + res[i] = '\0'; + return (res); +} diff --git a/ft_printf/Libft/ft_strlcat.c b/ft_printf/Libft/ft_strlcat.c new file mode 100644 index 0000000..93578b9 --- /dev/null +++ b/ft_printf/Libft/ft_strlcat.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/02 18:21:29 by hjung #+# #+# */ +/* Updated: 2020/04/06 00:09:34 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t i; + size_t j; + size_t dstlen; + size_t srclen; + + dstlen = ft_strlen(dst); + srclen = ft_strlen(src); + if (dstlen >= size) + return (srclen + size); + else + { + i = 0; + j = dstlen; + while (size - dstlen - 1 > 0 && src[i] != '\0') + { + dst[j] = src[i]; + j++; + i++; + size--; + } + dst[j] = '\0'; + return (dstlen + srclen); + } +} diff --git a/ft_printf/Libft/ft_strlcpy.c b/ft_printf/Libft/ft_strlcpy.c new file mode 100644 index 0000000..9633a02 --- /dev/null +++ b/ft_printf/Libft/ft_strlcpy.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/02 17:45:07 by hjung #+# #+# */ +/* Updated: 2020/04/15 03:39:41 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dst, const char *src, size_t size) +{ + size_t i; + size_t len; + + if (dst == NULL && src == NULL) + return (0); + i = 0; + len = ft_strlen(src); + if (size == 0) + return (len); + while ((i < (size - 1)) && (src[i] != '\0')) + { + dst[i] = src[i]; + i++; + } + dst[i] = '\0'; + return (len); +} diff --git a/ft_printf/Libft/ft_strlen.c b/ft_printf/Libft/ft_strlen.c new file mode 100644 index 0000000..4be555e --- /dev/null +++ b/ft_printf/Libft/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/02 17:39:01 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:10:00 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + int len; + + len = 0; + while (str[len] != '\0') + { + len++; + } + return (len); +} diff --git a/ft_printf/Libft/ft_strmapi.c b/ft_printf/Libft/ft_strmapi.c new file mode 100644 index 0000000..cb93701 --- /dev/null +++ b/ft_printf/Libft/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/09 11:57:30 by hjung #+# #+# */ +/* Updated: 2020/04/17 16:43:55 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *res; + unsigned int i; + + if (s == NULL) + return (NULL); + res = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1)); + if (!res) + return (NULL); + i = 0; + while (s[i] != '\0') + { + res[i] = f(i, s[i]); + i++; + } + res[i] = '\0'; + return (res); +} diff --git a/ft_printf/Libft/ft_strncmp.c b/ft_printf/Libft/ft_strncmp.c new file mode 100644 index 0000000..e286653 --- /dev/null +++ b/ft_printf/Libft/ft_strncmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 17:49:45 by hjung #+# #+# */ +/* Updated: 2020/04/06 00:20:34 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + unsigned char *ps1; + unsigned char *ps2; + + i = 0; + ps1 = (unsigned char *)s1; + ps2 = (unsigned char *)s2; + if (n == 0) + return (0); + while (i < (n - 1) && (ps1[i] != '\0' && ps2[i] != '\0')) + { + if (ps1[i] != ps2[i]) + return (ps1[i] - ps2[i]); + else + i++; + } + return (ps1[i] - ps2[i]); +} diff --git a/ft_printf/Libft/ft_strnstr.c b/ft_printf/Libft/ft_strnstr.c new file mode 100644 index 0000000..8731336 --- /dev/null +++ b/ft_printf/Libft/ft_strnstr.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 15:01:04 by hjung #+# #+# */ +/* Updated: 2020/04/15 04:17:11 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_cmp(const char *s1, const char *s2) +{ + int i; + + i = 0; + while (s2[i] != '\0') + { + if (s1[i] == s2[i]) + i++; + else + return (0); + } + return (1); +} + +char *ft_strnstr(const char *str, const char *to_find, size_t n) +{ + size_t i; + + i = 0; + if (*to_find == '\0') + return (char *)(str); + while (str[i] && (i < n)) + { + if (n - i < ft_strlen(to_find)) + return (char *)(NULL); + if (ft_cmp(&str[i], to_find) == 1) + return ((char *)&str[i]); + i++; + } + return (char*)(NULL); +} diff --git a/ft_printf/Libft/ft_strrchr.c b/ft_printf/Libft/ft_strrchr.c new file mode 100644 index 0000000..9c43e27 --- /dev/null +++ b/ft_printf/Libft/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 14:06:16 by hjung #+# #+# */ +/* Updated: 2020/04/05 20:04:46 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int i; + char *tmp; + + i = 0; + tmp = NULL; + while (s[i] != '\0') + { + if (s[i] == (char)c) + tmp = (char *)s + i; + i++; + } + if (c == 0) + return (char *)(s + i); + return (tmp); +} diff --git a/ft_printf/Libft/ft_strtrim.c b/ft_printf/Libft/ft_strtrim.c new file mode 100644 index 0000000..f28b7ed --- /dev/null +++ b/ft_printf/Libft/ft_strtrim.c @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/06 22:28:38 by hjung #+# #+# */ +/* Updated: 2020/04/18 23:59:24 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_check(char const *set, char const letter) +{ + int i; + + i = 0; + while (set[i] != '\0') + { + if (letter == set[i]) + return (1); + i++; + } + return (0); +} + +int ft_res_len(char const *s1, char const *set) +{ + int head; + int tail; + int i; + + i = 0; + while (s1[i] != '\0') + { + if (ft_check(set, s1[i])) + i++; + else + break ; + } + head = i; + i = (int)(ft_strlen(s1)) - 1; + if (head == i + 1) + return (0); + while (i >= 0) + { + if (ft_check(set, s1[i])) + i--; + else + break ; + } + tail = i; + return (tail - head + 1); +} + +char *ft_input(char const *s1, char const *set) +{ + int res_len; + int i; + + i = 0; + res_len = ft_res_len(s1, set) + 1; + if (res_len == 1) + return (ft_strdup("")); + else + { + while (s1[i] != '\0') + { + if (ft_check(set, s1[i])) + i++; + else + break ; + } + return (ft_substr(s1, i, res_len - 1)); + } +} + +char *ft_strtrim(char const *s1, char const *set) +{ + char *res; + + if (s1 == NULL || set == NULL) + return (NULL); + res = ft_input(s1, set); + return (res); +} diff --git a/ft_printf/Libft/ft_substr.c b/ft_printf/Libft/ft_substr.c new file mode 100644 index 0000000..7c86f14 --- /dev/null +++ b/ft_printf/Libft/ft_substr.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/06 14:49:08 by hjung #+# #+# */ +/* Updated: 2020/04/17 16:38:58 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *res; + size_t i; + + if (s == NULL) + return (NULL); + if (start > ft_strlen(s)) + return (ft_strdup("")); + res = (char *)malloc(len + 1); + if (!res) + return (NULL); + i = 0; + while (i < len && s[i + start] != '\0') + { + res[i] = s[i + start]; + i++; + } + res[i] = '\0'; + return (res); +} diff --git a/ft_printf/Libft/ft_tolower.c b/ft_printf/Libft/ft_tolower.c new file mode 100644 index 0000000..89556c0 --- /dev/null +++ b/ft_printf/Libft/ft_tolower.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:39:45 by hjung #+# #+# */ +/* Updated: 2020/04/04 15:35:47 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + else + return (c); +} diff --git a/ft_printf/Libft/ft_toupper.c b/ft_printf/Libft/ft_toupper.c new file mode 100644 index 0000000..a782212 --- /dev/null +++ b/ft_printf/Libft/ft_toupper.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/03/03 22:33:18 by hjung #+# #+# */ +/* Updated: 2020/03/03 22:39:23 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + else + return (c); +} diff --git a/ft_printf/Libft/libft.h b/ft_printf/Libft/libft.h new file mode 100644 index 0000000..890e18d --- /dev/null +++ b/ft_printf/Libft/libft.h @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hjung +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/06 11:47:57 by hjung #+# #+# */ +/* Updated: 2020/04/06 18:09:07 by hjung ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H +# include +# include + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +void *ft_memset(void *b, int c, size_t n); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memccpy(void *dst, const void *src, int c, size_t n); +void *ft_memmove(void *dst, const void *src, size_t n); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +size_t ft_strlen(const char *str); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strnstr(const char *str, const char *to_find, size_t n); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_atoi(const char *str); +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_toupper(int c); +int ft_tolower(int c); +void *ft_calloc(size_t count, size_t size); +char *ft_strdup(const char *src); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_itoa(int n); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **lst, t_list *new); +void ft_lstdelone(t_list *lst, void (*del)(void *)); +void ft_lstclear(t_list **lst, void (*del)(void *)); +void ft_lstiter(t_list *lst, void (*f)(void *)); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), + void (*del)(void *)); +#endif diff --git a/ft_printf/Makefile b/ft_printf/Makefile new file mode 100644 index 0000000..1140156 --- /dev/null +++ b/ft_printf/Makefile @@ -0,0 +1,38 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: hysimok +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/06/19 22:35:11 by hysimok #+# #+# # +# Updated: 2020/06/22 15:02:46 by hysimok ### ########.fr # +# # +# **************************************************************************** # + +NAME = libftprintf.a +FLAGS = -Wall -Wextra -Werror +SRC = ft_printf.c +OBJ = $(SRC:.c=.o) +INC_LINK = -I./includes +LIBFT = -L./Libft -lft + +all : $(NAME) +$(NAME) : $(OBJ) libft + cp Libft/libft.a ./$(NAME) + ar rsc $(NAME) $(OBJ) + +%.o: %.c + gcc $(FLAGS) $(INC_LINK) -c $< -o $(<:.c=.o) + +# libft compile +libft : + @$(MAKE) -C ./Libft all +clean : + @$(MAKE) -C ./Libft clean + @rm -rf ${OBJ} +fclean : clean + @$(MAKE) -C ./Libft fclean + @rm -rf $(NAME) +re : fclean all +.PHONY: all clean fclean re libft \ No newline at end of file diff --git a/ft_printf/ft_printf.c b/ft_printf/ft_printf.c new file mode 100644 index 0000000..883b0e8 --- /dev/null +++ b/ft_printf/ft_printf.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hysimok +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/20 01:13:55 by hysimok #+# #+# */ +/* Updated: 2020/06/22 11:57:53 by hysimok ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +#include "ft_printf.h" + +int main(){ + char word[10] = "apple"; + printf("%zu\n", ft_strlen(word)); +} \ No newline at end of file diff --git a/ft_printf/includes/ft_printf.h b/ft_printf/includes/ft_printf.h new file mode 100644 index 0000000..fc6bb07 --- /dev/null +++ b/ft_printf/includes/ft_printf.h @@ -0,0 +1,7 @@ +#ifndef FT_PRINTF_H +# define FT_PRINTF_H +# include +# include +# include "../Libft/libft.h" + +#endif \ No newline at end of file diff --git a/ft_printf/run.sh b/ft_printf/run.sh new file mode 100755 index 0000000..65d4ad4 --- /dev/null +++ b/ft_printf/run.sh @@ -0,0 +1 @@ +gcc -Wall -Werror -Wextra ft_printf.o -I./includes -L. -lftprintf -o a.out \ No newline at end of file