Convert Libft from submodule to directory
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 30 Jan 2024 17:30:18 +0000 (18:30 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 30 Jan 2024 17:30:18 +0000 (18:30 +0100)
Do this so that 42 can use this project without any
additional downloads of dependencies.
Change Makefile accordingly.

103 files changed:
.gitmodules [deleted file]
Libft [deleted submodule]
Libft/Makefile [new file with mode: 0644]
Libft/ft_arr/ft_mat_access.c [new file with mode: 0644]
Libft/ft_arr/ft_mat_append.c [new file with mode: 0644]
Libft/ft_arr/ft_mat_free.c [new file with mode: 0644]
Libft/ft_arr/ft_mat_init.c [new file with mode: 0644]
Libft/ft_arr/ft_mat_insert_col.c [new file with mode: 0644]
Libft/ft_arr/ft_mat_insert_row.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_access.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_append.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_enlarge.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_erase.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_find.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_find_index.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_forget.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_free.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_init.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_insert.c [new file with mode: 0644]
Libft/ft_arr/ft_vec_reserve.c [new file with mode: 0644]
Libft/ft_check/ft_isalnum.c [new file with mode: 0644]
Libft/ft_check/ft_isalpha.c [new file with mode: 0644]
Libft/ft_check/ft_isascii.c [new file with mode: 0644]
Libft/ft_check/ft_isdigit.c [new file with mode: 0644]
Libft/ft_check/ft_islower.c [new file with mode: 0644]
Libft/ft_check/ft_isprint.c [new file with mode: 0644]
Libft/ft_check/ft_isspace.c [new file with mode: 0644]
Libft/ft_check/ft_isupper.c [new file with mode: 0644]
Libft/ft_conv/ft_atoi.c [new file with mode: 0644]
Libft/ft_conv/ft_ctoa.c [new file with mode: 0644]
Libft/ft_conv/ft_itoa.c [new file with mode: 0644]
Libft/ft_conv/ft_itoa_base.c [new file with mode: 0644]
Libft/ft_conv/ft_tolower.c [new file with mode: 0644]
Libft/ft_conv/ft_toupper.c [new file with mode: 0644]
Libft/ft_conv/ft_uitoa_base.c [new file with mode: 0644]
Libft/ft_gen/ft_swap.c [new file with mode: 0644]
Libft/ft_io/ft_printf/conversion.c [new file with mode: 0644]
Libft/ft_io/ft_printf/formatting.c [new file with mode: 0644]
Libft/ft_io/ft_printf/ft_printf.c [new file with mode: 0644]
Libft/ft_io/ft_printf/ft_printf.h [new file with mode: 0644]
Libft/ft_io/ft_printf/padding.c [new file with mode: 0644]
Libft/ft_io/ft_printf/parsing.c [new file with mode: 0644]
Libft/ft_io/ft_putchar_fd.c [new file with mode: 0644]
Libft/ft_io/ft_putendl_fd.c [new file with mode: 0644]
Libft/ft_io/ft_putnbr_fd.c [new file with mode: 0644]
Libft/ft_io/ft_putstr_fd.c [new file with mode: 0644]
Libft/ft_io/get_next_line.c [new file with mode: 0644]
Libft/ft_io/get_next_line.h [new file with mode: 0644]
Libft/ft_lst/ft_lst_at.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_find.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_foreach_if.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_merge.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_remove_if.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_reverse.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_sort.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_sorted_insert.c [new file with mode: 0644]
Libft/ft_lst/ft_lst_sorted_merge.c [new file with mode: 0644]
Libft/ft_lst/ft_lstadd_back.c [new file with mode: 0644]
Libft/ft_lst/ft_lstadd_front.c [new file with mode: 0644]
Libft/ft_lst/ft_lstclear.c [new file with mode: 0644]
Libft/ft_lst/ft_lstdelone.c [new file with mode: 0644]
Libft/ft_lst/ft_lstiter.c [new file with mode: 0644]
Libft/ft_lst/ft_lstlast.c [new file with mode: 0644]
Libft/ft_lst/ft_lstmap.c [new file with mode: 0644]
Libft/ft_lst/ft_lstnew.c [new file with mode: 0644]
Libft/ft_lst/ft_lstsize.c [new file with mode: 0644]
Libft/ft_math/ft_abs.c [new file with mode: 0644]
Libft/ft_math/ft_sgn.c [new file with mode: 0644]
Libft/ft_mem/ft_bzero.c [new file with mode: 0644]
Libft/ft_mem/ft_calloc.c [new file with mode: 0644]
Libft/ft_mem/ft_memchr.c [new file with mode: 0644]
Libft/ft_mem/ft_memcmp.c [new file with mode: 0644]
Libft/ft_mem/ft_memcpy.c [new file with mode: 0644]
Libft/ft_mem/ft_memmove.c [new file with mode: 0644]
Libft/ft_mem/ft_memset.c [new file with mode: 0644]
Libft/ft_str/ft_split.c [new file with mode: 0644]
Libft/ft_str/ft_strchr.c [new file with mode: 0644]
Libft/ft_str/ft_strcmp.c [new file with mode: 0644]
Libft/ft_str/ft_strdup.c [new file with mode: 0644]
Libft/ft_str/ft_striteri.c [new file with mode: 0644]
Libft/ft_str/ft_strjoin.c [new file with mode: 0644]
Libft/ft_str/ft_strlcat.c [new file with mode: 0644]
Libft/ft_str/ft_strlcpy.c [new file with mode: 0644]
Libft/ft_str/ft_strlen.c [new file with mode: 0644]
Libft/ft_str/ft_strmapi.c [new file with mode: 0644]
Libft/ft_str/ft_strncat_alloc.c [new file with mode: 0644]
Libft/ft_str/ft_strncmp.c [new file with mode: 0644]
Libft/ft_str/ft_strndup.c [new file with mode: 0644]
Libft/ft_str/ft_strnstr.c [new file with mode: 0644]
Libft/ft_str/ft_strrchr.c [new file with mode: 0644]
Libft/ft_str/ft_strtrim.c [new file with mode: 0644]
Libft/ft_str/ft_substr.c [new file with mode: 0644]
Libft/inc/ft_arr.h [new file with mode: 0644]
Libft/inc/ft_check.h [new file with mode: 0644]
Libft/inc/ft_conv.h [new file with mode: 0644]
Libft/inc/ft_gen.h [new file with mode: 0644]
Libft/inc/ft_io.h [new file with mode: 0644]
Libft/inc/ft_lst.h [new file with mode: 0644]
Libft/inc/ft_math.h [new file with mode: 0644]
Libft/inc/ft_mem.h [new file with mode: 0644]
Libft/inc/ft_str.h [new file with mode: 0644]
Libft/inc/libft.h [new file with mode: 0644]
Makefile

diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644 (file)
index 626d139..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "Libft"]
-       path = Libft
-       url = git://ljiriste.work/Libft
diff --git a/Libft b/Libft
deleted file mode 160000 (submodule)
index cb00b99..0000000
--- a/Libft
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit cb00b9904afce575523dd828efc2f6ff5e28ad5e
diff --git a/Libft/Makefile b/Libft/Makefile
new file mode 100644 (file)
index 0000000..3fffc1f
--- /dev/null
@@ -0,0 +1,132 @@
+CC := cc
+CFLAGS := -std=c99 -Wall -Wextra -Werror -Wpedantic
+AR := ar
+
+RM := rm -f
+
+INCDIR = ./inc
+INCLUDE := $(addprefix -I, $(INCDIR))
+
+SRCDIR := ft_gen ft_math ft_str ft_mem ft_io ft_check ft_conv ft_lst ft_arr
+
+SRCgen :=      ft_swap.c                               \
+
+SRCmath        :=      ft_abs.c                                \
+                       ft_sgn.c                                \
+
+SRCstr :=      ft_strncat_alloc.c              \
+                       ft_strcmp.c                             \
+                       ft_strncmp.c                    \
+                       ft_strndup.c                    \
+                       ft_strchr.c                             \
+                       ft_strtrim.c                    \
+                       ft_strlen.c                             \
+                       ft_strdup.c                             \
+                       ft_strlcpy.c                    \
+                       ft_strnstr.c                    \
+                       ft_striteri.c                   \
+                       ft_strmapi.c                    \
+                       ft_strjoin.c                    \
+                       ft_split.c                              \
+                       ft_substr.c                             \
+                       ft_strlcat.c                    \
+                       ft_strrchr.c                    \
+
+SRCmem :=      ft_calloc.c                             \
+                       ft_memchr.c                             \
+                       ft_memcmp.c                             \
+                       ft_memset.c                             \
+                       ft_memmove.c                    \
+                       ft_memcpy.c                             \
+                       ft_bzero.c                              \
+
+SRCio  :=      ft_putendl_fd.c                 \
+                       ft_putnbr_fd.c                  \
+                       ft_printf/conversion.c  \
+                       ft_printf/ft_printf.c   \
+                       ft_printf/padding.c             \
+                       ft_printf/parsing.c             \
+                       ft_printf/formatting.c  \
+                       ft_putchar_fd.c                 \
+                       get_next_line.c                 \
+                       ft_putstr_fd.c                  \
+
+SRCcheck:=     ft_isalnum.c                    \
+                       ft_isspace.c                    \
+                       ft_isdigit.c                    \
+                       ft_isascii.c                    \
+                       ft_isalpha.c                    \
+                       ft_islower.c                    \
+                       ft_isupper.c                    \
+                       ft_isprint.c                    \
+
+SRCconv        :=      ft_itoa_base.c                  \
+                       ft_tolower.c                    \
+                       ft_toupper.c                    \
+                       ft_atoi.c                               \
+                       ft_ctoa.c                               \
+                       ft_itoa.c                               \
+                       ft_uitoa_base.c                 \
+
+SRClst :=      ft_lst_reverse.c                \
+                       ft_lstdelone.c                  \
+                       ft_lst_foreach_if.c             \
+                       ft_lstlast.c                    \
+                       ft_lstclear.c                   \
+                       ft_lst_at.c                             \
+                       ft_lst_sorted_merge.c   \
+                       ft_lst_find.c                   \
+                       ft_lstmap.c                             \
+                       ft_lst_remove_if.c              \
+                       ft_lstnew.c                             \
+                       ft_lst_merge.c                  \
+                       ft_lstsize.c                    \
+                       ft_lstadd_front.c               \
+                       ft_lstadd_back.c                \
+                       ft_lstiter.c                    \
+                       ft_lst_sort.c                   \
+                       ft_lst_sorted_insert.c  \
+
+SRCarr :=      ft_vec_init.c                   \
+                       ft_vec_reserve.c                \
+                       ft_vec_enlarge.c                \
+                       ft_vec_insert.c                 \
+                       ft_vec_append.c                 \
+                       ft_vec_forget.c                 \
+                       ft_vec_erase.c                  \
+                       ft_vec_access.c                 \
+                       ft_vec_free.c                   \
+                       ft_vec_find.c                   \
+                       ft_vec_find_index.c             \
+                                                                       \
+                       ft_mat_init.c                   \
+                       ft_mat_append.c                 \
+                       ft_mat_insert_col.c             \
+                       ft_mat_insert_row.c             \
+                       ft_mat_access.c                 \
+                       ft_mat_free.c                   \
+
+SOURCES := $(foreach dir, $(SRCDIR), $(addprefix $(dir)/, $($(dir:ft_%=SRC%))))
+OBJECTS := $(SOURCES:.c=.o)
+
+NAME = libft.a
+
+all : $(NAME)
+
+debug : CFLAGS += -g
+debug : $(NAME)
+
+$(NAME) : $(OBJECTS)
+       $(AR) rcs $@ $^
+
+%.o : %.c
+       $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE)
+
+clean :
+       $(RM) $(OBJECTS)
+
+fclean : clean
+       $(RM) $(NAME)
+
+re : fclean
+       $(MAKE) all
diff --git a/Libft/ft_arr/ft_mat_access.c b/Libft/ft_arr/ft_mat_access.c
new file mode 100644 (file)
index 0000000..b8886e9
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_access.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/17 11:32:45 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/17 13:03:13 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include <stddef.h>
+
+void   *ft_mat_access(t_mat *mat, size_t row, size_t col)
+{
+       if (!mat)
+               return (NULL);
+       if (row >= mat->rows || col >= mat->cols)
+               return (NULL);
+       return ((char *)mat->vec.vec + (row * mat->cols + col) * mat->vec.el_size);
+}
diff --git a/Libft/ft_arr/ft_mat_append.c b/Libft/ft_arr/ft_mat_append.c
new file mode 100644 (file)
index 0000000..50031f8
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_append.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/12 10:25:34 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/12 10:28:46 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+t_arr_stat     ft_mat_append_row(t_mat *mat, const t_vec *vec)
+{
+       return (ft_mat_insert_row(mat, vec, mat->rows));
+}
+
+t_arr_stat     ft_mat_append_col(t_mat *mat, const t_vec *vec)
+{
+       return (ft_mat_insert_col(mat, vec, mat->cols));
+}
diff --git a/Libft/ft_arr/ft_mat_free.c b/Libft/ft_arr/ft_mat_free.c
new file mode 100644 (file)
index 0000000..b166885
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_free.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/11 19:06:07 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 19:08:21 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+void   ft_mat_free(t_mat *mat, void (*free_el)(void *))
+{
+       ft_vec_free(&(mat->vec), free_el);
+       mat->cols = 0;
+       mat->rows = 0;
+       return ;
+}
diff --git a/Libft/ft_arr/ft_mat_init.c b/Libft/ft_arr/ft_mat_init.c
new file mode 100644 (file)
index 0000000..bf70cb8
--- /dev/null
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_init.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/11 19:03:27 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 19:05:45 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+t_arr_stat     ft_mat_init(t_mat *mat, size_t el_size)
+{
+       mat->rows = 0;
+       mat->cols = 0;
+       return (ft_vec_init(&(mat->vec), el_size));
+}
diff --git a/Libft/ft_arr/ft_mat_insert_col.c b/Libft/ft_arr/ft_mat_insert_col.c
new file mode 100644 (file)
index 0000000..9b92aee
--- /dev/null
@@ -0,0 +1,97 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_insert_col.c                                :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/12 08:57:22 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/17 13:12:34 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include "ft_mem.h"
+
+// Creates space for the inserted column inside the mat->vec
+void   reorganize(t_mat *mat, size_t move_index, size_t change)
+{
+       size_t          i;
+
+       i = mat->rows - 1;
+       if (move_index < mat->cols)
+       {
+               ft_memmove((char *)mat->vec.vec
+                       + ((mat->rows - 1) * mat->cols + move_index) * mat->vec.el_size,
+                       (char *)mat->vec.vec + ((mat->rows - 1)
+                               * (mat->cols + change) + move_index) * mat->vec.el_size,
+                       (mat->cols - move_index) * mat->vec.el_size);
+       }
+       --i;
+       while (i + 1 > 0)
+       {
+               ft_memmove((char *)mat->vec.vec
+                       + (i * mat->cols + move_index) * mat->vec.el_size,
+                       (char *)mat->vec.vec
+                       + (i * (mat->cols + change) + move_index) * mat->vec.el_size,
+                       mat->cols * mat->vec.el_size);
+               --i;
+       }
+       mat->cols += change;
+       return ;
+}
+
+static void    copy(t_mat *mat, const t_vec *vec, size_t index)
+{
+       size_t  i;
+
+       i = 0;
+       while (i < mat->rows)
+       {
+               ft_memmove((char *)vec->vec + i * vec->el_size,
+                       (char *)mat->vec.vec + (i * mat->cols + index)
+                       * mat->vec.el_size, vec->el_size);
+               ++i;
+       }
+       return ;
+}
+
+static void    set_auxiliary_vars(t_mat *mat, size_t index,
+               size_t *cols_change, size_t *move_index)
+{
+       if (index > mat->cols)
+       {
+               *cols_change = index - mat->cols + 1;
+               *move_index = mat->cols;
+       }
+       else
+       {
+               *cols_change = 1;
+               *move_index = index;
+       }
+       return ;
+}
+
+t_arr_stat     ft_mat_insert_col(t_mat *mat, const t_vec *vec, size_t index)
+{
+       size_t          cols_change;
+       size_t          move_index;
+       t_arr_stat      res;
+
+       if (!mat || !vec || vec->size == 0)
+               return (invalid_input);
+       if (mat->rows == 0)
+               mat->rows = vec->size;
+       else if (mat->rows != vec->size)
+               return (invalid_input);
+       set_auxiliary_vars(mat, index, &cols_change, &move_index);
+       while ((mat->cols + cols_change) * mat->rows < mat->vec.capacity)
+       {
+               res = ft_vec_enlarge(&(mat->vec));
+               if (res != success)
+                       return (res);
+       }
+       reorganize(mat, move_index, cols_change);
+       copy(mat, vec, index);
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_mat_insert_row.c b/Libft/ft_arr/ft_mat_insert_row.c
new file mode 100644 (file)
index 0000000..b64944a
--- /dev/null
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mat_insert_row.c                                :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/11 19:20:00 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/17 13:53:42 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+t_arr_stat     ft_mat_insert_row(t_mat *mat, const t_vec *vec, size_t index)
+{
+       size_t  res;
+
+       if (!mat || !vec || vec->size == 0)
+               return (invalid_input);
+       if (mat->cols == 0)
+               mat->cols = vec->size;
+       else if (mat->cols != vec->size)
+               return (invalid_input);
+       res = ft_vec_insert_range(&(mat->vec), vec->vec,
+                       mat->cols, index * mat->cols);
+       if (res != success)
+               return (res);
+       if (index < mat->rows)
+               ++mat->rows;
+       else
+               mat->rows += index - mat->rows + 1;
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_access.c b/Libft/ft_arr/ft_vec_access.c
new file mode 100644 (file)
index 0000000..8606b25
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_access.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 17:14:49 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 20:00:39 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include <stddef.h>
+
+void   *ft_vec_access(t_vec *vec, size_t index)
+{
+       if (!vec)
+               return (NULL);
+       if (index >= vec->size)
+               return (NULL);
+       return ((char *)vec->vec + vec->el_size * index);
+}
diff --git a/Libft/ft_arr/ft_vec_append.c b/Libft/ft_arr/ft_vec_append.c
new file mode 100644 (file)
index 0000000..fb5e0da
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_append.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 16:39:20 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 10:21:49 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+t_arr_stat     ft_vec_append(t_vec *vec, const void *element)
+{
+       return (ft_vec_append_range(vec, element, 1));
+}
+
+t_arr_stat     ft_vec_append_range(t_vec *vec, const void *element, size_t count)
+{
+       return (ft_vec_insert_range(vec, element, count, vec->size));
+}
diff --git a/Libft/ft_arr/ft_vec_enlarge.c b/Libft/ft_arr/ft_vec_enlarge.c
new file mode 100644 (file)
index 0000000..7778eaf
--- /dev/null
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_enlarge.c                                   :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/12 17:03:50 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/12 17:06:04 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include <stdint.h>
+
+t_arr_stat     ft_vec_enlarge(t_vec *vec)
+{
+       if (vec->capacity == SIZE_MAX)
+               return (alloc_fail);
+       if (vec->capacity > SIZE_MAX / 2)
+       {
+               if (ft_vec_reserve(vec, SIZE_MAX))
+                       return (alloc_fail);
+       }
+       else if (vec->capacity == 0)
+       {
+               if (ft_vec_reserve(vec, V_DEFAULT_CAPACITY))
+                       return (alloc_fail);
+       }
+       else
+       {
+               if (ft_vec_reserve(vec, vec->capacity * 2))
+                       return (alloc_fail);
+       }
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_erase.c b/Libft/ft_arr/ft_vec_erase.c
new file mode 100644 (file)
index 0000000..c81b95b
--- /dev/null
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_erase.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 17:10:39 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/11 10:53:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+
+t_arr_stat     ft_vec_erase(t_vec *vec, size_t index, void (*free_el)(void *))
+{
+       return (ft_vec_erase_range(vec, 1, index, free_el));
+}
+
+t_arr_stat     ft_vec_erase_range(t_vec *vec, size_t count, size_t index,
+                               void (*free_el)(void *))
+{
+       char    *p;
+
+       if (free_el)
+       {
+               p = (char *)vec->vec + index * vec->el_size;
+               while (p < (char *)vec->vec
+                       + (index + count) * vec->el_size)
+               {
+                       free_el(p);
+                       p += vec->el_size;
+               }
+       }
+       ft_vec_forget_range(vec, count, index);
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_find.c b/Libft/ft_arr/ft_vec_find.c
new file mode 100644 (file)
index 0000000..93564ab
--- /dev/null
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_find.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/11 11:04:05 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/11 12:27:10 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void   *ft_vec_find(t_vec *vec, void *wanted)
+{
+       size_t  i;
+
+       if (!vec || !wanted)
+               return (NULL);
+       i = 0;
+       while (i < vec->size)
+       {
+               if (!ft_memcmp(ft_vec_access(vec, i), wanted, vec->el_size))
+               {
+                       return (ft_vec_access(vec, i));
+               }
+               ++i;
+       }
+       return (NULL);
+}
diff --git a/Libft/ft_arr/ft_vec_find_index.c b/Libft/ft_arr/ft_vec_find_index.c
new file mode 100644 (file)
index 0000000..988acfc
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_find_index.c                                :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/11 11:49:41 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/12 17:10:23 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+t_arr_stat     ft_vec_find_index(t_vec *vec, void *wanted, size_t *index)
+{
+       if (!vec || !wanted || !index)
+               return (invalid_input);
+       wanted = ft_vec_find(vec, wanted);
+       if (wanted == NULL)
+               return (non_specific_failure);
+       *index = (size_t)(((char *)wanted - (char *)vec->vec) / vec->el_size);
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_forget.c b/Libft/ft_arr/ft_vec_forget.c
new file mode 100644 (file)
index 0000000..284d6b5
--- /dev/null
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_forget.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/12 10:11:45 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/23 12:46:49 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include "libft.h"
+
+t_arr_stat     ft_vec_forget(t_vec *vec, size_t index)
+{
+       return (ft_vec_forget_range(vec, 1, index));
+}
+
+t_arr_stat     ft_vec_forget_range(t_vec *vec, size_t count, size_t index)
+{
+       if (!vec || index + count > vec->size || index > SIZE_MAX - count)
+               return (invalid_input);
+       vec->size -= count;
+       ft_memmove((char *)vec->vec + index,
+               (char *)vec->vec + vec->el_size * (index + count),
+               vec->el_size * (vec->size - index));
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_free.c b/Libft/ft_arr/ft_vec_free.c
new file mode 100644 (file)
index 0000000..c2cdd80
--- /dev/null
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_free.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 17:37:13 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 20:01:30 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include <stdlib.h>
+
+void   ft_vec_free(t_vec *vec, void (*free_el)(void *))
+{
+       size_t  i;
+
+       if (!vec)
+               return ;
+       i = 0;
+       if (free_el)
+       {
+               while (i < vec->size)
+               {
+                       free_el((char *)vec->vec + i * vec->el_size);
+                       ++i;
+               }
+       }
+       free(vec->vec);
+       ft_vec_init(vec, vec->el_size);
+       return ;
+}
diff --git a/Libft/ft_arr/ft_vec_init.c b/Libft/ft_arr/ft_vec_init.c
new file mode 100644 (file)
index 0000000..0e270f7
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_init.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 16:04:26 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/14 16:02:28 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include "libft.h"
+#include <stddef.h>
+
+t_arr_stat     ft_vec_init(t_vec *vec, size_t el_size)
+{
+       if (el_size == 0 || !vec)
+               return (invalid_input);
+       vec->capacity = 0;
+       vec->size = 0;
+       vec->el_size = el_size;
+       vec->vec = NULL;
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_insert.c b/Libft/ft_arr/ft_vec_insert.c
new file mode 100644 (file)
index 0000000..9458136
--- /dev/null
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_insert.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 16:50:57 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/12 17:03:45 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include "libft.h"
+
+t_arr_stat     ft_vec_insert(t_vec *vec, void const *element, size_t index)
+{
+       return (ft_vec_insert_range(vec, element, 1, index));
+}
+
+t_arr_stat     ft_vec_insert_range(t_vec *vec, void const *element,
+                               size_t count, size_t index)
+{
+       if (count == 0)
+               return (success);
+       if (!element || !vec || index > SIZE_MAX - count)
+               return (invalid_input);
+       while (vec->size == vec->capacity || index + count > vec->capacity)
+       {
+               if (ft_vec_enlarge(vec))
+                       return (alloc_fail);
+       }
+       if (index < vec->size)
+               ft_memmove((char *)vec->vec + vec->el_size * (index + count),
+                       (char *)vec->vec + vec->el_size * index,
+                       vec->el_size * (vec->size - index));
+       ft_memmove((char *)vec->vec + vec->el_size * index, element,
+               vec->el_size * count);
+       if (index > vec->size)
+               vec->size = index;
+       vec->size += count;
+       return (success);
+}
diff --git a/Libft/ft_arr/ft_vec_reserve.c b/Libft/ft_arr/ft_vec_reserve.c
new file mode 100644 (file)
index 0000000..1160785
--- /dev/null
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_vec_reserve.c                                   :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 16:17:46 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 10:21:49 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_arr.h"
+#include "libft.h"
+#include <stdlib.h>
+
+t_arr_stat     ft_vec_reserve(t_vec *vec, size_t capacity)
+{
+       void    *tmp;
+
+       if (!vec)
+               return (invalid_input);
+       if (vec->capacity >= capacity)
+               return (invalid_input);
+       tmp = vec->vec;
+       vec->vec = ft_calloc(capacity, vec->el_size);
+       if (!vec->vec)
+       {
+               vec->vec = tmp;
+               return (alloc_fail);
+       }
+       vec->capacity = capacity;
+       ft_memcpy(vec->vec, tmp, vec->size * vec->el_size);
+       free(tmp);
+       return (success);
+}
diff --git a/Libft/ft_check/ft_isalnum.c b/Libft/ft_check/ft_isalnum.c
new file mode 100644 (file)
index 0000000..d596a2c
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isalnum.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:02:16 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isalnum(int c)
+{
+       return (ft_isdigit(c) || ft_isalpha(c));
+}
diff --git a/Libft/ft_check/ft_isalpha.c b/Libft/ft_check/ft_isalpha.c
new file mode 100644 (file)
index 0000000..af5737f
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isalpha.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:32:19 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isalpha(int c)
+{
+       return (ft_isupper(c) || ft_islower(c));
+}
diff --git a/Libft/ft_check/ft_isascii.c b/Libft/ft_check/ft_isascii.c
new file mode 100644 (file)
index 0000000..f8971c9
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isascii.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 12:19:40 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isascii(int c)
+{
+       return (0x00 <= c && c <= 0x7F);
+}
diff --git a/Libft/ft_check/ft_isdigit.c b/Libft/ft_check/ft_isdigit.c
new file mode 100644 (file)
index 0000000..ae10fdc
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isdigit.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:32:47 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isdigit(int c)
+{
+       return ('0' <= c && c <= '9');
+}
diff --git a/Libft/ft_check/ft_islower.c b/Libft/ft_check/ft_islower.c
new file mode 100644 (file)
index 0000000..60078ac
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_islower.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:31:47 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_islower(int c)
+{
+       return ('a' <= c && c <= 'z');
+}
diff --git a/Libft/ft_check/ft_isprint.c b/Libft/ft_check/ft_isprint.c
new file mode 100644 (file)
index 0000000..9f116ba
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isprint.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 12:17:32 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isprint(int c)
+{
+       return (0x20 <= c && c <= 0x7E);
+}
diff --git a/Libft/ft_check/ft_isspace.c b/Libft/ft_check/ft_isspace.c
new file mode 100644 (file)
index 0000000..02948c1
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isspace.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 11:29:54 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isspace(int c)
+{
+       return (c == ' ' || ('\t' <= c && c <= '\r'));
+}
diff --git a/Libft/ft_check/ft_isupper.c b/Libft/ft_check/ft_isupper.c
new file mode 100644 (file)
index 0000000..2a426c2
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isupper.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:31:05 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:20:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+
+int    ft_isupper(int c)
+{
+       return ('A' <= c && c <= 'Z');
+}
diff --git a/Libft/ft_conv/ft_atoi.c b/Libft/ft_conv/ft_atoi.c
new file mode 100644 (file)
index 0000000..ec7dbde
--- /dev/null
@@ -0,0 +1,86 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_atoi.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/13 13:44:39 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:54:24 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include "libft.h"
+
+int    ft_atoi(const char *nptr)
+{
+       int     res;
+       int     sign;
+
+       res = 0;
+       sign = 1;
+       while (ft_isspace(*nptr))
+               ++nptr;
+       if ((*nptr == '+' || *nptr == '-'))
+       {
+               if (*nptr == '-')
+                       sign *= -1;
+               ++nptr;
+       }
+       while (ft_isdigit(*nptr))
+       {
+               res *= 10;
+               res += *nptr - '0';
+               ++nptr;
+       }
+       return (sign * res);
+}
+
+long   ft_atol(const char *nptr)
+{
+       long    res;
+       int             sign;
+
+       res = 0;
+       sign = 1;
+       while (ft_isspace(*nptr))
+               ++nptr;
+       if ((*nptr == '+' || *nptr == '-'))
+       {
+               if (*nptr == '-')
+                       sign *= -1;
+               ++nptr;
+       }
+       while (ft_isdigit(*nptr))
+       {
+               res *= 10;
+               res += *nptr - '0';
+               ++nptr;
+       }
+       return (sign * res);
+}
+
+long long      ft_atoll(const char *nptr)
+{
+       long long       res;
+       int                     sign;
+
+       res = 0;
+       sign = 1;
+       while (ft_isspace(*nptr))
+               ++nptr;
+       if ((*nptr == '+' || *nptr == '-'))
+       {
+               if (*nptr == '-')
+                       sign *= -1;
+               ++nptr;
+       }
+       while (ft_isdigit(*nptr))
+       {
+               res *= 10;
+               res += *nptr - '0';
+               ++nptr;
+       }
+       return (sign * res);
+}
diff --git a/Libft/ft_conv/ft_ctoa.c b/Libft/ft_conv/ft_ctoa.c
new file mode 100644 (file)
index 0000000..e10520f
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_ctoa.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 09:55:17 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:44:01 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include <stdlib.h>    //malloc
+
+char   *ft_ctoa(char c)
+{
+       char    *res;
+
+       res = malloc(2 * sizeof(char));
+       if (res == NULL)
+               return (res);
+       res[0] = c;
+       res[1] = '\0';
+       return (res);
+}
diff --git a/Libft/ft_conv/ft_itoa.c b/Libft/ft_conv/ft_itoa.c
new file mode 100644 (file)
index 0000000..dbf4bf3
--- /dev/null
@@ -0,0 +1,57 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_itoa.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 15:58:10 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:44:23 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include <stdlib.h>
+
+static unsigned int    size_needed(int n)
+{
+       unsigned int    res;
+
+       res = 1;
+       if (n == 0)
+               return (2);
+       if (n < 0)
+               ++res;
+       while (n != 0)
+       {
+               ++res;
+               n /= 10;
+       }
+       return (res);
+}
+
+char   *ft_itoa(int n)
+{
+       unsigned int    size;
+       char                    *res;
+
+       size = size_needed(n);
+       res = malloc(size * sizeof(char));
+       if (res == NULL)
+               return (res);
+       res[--size] = '\0';
+       if (n == 0 && res)
+               res[0] = '0';
+       else if (n < 0 && res)
+       {
+               res[0] = '-';
+               res[--size] = '0' - (n % 10);
+               n = -(n / 10);
+       }
+       while (n > 0 && res)
+       {
+               res[--size] = '0' + (n % 10);
+               n /= 10;
+       }
+       return (res);
+}
diff --git a/Libft/ft_conv/ft_itoa_base.c b/Libft/ft_conv/ft_itoa_base.c
new file mode 100644 (file)
index 0000000..935f217
--- /dev/null
@@ -0,0 +1,86 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_itoa_base.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 09:46:11 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:53:11 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include "libft.h"
+#include <stdlib.h>    //malloc
+#include <stdint.h>    //intmax_t
+
+static intmax_t        abs_max(intmax_t n)
+{
+       if (n < 0)
+               return (-n);
+       else
+               return (n);
+}
+
+static int     size_needed(intmax_t n, size_t base_len)
+{
+       int     res;
+
+       if (n == 0)
+               return (2);
+       res = 1;
+       if (n < 0)
+               ++res;
+       while (n != 0)
+       {
+               ++res;
+               n /= base_len;
+       }
+       return (res);
+}
+
+static int     valid_base(const char *base)
+{
+       int     i;
+       int     j;
+
+       if (ft_strlen(base) < 2)
+               return (0);
+       i = 0;
+       while (base[i])
+       {
+               j = i + 1;
+               while (base[j])
+                       if (base[i] == base[j++])
+                               return (0);
+               ++i;
+       }
+       return (1);
+}
+
+char   *ft_itoa_base(intmax_t n, const char *base)
+{
+       int             size;
+       int             base_len;
+       char    *res;
+
+       if (!valid_base(base))
+               return (NULL);
+       base_len = ft_strlen(base);
+       size = size_needed(n, base_len);
+       res = malloc(size);
+       if (res == NULL)
+               return (res);
+       if (n < 0)
+               res[0] = '-';
+       res[--size] = '\0';
+       if (n == 0)
+               res[0] = base[0];
+       while (n != 0)
+       {
+               res[--size] = base[abs_max(n % base_len)];
+               n /= base_len;
+       }
+       return (res);
+}
diff --git a/Libft/ft_conv/ft_tolower.c b/Libft/ft_conv/ft_tolower.c
new file mode 100644 (file)
index 0000000..b8a5b90
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_tolower.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 10:36:54 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:53:39 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include "libft.h"
+
+int    ft_tolower(int c)
+{
+       if (ft_isupper(c))
+               c = c + 'a' - 'A';
+       return (c);
+}
diff --git a/Libft/ft_conv/ft_toupper.c b/Libft/ft_conv/ft_toupper.c
new file mode 100644 (file)
index 0000000..48f7567
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_toupper.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 10:35:21 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:54:01 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include "libft.h"
+
+int    ft_toupper(int c)
+{
+       if (ft_islower(c))
+               c = c + 'A' - 'a';
+       return (c);
+}
diff --git a/Libft/ft_conv/ft_uitoa_base.c b/Libft/ft_conv/ft_uitoa_base.c
new file mode 100644 (file)
index 0000000..4b29e05
--- /dev/null
@@ -0,0 +1,74 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_uitoa_base.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 09:46:11 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:54:44 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_conv.h"
+#include "libft.h"
+#include <stdlib.h>    //malloc
+#include <stdint.h>    //intmax_t
+
+static int     size_needed(uintmax_t n, size_t base_len)
+{
+       int     res;
+
+       if (n == 0)
+               return (2);
+       res = 1;
+       while (n != 0)
+       {
+               ++res;
+               n /= base_len;
+       }
+       return (res);
+}
+
+static int     valid_base(const char *base)
+{
+       int     i;
+       int     j;
+
+       if (ft_strlen(base) < 2)
+               return (0);
+       i = 0;
+       while (base[i])
+       {
+               j = i + 1;
+               while (base[j])
+                       if (base[i] == base[j++])
+                               return (0);
+               ++i;
+       }
+       return (1);
+}
+
+char   *ft_uitoa_base(uintmax_t n, const char *base)
+{
+       int             size;
+       int             base_len;
+       char    *res;
+
+       if (!valid_base(base))
+               return (NULL);
+       base_len = ft_strlen(base);
+       size = size_needed(n, base_len);
+       res = malloc(size);
+       if (res == NULL)
+               return (res);
+       res[--size] = '\0';
+       if (n == 0)
+               res[0] = base[0];
+       while (n != 0)
+       {
+               res[--size] = base[n % base_len];
+               n /= base_len;
+       }
+       return (res);
+}
diff --git a/Libft/ft_gen/ft_swap.c b/Libft/ft_gen/ft_swap.c
new file mode 100644 (file)
index 0000000..edee772
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_swap.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/11/03 13:59:28 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:21:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_gen.h"
+
+void   ft_swap(void **a, void **b)
+{
+       void    *tmp;
+
+       tmp = *a;
+       *a = *b;
+       *b = tmp;
+       return ;
+}
diff --git a/Libft/ft_io/ft_printf/conversion.c b/Libft/ft_io/ft_printf/conversion.c
new file mode 100644 (file)
index 0000000..f7e2010
--- /dev/null
@@ -0,0 +1,107 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   conversion.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 11:30:56 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:49:45 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_printf.h" 
+#include "libft.h"
+#include <stdlib.h>    // NULL, free
+#include <stdarg.h>    //va*
+
+static char    *base_str_constr(char type, va_list *args)
+{
+       char    *res;
+
+       res = NULL;
+       if (type == 'd' || type == 'i')
+               res = ft_itoa(va_arg(*args, int));
+       else if (type == 'o')
+               res = ft_uitoa_base(va_arg(*args, unsigned int), "01234567");
+       else if (type == 'u')
+               res = ft_uitoa_base(va_arg(*args, unsigned int), "0123456789");
+       else if (type == 'x')
+               res = ft_uitoa_base(va_arg(*args, unsigned int), "0123456789abcdef");
+       else if (type == 'X')
+               res = ft_uitoa_base(va_arg(*args, unsigned int), "0123456789ABCDEF");
+       else if (type == 'c')
+               res = ft_ctoa(va_arg(*args, int));
+       else if (type == 's')
+               res = ft_strdup(va_arg(*args, char *));
+       else if (type == 'p')
+               res = ft_uitoa_base((uintptr_t)va_arg(*args, void *),
+                               "0123456789abcdef");
+       return (res);
+}
+
+static int     valid_toprint(t_to_print tp)
+{
+       return (tp.left_pad && tp.zero_pad && tp.main_part && tp.right_pad);
+}
+
+static size_t  to_print_len(t_to_print *tp)
+{
+       size_t  len;
+
+       len = 0;
+       len += ft_strlen(tp->left_pad);
+       len += (tp->sign != '\0');
+       len += ft_strlen(tp->alt);
+       len += ft_strlen(tp->zero_pad);
+       len += ft_strlen(tp->main_part);
+       len += ft_strlen(tp->right_pad);
+       return (len);
+}
+
+int    tp_print_and_free_members(t_to_print *tp, t_conv conv)
+{
+       int     len;
+
+       len = to_print_len(tp);
+       ft_putstr_fd(tp->left_pad, 1);
+       if (tp->sign != '\0')
+               ft_putchar_fd(tp->sign, 1);
+       ft_putstr_fd(tp->alt, 1);
+       ft_putstr_fd(tp->zero_pad, 1);
+       if (*(tp->main_part) == '\0' && conv.type == 'c')
+       {
+               ft_putchar_fd('\0', 1);
+               ++len;
+       }
+       else
+               ft_putstr_fd(tp->main_part, 1);
+       ft_putstr_fd(tp->right_pad, 1);
+       free(tp->left_pad);
+       free(tp->alt);
+       free(tp->zero_pad);
+       free(tp->main_part);
+       free(tp->right_pad);
+       return (len);
+}
+
+int    handle_conversion(const char **format, va_list *args)
+{
+       t_conv          conv;
+       char            *temp;
+       t_to_print      to_print;
+
+       ++(*format);
+       conv = parse_format(format, args);
+       if (conv.type == '%')
+       {
+               ft_putchar_fd('%', 1);
+               return (1);
+       }
+       temp = base_str_constr(conv.type, args);
+       to_print = formatting(&temp, conv);
+       free(temp);
+       if (!valid_toprint(to_print))
+               return (-1);
+       return (tp_print_and_free_members(&to_print, conv));
+}
diff --git a/Libft/ft_io/ft_printf/formatting.c b/Libft/ft_io/ft_printf/formatting.c
new file mode 100644 (file)
index 0000000..8c60dcb
--- /dev/null
@@ -0,0 +1,106 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   formatting.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 11:28:21 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:51:30 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_printf.h"
+#include "libft.h"
+#include <stdlib.h>    // NULL, free
+#include <limits.h>
+
+static int     starts_with_zero(t_to_print *tp, t_conv conv)
+{
+       return ((intmax_t)ft_strlen(tp->main_part) < conv.prec);
+}
+
+static void    create_alt(t_to_print *tp, t_conv conv)
+{
+       if (conv.type == 'p' && *(tp->main_part) != '(')
+               tp->alt = ft_strdup("0x");
+       else if (conv.type == 's' || conv.type == 'c'
+               || ft_strncmp(tp->main_part, "0", 2) == 0
+               || ((*(tp->main_part) == '\0' || !conv.flags.alt_mode)
+                       && conv.type != 'o'))
+               tp->alt = ft_strdup("");
+       else if (conv.flags.alt_mode)
+       {
+               if (conv.type == 'x')
+                       tp->alt = ft_strdup("0x");
+               else if (conv.type == 'X')
+                       tp->alt = ft_strdup("0X");
+               else if (conv.type == 'o' && !starts_with_zero(tp, conv))
+                       tp->alt = ft_strdup("0");
+               else
+                       tp->alt = ft_strdup("");
+       }
+       else
+               tp->alt = ft_strdup("");
+       return ;
+}
+
+static void    create_main(char *str, t_to_print *tp, t_conv conv)
+{
+       if (conv.type != 's' && conv.type != 'c'
+               && ft_strncmp(str, "0", 2) == 0 && conv.prec == 0)
+               tp->main_part = ft_strdup("");
+       else if (conv.type == 'd' || conv.type == 'i')
+       {
+               if (*str == '-')
+               {
+                       tp->sign = '-';
+                       tp->main_part = ft_strdup(str + 1);
+               }
+               else
+               {
+                       tp->main_part = ft_strdup(str);
+                       if (conv.flags.sign_show)
+                               tp->sign = '+';
+                       else if (conv.flags.sign_allign)
+                               tp->sign = ' ';
+               }
+       }
+       else if (conv.type == 's'
+               && (size_t)conv.prec < ft_strlen(str) && conv.prec >= 0)
+               tp->main_part = ft_strndup(str, conv.prec);
+       else
+               tp->main_part = ft_strdup(str);
+       return ;
+}
+
+static void    init_printed(t_to_print *tp)
+{
+       tp->left_pad = NULL;
+       tp->sign = '\0';
+       tp->zero_pad = NULL;
+       tp->main_part = NULL;
+       tp->right_pad = NULL;
+       return ;
+}
+
+t_to_print     formatting(char **str, t_conv conv)
+{
+       t_to_print      res;
+
+       if ((conv.type == 'p' && ft_strncmp(*str, "0", 2) == 0))
+       {
+               free (*str);
+               *str = ft_strdup("(nil)");
+       }
+       else if (conv.type == 's' && *str == NULL
+               && (conv.prec >= 6 || conv.prec < 0))
+               *str = ft_strdup("(null)");
+       else if (conv.type == 's' && *str == NULL)
+               *str = ft_strdup("");
+       init_printed(&res);
+       create_main(*str, &res, conv);
+       create_alt(&res, conv);
+       create_padding(&res, conv);
+       return (res);
+}
diff --git a/Libft/ft_io/ft_printf/ft_printf.c b/Libft/ft_io/ft_printf/ft_printf.c
new file mode 100644 (file)
index 0000000..9d056d9
--- /dev/null
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_printf.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/17 09:14:21 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:41:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_printf.h"
+#include <stdarg.h>    // va_*
+#include <unistd.h>    // write
+
+int    print_ordinary(const char **s)
+{
+       int     len;
+
+       len = 0;
+       while ((*s)[len] && (*s)[len] != '%')
+               ++len;
+       write(1, *s, len);
+       *s += len;
+       return (len);
+}
+
+int    ft_printf(const char *format, ...)
+{
+       va_list args;
+       int             res;
+
+       res = 0;
+       va_start(args, format);
+       while (*format)
+       {
+               res += print_ordinary(&format);
+               if (!*format)
+                       break ;
+               res += handle_conversion(&format, &args);
+       }
+       va_end(args);
+       return (res);
+}
diff --git a/Libft/ft_io/ft_printf/ft_printf.h b/Libft/ft_io/ft_printf/ft_printf.h
new file mode 100644 (file)
index 0000000..2faba16
--- /dev/null
@@ -0,0 +1,51 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_printf.h                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 12:00:16 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_PRINTF_H
+# define FT_PRINTF_H
+
+# include <stdarg.h>
+
+typedef struct s_flags
+{
+       int     alt_mode;
+       int     zero_pad;
+       int     left_adjust;
+       int     sign_allign;
+       int     sign_show;
+}              t_flags;
+
+typedef struct s_conv
+{
+       t_flags flags;
+       int             minwidth;
+       int             prec;
+       char    type;
+}                      t_conv;
+
+typedef struct s_to_print
+{
+       char    *left_pad;
+       char    sign;
+       char    *alt;
+       char    *zero_pad;
+       char    *main_part;
+       char    *right_pad;
+}                      t_to_print;
+
+int                    ft_printf(const char *format, ...);
+int                    handle_conversion(const char **format, va_list *args);
+t_to_print     formatting(char **str, t_conv conv);
+t_conv         parse_format(const char **format, va_list *args);
+void           create_padding(t_to_print *tp, t_conv conv);
+
+#endif
diff --git a/Libft/ft_io/ft_printf/padding.c b/Libft/ft_io/ft_printf/padding.c
new file mode 100644 (file)
index 0000000..057cd14
--- /dev/null
@@ -0,0 +1,82 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   padding.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 11:25:46 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:50:15 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_printf.h"
+#include "libft.h"
+#include <stdlib.h>    //malloc
+
+static char    *repeat_char(char c, int n)
+{
+       char    *res;
+
+       if (n < 0)
+               n = 0;
+       res = malloc(++n);
+       if (res == NULL)
+               return (res);
+       res[--n] = '\0';
+       while (n > 0)
+               res[--n] = c;
+       return (res);
+}
+
+static void    lengthen_by_zeros(char **str, int n)
+{
+       char    *temp;
+       size_t  size;
+
+       if (n <= 0)
+               return ;
+       temp = *str;
+       size = ft_strlen(temp) + n + 1;
+       *str = malloc(size);
+       if (*str == NULL)
+       {
+               free(temp);
+               return ;
+       }
+       ft_strlcpy(*str, temp, size);
+       free(temp);
+       while (n > 0)
+               (*str)[size - (n--) - 1] = '0';
+       (*str)[size - 1] = '\0';
+       return ;
+}
+
+void   create_padding(t_to_print *tp, t_conv cv)
+{
+       size_t  len;
+
+       len = ft_strlen(tp->main_part) + (!tp->main_part[0] && cv.type == 'c');
+       if (cv.type == 's' || cv.type == 'c')
+               tp->zero_pad = ft_strdup("");
+       else
+               tp->zero_pad = repeat_char('0', cv.prec - len);
+       len += ft_strlen(tp->zero_pad) + ft_strlen(tp->alt) + (tp->sign != '\0');
+       if (cv.flags.left_adjust)
+       {
+               tp->right_pad = repeat_char(' ', cv.minwidth - len);
+               tp->left_pad = ft_strdup("");
+       }
+       else
+       {
+               tp->right_pad = ft_strdup("");
+               if (cv.flags.zero_pad && cv.prec < 0 && ft_strchr("diouxX", cv.type))
+               {
+                       tp->left_pad = ft_strdup("");
+                       lengthen_by_zeros(&(tp->zero_pad), cv.minwidth - len);
+               }
+               else
+                       tp->left_pad = repeat_char(' ', cv.minwidth - len);
+       }
+       return ;
+}
diff --git a/Libft/ft_io/ft_printf/parsing.c b/Libft/ft_io/ft_printf/parsing.c
new file mode 100644 (file)
index 0000000..660fcc0
--- /dev/null
@@ -0,0 +1,78 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   parsing.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 10:50:54 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:50:30 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_printf.h"
+#include "libft.h"
+#include <stdarg.h>    // va_*
+
+static t_flags parse_flags(const char **format)
+{
+       t_flags flags;
+
+       flags.alt_mode = 0;
+       flags.zero_pad = 0;
+       flags.left_adjust = 0;
+       flags.sign_allign = 0;
+       flags.sign_show = 0;
+       while (1)
+       {
+               if (**format == '#')
+                       flags.alt_mode = 1;
+               else if (**format == '0')
+                       flags.zero_pad = 1;
+               else if (**format == '-')
+                       flags.left_adjust = 1;
+               else if (**format == ' ')
+                       flags.sign_allign = 1;
+               else if (**format == '+')
+                       flags.sign_show = 1;
+               else
+                       return (flags);
+               ++(*format);
+       }
+}
+
+static int     parse_int(const char **format, va_list *args)
+{
+       int     res;
+
+       res = 0;
+       if (**format == '*')
+       {
+               res = va_arg(*args, int);
+               ++(*format);
+       }
+       else if (**format == '-' || ft_isdigit(**format))
+       {
+               res = ft_atoi(*format);
+               while (**format == '-' || ft_isdigit(**format))
+                       ++(*format);
+       }
+       return (res);
+}
+
+t_conv parse_format(const char **format, va_list *args)
+{
+       t_conv  conv;
+
+       conv.flags = parse_flags(format);
+       conv.minwidth = parse_int(format, args);
+       if (**format == '.')
+       {
+               ++(*format);
+               conv.prec = parse_int(format, args);
+       }
+       else
+               conv.prec = -1;
+       conv.type = *((*format)++);
+       return (conv);
+}
diff --git a/Libft/ft_io/ft_putchar_fd.c b/Libft/ft_io/ft_putchar_fd.c
new file mode 100644 (file)
index 0000000..dadcedf
--- /dev/null
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_putchar_fd.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:20:18 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:42:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_io.h"
+#include <unistd.h>
+
+void   ft_putchar_fd(char c, int fd)
+{
+       write(fd, &c, 1);
+       return ;
+}
diff --git a/Libft/ft_io/ft_putendl_fd.c b/Libft/ft_io/ft_putendl_fd.c
new file mode 100644 (file)
index 0000000..5e7bff9
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_putendl_fd.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:25:41 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:40:38 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_io.h"
+#include <unistd.h>
+
+void   ft_putendl_fd(char *s, int fd)
+{
+       ft_putstr_fd(s, fd);
+       write(fd, "\n", 1);
+       return ;
+}
diff --git a/Libft/ft_io/ft_putnbr_fd.c b/Libft/ft_io/ft_putnbr_fd.c
new file mode 100644 (file)
index 0000000..1b510dd
--- /dev/null
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_putnbr_fd.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:27:25 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:40:46 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_io.h"
+#include <unistd.h>
+
+void   ft_putnbr_fd(int n, int fd)
+{
+       char    digit;
+
+       if (n < 0)
+       {
+               write(fd, "-", 1);
+               digit = '0' - (n % 10);
+               if (n / 10 != 0)
+                       ft_putnbr_fd(-(n / 10), fd);
+       }
+       else if (n < 10)
+               digit = '0' + n;
+       else
+       {
+               digit = '0' + n % 10;
+               ft_putnbr_fd(n / 10, fd);
+       }
+       write(fd, &digit, 1);
+       return ;
+}
diff --git a/Libft/ft_io/ft_putstr_fd.c b/Libft/ft_io/ft_putstr_fd.c
new file mode 100644 (file)
index 0000000..812abb2
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_putstr_fd.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:23:36 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:52:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_io.h"
+#include "libft.h"
+#include <unistd.h>
+
+void   ft_putstr_fd(char *s, int fd)
+{
+       if (s == NULL)
+               return ;
+       write(fd, s, ft_strlen(s));
+       return ;
+}
diff --git a/Libft/ft_io/get_next_line.c b/Libft/ft_io/get_next_line.c
new file mode 100644 (file)
index 0000000..dcc2579
--- /dev/null
@@ -0,0 +1,140 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   get_next_line.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/28 00:01:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:52:02 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "get_next_line.h"
+#include "ft_io.h"
+#include "libft.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+t_list *new_ft_node(int fd)
+{
+       t_list  *node;
+       t_ft    *thread;
+
+       thread = malloc(sizeof(t_ft));
+       if (thread == NULL)
+               return (NULL);
+       node = ft_lstnew(thread);
+       if (node == NULL)
+       {
+               free(thread);
+               return (NULL);
+       }
+       thread->buffer = malloc((BUFFER_SIZE + 1) * sizeof(char));
+       if (thread->buffer == NULL)
+       {
+               free(thread);
+               free(node);
+               return (NULL);
+       }
+       (thread->buffer)[0] = '\0';
+       thread->fd = fd;
+       return (node);
+}
+
+// How to free?
+// static in get_next_line? So it could be passed to select AND delete
+static char    *select_file_buffer(int fd, t_list **list)
+{
+       t_list  *local_head;
+
+       if (*list == NULL)
+       {
+               *list = new_ft_node(fd);
+               if (list == NULL)
+                       return (NULL);
+               return (((t_ft *)((*list)->content))->buffer);
+       }
+       local_head = *list;
+       while (local_head->next && ((t_ft *)(local_head->content))->fd != fd)
+               local_head = local_head->next;
+       if (((t_ft *)(local_head->content))->fd == fd)
+               return (((t_ft *)(local_head->content))->buffer);
+       local_head->next = new_ft_node(fd);
+       if (local_head->next == NULL)
+               return (NULL);
+       return (((t_ft *)(local_head->next->content))->buffer);
+}
+
+static void    delete_file_node(int fd, t_list **list)
+{
+       t_list  *cur;
+       t_list  *prev;
+
+       prev = NULL;
+       cur = *list;
+       while (((t_ft *)(cur->content))->fd != fd)
+       {
+               prev = cur;
+               cur = cur->next;
+       }
+       if (prev == NULL)
+               *list = cur->next;
+       else
+               prev->next = cur->next;
+       free(((t_ft *)(cur->content))->buffer);
+       free(cur->content);
+       free(cur);
+       return ;
+}
+
+/*     Concatenates res and buffer up to newline.
+       Shifts buffer by the transfered characters.
+       Returns 0 when buffer is empty (and needs filling with read).
+       Also returns 1 when newline is transfered
+       unless buffer empty (to delete node).
+       Otherwise returns true.
+*/
+static int     transfer_string(char **res, char *buffer)
+{
+       int     i;
+       int     nl;
+
+       i = 0;
+       while (buffer[i] && buffer[i] != '\n')
+               ++i;
+       nl = (buffer[i] == '\n');
+       i += nl;
+       ft_strncat_alloc(res, buffer, i);
+       ft_memmove(buffer, buffer + i, BUFFER_SIZE + 1 - i);
+       return (buffer[0] || nl);
+}
+
+char   *get_next_line(int fd)
+{
+       static t_list   *list;
+       char                    *buffer;
+       char                    *res;
+       int                             i;
+
+       res = NULL;
+       buffer = select_file_buffer(fd, &list);
+       while (!transfer_string(&res, buffer))
+       {
+               if (buffer[0] == '\0')
+               {
+                       i = read(fd, buffer, BUFFER_SIZE);
+                       if (i <= 0)
+                               delete_file_node(fd, &list);
+                       if (i < 0)
+                       {
+                               free(res);
+                               return (NULL);
+                       }
+                       if (i == 0)
+                               return (res);
+                       buffer[i] = '\0';
+               }
+       }
+       return (res);
+}
diff --git a/Libft/ft_io/get_next_line.h b/Libft/ft_io/get_next_line.h
new file mode 100644 (file)
index 0000000..2ddfa98
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   get_next_line.h                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/28 11:24:52 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef GET_NEXT_LINE_H
+# define GET_NEXT_LINE_H
+
+# ifndef BUFFER_SIZE
+#  define BUFFER_SIZE 80
+# endif
+
+# include <stddef.h>
+
+typedef struct s_file_thread
+{
+       int             fd;
+       char    *buffer;
+}                      t_ft;
+
+#endif
diff --git a/Libft/ft_lst/ft_lst_at.c b/Libft/ft_lst/ft_lst_at.c
new file mode 100644 (file)
index 0000000..08836f3
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_at.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 14:19:21 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+
+t_list *ft_lst_at(t_list *lst, unsigned int i)
+{
+       unsigned int    j;
+
+       j = 0;
+       while (j < i && lst)
+       {
+               lst = lst->next;
+               ++j;
+       }
+       return (lst);
+}
diff --git a/Libft/ft_lst/ft_lst_find.c b/Libft/ft_lst/ft_lst_find.c
new file mode 100644 (file)
index 0000000..86a8ca0
--- /dev/null
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_find.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 14:47:42 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_lst.h"
+
+t_list *ft_lst_find(t_list *lst, void *content_ref, int (*cmp)())
+{
+       while (lst)
+       {
+               if (cmp(lst->content, content_ref) == 0)
+                       return (lst);
+               lst = lst->next;
+       }
+       return (NULL);
+}
diff --git a/Libft/ft_lst/ft_lst_foreach_if.c b/Libft/ft_lst/ft_lst_foreach_if.c
new file mode 100644 (file)
index 0000000..d333fe2
--- /dev/null
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_foreach_if.c                                :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 14:42:33 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+
+void   ft_lst_foreach_if(t_list *lst, void (*f)(void *),
+                       void *content_ref, int (*cmp)())
+{
+       while (lst)
+       {
+               if (cmp(lst->content, content_ref) == 0)
+                       f(lst->content);
+               lst = lst->next;
+       }
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_merge.c b/Libft/ft_lst/ft_lst_merge.c
new file mode 100644 (file)
index 0000000..f79a004
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_merge.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 15:09:00 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+
+void   ft_lst_merge(t_list **lst1, t_list *lst2)
+{
+       t_list  *last;
+
+       if (!*lst1)
+       {
+               *lst1 = lst2;
+               return ;
+       }
+       last = ft_lstlast(*lst1);
+       last->next = lst2;
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_remove_if.c b/Libft/ft_lst/ft_lst_remove_if.c
new file mode 100644 (file)
index 0000000..64bd2bd
--- /dev/null
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_remove_if.c                                 :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 14:49:53 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+static void    remove_next_el(t_list *prev, t_list **cur, void (*free_fct)(void *))
+{
+       prev->next = (*cur)->next;
+       free_fct((*cur)->content);
+       free(*cur);
+       *cur = prev->next;
+       return ;
+}
+
+void   ft_lst_remove_if(t_list **lst, void *content_ref,
+                       int (*cmp)(), void (*free_fct)(void *))
+{
+       t_list  *prev;
+
+       prev = NULL;
+       while (*lst)
+       {
+               if (cmp((*lst)->content, content_ref) == 0)
+                       remove_next_el(prev, lst, free_fct);
+               else
+                       *lst = (*lst)->next;
+       }
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_reverse.c b/Libft/ft_lst/ft_lst_reverse.c
new file mode 100644 (file)
index 0000000..a77dad8
--- /dev/null
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_reverse.c                                   :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 14:22:47 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_lst.h"
+
+void   ft_lst_reverse(t_list **lst)
+{
+       t_list  *prev;
+       t_list  *current;
+       t_list  *next;
+
+       prev = NULL;
+       current = *lst;
+       while (current)
+       {
+               next = current->next;
+               current->next = prev;
+               prev = current;
+               current = next;
+       }
+       *lst = prev;
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_sort.c b/Libft/ft_lst/ft_lst_sort.c
new file mode 100644 (file)
index 0000000..40f3499
--- /dev/null
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_sort.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 15:13:29 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:55:45 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+#include "libft.h"
+
+static void    ft_max_to_end(t_list *lst, int (*cmp)(), int size)
+{
+       int     i;
+
+       i = 0;
+       while (i < size - 1)
+       {
+               if (cmp(lst->content, lst->next->content) > 0)
+                       ft_swap(&(lst->content), &(lst->next->content));
+               lst = lst->next;
+       }
+       return ;
+}
+
+// Bubble sort
+void   ft_lst_sort(t_list **lst, int (*cmp)())
+{
+       int     size;
+       int     i;
+
+       size = ft_lstsize(*lst);
+       i = 0;
+       while (i < size)
+       {
+               ft_max_to_end(*lst, cmp, size - i);
+               ++i;
+       }
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_sorted_insert.c b/Libft/ft_lst/ft_lst_sorted_insert.c
new file mode 100644 (file)
index 0000000..5705a3f
--- /dev/null
@@ -0,0 +1,51 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_sorted_insert.c                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 15:53:26 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+static void    insert_after(t_list *prev, t_list *new)
+{
+       if (!new)
+               return ;
+       new->next = prev->next;
+       prev->next = new;
+       return ;
+}
+
+void   ft_lst_sorted_insert(t_list **lst, t_list *new, int (*cmp)())
+{
+       t_list  *prev;
+       t_list  *cur;
+
+       if (!lst || !new)
+               return ;
+       if (!*lst)
+       {
+               *lst = new;
+               return ;
+       }
+       prev = NULL;
+       cur = *lst;
+       while (cur)
+       {
+               if (cmp(new->content, cur->content) <= 0)
+                       break ;
+               prev = cur;
+               cur = cur->next;
+       }
+       if (prev)
+               insert_after(prev, new);
+       else
+               ft_lstadd_front(lst, new);
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lst_sorted_merge.c b/Libft/ft_lst/ft_lst_sorted_merge.c
new file mode 100644 (file)
index 0000000..f80caa7
--- /dev/null
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst_sorted_merge.c                              :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/28 17:13:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:55:15 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+#include "libft.h"
+
+void   ft_lst_sorted_merge(t_list **lst1, t_list *lst2, int (*cmp)())
+{
+       t_list  *main;
+
+       if (cmp((*lst1)->content, lst2->content) > 0)
+       {
+               main = lst2;
+               lst2 = *lst1;
+               *lst1 = main;
+       }
+       else
+               main = *lst1;
+       while (main->next)
+       {
+               if (cmp(main->next->content, lst2->content) > 0)
+                       ft_swap((void **)&main, (void **)&lst2);
+               main = main->next;
+       }
+       main->next = lst2;
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstadd_back.c b/Libft/ft_lst/ft_lstadd_back.c
new file mode 100644 (file)
index 0000000..f127224
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstadd_back.c                                   :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:33:28 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_lst.h"
+
+void   ft_lstadd_back(t_list **lst, t_list *new)
+{
+       if (!new)
+               return ;
+       if (*lst == NULL)
+       {
+               *lst = new;
+               return ;
+       }
+       ft_lstlast(*lst)->next = new;
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstadd_front.c b/Libft/ft_lst/ft_lstadd_front.c
new file mode 100644 (file)
index 0000000..55ca676
--- /dev/null
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstadd_front.c                                  :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:26:20 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+
+void   ft_lstadd_front(t_list **lst, t_list *new)
+{
+       if (!new)
+               return ;
+       new->next = *lst;
+       *lst = new;
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstclear.c b/Libft/ft_lst/ft_lstclear.c
new file mode 100644 (file)
index 0000000..a3b83a6
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstclear.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:45:28 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+void   ft_lstclear(t_list **lst, void (*del)(void *))
+{
+       t_list  *temp;
+
+       if (lst == NULL || del == NULL)
+               return ;
+       while (*lst)
+       {
+               temp = (*lst)->next;
+               ft_lstdelone(*lst, del);
+               *lst = temp;
+       }
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstdelone.c b/Libft/ft_lst/ft_lstdelone.c
new file mode 100644 (file)
index 0000000..35289e8
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstdelone.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:43:02 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+void   ft_lstdelone(t_list *lst, void (*del)(void *))
+{
+       if (lst == NULL || del == NULL)
+               return ;
+       del(lst->content);
+       free(lst);
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstiter.c b/Libft/ft_lst/ft_lstiter.c
new file mode 100644 (file)
index 0000000..9960fe5
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstiter.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:50:31 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_lst.h"
+
+void   ft_lstiter(t_list *lst, void (*f)(void *))
+{
+       while (lst)
+       {
+               f(lst->content);
+               lst = lst->next;
+       }
+       return ;
+}
diff --git a/Libft/ft_lst/ft_lstlast.c b/Libft/ft_lst/ft_lstlast.c
new file mode 100644 (file)
index 0000000..d827d38
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstlast.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:31:01 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_lst.h"
+
+t_list *ft_lstlast(t_list *lst)
+{
+       if (lst == NULL)
+               return (lst);
+       while (lst->next)
+               lst = lst->next;
+       return (lst);
+}
diff --git a/Libft/ft_lst/ft_lstmap.c b/Libft/ft_lst/ft_lstmap.c
new file mode 100644 (file)
index 0000000..15efc8e
--- /dev/null
@@ -0,0 +1,54 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstmap.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:51:57 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+static t_list  *first_el(t_list *lst, void *(*f)(void *), void (*del)(void *))
+{
+       t_list  *res;
+       void    *cont;
+
+       if (lst == NULL)
+               return (NULL);
+       cont = f(lst->content);
+       res = ft_lstnew(cont);
+       if (res == NULL)
+               del(cont);
+       return (res);
+}
+
+t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
+{
+       t_list  *res;
+       t_list  *new_node;
+       void    *new_cont;
+
+       res = first_el(lst, f, del);
+       if (res == NULL)
+               return (res);
+       new_node = res;
+       lst = lst->next;
+       while (lst && res)
+       {
+               new_cont = f(lst->content);
+               new_node->next = ft_lstnew(new_cont);
+               new_node = new_node->next;
+               if (new_node == NULL)
+               {
+                       del(new_cont);
+                       ft_lstclear(&res, del);
+               }
+               lst = lst->next;
+       }
+       return (res);
+}
diff --git a/Libft/ft_lst/ft_lstnew.c b/Libft/ft_lst/ft_lstnew.c
new file mode 100644 (file)
index 0000000..b902847
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstnew.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:23:00 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_lst.h"
+
+t_list *ft_lstnew(void *content)
+{
+       t_list  *res;
+
+       res = malloc(sizeof(t_list));
+       if (res)
+       {
+               res->content = content;
+               res->next = NULL;
+       }
+       return (res);
+}
diff --git a/Libft/ft_lst/ft_lstsize.c b/Libft/ft_lst/ft_lstsize.c
new file mode 100644 (file)
index 0000000..106602e
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lstsize.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/16 13:28:58 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:22:53 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_lst.h"
+
+int    ft_lstsize(t_list *lst)
+{
+       int     res;
+
+       res = 0;
+       while (lst)
+       {
+               lst = lst->next;
+               ++res;
+       }
+       return (res);
+}
diff --git a/Libft/ft_math/ft_abs.c b/Libft/ft_math/ft_abs.c
new file mode 100644 (file)
index 0000000..5fc5552
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_abs.c                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/05 09:48:21 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:23:57 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_math.h"
+
+int    ft_abs(int n)
+{
+       if (n < 0)
+               return (-n);
+       else
+               return (n);
+}
diff --git a/Libft/ft_math/ft_sgn.c b/Libft/ft_math/ft_sgn.c
new file mode 100644 (file)
index 0000000..da3b0ae
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_sgn.c                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/18 09:41:56 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/30 18:09:32 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_math.h"
+
+int    ft_sgn(int n)
+{
+       return ((n > 0) - (n < 0));
+}
+
+/*
+int    ft_sgn(int n)
+{
+       if (n > 0)
+               return (1);
+       if (n < 0)
+               return (-1);
+       return (0);
+}
+*/
diff --git a/Libft/ft_mem/ft_bzero.c b/Libft/ft_mem/ft_bzero.c
new file mode 100644 (file)
index 0000000..048354d
--- /dev/null
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_bzero.c                                         :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:38:08 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "ft_mem.h"
+
+void   ft_bzero(void *s, size_t n)
+{
+       ft_memset(s, 0, n);
+       return ;
+}
diff --git a/Libft/ft_mem/ft_calloc.c b/Libft/ft_mem/ft_calloc.c
new file mode 100644 (file)
index 0000000..6e4a0fa
--- /dev/null
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_calloc.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 11:34:52 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+/*     This should not be commented as to emulate builtin calloc
+       but errno calls function which is deemed forbidden by Moulinette
+#include <errno.h>
+       if (total_bytes / size != nmemb)
+       {
+               errno = ENOMEM;
+               return (NULL);
+       }
+*/
+#include <stdlib.h>    // for malloc
+#include "ft_mem.h"
+
+void   *ft_calloc(size_t nmemb, size_t size)
+{
+       size_t  total_bytes;
+       void    *res;
+
+       if (nmemb == 0 || size == 0)
+               return (malloc(0));
+       total_bytes = nmemb * size;
+       if (total_bytes / size != nmemb)
+               return (NULL);
+       res = malloc(total_bytes);
+       if (res == NULL)
+               return (NULL);
+       ft_memset(res, 0, total_bytes);
+       return (res);
+}
diff --git a/Libft/ft_mem/ft_memchr.c b/Libft/ft_mem/ft_memchr.c
new file mode 100644 (file)
index 0000000..ec84ed5
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memchr.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 10:56:53 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "ft_mem.h"
+
+void   *ft_memchr(const void *s, int c, size_t n)
+{
+       size_t  i;
+
+       i = 0;
+       while (i < n)
+       {
+               if (*((unsigned char *)s + i) == (unsigned char)c)
+                       return ((unsigned char *)s + i);
+               ++i;
+       }
+       return (NULL);
+}
diff --git a/Libft/ft_mem/ft_memcmp.c b/Libft/ft_mem/ft_memcmp.c
new file mode 100644 (file)
index 0000000..f51279b
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memcmp.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 11:06:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "ft_mem.h"
+
+int    ft_memcmp(const void *s1, const void *s2, size_t n)
+{
+       size_t  i;
+
+       i = 0;
+       while (*((unsigned char *)s1 + i) == *((unsigned char *)s2 + i)
+               && i + 1 < n)
+               ++i;
+       if (n > 0)
+               return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i));
+       else
+               return (0);
+}
diff --git a/Libft/ft_mem/ft_memcpy.c b/Libft/ft_mem/ft_memcpy.c
new file mode 100644 (file)
index 0000000..fd58af4
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memcpy.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:35:59 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "ft_mem.h"
+
+void   *ft_memcpy(void *dest, const void *src, size_t n)
+{
+       if (dest == NULL && src == NULL)
+               return (NULL);
+       while (n > 0)
+       {
+               --n;
+               *((unsigned char *)dest + n) = *((unsigned char *)src + n);
+       }
+       return (dest);
+}
diff --git a/Libft/ft_mem/ft_memmove.c b/Libft/ft_mem/ft_memmove.c
new file mode 100644 (file)
index 0000000..ffd024b
--- /dev/null
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memmove.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:36:32 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "ft_mem.h"
+
+void   *ft_memmove(void *dest, const void *src, size_t n)
+{
+       size_t  i;
+
+       if (dest > src)
+       {
+               i = n;
+               while (i > 0)
+               {
+                       --i;
+                       *((unsigned char *)dest + i) = *((unsigned char *)src + i);
+               }
+       }
+       else if (dest < src)
+       {
+               i = 0;
+               while (i < n)
+               {
+                       *((unsigned char *)dest + i) = *((unsigned char *)src + i);
+                       ++i;
+               }
+       }
+       return (dest);
+}
diff --git a/Libft/ft_mem/ft_memset.c b/Libft/ft_mem/ft_memset.c
new file mode 100644 (file)
index 0000000..30ce07a
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memset.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:13:22 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "ft_mem.h"
+
+void   *ft_memset(void *s, int c, size_t n)
+{
+       while (n > 0)
+               *((unsigned char *)s + (--n)) = (unsigned char)c;
+       return (s);
+}
diff --git a/Libft/ft_str/ft_split.c b/Libft/ft_str/ft_split.c
new file mode 100644 (file)
index 0000000..710248d
--- /dev/null
@@ -0,0 +1,92 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_split.c                                         :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 15:30:26 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_str.h"
+
+static void    free_str_array(char **arr)
+{
+       size_t  i;
+
+       i = 0;
+       while (arr[i] != NULL)
+               free(arr[i++]);
+       free(arr);
+       return ;
+}
+
+// Returns 0 when terminating null is encountered, otherwise returns true.
+static int     to_next_word(const char **s, char c)
+{
+       while (**s && **s == c)
+               ++(*s);
+       return (**s);
+}
+
+static int     word_count(const char *s, char c)
+{
+       int     count;
+
+       if (s == NULL)
+               return (-1);
+       if (c == '\0')
+               return (1);
+       count = 0;
+       while (*s)
+       {
+               while (*s == c)
+                       ++s;
+               if (*s)
+                       ++count;
+               while (*s != c && *s)
+                       ++s;
+       }
+       return (count);
+}
+
+static size_t  strlen_to_char(const char *s, char c)
+{
+       size_t  len;
+
+       len = 0;
+       while (s[len] != c && s[len])
+               ++len;
+       return (len);
+}
+
+char   **ft_split(const char *s, char c)
+{
+       char            **res;
+       size_t          size;
+       size_t          i;
+
+       res = malloc((word_count(s, c) + 1) * sizeof(char *));
+       if (res == NULL || s == NULL)
+               return (res);
+       i = 0;
+       while (*s)
+       {
+               if (!to_next_word(&s, c))
+                       break ;
+               size = (strlen_to_char(s, c) + 1);
+               res[i] = malloc(size * sizeof(char));
+               if (res[i] == NULL)
+               {
+                       free_str_array(res);
+                       return (NULL);
+               }
+               ft_strlcpy(res[i++], s, size);
+               s += size - 1;
+       }
+       res[i] = NULL;
+       return (res);
+}
diff --git a/Libft/ft_str/ft_strchr.c b/Libft/ft_str/ft_strchr.c
new file mode 100644 (file)
index 0000000..6a4e3b6
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strchr.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 10:41:10 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:44:56 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <stddef.h>
+
+char   *ft_strchr(const char *s, int c)
+{
+       while (*s)
+       {
+               if (*s == (char)c)
+                       return ((char *)s);
+               ++s;
+       }
+       if (c == '\0')
+               return ((char *)s);
+       return (NULL);
+}
diff --git a/Libft/ft_str/ft_strcmp.c b/Libft/ft_str/ft_strcmp.c
new file mode 100644 (file)
index 0000000..e20ddb5
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strcmp.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/13 14:11:31 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/13 15:00:17 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+
+int    ft_strcmp(const char *s1, const char *s2)
+{
+       size_t  i;
+
+       i = 0;
+       while (s1[i] == s2[i] && s1[i] && s2[i])
+               ++i;
+       return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+}
diff --git a/Libft/ft_str/ft_strdup.c b/Libft/ft_str/ft_strdup.c
new file mode 100644 (file)
index 0000000..6c725f4
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strdup.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/17 13:33:49 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:31 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <stdlib.h>    // For the malloc function
+
+char   *ft_strdup(const char *s)
+{
+       char    *dest;
+       size_t  s_len;
+
+       if (s == NULL)
+               return (NULL);
+       s_len = ft_strlen(s);
+       dest = malloc((s_len + 1) * sizeof(char));
+       if (dest)
+               ft_strlcpy(dest, s, s_len + 1);
+       return (dest);
+}
diff --git a/Libft/ft_str/ft_striteri.c b/Libft/ft_str/ft_striteri.c
new file mode 100644 (file)
index 0000000..ac2bce2
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_striteri.c                                      :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:18:09 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:55 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <stddef.h>
+
+void   ft_striteri(char *s, void (*f)(unsigned int, char *))
+{
+       unsigned int    i;
+
+       if (s == NULL || f == NULL)
+               return ;
+       i = 0;
+       while (s[i])
+       {
+               f(i, s + i);
+               ++i;
+       }
+       return ;
+}
diff --git a/Libft/ft_str/ft_strjoin.c b/Libft/ft_str/ft_strjoin.c
new file mode 100644 (file)
index 0000000..39ff7e9
--- /dev/null
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strjoin.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 15:04:10 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_str.h"
+
+char   *ft_strjoin(const char *s1, const char *s2)
+{
+       char    *res;
+       size_t  size;
+
+       if (s1 == NULL || s2 == NULL)
+               return (NULL);
+       size = ft_strlen(s1) + ft_strlen(s2) + 1;
+       res = malloc(size * sizeof(char));
+       if (res == NULL)
+               return (res);
+       res[0] = '\0';
+       ft_strlcat(res, s1, size);
+       ft_strlcat(res, s2, size);
+       return (res);
+}
diff --git a/Libft/ft_str/ft_strlcat.c b/Libft/ft_str/ft_strlcat.c
new file mode 100644 (file)
index 0000000..ba6de01
--- /dev/null
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlcat.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/12 17:32:33 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "ft_str.h"
+
+size_t ft_strlcat(char *dst, const char *src, size_t size)
+{
+       size_t  length;
+
+       if ((dst == NULL && src == NULL) || size == 0)
+               return (0);
+       length = 0;
+       while (*dst && size > length)
+       {
+               ++dst;
+               ++length;
+       }
+       while (*src && size > length + 1)
+       {
+               *dst = *src;
+               ++src;
+               ++dst;
+               ++length;
+       }
+       if (size > length)
+               *dst = '\0';
+       while (*src)
+       {
+               ++length;
+               ++src;
+       }
+       return (length);
+}
diff --git a/Libft/ft_str/ft_strlcpy.c b/Libft/ft_str/ft_strlcpy.c
new file mode 100644 (file)
index 0000000..cae2832
--- /dev/null
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlcpy.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/11 17:28:43 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+
+size_t ft_strlcpy(char *dst, const char *src, size_t size)
+{
+       size_t  i;
+
+       i = 0;
+       while (src[i] && i + 1 < size)
+       {
+               dst[i] = src[i];
+               ++i;
+       }
+       if (size > 0)
+               dst[i] = '\0';
+       while (src[i])
+               ++i;
+       return (i);
+}
diff --git a/Libft/ft_str/ft_strlen.c b/Libft/ft_str/ft_strlen.c
new file mode 100644 (file)
index 0000000..498c745
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlen.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:40:59 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:21 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+
+size_t ft_strlen(const char *s)
+{
+       size_t  len;
+
+       len = 0;
+       while (s[len] != '\0')
+               ++len;
+       return (len);
+}
diff --git a/Libft/ft_str/ft_strmapi.c b/Libft/ft_str/ft_strmapi.c
new file mode 100644 (file)
index 0000000..cb44e80
--- /dev/null
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strmapi.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:12:48 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_str.h"
+
+char   *ft_strmapi(const char *s, char (*f)(unsigned int, char))
+{
+       char                    *res;
+       unsigned int    i;
+
+       if (s == NULL || f == NULL)
+               return (NULL);
+       res = malloc((ft_strlen(s) + 1) * sizeof(char));
+       if (res == NULL)
+               return (NULL);
+       i = 0;
+       while (s[i])
+       {
+               res[i] = f(i, s[i]);
+               ++i;
+       }
+       res[i] = '\0';
+       return (res);
+}
diff --git a/Libft/ft_str/ft_strncat_alloc.c b/Libft/ft_str/ft_strncat_alloc.c
new file mode 100644 (file)
index 0000000..45d2cfa
--- /dev/null
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strncat_alloc.c                                 :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/09/11 13:36:53 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:48:57 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include "libft.h"
+#include <stdlib.h>    // malloc etc.
+
+/*     Functions like ft_strncat but reallocates dest to
+       make sure it is large enough    */
+char   *ft_strncat_alloc(char **dest, const char *src, size_t n)
+{
+       int             size;
+       char    *temp;
+
+       if (n == 0)
+               return (*dest);
+       temp = *dest;
+       size = 0;
+       if (temp)
+               while (temp[size])
+                       ++size;
+       size += n + 1;
+       *dest = malloc(size);
+       if (*dest == NULL)
+       {
+               free(temp);
+               return (NULL);
+       }
+       ft_memmove(*dest, temp, size - n - 1);
+       ft_memmove(*dest + size - n - 1, src, n);
+       (*dest)[size - 1] = '\0';
+       free(temp);
+       return (*dest);
+}
diff --git a/Libft/ft_str/ft_strncmp.c b/Libft/ft_str/ft_strncmp.c
new file mode 100644 (file)
index 0000000..ad5f582
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strncmp.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/12 17:02:07 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:44:40 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+
+int    ft_strncmp(const char *s1, const char *s2, size_t n)
+{
+       size_t  i;
+
+       i = 0;
+       while (s1[i] == s2[i] && s1[i] && s2[i] && i + 1 < n)
+               ++i;
+       if (n > 0)
+               return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+       else
+               return (0);
+}
diff --git a/Libft/ft_str/ft_strndup.c b/Libft/ft_str/ft_strndup.c
new file mode 100644 (file)
index 0000000..03608ca
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strndup.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/24 09:18:49 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:44:47 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <stdlib.h>    // For the malloc function
+
+char   *ft_strndup(const char *s, size_t n)
+{
+       char    *dest;
+       size_t  s_len;
+
+       s_len = ft_strlen(s);
+       if (s_len < n)
+               n = s_len;
+       dest = malloc((n + 1) * sizeof(char));
+       if (dest == NULL)
+               return (dest);
+       ft_strlcpy(dest, s, n + 1);
+       return (dest);
+}
diff --git a/Libft/ft_str/ft_strnstr.c b/Libft/ft_str/ft_strnstr.c
new file mode 100644 (file)
index 0000000..afb9326
--- /dev/null
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strnstr.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/12 17:15:34 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:47 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <stddef.h>    // For the NULL pointer
+#include <sys/types.h>
+
+char   *ft_strnstr(const char *big, const char *little, size_t len)
+{
+       size_t  little_len;
+       size_t  i;
+
+       if (little == NULL && len == 0)
+               return ((char *)big);
+       if (*little == '\0')
+               return ((char *)big);
+       if (big == NULL && len == 0)
+               return (NULL);
+       little_len = ft_strlen(little);
+       i = 0;
+       while (big[i] && i + little_len <= len)
+       {
+               if (!(ft_strncmp(big + i, little, little_len)))
+                       return ((char *)big + i);
+               ++i;
+       }
+       return (NULL);
+}
diff --git a/Libft/ft_str/ft_strrchr.c b/Libft/ft_str/ft_strrchr.c
new file mode 100644 (file)
index 0000000..1afc2c1
--- /dev/null
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strrchr.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 10:46:09 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_str.h"
+
+char   *ft_strrchr(const char *s, int c)
+{
+       char    *result;
+
+       result = NULL;
+       while (*s)
+       {
+               if (*s == (char)c)
+                       result = (char *)s;
+               ++s;
+       }
+       if (c == '\0')
+               return ((char *)s);
+       return (result);
+}
diff --git a/Libft/ft_str/ft_strtrim.c b/Libft/ft_str/ft_strtrim.c
new file mode 100644 (file)
index 0000000..6494bd3
--- /dev/null
@@ -0,0 +1,59 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strtrim.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 15:11:52 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:45:03 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+#include <stdlib.h>
+
+static size_t  size_needed(const char *s1, const char *set)
+{
+       size_t  at_start;
+       size_t  at_end;
+       size_t  whole;
+
+       whole = ft_strlen(s1);
+       at_start = 0;
+       at_end = 0;
+       while (ft_strchr(set, *s1) && *s1)
+       {
+               ++s1;
+               ++at_start;
+       }
+       if (*s1 == '\0')
+               return (1);
+       while (*s1)
+               ++s1;
+       --s1;
+       while (ft_strchr(set, *s1))
+       {
+               --s1;
+               ++at_end;
+       }
+       return (whole - at_start - at_end + 1);
+}
+
+char   *ft_strtrim(const char *s1, const char *set)
+{
+       size_t  size;
+       char    *res;
+
+       if (s1 == NULL)
+               return (NULL);
+       size = size_needed(s1, set);
+       res = malloc(size * sizeof(char));
+       if (res == NULL)
+               return (res);
+       while (ft_strchr(set, *s1) && *s1)
+               ++s1;
+       ft_strlcpy(res, s1, size);
+       return (res);
+}
diff --git a/Libft/ft_str/ft_substr.c b/Libft/ft_str/ft_substr.c
new file mode 100644 (file)
index 0000000..ededd6a
--- /dev/null
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_substr.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 15:04:24 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:24:36 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_str.h"
+
+char   *ft_substr(const char *s, unsigned int start, size_t len)
+{
+       char    *res;
+       size_t  size;
+
+       if (s == NULL)
+               return (NULL);
+       size = ft_strlen(s) + 1;
+       if (start > size)
+       {
+               res = malloc(1 * sizeof(char));
+               if (res == NULL)
+                       return (NULL);
+               *res = '\0';
+               return (res);
+       }
+       else
+               size -= start;
+       if (size > len + 1)
+               size = len + 1;
+       res = malloc(size * sizeof(char));
+       if (res == NULL)
+               return (NULL);
+       ft_strlcpy(res, s + start, size);
+       return (res);
+}
diff --git a/Libft/inc/ft_arr.h b/Libft/inc/ft_arr.h
new file mode 100644 (file)
index 0000000..4b69c95
--- /dev/null
@@ -0,0 +1,96 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_arr.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 13:58:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/17 14:52:46 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_ARR_H
+# define FT_ARR_H
+
+# include <stddef.h>
+
+# ifndef V_DEFAULT_CAPACITY
+#  define V_DEFAULT_CAPACITY 8
+# endif
+
+typedef enum e_arr_stat
+{
+       success,
+       alloc_fail,
+       invalid_size,
+       invalid_input,
+       non_specific_failure,
+}                      t_arr_stat;
+
+// It should be possible to remove el_size with the use of macros?
+typedef struct s_vec
+{
+       size_t  capacity;
+       size_t  size;
+       size_t  el_size;
+       void    *vec;
+}                      t_vec;
+
+typedef struct s_mat
+{
+       size_t  rows;
+       size_t  cols;
+       t_vec   vec;
+}                      t_mat;
+
+t_arr_stat     ft_vec_reserve(t_vec *vec, size_t capacity);
+t_arr_stat     ft_vec_enlarge(t_vec *vec);
+t_arr_stat     ft_vec_insert(t_vec *vec, const void *element, size_t index);
+t_arr_stat     ft_vec_append(t_vec *vec, const void *element);
+t_arr_stat     ft_vec_forget(t_vec *vec, size_t index);
+t_arr_stat     ft_vec_erase(t_vec *vec, size_t index, void (*free_el)(void *));
+
+t_arr_stat     ft_vec_insert_range(t_vec *vec, const void *element,
+                               size_t count, size_t index);
+t_arr_stat     ft_vec_append_range(t_vec *vec, const void *element, size_t count);
+t_arr_stat     ft_vec_forget_range(t_vec *vec, size_t index, size_t count);
+t_arr_stat     ft_vec_erase_range(t_vec *vec, size_t count, size_t index,
+                               void (*free_el)(void *));
+
+// This macro should have been used for static t_vec initialization
+// as I see no other way.
+// But the Norm forbids macro functions, so just use the literal itself
+/*
+# define VEC_INIT(x) \
+       (t_vec){.capacity = 0, .size = 0, .el_size = (x), .vec = NULL} \
+*/
+
+t_arr_stat     ft_vec_init(t_vec *vec, size_t el_size);
+void           ft_vec_free(t_vec *vec, void (*free_el)(void *));
+void           *ft_vec_access(t_vec *vec, size_t index);
+
+/* It is probably better to use        (type *)vec->vec + index for pointer
+ * or                                                          ((type *)vec->vec)[index] for value
+ * insted of                                           (type *)ft_vec_access(vec, index)
+ * because it is smaller, more readable. But it does not range-check!
+ * Also implement access function that casts to desired type
+ * eg. int *int_access(t_vec *vec, size_t ind){return ((int *)vec->vec + ind);}
+ */
+void           *ft_vec_find(t_vec *vec, void *wanted);
+t_arr_stat     ft_vec_find_index(t_vec *vec, void *wanted, size_t *index);
+
+t_arr_stat     ft_mat_init(t_mat *mat, size_t el_size);
+void           ft_mat_free(t_mat *mat, void (*free_el)(void *));
+t_arr_stat     ft_mat_resize(t_mat *mat, size_t rows, size_t cols);
+t_arr_stat     ft_mat_insert_row(t_mat *mat, const t_vec *vec, size_t index);
+t_arr_stat     ft_mat_insert_col(t_mat *mat, const t_vec *vec, size_t index);
+t_arr_stat     ft_mat_append_row(t_mat *mat, const t_vec *vec);
+t_arr_stat     ft_mat_append_col(t_mat *mat, const t_vec *vec);
+t_arr_stat     ft_mat_erase_rows(t_mat *mat, size_t count,
+                               size_t index, void (*free_el)(void *));
+t_arr_stat     ft_mat_erase_cols(t_mat *mat, size_t count,
+                               size_t index, void (*free_el)(void *));
+void           *ft_mat_access(t_mat *mat, size_t row, size_t col);
+
+#endif
diff --git a/Libft/inc/ft_check.h b/Libft/inc/ft_check.h
new file mode 100644 (file)
index 0000000..4c049dc
--- /dev/null
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_check.h                                         :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 11:55:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_CHECK_H
+# define FT_CHECK_H
+
+int            ft_isalnum(int c);
+int            ft_isalpha(int c);
+int            ft_isdigit(int c);
+int            ft_islower(int c);
+int            ft_isprint(int c);
+int            ft_isspace(int c);
+int            ft_isupper(int c);
+int            ft_isascii(int c);
+
+#endif
diff --git a/Libft/inc/ft_conv.h b/Libft/inc/ft_conv.h
new file mode 100644 (file)
index 0000000..421b1f0
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_conv.h                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 11:53:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_CONV_H
+# define FT_CONV_H
+
+# include <stdint.h>
+
+int                    ft_toupper(int c);
+int                    ft_tolower(int c);
+
+int                    ft_atoi(const char *nptr);
+long           ft_atol(const char *nptr);
+long long      ft_atoll(const char *nptr);
+char           *ft_itoa(int n);
+char           *ft_itoa_base(intmax_t n, const char *base);
+char           *ft_uitoa_base(uintmax_t n, const char *base);
+char           *ft_ctoa(char c);
+
+#endif
diff --git a/Libft/inc/ft_gen.h b/Libft/inc/ft_gen.h
new file mode 100644 (file)
index 0000000..f806400
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_gen.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 12:21:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_GEN_H
+# define FT_GEN_H
+
+void   ft_swap(void **a, void **b);
+
+#endif
diff --git a/Libft/inc/ft_io.h b/Libft/inc/ft_io.h
new file mode 100644 (file)
index 0000000..ddb28c8
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_io.h                                            :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 11:38:28 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_IO_H
+# define FT_IO_H
+
+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);
+int            ft_printf(const char *format, ...);
+char   *get_next_line(int fd);
+
+#endif
diff --git a/Libft/inc/ft_lst.h b/Libft/inc/ft_lst.h
new file mode 100644 (file)
index 0000000..7143526
--- /dev/null
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_lst.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 11:42:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:44 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_LST_H
+# define FT_LST_H
+
+typedef struct s_list
+{
+       struct s_list   *next;
+       void                    *content;
+}                                      t_list;
+
+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 *));
+t_list *ft_lst_at(t_list *lst, unsigned int i);
+t_list *ft_lst_find(t_list *lst, void *content_red, int (*cmp)());
+void   ft_lst_foreach_if(t_list *lst, void (*f)(void *),
+                       void *content_ref, int (*cmp)());
+void   ft_lst_merge(t_list **lst1, t_list *lst2);
+void   ft_lst_remove_if(t_list **lst, void *content_ref,
+                       int (*cmp)(), void (*free_fct)(void *));
+void   ft_lst_reverse(t_list **lst);
+void   ft_lst_sort(t_list **lst, int (*cmp)());
+void   ft_lst_sorted_insert(t_list **lst, t_list *new, int (*cmp)());
+void   ft_lst_sorted_merge(t_list **lst1, t_list *lst2, int (*cmp)());
+
+#endif
diff --git a/Libft/inc/ft_math.h b/Libft/inc/ft_math.h
new file mode 100644 (file)
index 0000000..657642e
--- /dev/null
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_math.h                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 12:19:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/18 09:44:29 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_MATH_H
+# define FT_MATH_H
+
+int            ft_abs(int n);
+int            ft_sgn(int n);
+
+#endif
diff --git a/Libft/inc/ft_mem.h b/Libft/inc/ft_mem.h
new file mode 100644 (file)
index 0000000..073d9af
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_mem.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 12:45:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/09 15:13:44 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_MEM_H
+# define FT_MEM_H
+
+# include <stddef.h>
+
+void   *ft_memset(void *s, int c, size_t n);
+void   *ft_memcpy(void *dest, const void *src, size_t n);
+void   *ft_memmove(void *dest, const void *src, size_t n);
+void   *ft_memchr(const void *s, int c, size_t n);
+void   *ft_calloc(size_t nmemb, size_t size);
+void   ft_bzero(void *s, size_t n);
+int            ft_memcmp(const void *s1, const void *s2, size_t n);
+
+#endif
diff --git a/Libft/inc/ft_str.h b/Libft/inc/ft_str.h
new file mode 100644 (file)
index 0000000..c3c13ab
--- /dev/null
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_str.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/09 11:50:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/13 14:59:16 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FT_STR_H
+# define FT_STR_H
+
+# include <stddef.h>
+
+size_t ft_strlen(const char *s);
+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_strncat_alloc(char **dest, const char *src, size_t n);
+int            ft_strcmp(const char *s1, const char *s2);
+int            ft_strncmp(const char *s1, const char *s2, size_t n);
+char   *ft_strchr(const char *s, int c);
+char   *ft_strrchr(const char *s, int c);
+char   *ft_strnstr(const char *big, const char *little, size_t len);
+char   *ft_strdup(const char *s);
+char   *ft_strndup(const char *s, size_t n);
+char   *ft_substr(const char *s, unsigned int start, size_t len);
+char   *ft_strjoin(const char *s1, const char *s2);
+char   *ft_strtrim(const char *s1, const char *set);
+char   **ft_split(const char *s, char c);
+char   *ft_strmapi(const char *s, char (*f)(unsigned int, char));
+void   ft_striteri(char *s, void (*f)(unsigned int, char *));
+
+#endif
diff --git a/Libft/inc/libft.h b/Libft/inc/libft.h
new file mode 100644 (file)
index 0000000..33d0962
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   libft.h                                            :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 12:58:15 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/11 10:17:16 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef LIBFT_H
+# define LIBFT_H
+
+# include "ft_gen.h"
+# include "ft_math.h"
+# include "ft_check.h"
+# include "ft_conv.h"
+# include "ft_str.h"
+# include "ft_mem.h"
+# include "ft_io.h"
+# include "ft_lst.h"
+# include "ft_arr.h"
+
+#endif
index 22c77b6d79664e33edfeb742bcc0d8be51479615..b94091ca05d16efaf37358cc55fa3cf00e1aeefb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -52,9 +52,6 @@ endif
 %.o : %.c | $(SUBINCDIR)
        $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE)
 
-%/inc :
-       git submodule update --init $($@%/inc=%)
-
 clean :
        $(RM) $(OBJECTS)
        $(foreach proj, $(SUBPROJECTS), $(MAKE) -C $(proj) clean)