diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 21dc717..2a26cc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,4 +19,4 @@ jobs: - name: download the repository run: git submodule update --init --recursive - name: make - run: make + run: make all FLAGS="" diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6e923b8..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "libft"] - path = libft - url = git@github.com:hamza-cskn/42-libft.git -[submodule "memory-allocator"] - path = memory-allocator - url = git@github.com:hamza-cskn/memory-allocator.git diff --git a/Makefile b/Makefile index c2486a5..d11e1f6 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,10 @@ $(NAME): $(LIBFT_PATH) $(MINISHELL_OBJECTS) clean: rm -f $(MINISHELL_OBJECTS) + make -f libft/Makefile clean fclean: clean - rm -f $(NAME) $(TEST_PATH)/tests + rm -f $(NAME) $(TEST_PATH)/tests $(LIBFT_PATH) re: fclean all diff --git a/builtin/cd.c b/builtin/cd.c index 6f27dd4..d9be8e3 100644 --- a/builtin/cd.c +++ b/builtin/cd.c @@ -3,10 +3,15 @@ /* ::: :::::::: */ /* cd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: facetint +#+ +:+ +#+ */ +/* By: hcoskun +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/cd.c /* Created: 2024/03/03 11:48:16 by facetint #+# #+# */ /* Updated: 2024/03/03 11:48:37 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 20:38:03 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 14:34:36 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_putchar_fd.c /* */ /* ************************************************************************** */ @@ -14,3 +19,10 @@ #include "../libft/libft.h" #include +<<<<<<< HEAD:builtin/cd.c +======= +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} +>>>>>>> main:libft/ft_putchar_fd.c diff --git a/builtin/export.c b/builtin/export.c index 7909086..c654522 100644 --- a/builtin/export.c +++ b/builtin/export.c @@ -3,10 +3,15 @@ /* ::: :::::::: */ /* export.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: facetint +#+ +:+ +#+ */ +/* By: hcoskun +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/export.c /* Created: 2024/03/02 14:15:14 by facetint #+# #+# */ /* Updated: 2024/03/03 11:39:15 by facetint ### ########.fr */ +======= +/* Created: 2023/07/08 16:18:16 by hcoskun #+# #+# */ +/* Updated: 2023/07/11 14:47:49 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_lstadd_back.c /* */ /* ************************************************************************** */ @@ -17,6 +22,7 @@ void builtin_export(t_command *cmd, int fd[2]) { +<<<<<<< HEAD:builtin/export.c (void)cmd; t_envList *tmp = get_global_env(); while (tmp) @@ -29,4 +35,20 @@ void builtin_export(t_command *cmd, int fd[2]) tmp = tmp->next; } -} \ No newline at end of file +} +======= + t_list *last_node; + + if (!lst) + return ; + if (!*lst) + { + *lst = new; + return ; + } + last_node = ft_lstlast(*lst); + if (!last_node) + return ; + last_node -> next = new; +} +>>>>>>> main:libft/ft_lstadd_back.c diff --git a/builtin/pwd.c b/builtin/pwd.c index 459ab0d..4f0de57 100644 --- a/builtin/pwd.c +++ b/builtin/pwd.c @@ -3,8 +3,9 @@ /* ::: :::::::: */ /* pwd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: facetint +#+ +:+ +#+ */ +/* By: hcoskun +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/pwd.c /* Created: 2024/03/02 13:41:06 by facetint #+# #+# */ /* Updated: 2024/03/03 13:17:22 by facetint ### ########.fr */ /* */ @@ -13,10 +14,19 @@ #include "../includes/minishell.h" #include "../libft/libft.h" #include +======= +/* Created: 2023/06/24 20:30:45 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:40:54 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +>>>>>>> main:libft/ft_calloc.c #include "../memory-allocator/allocator.h" void builtin_pwd(t_command *cmd) { +<<<<<<< HEAD:builtin/pwd.c (void)cmd; char *path; @@ -24,4 +34,13 @@ void builtin_pwd(t_command *cmd) getcwd(path, 4097); printf("%s\n", path); safe_free(path); +======= + void *result; + + result = safe_malloc(count * size); + if (result == NULL) + return (NULL); + ft_bzero(result, count * size); + return (result); +>>>>>>> main:libft/ft_calloc.c } diff --git a/builtin/unset.c b/builtin/unset.c index 5902250..7f3be34 100644 --- a/builtin/unset.c +++ b/builtin/unset.c @@ -3,10 +3,15 @@ /* ::: :::::::: */ /* unset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: facetint +#+ +:+ +#+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/unset.c /* Created: 2024/03/03 13:19:04 by facetint #+# #+# */ /* Updated: 2024/03/03 13:19:46 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 21:58:10 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:58:18 by hcoskun42 ### ########.tr */ +>>>>>>> main:libft/ft_putendl_fd.c /* */ /* ************************************************************************** */ @@ -15,3 +20,11 @@ #include #include "../memory-allocator/allocator.h" +<<<<<<< HEAD:builtin/unset.c +======= +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + write(fd, "\n", 1); +} +>>>>>>> main:libft/ft_putendl_fd.c diff --git a/handler.c b/handler.c index 818b6f8..4c85768 100644 --- a/handler.c +++ b/handler.c @@ -46,6 +46,9 @@ char const *token_type_to_string(t_token_type type) # define PARSER_DEBUG void debug(t_token *token, t_command *cmd) { (void) token,(void) cmd; + + + #ifdef PARSER_DEBUG if (!cmd) { printf(""); diff --git a/libft b/libft deleted file mode 160000 index 1038096..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 10380966b0f9585ce86646302d5d45f41acde867 diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..9448e3b --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,25 @@ +NAME = libft.a +CC = gcc +CFLAGS= -Wall -Wextra -Werror +SOURCES = ft_atoi.c ft_bzero.c ft_calloc.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c ft_isprint.c ft_itoa.c ft_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c ft_memset.c ft_putchar_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_putstr_fd.c ft_split.c ft_strchr.c ft_strdup.c ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlcpy.c ft_strlen.c ft_strmapi.c ft_strncmp.c ft_strnstr.c ft_strrchr.c ft_strtrim.c ft_substr.c ft_tolower.c ft_toupper.c +OBJECTS = $(SOURCES:.c=.o) + +BONUS_SOURCES = 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 +BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o) + +all: $(OBJECTS) + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + ar -rcs $(NAME) $@ + +clean: + rm -f $(OBJECTS) $(BONUS_OBJECTS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +bonus: $(OBJECTS) $(BONUS_OBJECTS) + ar -rc $(NAME) $(OBJECTS) $(BONUS_OBJECTS) diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..c2cec7e --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:55:40 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:18:52 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int natural_atoi(const char *str) +{ + int res; + + res = 0; + while (*str >= '0' && *str <= '9') + { + res = res * 10 + *str - '0'; + str++; + } + return (res); +} + +int ft_atoi(const char *str) +{ + int sign; + + sign = 1; + while (*str == ' ' || (*str >= 9 && *str <= 13)) + str++; + if (!*str) + return (0); + if (*str == '+' || *str == '-') + { + if (*str == '-') + sign *= -1; + str++; + } + return (sign * natural_atoi(str)); +} diff --git a/libft/ft_atoi.c.orig b/libft/ft_atoi.c.orig new file mode 100644 index 0000000..c2cec7e --- /dev/null +++ b/libft/ft_atoi.c.orig @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:55:40 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:18:52 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int natural_atoi(const char *str) +{ + int res; + + res = 0; + while (*str >= '0' && *str <= '9') + { + res = res * 10 + *str - '0'; + str++; + } + return (res); +} + +int ft_atoi(const char *str) +{ + int sign; + + sign = 1; + while (*str == ' ' || (*str >= 9 && *str <= 13)) + str++; + if (!*str) + return (0); + if (*str == '+' || *str == '-') + { + if (*str == '-') + sign *= -1; + str++; + } + return (sign * natural_atoi(str)); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..a6bc5ae --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:29:52 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:29:54 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/libft/ft_bzero.c.orig b/libft/ft_bzero.c.orig new file mode 100644 index 0000000..a6bc5ae --- /dev/null +++ b/libft/ft_bzero.c.orig @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:29:52 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:29:54 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..4f0de57 --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pwd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/pwd.c +/* Created: 2024/03/02 13:41:06 by facetint #+# #+# */ +/* Updated: 2024/03/03 13:17:22 by facetint ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include +======= +/* Created: 2023/06/24 20:30:45 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:40:54 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +>>>>>>> main:libft/ft_calloc.c +#include "../memory-allocator/allocator.h" + +void builtin_pwd(t_command *cmd) +{ +<<<<<<< HEAD:builtin/pwd.c + (void)cmd; + char *path; + + path = safe_malloc(sizeof(char) * 4097); + getcwd(path, 4097); + printf("%s\n", path); + safe_free(path); +======= + void *result; + + result = safe_malloc(count * size); + if (result == NULL) + return (NULL); + ft_bzero(result, count * size); + return (result); +>>>>>>> main:libft/ft_calloc.c +} diff --git a/libft/ft_calloc.c.orig b/libft/ft_calloc.c.orig new file mode 100644 index 0000000..4f0de57 --- /dev/null +++ b/libft/ft_calloc.c.orig @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pwd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/pwd.c +/* Created: 2024/03/02 13:41:06 by facetint #+# #+# */ +/* Updated: 2024/03/03 13:17:22 by facetint ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include +======= +/* Created: 2023/06/24 20:30:45 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:40:54 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +>>>>>>> main:libft/ft_calloc.c +#include "../memory-allocator/allocator.h" + +void builtin_pwd(t_command *cmd) +{ +<<<<<<< HEAD:builtin/pwd.c + (void)cmd; + char *path; + + path = safe_malloc(sizeof(char) * 4097); + getcwd(path, 4097); + printf("%s\n", path); + safe_free(path); +======= + void *result; + + result = safe_malloc(count * size); + if (result == NULL) + return (NULL); + ft_bzero(result, count * size); + return (result); +>>>>>>> main:libft/ft_calloc.c +} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100644 index 0000000..b3093f3 --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:31:13 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:31:14 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isalpha(c) || ft_isdigit(c)); +} diff --git a/libft/ft_isalnum.c.orig b/libft/ft_isalnum.c.orig new file mode 100644 index 0000000..b3093f3 --- /dev/null +++ b/libft/ft_isalnum.c.orig @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:31:13 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:31:14 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isalpha(c) || ft_isdigit(c)); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..b3670f9 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:31:43 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/01 11:58:38 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} diff --git a/libft/ft_isalpha.c.orig b/libft/ft_isalpha.c.orig new file mode 100644 index 0000000..b3670f9 --- /dev/null +++ b/libft/ft_isalpha.c.orig @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:31:43 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/01 11:58:38 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..61f48ec --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:32:30 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:32:31 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return (c >= 0 && c <= 127); +} diff --git a/libft/ft_isascii.c.orig b/libft/ft_isascii.c.orig new file mode 100644 index 0000000..61f48ec --- /dev/null +++ b/libft/ft_isascii.c.orig @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:32:30 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:32:31 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return (c >= 0 && c <= 127); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..5d622c4 --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:32:54 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:32:55 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/ft_isdigit.c.orig b/libft/ft_isdigit.c.orig new file mode 100644 index 0000000..5d622c4 --- /dev/null +++ b/libft/ft_isdigit.c.orig @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:32:54 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:32:55 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..47aaa00 --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:33:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:33:17 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int n) +{ + return (n >= 32 && n <= 126); +} diff --git a/libft/ft_isprint.c.orig b/libft/ft_isprint.c.orig new file mode 100644 index 0000000..47aaa00 --- /dev/null +++ b/libft/ft_isprint.c.orig @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:33:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 20:33:17 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int n) +{ + return (n >= 32 && n <= 126); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..c381c1e --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:20:00 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:42:49 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int digits(unsigned int n) +{ + int i; + + if (n == 0) + return (1); + i = 0; + while (n != 0) + { + n /= 10; + i++; + } + return (i); +} + +void natural_itoa(int nb, char *str) +{ + if (nb >= 10) + natural_itoa(nb / 10, str - 1); + *str = nb % 10 + '0'; +} + +char *ft_itoa(int n) +{ + char *result; + int len; + int is_negative; + + is_negative = n < 0; + if (is_negative) + { + if (n == -2147483648) + return (ft_strdup("-2147483648")); + n = -n; + } + len = digits(n) + is_negative; + result = (char *) malloc(sizeof(char) * (len + 1)); + if (!result) + return (NULL); + if (is_negative) + *result = '-'; + natural_itoa(n, result + len - 1); + result[len] = '\0'; + return (result); +} diff --git a/libft/ft_itoa.c.orig b/libft/ft_itoa.c.orig new file mode 100644 index 0000000..c381c1e --- /dev/null +++ b/libft/ft_itoa.c.orig @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:20:00 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:42:49 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int digits(unsigned int n) +{ + int i; + + if (n == 0) + return (1); + i = 0; + while (n != 0) + { + n /= 10; + i++; + } + return (i); +} + +void natural_itoa(int nb, char *str) +{ + if (nb >= 10) + natural_itoa(nb / 10, str - 1); + *str = nb % 10 + '0'; +} + +char *ft_itoa(int n) +{ + char *result; + int len; + int is_negative; + + is_negative = n < 0; + if (is_negative) + { + if (n == -2147483648) + return (ft_strdup("-2147483648")); + n = -n; + } + len = digits(n) + is_negative; + result = (char *) malloc(sizeof(char) * (len + 1)); + if (!result) + return (NULL); + if (is_negative) + *result = '-'; + natural_itoa(n, result + len - 1); + result[len] = '\0'; + return (result); +} diff --git a/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c new file mode 100644 index 0000000..c654522 --- /dev/null +++ b/libft/ft_lstadd_back.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* export.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/export.c +/* Created: 2024/03/02 14:15:14 by facetint #+# #+# */ +/* Updated: 2024/03/03 11:39:15 by facetint ### ########.fr */ +======= +/* Created: 2023/07/08 16:18:16 by hcoskun #+# #+# */ +/* Updated: 2023/07/11 14:47:49 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_lstadd_back.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../includes/env.h" +#include +#include "../libft/libft.h" + +void builtin_export(t_command *cmd, int fd[2]) +{ +<<<<<<< HEAD:builtin/export.c + (void)cmd; + t_envList *tmp = get_global_env(); + while (tmp) + { + write(fd[1], "declare -x ", 12); + write(fd[1], tmp->key, ft_strlen(tmp->key)); + write(fd[1], "=", 1); + write(fd[1], tmp->value, ft_strlen(tmp->value)); + write(fd[1], "\n", 1); + tmp = tmp->next; + } + +} +======= + t_list *last_node; + + if (!lst) + return ; + if (!*lst) + { + *lst = new; + return ; + } + last_node = ft_lstlast(*lst); + if (!last_node) + return ; + last_node -> next = new; +} +>>>>>>> main:libft/ft_lstadd_back.c diff --git a/libft/ft_lstadd_back.c.orig b/libft/ft_lstadd_back.c.orig new file mode 100644 index 0000000..c654522 --- /dev/null +++ b/libft/ft_lstadd_back.c.orig @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* export.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/export.c +/* Created: 2024/03/02 14:15:14 by facetint #+# #+# */ +/* Updated: 2024/03/03 11:39:15 by facetint ### ########.fr */ +======= +/* Created: 2023/07/08 16:18:16 by hcoskun #+# #+# */ +/* Updated: 2023/07/11 14:47:49 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_lstadd_back.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../includes/env.h" +#include +#include "../libft/libft.h" + +void builtin_export(t_command *cmd, int fd[2]) +{ +<<<<<<< HEAD:builtin/export.c + (void)cmd; + t_envList *tmp = get_global_env(); + while (tmp) + { + write(fd[1], "declare -x ", 12); + write(fd[1], tmp->key, ft_strlen(tmp->key)); + write(fd[1], "=", 1); + write(fd[1], tmp->value, ft_strlen(tmp->value)); + write(fd[1], "\n", 1); + tmp = tmp->next; + } + +} +======= + t_list *last_node; + + if (!lst) + return ; + if (!*lst) + { + *lst = new; + return ; + } + last_node = ft_lstlast(*lst); + if (!last_node) + return ; + last_node -> next = new; +} +>>>>>>> main:libft/ft_lstadd_back.c diff --git a/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c new file mode 100644 index 0000000..2f877f5 --- /dev/null +++ b/libft/ft_lstadd_front.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:37 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:18:10 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + if (!new) + return ; + new -> next = *lst; + *lst = new; +} diff --git a/libft/ft_lstadd_front.c.orig b/libft/ft_lstadd_front.c.orig new file mode 100644 index 0000000..2f877f5 --- /dev/null +++ b/libft/ft_lstadd_front.c.orig @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:37 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:18:10 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + if (!new) + return ; + new -> next = *lst; + *lst = new; +} diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c new file mode 100644 index 0000000..4be443a --- /dev/null +++ b/libft/ft_lstclear.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:56 by hcoskun #+# #+# */ +/* Updated: 2023/07/09 00:17:43 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *node; + t_list *tmp; + + if (!lst || !del) + return ; + node = *lst; + while (node) + { + tmp = node; + node = node -> next; + ft_lstdelone(tmp, del); + } + *lst = NULL; +} diff --git a/libft/ft_lstclear.c.orig b/libft/ft_lstclear.c.orig new file mode 100644 index 0000000..4be443a --- /dev/null +++ b/libft/ft_lstclear.c.orig @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:56 by hcoskun #+# #+# */ +/* Updated: 2023/07/09 00:17:43 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *node; + t_list *tmp; + + if (!lst || !del) + return ; + node = *lst; + while (node) + { + tmp = node; + node = node -> next; + ft_lstdelone(tmp, del); + } + *lst = NULL; +} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c new file mode 100644 index 0000000..4c0244a --- /dev/null +++ b/libft/ft_lstdelone.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:11 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:17:18 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst || !del) + return ; + del(lst -> content); + free(lst); +} diff --git a/libft/ft_lstdelone.c.orig b/libft/ft_lstdelone.c.orig new file mode 100644 index 0000000..4c0244a --- /dev/null +++ b/libft/ft_lstdelone.c.orig @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:17:11 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:17:18 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst || !del) + return ; + del(lst -> content); + free(lst); +} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c new file mode 100644 index 0000000..f8f34f6 --- /dev/null +++ b/libft/ft_lstiter.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:16:45 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:17:07 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + t_list *node; + + if (!lst || !f) + return ; + node = lst; + while (node) + { + f(node -> content); + node = node -> next; + } +} diff --git a/libft/ft_lstiter.c.orig b/libft/ft_lstiter.c.orig new file mode 100644 index 0000000..f8f34f6 --- /dev/null +++ b/libft/ft_lstiter.c.orig @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:16:45 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:17:07 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + t_list *node; + + if (!lst || !f) + return ; + node = lst; + while (node) + { + f(node -> content); + node = node -> next; + } +} diff --git a/libft/ft_lstlast.c b/libft/ft_lstlast.c new file mode 100644 index 0000000..d95018d --- /dev/null +++ b/libft/ft_lstlast.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:15:26 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:16:37 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + t_list *node; + + if (!lst) + return (NULL); + node = lst; + while (1) + { + if (node -> next) + node = node -> next; + else + return (node); + } +} diff --git a/libft/ft_lstlast.c.orig b/libft/ft_lstlast.c.orig new file mode 100644 index 0000000..d95018d --- /dev/null +++ b/libft/ft_lstlast.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:15:26 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:16:37 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + t_list *node; + + if (!lst) + return (NULL); + node = lst; + while (1) + { + if (node -> next) + node = node -> next; + else + return (node); + } +} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c new file mode 100644 index 0000000..d66b39b --- /dev/null +++ b/libft/ft_lstmap.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:14:57 by hcoskun #+# #+# */ +/* Updated: 2023/07/11 14:47:38 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *new_node; + void *content; + + if (!lst || !f || !del) + return (NULL); + content = f(lst -> content); + new_node = ft_lstnew(content); + if (!new_node) + { + del(content); + ft_lstclear(&new_node, del); + return (NULL); + } + new_node -> next = ft_lstmap(lst -> next, f, del); + return (new_node); +} diff --git a/libft/ft_lstmap.c.orig b/libft/ft_lstmap.c.orig new file mode 100644 index 0000000..d66b39b --- /dev/null +++ b/libft/ft_lstmap.c.orig @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:14:57 by hcoskun #+# #+# */ +/* Updated: 2023/07/11 14:47:38 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *new_node; + void *content; + + if (!lst || !f || !del) + return (NULL); + content = f(lst -> content); + new_node = ft_lstnew(content); + if (!new_node) + { + del(content); + ft_lstclear(&new_node, del); + return (NULL); + } + new_node -> next = ft_lstmap(lst -> next, f, del); + return (new_node); +} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c new file mode 100644 index 0000000..f9afe7a --- /dev/null +++ b/libft/ft_lstnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:13:30 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:14:49 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *node; + + node = (t_list *) malloc(sizeof(t_list)); + if (!node) + return (NULL); + node -> content = content; + node -> next = NULL; + return (node); +} diff --git a/libft/ft_lstnew.c.orig b/libft/ft_lstnew.c.orig new file mode 100644 index 0000000..f9afe7a --- /dev/null +++ b/libft/ft_lstnew.c.orig @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:13:30 by hcoskun #+# #+# */ +/* Updated: 2023/07/08 16:14:49 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *node; + + node = (t_list *) malloc(sizeof(t_list)); + if (!node) + return (NULL); + node -> content = content; + node -> next = NULL; + return (node); +} diff --git a/libft/ft_lstsize.c b/libft/ft_lstsize.c new file mode 100644 index 0000000..8e07629 --- /dev/null +++ b/libft/ft_lstsize.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:12:31 by hcoskun #+# #+# */ +/* Updated: 2023/07/10 17:14:56 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + t_list *node; + int len; + + if (!lst) + return (0); + node = lst; + len = 0; + while (node) + { + node = node -> next; + len++; + } + return (len); +} diff --git a/libft/ft_lstsize.c.orig b/libft/ft_lstsize.c.orig new file mode 100644 index 0000000..8e07629 --- /dev/null +++ b/libft/ft_lstsize.c.orig @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/08 16:12:31 by hcoskun #+# #+# */ +/* Updated: 2023/07/10 17:14:56 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + t_list *node; + int len; + + if (!lst) + return (0); + node = lst; + len = 0; + while (node) + { + node = node -> next; + len++; + } + return (len); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..0a2afe2 --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:34:22 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:23:07 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + const unsigned char *mem; + size_t i; + + mem = s; + i = 0; + while (i < n) + { + if (mem[i] == (unsigned char) c) + return ((void *)s + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_memchr.c.orig b/libft/ft_memchr.c.orig new file mode 100644 index 0000000..0a2afe2 --- /dev/null +++ b/libft/ft_memchr.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:34:22 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:23:07 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + const unsigned char *mem; + size_t i; + + mem = s; + i = 0; + while (i < n) + { + if (mem[i] == (unsigned char) c) + return ((void *)s + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..f4d69f4 --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:04:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 12:24:57 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *str1; + unsigned char *str2; + unsigned int i; + + str1 = (unsigned char *) s1; + str2 = (unsigned char *) s2; + if (n == 0) + return (0); + i = 0; + while (str1[i] == str2[i] && i < n - 1) + ++i; + return (str1[i] - str2[i]); +} diff --git a/libft/ft_memcmp.c.orig b/libft/ft_memcmp.c.orig new file mode 100644 index 0000000..f4d69f4 --- /dev/null +++ b/libft/ft_memcmp.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:04:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 12:24:57 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *str1; + unsigned char *str2; + unsigned int i; + + str1 = (unsigned char *) s1; + str2 = (unsigned char *) s2; + if (n == 0) + return (0); + i = 0; + while (str1[i] == str2[i] && i < n - 1) + ++i; + return (str1[i] - str2[i]); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..25a2056 --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:58:36 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:22:02 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + unsigned char *dest; + const unsigned char *source; + + dest = dst; + source = src; + if (!dest && !source) + return (dest); + i = 0; + while (i < n) + { + dest[i] = source[i]; + i++; + } + return (dest); +} diff --git a/libft/ft_memcpy.c.orig b/libft/ft_memcpy.c.orig new file mode 100644 index 0000000..25a2056 --- /dev/null +++ b/libft/ft_memcpy.c.orig @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:58:36 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:22:02 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + unsigned char *dest; + const unsigned char *source; + + dest = dst; + source = src; + if (!dest && !source) + return (dest); + i = 0; + while (i < n) + { + dest[i] = source[i]; + i++; + } + return (dest); +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..4c9452d --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:36:26 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:22:30 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + char *dest; + const char *source; + int i; + + if (!dst && !src) + return ((void *) dst); + dest = dst; + source = src; + if (dest < source) + { + ft_memcpy(dest, source, len); + return (dst); + } + i = len - 1; + while (i >= 0) + { + dest[i] = source[i]; + i--; + } + return (dst); +} diff --git a/libft/ft_memmove.c.orig b/libft/ft_memmove.c.orig new file mode 100644 index 0000000..4c9452d --- /dev/null +++ b/libft/ft_memmove.c.orig @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:36:26 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:22:30 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + char *dest; + const char *source; + int i; + + if (!dst && !src) + return ((void *) dst); + dest = dst; + source = src; + if (dest < source) + { + ft_memcpy(dest, source, len); + return (dst); + } + i = len - 1; + while (i >= 0) + { + dest[i] = source[i]; + i--; + } + return (dst); +} diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..5b7d3c3 --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:37:39 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:20:12 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t len) +{ + size_t i; + char *mem; + + mem = b; + i = 0; + while (i < len) + { + mem[i] = (char) c; + i++; + } + return (b); +} diff --git a/libft/ft_memset.c.orig b/libft/ft_memset.c.orig new file mode 100644 index 0000000..5b7d3c3 --- /dev/null +++ b/libft/ft_memset.c.orig @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:37:39 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:20:12 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t len) +{ + size_t i; + char *mem; + + mem = b; + i = 0; + while (i < len) + { + mem[i] = (char) c; + i++; + } + return (b); +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..d9be8e3 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/cd.c +/* Created: 2024/03/03 11:48:16 by facetint #+# #+# */ +/* Updated: 2024/03/03 11:48:37 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 20:38:03 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 14:34:36 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_putchar_fd.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include + +<<<<<<< HEAD:builtin/cd.c +======= +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} +>>>>>>> main:libft/ft_putchar_fd.c diff --git a/libft/ft_putchar_fd.c.orig b/libft/ft_putchar_fd.c.orig new file mode 100644 index 0000000..d9be8e3 --- /dev/null +++ b/libft/ft_putchar_fd.c.orig @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/cd.c +/* Created: 2024/03/03 11:48:16 by facetint #+# #+# */ +/* Updated: 2024/03/03 11:48:37 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 20:38:03 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 14:34:36 by hcoskun ### ########.fr */ +>>>>>>> main:libft/ft_putchar_fd.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include + +<<<<<<< HEAD:builtin/cd.c +======= +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} +>>>>>>> main:libft/ft_putchar_fd.c diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100644 index 0000000..7f3be34 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* unset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/unset.c +/* Created: 2024/03/03 13:19:04 by facetint #+# #+# */ +/* Updated: 2024/03/03 13:19:46 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 21:58:10 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:58:18 by hcoskun42 ### ########.tr */ +>>>>>>> main:libft/ft_putendl_fd.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include +#include "../memory-allocator/allocator.h" + +<<<<<<< HEAD:builtin/unset.c +======= +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + write(fd, "\n", 1); +} +>>>>>>> main:libft/ft_putendl_fd.c diff --git a/libft/ft_putendl_fd.c.orig b/libft/ft_putendl_fd.c.orig new file mode 100644 index 0000000..7f3be34 --- /dev/null +++ b/libft/ft_putendl_fd.c.orig @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* unset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +<<<<<<< HEAD:builtin/unset.c +/* Created: 2024/03/03 13:19:04 by facetint #+# #+# */ +/* Updated: 2024/03/03 13:19:46 by facetint ### ########.fr */ +======= +/* Created: 2023/06/24 21:58:10 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:58:18 by hcoskun42 ### ########.tr */ +>>>>>>> main:libft/ft_putendl_fd.c +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" +#include "../libft/libft.h" +#include +#include "../memory-allocator/allocator.h" + +<<<<<<< HEAD:builtin/unset.c +======= +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + write(fd, "\n", 1); +} +>>>>>>> main:libft/ft_putendl_fd.c diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..63de4b8 --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:03:40 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:49:09 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n < 0) + { + ft_putchar_fd('-', fd); + if (n == -2147483648) + { + ft_putstr_fd("2147483648", fd); + return ; + } + n = -n; + } + if (n >= 10) + { + ft_putnbr_fd(n / 10, fd); + n = n % 10; + } + ft_putchar_fd(n + '0', fd); +} diff --git a/libft/ft_putnbr_fd.c.orig b/libft/ft_putnbr_fd.c.orig new file mode 100644 index 0000000..63de4b8 --- /dev/null +++ b/libft/ft_putnbr_fd.c.orig @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:03:40 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:49:09 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n < 0) + { + ft_putchar_fd('-', fd); + if (n == -2147483648) + { + ft_putstr_fd("2147483648", fd); + return ; + } + n = -n; + } + if (n >= 10) + { + ft_putnbr_fd(n / 10, fd); + n = n % 10; + } + ft_putchar_fd(n + '0', fd); +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..7e32b59 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:38:17 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:11:17 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putstr_fd(char *s, int fd) +{ + if (!s) + return ; + while (*s) + write(fd, s++, 1); +} diff --git a/libft/ft_putstr_fd.c.orig b/libft/ft_putstr_fd.c.orig new file mode 100644 index 0000000..7e32b59 --- /dev/null +++ b/libft/ft_putstr_fd.c.orig @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:38:17 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:11:17 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putstr_fd(char *s, int fd) +{ + if (!s) + return ; + while (*s) + write(fd, s++, 1); +} diff --git a/libft/ft_split.c b/libft/ft_split.c new file mode 100644 index 0000000..b6ad513 --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:38:47 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:09 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +static int wlen(char const *str, char c) +{ + int i; + + i = 0; + while (str[i] && str[i] != c) + i++; + return (i); +} + +static int count_words(char const *str, char c) +{ + int count; + + count = 0; + while (*str) + { + while (*str && *str == c) + str++; + if (*str) + count++; + while (*str && *str != c) + str++; + } + return (count); +} + +char **free_all(char **result) +{ + int i; + + i = 0; + while (result[i]) + { + safe_free(result[i]); + i++; + } + safe_free(result); + return (NULL); +} + +char **ft_split(char const *str, char c) +{ + char **result; + int word_index; + int i; + int len; + + if (!str) + return (NULL); + result = (char **) ft_calloc(sizeof(char *), count_words(str, c) + 1); + if (!result) + return (NULL); + word_index = 0; + i = 0; + while (str[i]) + { + while (str[i] && str[i] == c) + i++; + if (!str[i]) + break ; + len = wlen(str + i, c); + result[word_index] = ft_substr(str, i, len); + if (!result[word_index++]) + return (free_all(result)); + i += len; + } + return (result); +} diff --git a/libft/ft_split.c.orig b/libft/ft_split.c.orig new file mode 100644 index 0000000..b6ad513 --- /dev/null +++ b/libft/ft_split.c.orig @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:38:47 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:09 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +static int wlen(char const *str, char c) +{ + int i; + + i = 0; + while (str[i] && str[i] != c) + i++; + return (i); +} + +static int count_words(char const *str, char c) +{ + int count; + + count = 0; + while (*str) + { + while (*str && *str == c) + str++; + if (*str) + count++; + while (*str && *str != c) + str++; + } + return (count); +} + +char **free_all(char **result) +{ + int i; + + i = 0; + while (result[i]) + { + safe_free(result[i]); + i++; + } + safe_free(result); + return (NULL); +} + +char **ft_split(char const *str, char c) +{ + char **result; + int word_index; + int i; + int len; + + if (!str) + return (NULL); + result = (char **) ft_calloc(sizeof(char *), count_words(str, c) + 1); + if (!result) + return (NULL); + word_index = 0; + i = 0; + while (str[i]) + { + while (str[i] && str[i] == c) + i++; + if (!str[i]) + break ; + len = wlen(str + i, c); + result[word_index] = ft_substr(str, i, len); + if (!result[word_index++]) + return (free_all(result)); + i += len; + } + return (result); +} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100644 index 0000000..2ef9404 --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:41:33 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 18:20:11 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *str, int c) +{ + int i; + + i = 0; + if (!str[0] && !c) + return ((char *) str); + while (str[i]) + { + if (str[i] == (unsigned char) c) + return ((char *) str + i); + i++; + } + if ((unsigned char) c) + return (NULL); + return ((char *) str + i); +} diff --git a/libft/ft_strchr.c.orig b/libft/ft_strchr.c.orig new file mode 100644 index 0000000..2ef9404 --- /dev/null +++ b/libft/ft_strchr.c.orig @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 20:41:33 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 18:20:11 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *str, int c) +{ + int i; + + i = 0; + if (!str[0] && !c) + return ((char *) str); + while (str[i]) + { + if (str[i] == (unsigned char) c) + return ((char *) str + i); + i++; + } + if ((unsigned char) c) + return (NULL); + return ((char *) str + i); +} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100644 index 0000000..ebdbcdb --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:40:48 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:22 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +//tocheck +char *ft_strdup(const char *str) +{ + char *res; + size_t size; + + size = ft_strlen(str) + 1; + res = safe_malloc(sizeof(char) * size); + if (!res) + return (NULL); + ft_strlcpy(res, str, size); + return (res); +} diff --git a/libft/ft_strdup.c.orig b/libft/ft_strdup.c.orig new file mode 100644 index 0000000..ebdbcdb --- /dev/null +++ b/libft/ft_strdup.c.orig @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:40:48 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:22 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +//tocheck +char *ft_strdup(const char *str) +{ + char *res; + size_t size; + + size = ft_strlen(str) + 1; + res = safe_malloc(sizeof(char) * size); + if (!res) + return (NULL); + ft_strlcpy(res, str, size); + return (res); +} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100644 index 0000000..093758f --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:41:50 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:45:05 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + int i; + + if (!s) + return ; + i = 0; + while (s[i]) + { + f(i, s + i); + i++; + } +} diff --git a/libft/ft_striteri.c.orig b/libft/ft_striteri.c.orig new file mode 100644 index 0000000..093758f --- /dev/null +++ b/libft/ft_striteri.c.orig @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:41:50 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:45:05 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + int i; + + if (!s) + return ; + i = 0; + while (s[i]) + { + f(i, s + i); + i++; + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100644 index 0000000..51f927d --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hamza +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:43:00 by hcoskun42 #+# #+# */ +/* Updated: 2024/02/15 20:54:04 by hamza ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *string; + int size; + + if (!s1 && !s2) + return (NULL); + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + size = ft_strlen(s1) + ft_strlen(s2) + 1; + string = safe_malloc(sizeof(char) * size); + if (!string) + return (NULL); + ft_strlcpy(string, s1, size); + ft_strlcat(string, s2, size); + return (string); +} diff --git a/libft/ft_strjoin.c.orig b/libft/ft_strjoin.c.orig new file mode 100644 index 0000000..51f927d --- /dev/null +++ b/libft/ft_strjoin.c.orig @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hamza +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:43:00 by hcoskun42 #+# #+# */ +/* Updated: 2024/02/15 20:54:04 by hamza ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *string; + int size; + + if (!s1 && !s2) + return (NULL); + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + size = ft_strlen(s1) + ft_strlen(s2) + 1; + string = safe_malloc(sizeof(char) * size); + if (!string) + return (NULL); + ft_strlcpy(string, s1, size); + ft_strlcat(string, s2, size); + return (string); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..e3132bc --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:44:11 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:44:50 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t cpy_len; + size_t extra; + + cpy_len = 0; + extra = 0; + if (!dst && !size) + return (ft_strlen(src) * sizeof(char)); + while (dst[cpy_len] && cpy_len < size) + cpy_len++; + while (src[extra] && (cpy_len + extra + 1) < size) + { + dst[cpy_len + extra] = src[extra]; + extra++; + } + if (cpy_len < size) + dst[cpy_len + extra] = 0; + return ((cpy_len + ft_strlen(src)) * sizeof(char)); +} diff --git a/libft/ft_strlcat.c.orig b/libft/ft_strlcat.c.orig new file mode 100644 index 0000000..e3132bc --- /dev/null +++ b/libft/ft_strlcat.c.orig @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:44:11 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:44:50 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t cpy_len; + size_t extra; + + cpy_len = 0; + extra = 0; + if (!dst && !size) + return (ft_strlen(src) * sizeof(char)); + while (dst[cpy_len] && cpy_len < size) + cpy_len++; + while (src[extra] && (cpy_len + extra + 1) < size) + { + dst[cpy_len + extra] = src[extra]; + extra++; + } + if (cpy_len < size) + dst[cpy_len + extra] = 0; + return ((cpy_len + ft_strlen(src)) * sizeof(char)); +} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..c527f12 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:45:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:15:31 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t dstsize) +{ + size_t i; + + if (dstsize == 0) + return (ft_strlen(src)); + i = 0; + while (src[i] && i < dstsize - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (ft_strlen(src)); +} diff --git a/libft/ft_strlcpy.c.orig b/libft/ft_strlcpy.c.orig new file mode 100644 index 0000000..c527f12 --- /dev/null +++ b/libft/ft_strlcpy.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:45:16 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:15:31 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t dstsize) +{ + size_t i; + + if (dstsize == 0) + return (ft_strlen(src)); + i = 0; + while (src[i] && i < dstsize - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (ft_strlen(src)); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..738d066 --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:46:08 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:15:43 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i] != 0) + i++; + return (i * sizeof(char)); +} diff --git a/libft/ft_strlen.c.orig b/libft/ft_strlen.c.orig new file mode 100644 index 0000000..738d066 --- /dev/null +++ b/libft/ft_strlen.c.orig @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:46:08 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:15:43 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i] != 0) + i++; + return (i * sizeof(char)); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..2008488 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:48:12 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:48:36 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *result; + size_t len; + int i; + + if (!s || !f) + return (NULL); + len = ft_strlen(s); + result = (char *) malloc(sizeof(char) * (len + 1)); + if (!result) + return (NULL); + i = 0; + while (s[i]) + { + result[i] = f(i, s[i]); + i++; + } + result[i] = 0; + return (result); +} diff --git a/libft/ft_strmapi.c.orig b/libft/ft_strmapi.c.orig new file mode 100644 index 0000000..2008488 --- /dev/null +++ b/libft/ft_strmapi.c.orig @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:48:12 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:48:36 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *result; + size_t len; + int i; + + if (!s || !f) + return (NULL); + len = ft_strlen(s); + result = (char *) malloc(sizeof(char) * (len + 1)); + if (!result) + return (NULL); + i = 0; + while (s[i]) + { + result[i] = f(i, s[i]); + i++; + } + result[i] = 0; + return (result); +} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100644 index 0000000..cf43f80 --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:48:52 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:54:35 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned int i; + + if (n == 0) + return (0); + i = 0; + while (*s1 && *s1 == *s2 && i < n - 1) + { + ++s1; + ++s2; + ++i; + } + return ((unsigned char) *s1 - (unsigned char) *s2); +} diff --git a/libft/ft_strncmp.c.orig b/libft/ft_strncmp.c.orig new file mode 100644 index 0000000..cf43f80 --- /dev/null +++ b/libft/ft_strncmp.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:48:52 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:54:35 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned int i; + + if (n == 0) + return (0); + i = 0; + while (*s1 && *s1 == *s2 && i < n - 1) + { + ++s1; + ++s2; + ++i; + } + return ((unsigned char) *s1 - (unsigned char) *s2); +} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..e461927 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:49:28 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:18:48 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + size_t needle_len; + size_t i; + + if (!haystack && !len) + return (NULL); + if (*needle == 0) + return ((char *) haystack); + needle_len = ft_strlen(needle); + i = 0; + while (haystack[i] && i < len && needle_len <= len - i) + { + if (ft_strncmp(haystack + i, needle, needle_len) == 0) + return ((char *) haystack + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_strnstr.c.orig b/libft/ft_strnstr.c.orig new file mode 100644 index 0000000..e461927 --- /dev/null +++ b/libft/ft_strnstr.c.orig @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:49:28 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 13:18:48 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + size_t needle_len; + size_t i; + + if (!haystack && !len) + return (NULL); + if (*needle == 0) + return ((char *) haystack); + needle_len = ft_strlen(needle); + i = 0; + while (haystack[i] && i < len && needle_len <= len - i) + { + if (ft_strncmp(haystack + i, needle, needle_len) == 0) + return ((char *) haystack + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100644 index 0000000..b0a3ca6 --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:50:27 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:40:12 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *str, int c) +{ + int i; + + i = (int) ft_strlen(str); + while (i >= 0) + { + if (str[i] == (unsigned char) c) + return ((char *) str + i); + i--; + } + if (c) + return (NULL); + return ((char *) str + i); +} diff --git a/libft/ft_strrchr.c.orig b/libft/ft_strrchr.c.orig new file mode 100644 index 0000000..b0a3ca6 --- /dev/null +++ b/libft/ft_strrchr.c.orig @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:50:27 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/08 16:40:12 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *str, int c) +{ + int i; + + i = (int) ft_strlen(str); + while (i >= 0) + { + if (str[i] == (unsigned char) c) + return ((char *) str + i); + i--; + } + if (c) + return (NULL); + return ((char *) str + i); +} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100644 index 0000000..e9afbb1 --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:51:17 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:41:37 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int contains(char const *set, char const c) +{ + while (*set) + { + if (*set == c) + return (1); + set++; + } + return (0); +} + +int find_start(char const *str, char const *set) +{ + int i; + + i = 0; + while (str[i] && contains(set, str[i])) + i++; + return (i); +} + +int find_end(char const *str, char const *set, int len) +{ + int i; + + i = (int) len - 1; + while (i > 0 && contains(set, str[i])) + i--; + return (i); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + int start; + int end; + + if (!s1) + return (NULL); + start = find_start(s1, set); + end = find_end(s1, set, ft_strlen(s1)); + if (end < start || (!*s1 && !*set)) + return (ft_strdup("")); + return (ft_substr(s1, start, end - start + 1)); +} diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..a11d930 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:53:38 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:48 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + size_t i; + char *result; + + i = len; + if (!s) + return (NULL); + if (start >= ft_strlen(s) || len == 0) + return (ft_strdup("")); + if (len > ft_strlen(s + start)) + i = ft_strlen(s + start); + result = (char *) safe_malloc(sizeof(char) * (i + 1)); + if (!result) + return (NULL); + ft_strlcpy(result, s + start, i + 1); + return (result); +} diff --git a/libft/ft_substr.c.orig b/libft/ft_substr.c.orig new file mode 100644 index 0000000..a11d930 --- /dev/null +++ b/libft/ft_substr.c.orig @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:53:38 by hcoskun42 #+# #+# */ +/* Updated: 2023/12/31 15:41:48 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "../memory-allocator/allocator.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + size_t i; + char *result; + + i = len; + if (!s) + return (NULL); + if (start >= ft_strlen(s) || len == 0) + return (ft_strdup("")); + if (len > ft_strlen(s + start)) + i = ft_strlen(s + start); + result = (char *) safe_malloc(sizeof(char) * (i + 1)); + if (!result) + return (NULL); + ft_strlcpy(result, s + start, i + 1); + return (result); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..2deea6b --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:54:47 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:54:49 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + else + return (c); +} diff --git a/libft/ft_tolower.c.orig b/libft/ft_tolower.c.orig new file mode 100644 index 0000000..2deea6b --- /dev/null +++ b/libft/ft_tolower.c.orig @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:54:47 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:54:49 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + else + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100644 index 0000000..f834c37 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:55:04 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:55:24 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + else + return (c); +} diff --git a/libft/ft_toupper.c.orig b/libft/ft_toupper.c.orig new file mode 100644 index 0000000..f834c37 --- /dev/null +++ b/libft/ft_toupper.c.orig @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun42 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 21:55:04 by hcoskun42 #+# #+# */ +/* Updated: 2023/06/24 21:55:24 by hcoskun42 ### ########.tr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + else + return (c); +} diff --git a/libft/libft.a b/libft/libft.a new file mode 100644 index 0000000..3a3fc2a Binary files /dev/null and b/libft/libft.a differ diff --git a/libft/libft.h b/libft/libft.h new file mode 100644 index 0000000..bcd0da0 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:05:04 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:44:16 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include + +size_t ft_strlen(const char *s); +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); +size_t ft_strlcat(char *dst, const char *src, size_t dstsize); + +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); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +int ft_atoi(const char *str); + +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strnstr(const char *haystack, const char *needle, size_t len); +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)); +char *ft_strdup(const char *str); + +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +void *ft_calloc(size_t count, size_t size); +void ft_striteri(char *s, void (*f)(unsigned int, char *)); +void ft_putchar_fd(char c, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(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 *)); +t_list *ft_lstlast(t_list *lst); +#endif \ No newline at end of file diff --git a/libft/libft.h.orig b/libft/libft.h.orig new file mode 100644 index 0000000..bcd0da0 --- /dev/null +++ b/libft/libft.h.orig @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hcoskun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/24 22:05:04 by hcoskun42 #+# #+# */ +/* Updated: 2023/07/11 14:44:16 by hcoskun ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include + +size_t ft_strlen(const char *s); +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); +size_t ft_strlcat(char *dst, const char *src, size_t dstsize); + +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); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +int ft_atoi(const char *str); + +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strnstr(const char *haystack, const char *needle, size_t len); +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)); +char *ft_strdup(const char *str); + +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +void *ft_calloc(size_t count, size_t size); +void ft_striteri(char *s, void (*f)(unsigned int, char *)); +void ft_putchar_fd(char c, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(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 *)); +t_list *ft_lstlast(t_list *lst); +#endif \ No newline at end of file