diff --git a/.Makefile.swp b/.Makefile.swp new file mode 100644 index 0000000..8fc8cc0 Binary files /dev/null and b/.Makefile.swp differ diff --git a/Makefile b/Makefile index 039f878..c5a4a67 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,37 @@ -SRCS = philo/philo.c +SRCS = philo/main.c philo/parsing.c philo/philo.c philo/threads.c SRCS_BONUS = OBJS = ${SRCS:.c=.o} OBJS_BONUS = ${SRCS_BONUS:.c=.o} -LIBS = libft/libft.a +UTILS = utils/utils.a CC = clang -CFLAGS = -g -pthread -Wall -Wextra -Werror +CFLAGS = -g -Wall -Wextra -Werror -pthread NAME = philosopher all: ${NAME} ${NAME}: ${OBJS} - make -C libft - ${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${LIBS} + make -C utils + ${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${UTILS} bonus: ${OBJS_BONUS} - make -C libft - ${CC} ${CFLAGS} -o ${NAME} ${OBJS_BONUS} ${LIBS} - -%.o:%.c - ${CC} ${CFLAGS} -c -o $@ $< + make -C utils + ${CC} ${CFLAGS} -o ${NAME} ${OBJS_BONUS} ${UTILS} clean: rm -f ${OBJS} rm -f ${OBJS_BONUS} - make -C libft clean + make -C utils clean fclean: rm -f ${OBJS} ${NAME} rm -f ${OBJS_BONUS} ${NAME} - make -C libft fclean + make -C utils fclean re: fclean all -.PHONY: all clean fclean re coffee +rebonus: fclean bonus + +.PHONY: all clean fclean re rebonus coffee bozo coffee: @clear @@ -135,3 +134,14 @@ coffee: @echo ' ""--..,,_____ _____,,..--"""''' @echo ' """------"""' make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 4.26 + @#@printf '\e[?1049h' + @#tput smcup + @#@xdotool key F11 + @#@sleep 4.1 + @pkill eog + @rm bozo.gif diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c deleted file mode 100644 index b23c00f..0000000 --- a/libft/ft_isalpha.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/17 17:34:33 by erey-bet #+# #+# */ -/* Updated: 2022/09/26 14:40:50 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isalpha(int c) -{ - if (!(c >= 'A' && c <= 'Z')) - if (!(c >= 'a' && c <= 'z')) - return (0); - return (1); -} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c deleted file mode 100644 index 82b1c10..0000000 --- a/libft/ft_isascii.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/17 18:06:14 by erey-bet #+# #+# */ -/* Updated: 2022/09/26 14:36:18 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - return (0); -} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c deleted file mode 100644 index c8b42c6..0000000 --- a/libft/ft_isprint.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/17 18:24:36 by erey-bet #+# #+# */ -/* Updated: 2022/07/17 18:27:27 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (1); - return (0); -} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c deleted file mode 100644 index 54e40ab..0000000 --- a/libft/ft_itoa.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/04 17:12:52 by erey-bet #+# #+# */ -/* Updated: 2022/10/26 16:00:48 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static void ft_itoa_bis(char *str, int len, int i, long nl) -{ - while (len > 1) - { - len--; - str[i] = (nl / ft_power(10, len) % 10) + 48; - i++; - } - str[i] = nl % 10 + 48; - i++; - str[i] = '\0'; -} - -char *ft_itoa(int n) -{ - char *str; - int len; - int i; - long nl; - - nl = n; - if (nl < 0) - nl *= -1; - len = ft_get_size(nl); - i = 0; - if (n < 0) - { - str = malloc(len + 2); - if (str == NULL) - return (NULL); - str[i] = '-'; - i++; - } - else - str = malloc(len + 1); - if (str == NULL) - return (NULL); - ft_itoa_bis(str, len, i, nl); - return (str); -} diff --git a/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c deleted file mode 100644 index 1e6c411..0000000 --- a/libft/ft_lstadd_back.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 23:14:10 by erey-bet #+# #+# */ -/* Updated: 2022/10/09 23:22:24 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_back(t_list **lst, t_list *new) -{ - if (*lst != NULL) - ft_lstlast(*lst)->next = new; - else - *lst = new; -} diff --git a/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c deleted file mode 100644 index 746f007..0000000 --- a/libft/ft_lstadd_front.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 21:43:39 by erey-bet #+# #+# */ -/* Updated: 2022/10/09 22:02:22 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_front(t_list **lst, t_list *new) -{ - new->next = *lst; - *lst = new; -} diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c deleted file mode 100644 index 1778aa4..0000000 --- a/libft/ft_lstclear.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 23:56:15 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:13:45 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstclear(t_list **lst, void (*del)(void*)) -{ - t_list *temp; - - if (lst == NULL || del == NULL) - return ; - while (*lst != NULL) - { - temp = (*lst)->next; - ft_lstdelone(*lst, del); - *lst = temp; - } -} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c deleted file mode 100644 index d06004c..0000000 --- a/libft/ft_lstdelone.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 23:22:38 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:15:03 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstdelone(t_list *lst, void (*del)(void*)) -{ - if (lst == NULL || del == NULL) - return ; - del(lst->content); - free(lst); -} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c deleted file mode 100644 index 1680813..0000000 --- a/libft/ft_lstiter.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/10 00:42:33 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 00:56:30 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(void *)) -{ - while (lst != NULL) - { - f(lst->content); - lst = lst->next; - } -} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c deleted file mode 100644 index 217944a..0000000 --- a/libft/ft_lstmap.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/10 01:03:28 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 14:55:38 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) -{ - t_list *head; - t_list *new; - - if (lst == NULL || f == NULL || del == NULL) - return (NULL); - new = ft_lstnew(f(lst->content)); - if (new == NULL) - { - ft_lstclear(&new, del); - return (NULL); - } - head = new; - lst = lst->next; - while (lst != NULL) - { - new->next = ft_lstnew(f(lst->content)); - if (new == NULL) - { - ft_lstclear(&head, del); - return (NULL); - } - new = new->next; - lst = lst->next; - } - return (head); -} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c deleted file mode 100644 index 8ef323a..0000000 --- a/libft/ft_lstnew.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 21:34:58 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:13:33 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstnew(void *content) -{ - t_list *list; - - list = malloc(sizeof(t_list)); - if (list == NULL) - return (NULL); - list->content = content; - list->next = NULL; - return (list); -} diff --git a/libft/ft_lstsize.c b/libft/ft_lstsize.c deleted file mode 100644 index b510d2f..0000000 --- a/libft/ft_lstsize.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstsize.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 22:59:07 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:14:41 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_lstsize(t_list *lst) -{ - int size; - - size = 0; - while (lst != NULL) - { - size++; - lst = lst->next; - } - return (size); -} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c deleted file mode 100644 index f4e3580..0000000 --- a/libft/ft_memchr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 19:02:18 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 02:19:17 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memchr(const void *memory_block, int searched_char, size_t size) -{ - size_t i; - unsigned char *tmp; - - i = 0; - tmp = (unsigned char *)memory_block; - while (i < size) - { - if (tmp[i] == (unsigned char)searched_char) - return (&tmp[i]); - i++; - } - return (NULL); -} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c deleted file mode 100644 index eea3c83..0000000 --- a/libft/ft_memcmp.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 19:18:16 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 14:45:03 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_memcmp(const void *pointer1, const void *pointer2, size_t size) -{ - size_t i; - unsigned char *tmp1; - unsigned char *tmp2; - - if (size == 0) - return (0); - tmp1 = (unsigned char *)pointer1; - tmp2 = (unsigned char *)pointer2; - i = 0; - while (i < size - 1 && tmp1[i] == tmp2[i]) - i++; - return (tmp1[i] - tmp2[i]); -} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c deleted file mode 100644 index f7699a7..0000000 --- a/libft/ft_memcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/26 15:32:11 by erey-bet #+# #+# */ -/* Updated: 2022/09/27 06:36:02 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memcpy(void *dest, const void *src, size_t s) -{ - size_t i; - char *tmp_dest; - const char *tmp_src; - - if (dest == NULL && src == NULL) - return (NULL); - i = 0; - tmp_dest = dest; - tmp_src = src; - while (i < s) - { - tmp_dest[i] = tmp_src[i]; - i++; - } - return (dest); -} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c deleted file mode 100644 index 7101813..0000000 --- a/libft/ft_memmove.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 06:50:08 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 14:35:27 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memmove(void *dest, const void *src, size_t s) -{ - size_t i; - char *d; - const char *sc; - - if (dest == NULL && src == NULL) - return (dest); - d = dest; - sc = src; - if (d < sc) - ft_memcpy(d, sc, s); - else - { - i = s; - while (i > 0) - { - i--; - d[i] = sc[i]; - } - } - return (dest); -} diff --git a/libft/ft_power.c b/libft/ft_power.c deleted file mode 100644 index 2f9df8d..0000000 --- a/libft/ft_power.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_power.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/10 22:50:22 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 22:50:31 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_power(int nb, int power) -{ - int i; - int new_nb; - - if (power < 0) - return (0); - i = 0; - new_nb = 1; - while (i < power) - { - i++; - new_nb *= nb; - } - return (new_nb); -} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c deleted file mode 100644 index 9484dd0..0000000 --- a/libft/ft_putendl_fd.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/05 00:48:29 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 22:14:10 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl_fd(char *s, int fd) -{ - if (s == NULL) - return ; - while (*s) - { - ft_putchar_fd(*s, fd); - s++; - } - ft_putchar_fd('\n', fd); -} diff --git a/libft/ft_split.c b/libft/ft_split.c deleted file mode 100644 index 5947f62..0000000 --- a/libft/ft_split.c +++ /dev/null @@ -1,117 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/28 09:52:05 by erey-bet #+# #+# */ -/* Updated: 2023/01/17 15:40:25 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int get_len_all(char const *s, char c) -{ - int i; - int check; - int count; - - i = 0; - check = 0; - count = 0; - while (s[i]) - { - if (s[i] != c && check == 0) - { - count++; - check = 1; - } - else if (s[i] == c && check == 1) - check = 0; - i++; - } - return (count); -} - -static int get_len_next(char const *s, char c, int i) -{ - int y; - int count; - - y = i; - count = 0; - while (s[y] == c) - y++; - while (s[y] && s[y++] != c) - count++; - return (count); -} - -static void *ft_malloc_split(char **strs, int *iyx, char const *s, char c) -{ - iyx[1]++; - strs[iyx[1]] = malloc(get_len_next(s, c, iyx[0]) + 1); - if (strs[iyx[1]] == NULL) - { - iyx[1]--; - while (iyx[1] >= 0) - { - free(strs[iyx[1]]); - iyx[1]--; - } - free(strs); - return (NULL); - } - return (""); -} - -static char **ft_split_bis(char const *s, char c, char **strs, int *iyx) -{ - int boo; - - boo = 0; - while (s[iyx[0]]) - { - if (s[iyx[0]] != c) - { - if (boo == 0) - if (ft_malloc_split(strs, iyx, s, c) == NULL) - return (NULL); - boo = 1; - strs[iyx[1]][iyx[2]] = s[iyx[0]]; - iyx[2]++; - } - else if (boo == 1) - { - strs[iyx[1]][iyx[2]] = '\0'; - iyx[2] = 0; - boo = 0; - } - iyx[0]++; - } - if (boo == 1) - strs[iyx[1]][iyx[2]] = '\0'; - return (strs); -} - -char **ft_split(char const *s, char c) -{ - char **strs; - int iyx[3]; - - iyx[0] = 0; - iyx[1] = -1; - iyx[2] = 0; - if (s == NULL) - return (NULL); - strs = malloc(sizeof(char *) * (get_len_all(s, c) + 2)); - if (strs == NULL) - return (NULL); - if (ft_split_bis(s, c, strs, iyx) == NULL) - return (NULL); - iyx[1]++; - strs[iyx[1]] = NULL; - return (strs); -} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c deleted file mode 100644 index a6eabee..0000000 --- a/libft/ft_strchr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 10:05:58 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 02:22:26 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strchr(const char *str, int search) -{ - int i; - - i = 0; - while (str[i] || str[i] == (unsigned char)search) - { - if (str[i] == (unsigned char)search) - { - return ((char *)&str[i]); - } - i++; - } - return (NULL); -} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c deleted file mode 100644 index 1830bfc..0000000 --- a/libft/ft_strdup.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */ -/* Updated: 2022/09/28 16:32:55 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strdup(const char *src) -{ - char *src_copy; - int i; - - src_copy = (char *)malloc(sizeof(char) * ft_strlen(src) + 1); - if (src_copy == NULL) - return (NULL); - i = 0; - while (src[i]) - { - src_copy[i] = src[i]; - i++; - } - src_copy[i] = '\0'; - return (src_copy); -} diff --git a/libft/ft_strdup_free.c b/libft/ft_strdup_free.c deleted file mode 100644 index af831cf..0000000 --- a/libft/ft_strdup_free.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */ -/* Updated: 2022/09/28 16:32:55 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strdup_free(char *src) -{ - char *src_copy; - int i; - - src_copy = (char *)malloc(sizeof(char) * ft_strlen(src) + 1); - if (src_copy == NULL) - return (NULL); - i = 0; - while (src[i]) - { - src_copy[i] = src[i]; - i++; - } - src_copy[i] = '\0'; - free(src); - return (src_copy); -} diff --git a/libft/ft_strdups.c b/libft/ft_strdups.c deleted file mode 100644 index d9e0c2c..0000000 --- a/libft/ft_strdups.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdups.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */ -/* Updated: 2022/12/29 18:05:24 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char **ft_strdups(char **src) -{ - char **src_copy; - int x; - int y; - - src_copy = ft_calloc(ft_strslen(src) + 1, (sizeof(char *))); - if (src_copy == NULL) - return (NULL); - x = -1; - while (src[++x]) - { - src_copy[x] = ft_calloc(ft_strlen(src[x]) + 1, 1); - y = -1; - while (src[x][++y]) - src_copy[x][y] = src[x][y]; - src_copy[x][y] = '\0'; - } - src_copy[x] = NULL; - return (src_copy); -} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c deleted file mode 100644 index 5f63e33..0000000 --- a/libft/ft_striteri.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striteri.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/04 23:17:51 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 22:14:20 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_striteri(char *s, void (*f)(unsigned int, char*)) -{ - unsigned int i; - - if (f == NULL || s == NULL) - return ; - i = 0; - while (s[i]) - { - f(i, &s[i]); - i++; - } -} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c deleted file mode 100644 index 3af4212..0000000 --- a/libft/ft_strjoin.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/27 14:47:27 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 14:19:45 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strjoin(char const *s1, char const *s2) -{ - char *tmp; - int size; - - if (s1 == NULL || s2 == NULL) - return (NULL); - size = ft_strlen(s1) + ft_strlen(s2) + 1; - tmp = malloc(size); - if (tmp == NULL) - return (NULL); - ft_strlcpy(tmp, s1, size); - ft_strlcat(tmp, s2, size); - return (tmp); -} diff --git a/libft/ft_strjoin_free.c b/libft/ft_strjoin_free.c deleted file mode 100644 index 2dc9a56..0000000 --- a/libft/ft_strjoin_free.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/27 14:47:27 by erey-bet #+# #+# */ -/* Updated: 2023/01/17 16:25:07 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strjoin_free(char *s1, char *s2, int b) -{ - char *tmp; - int size; - - if (s1 == NULL) - return (s2); - else if (s2 == NULL) - return (s1); - size = ft_strlen(s1) + ft_strlen(s2) + 1; - tmp = ft_calloc(size, 1); - if (tmp == NULL) - return (NULL); - ft_strlcpy(tmp, s1, size); - ft_strlcat(tmp, s2, size); - if (b > 0) - free(s1); - if (b > 1) - free(s2); - return (tmp); -} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c deleted file mode 100644 index dd71c78..0000000 --- a/libft/ft_strlcat.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/19 13:02:39 by erey-bet #+# #+# */ -/* Updated: 2022/10/14 17:49:58 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcat(char *dest, const char *src, size_t size) -{ - size_t len_dest; - size_t len_src; - - if (size == 0) - return (ft_strlen(src)); - len_dest = ft_strlen(dest); - if (len_dest >= size) - return (ft_strlen(src) + (size)); - len_src = ft_strlcpy(dest + len_dest, src, size - len_dest); - return (len_dest + len_src); -} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c deleted file mode 100644 index b80d474..0000000 --- a/libft/ft_strlcpy.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/17 19:03:49 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 14:37:25 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcpy(char *dest, const char *src, size_t size) -{ - size_t i; - - i = 0; - if (size) - { - while (i < size - 1 && src[i] != '\0') - { - dest[i] = src[i]; - i++; - } - dest[i] = '\0'; - } - return (ft_strlen(src)); -} diff --git a/libft/ft_strlen_double.c b/libft/ft_strlen_double.c deleted file mode 100644 index 8ea0ac7..0000000 --- a/libft/ft_strlen_double.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen_double.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/12/12 13:45:14 by erey-bet #+# #+# */ -/* Updated: 2022/12/12 13:46:16 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_strlen_double(char **strs) -{ - int i; - int y; - int count; - - i = 0; - while (strs[i]) - { - y = 0; - while (strs[i][y]) - { - count++; - } - i++; - } - return (count); -} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c deleted file mode 100644 index 325e929..0000000 --- a/libft/ft_strmapi.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/04 22:55:32 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 15:43:18 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) -{ - unsigned int i; - char *str; - - if (s == NULL || f == NULL) - return (NULL); - str = ft_strdup(s); - if (str == NULL) - return (NULL); - i = 0; - while (s[i]) - { - str[i] = f(i, s[i]); - i++; - } - return (str); -} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c deleted file mode 100644 index 9ca8735..0000000 --- a/libft/ft_strncmp.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/18 19:09:01 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 15:04:46 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t n) -{ - size_t i; - unsigned char *tmp_s1; - unsigned char *tmp_s2; - - if (n <= 0) - return (0); - tmp_s1 = (unsigned char *)s1; - tmp_s2 = (unsigned char *)s2; - i = 1; - while (*tmp_s1 == *tmp_s2 && (*tmp_s1 != '\0' && *tmp_s2 != '\0') && i < n) - { - tmp_s1++; - tmp_s2++; - i++; - } - return (*tmp_s1 - *tmp_s2); -} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c deleted file mode 100644 index 2845cbc..0000000 --- a/libft/ft_strnstr.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/28 09:37:24 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 16:39:12 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strnstr(const char *big, const char *little, size_t len) -{ - size_t i; - size_t y; - char *b; - - b = (char *)big; - i = 0; - if (!*little || (little == big && ft_strlen(little) <= len)) - return (b); - while (i < len && big[i]) - { - y = 0; - while (b[i + y] == little[y] && i + y < len) - { - y++; - if (little[y] == '\0') - return (&b[i]); - } - i++; - } - return (NULL); -} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c deleted file mode 100644 index 9e48783..0000000 --- a/libft/ft_strrchr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strrchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 11:13:35 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 02:23:25 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strrchr(const char *str, int search) -{ - int i; - char *last; - - i = 0; - last = NULL; - while (str[i] || str[i] == (unsigned char)search) - { - if (str[i] == (unsigned char)search) - { - last = (char *)&str[i]; - if (str[i] == 0) - return (last); - } - i++; - } - return (last); -} diff --git a/libft/ft_strslen.c b/libft/ft_strslen.c deleted file mode 100644 index c91921d..0000000 --- a/libft/ft_strslen.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strslen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */ -/* Updated: 2023/01/12 16:51:53 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strslen(char **src) -{ - int i; - - i = 0; - while (src[i]) - i++; - return (i); -} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c deleted file mode 100644 index c54b7cc..0000000 --- a/libft/ft_strtrim.c +++ /dev/null @@ -1,86 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtrim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/29 02:41:32 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 14:41:29 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int get_start(const char *str, char const *set) -{ - int i; - int y; - int check; - - i = 0; - while (str[i]) - { - y = 0; - check = 0; - while (set[y]) - { - if (str[i] == set[y]) - check = 1; - y++; - } - if (check == 0) - return (i); - i++; - } - return (0); -} - -static int get_end(const char *str, char const *set) -{ - int i; - int y; - int check; - - i = ft_strlen(str) - 1; - while (i > 0) - { - y = 0; - check = 0; - while (set[y]) - { - if (str[i] == set[y]) - check = 1; - y++; - } - if (check == 0) - return (i + 1); - i--; - } - return (0); -} - -char *ft_strtrim(char const *s1, char const *set) -{ - char *str; - int i; - int start; - int end; - - if (s1 == NULL || set == NULL) - return (NULL); - start = get_start(s1, set); - end = get_end(s1, set); - str = malloc(end - start + 1); - if (str == NULL) - return (NULL); - i = 0; - while (start < end) - { - str[i] = s1[start]; - i++; - start++; - } - str[i] = '\0'; - return (str); -} diff --git a/libft/ft_substr.c b/libft/ft_substr.c deleted file mode 100644 index 2a41b7b..0000000 --- a/libft/ft_substr.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/28 16:33:43 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:09:26 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_substr(char const *s, unsigned int start, size_t len) -{ - long size; - char *new_s; - - if (s == NULL) - return (NULL); - size = ft_strlen(s) - start; - if (size < 0) - size = 0; - else if ((unsigned long)size > len) - size = len; - new_s = malloc(size + 1); - if (new_s == NULL) - return (NULL); - if (start <= ft_strlen(s)) - ft_strlcpy(new_s, s + start, len + 1); - else - new_s[0] = '\0'; - return (new_s); -} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c deleted file mode 100644 index eea41be..0000000 --- a/libft/ft_tolower.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 10:04:55 by erey-bet #+# #+# */ -/* Updated: 2022/09/27 10:05:32 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_tolower(int c) -{ - if (c >= 'A' && c <= 'Z') - c = c + 32; - return (c); -} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c deleted file mode 100644 index 3bb2a91..0000000 --- a/libft/ft_toupper.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/27 10:01:53 by erey-bet #+# #+# */ -/* Updated: 2022/09/27 10:04:19 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_toupper(int c) -{ - if (c >= 'a' && c <= 'z') - c = c - 32; - return (c); -} diff --git a/libft/libft.h b/libft/libft.h deleted file mode 100644 index c552ecc..0000000 --- a/libft/libft.h +++ /dev/null @@ -1,76 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/26 16:31:10 by erey-bet #+# #+# */ -/* Updated: 2022/12/13 13:23:44 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIBFT_H -# define LIBFT_H -# include -# include - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -int ft_isalpha(int c); -int ft_isdigit(int c); -int ft_isalnum(int c); -int ft_isascii(int c); -int ft_isprint(int c); -int ft_toupper(int c); -int ft_tolower(int c); -size_t ft_strlen(const char *str); -void *ft_memset(void *ptr, int v, size_t count); -void ft_bzero(void *s, unsigned int n); -void *ft_memcpy(void *dest, const void *src, size_t s); -void *ft_memmove(void *dest, const void *src, size_t s); -void *ft_memchr(const void *memory_block, int searched_char, size_t size); -int ft_memcmp(const void *pointer1, const void *pointer2, size_t size); -size_t ft_strlcpy(char *dest, const char *src, size_t size); -char *ft_strnstr(const char *big, const char *little, size_t len); -char *ft_strchr(const char *str, int search); -char *ft_strrchr(const char *str, int search); -int ft_strncmp(const char *s1, const char *s2, size_t n); -size_t ft_strlcat(char *dest, const char *src, size_t size); -char *ft_strdup(const char *src); -char *ft_strdup_free(char *src); -char **ft_strdups(char **src); -int ft_atoi(const char *nptr); -char **ft_split(char const *s, char c); -void *ft_calloc(size_t nitems, size_t size); -char *ft_itoa(int n); -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); -void ft_striteri(char *s, void (*f)(unsigned int, char*)); -void ft_putchar_fd(char c, int fd); -void ft_putstr_fd(char *s, int fd); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -int ft_get_size(long n); -int ft_power(int nb, int power); -char *ft_strjoin(char const *s1, char const *s2); -char *ft_strjoin_free(char *s1, char *s2, int b); -char *ft_strtrim(char const *s1, char const *set); -char *ft_substr(char const *s, unsigned int start, size_t len); -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 *)); -int ft_atoi_check(const char *nptr); -int ft_strlen_double(char **strs); -int ft_strslen(char **src); - -#endif diff --git a/philo/.philo.c.swp b/philo/.philo.c.swp new file mode 100644 index 0000000..d67e480 Binary files /dev/null and b/philo/.philo.c.swp differ diff --git a/libft/ft_isdigit.c b/philo/main.c similarity index 59% rename from libft/ft_isdigit.c rename to philo/main.c index 3b5cb1b..128deb8 100644 --- a/libft/ft_isdigit.c +++ b/philo/main.c @@ -1,18 +1,35 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ +/* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2022/07/17 18:06:14 by erey-bet #+# #+# */ -/* Updated: 2022/09/26 14:41:48 by erey-bet ### ########.fr */ +/* Created: 2023/02/24 14:21:54 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:53:38 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isdigit(int c) +#include "philo.h" + +int main(int argc, char *argv[]) { - if (c > 47 && c < 58) + t_config config; + + if (argc < 5) + { + write(2, "Not enought argument\n", 21); return (1); + } + if (parsing(argv, &config)) + { + write(2, "Error parsing\n", 14); + return (2); + } + if (manage_threads(&config)) + { + write(2, "Error Philo\n", 12); + return (3); + } return (0); } diff --git a/philo/main.o b/philo/main.o new file mode 100644 index 0000000..63f0f7d Binary files /dev/null and b/philo/main.o differ diff --git a/libft/ft_isalnum.c b/philo/parsing.c similarity index 53% rename from libft/ft_isalnum.c rename to philo/parsing.c index 59a05d6..e19d923 100644 --- a/libft/ft_isalnum.c +++ b/philo/parsing.c @@ -1,20 +1,37 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_isalnum.c :+: :+: :+: */ +/* parsing.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2022/09/26 16:47:30 by erey-bet #+# #+# */ -/* Updated: 2022/09/26 16:50:25 by erey-bet ### ########.fr */ +/* Created: 2023/03/08 14:59:29 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:53:19 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isalnum(int c) +#include "philo.h" + +int parsing(char *argv[], t_config *conf) { - if (!(c >= 'A' && c <= 'Z')) - if (!(c >= 'a' && c <= 'z')) - if (!(c >= '0' && c <= '9')) + if (ft_atoi_check(argv[1])) + { + conf->nbr_philo = ft_atoi(argv[1]); + if (ft_atoi_check(argv[2])) + { + conf->time_die = ft_atoi(argv[2]); + if (ft_atoi_check(argv[3])) + { + conf->time_eat = ft_atoi(argv[3]); + if (ft_atoi_check(argv[4])) + { + conf->time_sleep = ft_atoi(argv[4]); + if (ft_atoi_check(argv[5])) + conf->must_eat = ft_atoi(argv[5]); + } return (0); + } + } + } return (1); } diff --git a/philo/parsing.o b/philo/parsing.o new file mode 100644 index 0000000..ae92db3 Binary files /dev/null and b/philo/parsing.o differ diff --git a/philo/philo.c b/philo/philo.c index 20261af..333224e 100644 --- a/philo/philo.c +++ b/philo/philo.c @@ -5,9 +5,17 @@ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/24 14:21:54 by erey-bet #+# #+# */ -/* Updated: 2023/02/24 14:21:55 by erey-bet ### ########.fr */ +/* Created: 2023/03/08 20:43:51 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:54:49 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ +#include "philo.h" +void *philosopher(t_philo *philo) +{ + write(1, "Hey i'm ", 8); + ft_putnbr_fd(philo->id, 1); + write(1, "\n", 1); + return (NULL); +} diff --git a/libft/ft_lstlast.c b/philo/philo.h similarity index 52% rename from libft/ft_lstlast.c rename to philo/philo.h index 9ca97dd..e4d89d7 100644 --- a/libft/ft_lstlast.c +++ b/philo/philo.h @@ -1,25 +1,41 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstlast.c :+: :+: :+: */ +/* philo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/09 23:03:50 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:14:51 by erey-bet ### ########.fr */ +/* Created: 2023/03/08 14:51:16 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:56:46 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#ifndef PHILO_H +# define PHILO_H -t_list *ft_lstlast(t_list *lst) +typedef struct s_config { - t_list *current; + int nbr_philo; + int time_die; + int time_eat; + int time_sleep; + int must_eat; +} t_config; - current = lst; - if (current == NULL) - return (NULL); - while (current->next != NULL) - current = current->next; - return (current); -} +typedef struct s_philo +{ + t_config conf; + int id; +} t_philo; + +# include "../utils/utils.h" +# include +# include +# include +# include + +int parsing(char *argv[], t_config *conf); +int manage_threads(t_config *conf); +void *philosopher(t_philo *philo); + +#endif diff --git a/philo/philo.o b/philo/philo.o new file mode 100644 index 0000000..7f8a9b2 Binary files /dev/null and b/philo/philo.o differ diff --git a/philo/threads.c b/philo/threads.c new file mode 100644 index 0000000..78a76e2 --- /dev/null +++ b/philo/threads.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* threads.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/08 20:08:33 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:57:52 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "philo.h" +#include + +int manage_threads(t_config *config) +{ + pthread_t *threads; + t_philo philo; + int i; + + threads = malloc(config->nbr_philo * sizeof(pthread_t)); + if (threads == NULL) + return (1); + i = -1; + philo.conf = *config; + while (++i < config->nbr_philo) + { + philo.id = i; + if (pthread_create(&threads[i], NULL, (void *)&philosopher, &philo) != 0) + { + write(2, "Error thread creation\n", 21); + return (1); + } + write(1, "Thread created\n", 15); + } + while (--i > -1) + { + if (pthread_join(threads[i], NULL) != 0) + { + write(2, "Error thread finish\n", 20); + return (1); + } + write(1, "Thread finish execution\n", 24); + } + return (0); +} diff --git a/philo/threads.o b/philo/threads.o new file mode 100644 index 0000000..0e3e6c6 Binary files /dev/null and b/philo/threads.o differ diff --git a/philosopher b/philosopher new file mode 100755 index 0000000..95b8f9b Binary files /dev/null and b/philosopher differ diff --git a/libft/Makefile b/utils/Makefile similarity index 85% rename from libft/Makefile rename to utils/Makefile index b12262c..a4d935f 100644 --- a/libft/Makefile +++ b/utils/Makefile @@ -6,38 +6,22 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/12/13 13:23:28 by erey-bet ### ########.fr # +# Updated: 2023/03/08 21:29:13 by erey-bet ### ########.fr # # # # **************************************************************************** # -SRCS = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \ -ft_strlen.c ft_memset.c ft_bzero.c ft_memcpy.c ft_memmove.c ft_strlcpy.c \ -ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c ft_strrchr.c ft_strncmp.c \ -ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \ -ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \ -ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ -ft_get_size.c ft_power.c ft_atoi_check.c ft_strlen_double.c ft_strjoin_free.c \ -ft_strdup_free.c ft_strdups.c ft_strslen.c +SRCS = ft_atoi.c ft_calloc.c ft_putstr_fd.c ft_putnbr_fd.c ft_atoi_check.c \ +ft_calloc.c ft_memset.c ft_putchar_fd.c ft_strlen.c OBJS = ${SRCS:.c=.o} -BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \ -ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c -BONUS_OBJS = ${BONUS_SRCS:.c=.o} -CC = gcc -CFLAGS = -g -Wall -Wextra -Werror -NAME = libft.a - -ifdef BONUS - SRCS += ${BONUS_SRCS} -endif +CC = clang +CFLAGS = -Wall -Wextra -Werror +NAME = utils.a all: ${NAME} ${NAME}: ${OBJS} ar -rc ${NAME} ${OBJS} -%.o:%.c - ${CC} ${CFLAGS} -c -o $@ $< - clean: rm -f ${OBJS} ${BONUS_OBJS} @@ -46,9 +30,6 @@ fclean: clean re: fclean all -bonus: - @make BONUS=1 - coffee: @clear @echo "" diff --git a/libft/ft_atoi.c b/utils/ft_atoi.c similarity index 94% rename from libft/ft_atoi.c rename to utils/ft_atoi.c index a723bf6..c889314 100644 --- a/libft/ft_atoi.c +++ b/utils/ft_atoi.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:44:20 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:09:45 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" static int ft_isspace(char c) { diff --git a/utils/ft_atoi.o b/utils/ft_atoi.o new file mode 100644 index 0000000..c286187 Binary files /dev/null and b/utils/ft_atoi.o differ diff --git a/libft/ft_atoi_check.c b/utils/ft_atoi_check.c similarity index 91% rename from libft/ft_atoi_check.c rename to utils/ft_atoi_check.c index b549055..f848f96 100644 --- a/libft/ft_atoi_check.c +++ b/utils/ft_atoi_check.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */ -/* Updated: 2022/12/08 16:37:19 by erey-bet ### ########.fr */ +/* Updated: 2023/03/12 16:51:03 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" static int ft_isspace(char c) { @@ -25,15 +25,14 @@ int ft_atoi_check(const char *nptr) long result; int sign; + if (!nptr) + return (0); while (ft_isspace(*nptr)) nptr++; sign = 1; if (*nptr == '+' || *nptr == '-') - { - if (*nptr == '-') + if (*nptr++ == '-') sign = -1; - nptr++; - } result = 0; while (*nptr >= '0' && *nptr <= '9') { diff --git a/utils/ft_atoi_check.o b/utils/ft_atoi_check.o new file mode 100644 index 0000000..9796360 Binary files /dev/null and b/utils/ft_atoi_check.o differ diff --git a/libft/ft_bzero.c b/utils/ft_bzero.c similarity index 91% rename from libft/ft_bzero.c rename to utils/ft_bzero.c index 8688fb4..402a3ee 100644 --- a/libft/ft_bzero.c +++ b/utils/ft_bzero.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/26 15:21:33 by erey-bet #+# #+# */ -/* Updated: 2022/09/26 15:31:11 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:11:32 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" void ft_bzero(void *s, unsigned int n) { diff --git a/libft/ft_calloc.c b/utils/ft_calloc.c similarity index 92% rename from libft/ft_calloc.c rename to utils/ft_calloc.c index 15af293..ffcb062 100644 --- a/libft/ft_calloc.c +++ b/utils/ft_calloc.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/28 16:21:44 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 14:17:31 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:10:07 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" void *ft_calloc(size_t nitems, size_t size) { diff --git a/utils/ft_calloc.o b/utils/ft_calloc.o new file mode 100644 index 0000000..d1b6179 Binary files /dev/null and b/utils/ft_calloc.o differ diff --git a/libft/ft_memset.c b/utils/ft_memset.c similarity index 92% rename from libft/ft_memset.c rename to utils/ft_memset.c index 5c2adcd..c0858cb 100644 --- a/libft/ft_memset.c +++ b/utils/ft_memset.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/26 14:46:33 by erey-bet #+# #+# */ -/* Updated: 2022/10/15 23:31:18 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:11:59 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" void *ft_memset(void *ptr, int v, size_t count) { diff --git a/utils/ft_memset.o b/utils/ft_memset.o new file mode 100644 index 0000000..e624c43 Binary files /dev/null and b/utils/ft_memset.o differ diff --git a/libft/ft_putchar_fd.c b/utils/ft_putchar_fd.c similarity index 91% rename from libft/ft_putchar_fd.c rename to utils/ft_putchar_fd.c index 2cd47eb..e0faeaa 100644 --- a/libft/ft_putchar_fd.c +++ b/utils/ft_putchar_fd.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 00:21:56 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 00:31:51 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:14:16 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" void ft_putchar_fd(char c, int fd) { diff --git a/utils/ft_putchar_fd.o b/utils/ft_putchar_fd.o new file mode 100644 index 0000000..60f59bb Binary files /dev/null and b/utils/ft_putchar_fd.o differ diff --git a/libft/ft_putnbr_fd.c b/utils/ft_putnbr_fd.c similarity index 72% rename from libft/ft_putnbr_fd.c rename to utils/ft_putnbr_fd.c index 8c549e9..557ac3b 100644 --- a/libft/ft_putnbr_fd.c +++ b/utils/ft_putnbr_fd.c @@ -6,11 +6,44 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 10:22:16 by erey-bet #+# #+# */ -/* Updated: 2022/10/18 17:32:20 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:16:33 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" + +static int ft_get_size(long n) +{ + long i; + + if (n == 0) + return (1); + i = 0; + n *= (n > 0) - (n < 0); + while (n > 0) + { + i++; + n = n / 10; + } + return (i); +} + +static int ft_power(int nb, int power) +{ + int i; + int new_nb; + + if (power < 0) + return (0); + i = 0; + new_nb = 1; + while (i < power) + { + i++; + new_nb *= nb; + } + return (new_nb); +} void ft_putnbr_fd(int n, int fd) { diff --git a/utils/ft_putnbr_fd.o b/utils/ft_putnbr_fd.o new file mode 100644 index 0000000..54ac859 Binary files /dev/null and b/utils/ft_putnbr_fd.o differ diff --git a/libft/ft_putstr_fd.c b/utils/ft_putstr_fd.c similarity index 91% rename from libft/ft_putstr_fd.c rename to utils/ft_putstr_fd.c index 15457fa..794ac43 100644 --- a/libft/ft_putstr_fd.c +++ b/utils/ft_putstr_fd.c @@ -6,11 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 00:32:38 by erey-bet #+# #+# */ -/* Updated: 2022/10/10 22:13:50 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:10:18 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" void ft_putstr_fd(char *s, int fd) { diff --git a/utils/ft_putstr_fd.o b/utils/ft_putstr_fd.o new file mode 100644 index 0000000..99e5b55 Binary files /dev/null and b/utils/ft_putstr_fd.o differ diff --git a/libft/ft_strlen.c b/utils/ft_strlen.c similarity index 88% rename from libft/ft_strlen.c rename to utils/ft_strlen.c index f12b894..f11ff3d 100644 --- a/libft/ft_strlen.c +++ b/utils/ft_strlen.c @@ -6,13 +6,13 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/15 11:46:17 by erey-bet #+# #+# */ -/* Updated: 2023/01/18 18:04:47 by erey-bet ### ########.fr */ +/* Updated: 2023/03/08 21:14:06 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "utils.h" -size_t ft_strlen(const char *str) +int ft_strlen(const char *str) { int i; diff --git a/utils/ft_strlen.o b/utils/ft_strlen.o new file mode 100644 index 0000000..96f823d Binary files /dev/null and b/utils/ft_strlen.o differ diff --git a/utils/utils.a b/utils/utils.a new file mode 100644 index 0000000..bbeb583 Binary files /dev/null and b/utils/utils.a differ diff --git a/libft/ft_get_size.c b/utils/utils.h similarity index 53% rename from libft/ft_get_size.c rename to utils/utils.h index ec08039..a51bcf2 100644 --- a/libft/ft_get_size.c +++ b/utils/utils.h @@ -1,29 +1,29 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_get_size.c :+: :+: :+: */ +/* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/10 22:50:35 by erey-bet #+# #+# */ -/* Updated: 2022/10/11 22:14:29 by erey-bet ### ########.fr */ +/* Created: 2022/09/26 16:31:10 by erey-bet #+# #+# */ +/* Updated: 2023/03/12 16:49:53 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libft.h" +#ifndef LIBFT_H +# define LIBFT_H -int ft_get_size(long n) -{ - long i; +# include +# include - if (n == 0) - return (1); - i = 0; - n *= (n > 0) - (n < 0); - while (n > 0) - { - i++; - n = n / 10; - } - return (i); -} +int ft_atoi(const char *nptr); +int ft_atoi_check(const char *nptr); +int ft_strlen(const char *str); +void *ft_calloc(size_t nitems, size_t size); +void ft_bzero(void *s, unsigned int n); +void *ft_memset(void *ptr, int v, size_t count); +void ft_putnbr_fd(int n, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putchar_fd(char c, int fd); + +#endif