diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3123fa8 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +CLIENT = client +SERVER = server + +SOURCE_CLIENT = src/client/client.c +SOURCE_SERVER = src/server/server.c + +LIBFT = lib/libft/libft.a +FT_PRINTF = lib/ft_printf/libftprintf.a + +$(CLIENT): $(SOURCE_CLIENT) + cc -Iincludes -Wall -Werror -Wextra -g -o client $(SOURCE_CLIENT) $(LIBFT) + +$(SERVER): $(SOURCE_SERVER) + cc -Iincludes -Wall -Werror -Wextra -g -o server $(SOURCE_SERVER) $(FT_PRINTF) $(LIBFT) + +all : $(CLIENT) $(SERVER) + +clean : + @rm client + @rm server + +fclean : + @rm client + @rm server + +re : fclean + make all + +.PHONY: all re fclean clean diff --git a/client b/client new file mode 100755 index 0000000..466914a Binary files /dev/null and b/client differ diff --git a/includes/minitalk.h b/includes/minitalk.h new file mode 100644 index 0000000..c2d7861 --- /dev/null +++ b/includes/minitalk.h @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minitalk.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/26 23:04:05 by yantoine #+# #+# */ +/* Updated: 2024/04/16 05:50:54 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINITALK_H +# define MINITALK_H +# include +# include +# include "../lib/ft_printf/header/ft_printf.h" +# include "../lib/libft/libft.h" +#endif diff --git a/lib/ft_printf/Makefile b/lib/ft_printf/Makefile new file mode 100755 index 0000000..17a88e6 --- /dev/null +++ b/lib/ft_printf/Makefile @@ -0,0 +1,30 @@ +NAME = libftprintf.a +CC = cc +CFLAGS = -Wall -Wextra -Werror -c -I$(HEADER_DIR) -g3 +RM = rm -f +AR = ar rcs +SOURCES = ft_printf.c ft_putchar_fd.c ft_putnbr_fd.c ft_putptr_fd.c ft_put_unsigned_nbr_fd.c ft_puthex_upper_fd.c ft_puthex_lower_fd.c ft_putstr_fd.c +SOURCES_DIR = source/ +HEADER = ft_printf.h +HEADER_DIR = header/ +OBJECTS = $(addprefix $(SOURCES_DIR), $(SOURCES:.c=.o)) + +all: $(NAME) + +$(NAME): $(OBJECTS) + $(AR) $(NAME) $(OBJECTS) + +$(OBJECTS): $(SOURCES_DIR)%.o :$(SOURCES_DIR)%.c + $(CC) $(CFLAGS) $< -o $@ + +clean: + $(RM) $(OBJECTS) + +fclean: clean + $(RM) $(NAME) + +re: fclean + @make all + +.PHONY: all clean fclean re + diff --git a/lib/ft_printf/header/ft_printf.h b/lib/ft_printf/header/ft_printf.h new file mode 100755 index 0000000..19ef898 --- /dev/null +++ b/lib/ft_printf/header/ft_printf.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/22 10:18:58 by yantoine #+# #+# */ +/* Updated: 2023/12/26 16:09:17 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +# include +# include +# include +# include +# include + +int pf_puthex_lower_fd(unsigned int n, int fd); +int pf_puthex_upper_fd(unsigned int n, int fd); +int ft_printf(const char *format, ...); +int pf_putchar_fd(char c, int fd); +int pf_putstr_fd(char *s, int fd); +int pf_putnbr_fd(long int n, int fd); +int pf_put_unsigned_nbr_fd(unsigned int n, int fd); +int pf_putptr_fd(unsigned long long n, int fd); + +#endif diff --git a/lib/ft_printf/libftprintf.a b/lib/ft_printf/libftprintf.a new file mode 100644 index 0000000..4cd38f0 Binary files /dev/null and b/lib/ft_printf/libftprintf.a differ diff --git a/lib/ft_printf/source/ft_printf.c b/lib/ft_printf/source/ft_printf.c new file mode 100755 index 0000000..f4a7052 --- /dev/null +++ b/lib/ft_printf/source/ft_printf.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/29 19:11:52 by hexplor #+# #+# */ +/* Updated: 2023/12/26 16:06:47 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +static int ft_ptr_format(va_list parameters_info) +{ + unsigned long long ptr_check; + int count; + + count = 0; + ptr_check = va_arg(parameters_info, unsigned long long); + if (ptr_check == 0) + count += pf_putstr_fd("(nil)", 1); + else + { + count += pf_putstr_fd("0x", 1); + count += pf_putptr_fd(ptr_check, 1); + } + return (count); +} + +static int ft_format_c(char s, va_list parameters_info) +{ + int count; + + count = 0; + if (s == 'c') + count += pf_putchar_fd(va_arg(parameters_info, int), 1); + else if (s == 'i' || s == 'd') + count += pf_putnbr_fd(va_arg(parameters_info, long), 1); + else if (s == 'u') + count += pf_put_unsigned_nbr_fd(va_arg(parameters_info, \ + unsigned int), 1); + else if (s == 's') + count += pf_putstr_fd(va_arg(parameters_info, char *), 1); + else if (s == 'x') + count += pf_puthex_lower_fd(va_arg(parameters_info, long), 1); + else if (s == 'X') + count += pf_puthex_upper_fd(va_arg(parameters_info, long), 1); + else if (s == 'p') + count += ft_ptr_format(parameters_info); + else if (s == '%') + count += pf_putchar_fd('%', 1); + return (count); +} + +int ft_printf(const char *s, ...) +{ + va_list parameters_info; + unsigned int index; + int count; + + index = 0; + count = 0; + va_start(parameters_info, s); + while (s[index]) + { + if (s[index] == '%') + { + index++; + count += ft_format_c(s[index], parameters_info); + } + else if (s[index] != '%' && s[index]) + count += pf_putchar_fd(s[index], 1); + index++; + } + va_end(parameters_info); + return (count); +} diff --git a/lib/ft_printf/source/ft_printf.o b/lib/ft_printf/source/ft_printf.o new file mode 100644 index 0000000..728bfbc Binary files /dev/null and b/lib/ft_printf/source/ft_printf.o differ diff --git a/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c new file mode 100755 index 0000000..c808b54 --- /dev/null +++ b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_put_unsigned_nbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 23:56:02 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:23:28 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_put_unsigned_nbr_fd(unsigned int n, int fd) +{ + int count; + + count = 0; + if (n >= 10) + { + count += pf_put_unsigned_nbr_fd(n / 10, fd); + count += pf_put_unsigned_nbr_fd(n % 10, fd); + } + else + { + count += pf_putchar_fd(n + '0', fd); + } + return (count); +} diff --git a/lib/ft_printf/source/ft_put_unsigned_nbr_fd.o b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.o new file mode 100644 index 0000000..fc0ce83 Binary files /dev/null and b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.o differ diff --git a/lib/ft_printf/source/ft_putchar_fd.c b/lib/ft_printf/source/ft_putchar_fd.c new file mode 100755 index 0000000..f7aaf34 --- /dev/null +++ b/lib/ft_printf/source/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:08:31 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:23:41 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); + return (1); +} diff --git a/lib/ft_printf/source/ft_putchar_fd.o b/lib/ft_printf/source/ft_putchar_fd.o new file mode 100644 index 0000000..9533831 Binary files /dev/null and b/lib/ft_printf/source/ft_putchar_fd.o differ diff --git a/lib/ft_printf/source/ft_puthex_lower_fd.c b/lib/ft_printf/source/ft_puthex_lower_fd.c new file mode 100755 index 0000000..674c37d --- /dev/null +++ b/lib/ft_printf/source/ft_puthex_lower_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_puthex_lower_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:23:28 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:01 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_puthex_lower_fd(unsigned int n, int fd) +{ + int i; + char *hex; + + i = 0; + hex = "0123456789abcdef"; + if (n >= 16) + { + i += pf_puthex_lower_fd(n / 16, fd); + i += pf_puthex_lower_fd(n % 16, fd); + } + else + i += pf_putchar_fd(hex[n], fd); + return (i); +} diff --git a/lib/ft_printf/source/ft_puthex_lower_fd.o b/lib/ft_printf/source/ft_puthex_lower_fd.o new file mode 100644 index 0000000..ac2e831 Binary files /dev/null and b/lib/ft_printf/source/ft_puthex_lower_fd.o differ diff --git a/lib/ft_printf/source/ft_puthex_upper_fd.c b/lib/ft_printf/source/ft_puthex_upper_fd.c new file mode 100755 index 0000000..d6a6d05 --- /dev/null +++ b/lib/ft_printf/source/ft_puthex_upper_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_puthex_upper_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:27:12 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:21 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_puthex_upper_fd(unsigned int n, int fd) +{ + int i; + char *hex; + + i = 0; + hex = "0123456789ABCDEF"; + if (n >= 16) + { + i += pf_puthex_upper_fd(n / 16, fd); + i += pf_puthex_upper_fd(n % 16, fd); + } + else + i += pf_putchar_fd(hex[n], fd); + return (i); +} diff --git a/lib/ft_printf/source/ft_puthex_upper_fd.o b/lib/ft_printf/source/ft_puthex_upper_fd.o new file mode 100644 index 0000000..8de6263 Binary files /dev/null and b/lib/ft_printf/source/ft_puthex_upper_fd.o differ diff --git a/lib/ft_printf/source/ft_putnbr_fd.c b/lib/ft_printf/source/ft_putnbr_fd.c new file mode 100755 index 0000000..6a51f3e --- /dev/null +++ b/lib/ft_printf/source/ft_putnbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/01 23:41:52 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:42 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../header/ft_printf.h" + +int pf_putnbr_fd(long int n, int fd) +{ + int count; + + count = 0; + if (n < 0) + { + n = -n; + count += pf_putchar_fd('-', fd); + } + if ((n / 10) > 0) + count += pf_putnbr_fd(n / 10, fd); + pf_putchar_fd((n % 10) + 48, fd); + return (count + 1); +} diff --git a/lib/ft_printf/source/ft_putnbr_fd.o b/lib/ft_printf/source/ft_putnbr_fd.o new file mode 100644 index 0000000..da777c2 Binary files /dev/null and b/lib/ft_printf/source/ft_putnbr_fd.o differ diff --git a/lib/ft_printf/source/ft_putptr_fd.c b/lib/ft_printf/source/ft_putptr_fd.c new file mode 100755 index 0000000..09139bb --- /dev/null +++ b/lib/ft_printf/source/ft_putptr_fd.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putptr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:14:08 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:25:02 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_putptr_fd(unsigned long long n, int fd) +{ + int len; + + len = 0; + if (n >= 16) + { + len += pf_putptr_fd(n / 16, fd); + len += pf_putptr_fd(n % 16, fd); + } + else + { + if (n < 10) + len += pf_putchar_fd(n + '0', fd); + else + len += pf_putchar_fd(n + 'a' - 10, fd); + } + return (len); +} diff --git a/lib/ft_printf/source/ft_putptr_fd.o b/lib/ft_printf/source/ft_putptr_fd.o new file mode 100644 index 0000000..d3b93cd Binary files /dev/null and b/lib/ft_printf/source/ft_putptr_fd.o differ diff --git a/lib/ft_printf/source/ft_putstr_fd.c b/lib/ft_printf/source/ft_putstr_fd.c new file mode 100755 index 0000000..12f4fb9 --- /dev/null +++ b/lib/ft_printf/source/ft_putstr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:24:20 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:25:19 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../header/ft_printf.h" + +int pf_putstr_fd(char *s, int fd) +{ + unsigned int i; + int count; + + if (!s) + { + pf_putstr_fd("(null)", fd); + return (6); + } + i = 0; + count = 0; + while (*(s + i)) + { + count += pf_putchar_fd(*(s + i), fd); + i++; + } + return (count); +} diff --git a/lib/ft_printf/source/ft_putstr_fd.o b/lib/ft_printf/source/ft_putstr_fd.o new file mode 100644 index 0000000..2924de9 Binary files /dev/null and b/lib/ft_printf/source/ft_putstr_fd.o differ diff --git a/lib/libft/Makefile b/lib/libft/Makefile new file mode 100755 index 0000000..77d0b84 --- /dev/null +++ b/lib/libft/Makefile @@ -0,0 +1,31 @@ +SOURCES = ft_putnbr_fd.c ft_putendl_fd.c ft_putstr_fd.c ft_putchar_fd.c ft_striteri.c ft_strmapi.c ft_itoa.c ft_split.c ft_strtrim.c ft_strjoin.c ft_substr.c ft_strdup.c ft_calloc.c ft_atoi.c ft_strnstr.c ft_memcmp.c ft_memchr.c ft_strncmp.c ft_strrchr.c ft_strchr.c ft_tolower.c ft_toupper.c ft_strlcpy.c ft_strlen.c ft_isprint.c ft_strlcat.c ft_memmove.c ft_memcpy.c ft_bzero.c ft_isalpha.c ft_isdigit.c ft_memset.c ft_isalnum.c ft_isascii.c + +OBJECTS = $(SOURCES:.c=.o) + +EXTRA = a.out a.out.dSYM main.c + +NAME = libft.a + +COMPILER = cc + +FLAGS = -c -Wall -Werror -Wextra -I -g3 + +all : $(NAME) + +$(NAME) : $(OBJECTS) + @ar -rcs libft.a *.o + +$(OBJECTS) : $(SOURCES) + $(COMPILER) $(FLAGS) $(SOURCES) + +clean : + @rm -f $(OBJECTS) + +fclean : clean + @rm -rf $(NAME) $(EXTRA) + +re : + @make fclean + @make all + +.PHONY: fclean clean all re diff --git a/lib/libft/ft_atoi.c b/lib/libft/ft_atoi.c new file mode 100755 index 0000000..c660de7 --- /dev/null +++ b/lib/libft/ft_atoi.c @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/13 15:57:24 by hexplor #+# #+# */ +/* Updated: 2023/11/27 22:23:38 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_isspace(char c) +{ + if (c == '\t' || c == '\n' || c == '\v' \ + || c == '\f' || c == '\r' || c == ' ') + return (1); + return (0); +} + +static int ft_fsign(char c) +{ + if (c == '-') + return (-1); + return (1); +} + +int ft_atoi(const char *text) +{ + long sign; + long number; + + number = 0; + sign = 1; + while (ft_isspace(*text) == 1) + text++; + if (*text == '-' || *text == '+') + { + sign = ft_fsign(*text); + text++; + } + while (ft_isdigit(*text) == 1) + { + number *= 10; + number += *text - '0'; + text++; + } + return (sign * number); +} +/* +#include +#include +int main(void) +{ + + char *texte1 = "12"; + char *texte2 = "+12"; + char *texte3 = "-12"; + + char *texte4 = " \t\n\v\f\r12"; + char *texte5 = " \t\n\v\f\r+12"; + char *texte6 = " \t\n\v\f\r-12"; + + char *texte7 = "--12"; + char *texte8 = "++12"; + char *texte9 = "abcd7"; + + char *texte10 = "12abs"; + char *texte11 = ""; + char *texte12 = "0"; + char *texte13 = "-2147483649"; + char *texte14 = "2147483649"; + + if (ft_atoi(texte1) != 12) + printf("1: NON\n"); + if(ft_atoi(texte2) != 12) + printf("2: NON\n"); + if(ft_atoi(texte3) != -12) + printf("3: NON\n"); + if(ft_atoi(texte4) != 12) + printf("4: NON\n"); + if(ft_atoi(texte5) != 12) + printf("5: NON\n"); + if(ft_atoi(texte6) != -12) + printf("6: NON\n"); + if(ft_atoi(texte7) != 0) + printf("7: NON\n"); + if(ft_atoi(texte8) != 0) + printf("8: NON\n"); + if(ft_atoi(texte9) != 0) + printf("9: NON\n"); + if(ft_atoi(texte10) != 12) + printf("10: NON\n"); + if(ft_atoi(texte11) != 0) + printf("11: NON\n"); + if(ft_atoi(texte12) != 0) + printf("12: NON\n"); + if(ft_atoi(texte13) != -2147483649L) + printf("13: NON\n"); + if(ft_atoi(texte14) != 2147483649L) + printf("14: NON\n"); + write(1, "\n", 1); + return (0); +}*/ diff --git a/lib/libft/ft_atoi.o b/lib/libft/ft_atoi.o new file mode 100644 index 0000000..7636f66 Binary files /dev/null and b/lib/libft/ft_atoi.o differ diff --git a/lib/libft/ft_bzero.c b/lib/libft/ft_bzero.c new file mode 100755 index 0000000..a02eb4c --- /dev/null +++ b/lib/libft/ft_bzero.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:47:55 by yantoine #+# #+# */ +/* Updated: 2023/11/09 15:02:31 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include +#include +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + if (n <= 0) + return ; + ft_memset(s, 0, n); +} + +/*int main() +{ + void mess[10] = "oui"; + + ft_bzero() + return (0); +}*/ diff --git a/lib/libft/ft_bzero.o b/lib/libft/ft_bzero.o new file mode 100644 index 0000000..585bb41 Binary files /dev/null and b/lib/libft/ft_bzero.o differ diff --git a/lib/libft/ft_calloc.c b/lib/libft/ft_calloc.c new file mode 100755 index 0000000..152ee4c --- /dev/null +++ b/lib/libft/ft_calloc.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/14 15:24:33 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:53:17 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t n, size_t size) +{ + char *tab; + size_t sizemax; + + sizemax = n * size; + if (size && sizemax / size < n) + return (NULL); + if (n == 0 || size == 0) + { + tab = malloc(1); + return (tab); + } + tab = malloc(n * size); + if (!tab) + return (NULL); + ft_bzero(tab, n * size); + return (tab); +} +/*#include +int main() +{ + void *p; + + p = ft_calloc(SIZE_MAX, SIZE_MAX); + free(p); + return (0); +}*/ diff --git a/lib/libft/ft_calloc.o b/lib/libft/ft_calloc.o new file mode 100644 index 0000000..5add899 Binary files /dev/null and b/lib/libft/ft_calloc.o differ diff --git a/lib/libft/ft_isalnum.c b/lib/libft/ft_isalnum.c new file mode 100755 index 0000000..cbaa49b --- /dev/null +++ b/lib/libft/ft_isalnum.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:17:01 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:05:51 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isalnum.o b/lib/libft/ft_isalnum.o new file mode 100644 index 0000000..e53392f Binary files /dev/null and b/lib/libft/ft_isalnum.o differ diff --git a/lib/libft/ft_isalpha.c b/lib/libft/ft_isalpha.c new file mode 100755 index 0000000..b7095b0 --- /dev/null +++ b/lib/libft/ft_isalpha.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:02:38 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:13 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 65 && c <= 90) \ + || (c >= 97 && c <= 122)) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isalpha.o b/lib/libft/ft_isalpha.o new file mode 100644 index 0000000..42a78f5 Binary files /dev/null and b/lib/libft/ft_isalpha.o differ diff --git a/lib/libft/ft_isascii.c b/lib/libft/ft_isascii.c new file mode 100755 index 0000000..b9521fa --- /dev/null +++ b/lib/libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:17:41 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:30 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isascii.o b/lib/libft/ft_isascii.o new file mode 100644 index 0000000..11cdcbf Binary files /dev/null and b/lib/libft/ft_isascii.o differ diff --git a/lib/libft/ft_isdigit.c b/lib/libft/ft_isdigit.c new file mode 100755 index 0000000..b78fdd8 --- /dev/null +++ b/lib/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:06:07 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:49 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isdigit(int c) +{ + if ((c >= 48 && c <= 57)) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isdigit.o b/lib/libft/ft_isdigit.o new file mode 100644 index 0000000..9473b5f Binary files /dev/null and b/lib/libft/ft_isdigit.o differ diff --git a/lib/libft/ft_isprint.c b/lib/libft/ft_isprint.c new file mode 100755 index 0000000..9d79e61 --- /dev/null +++ b/lib/libft/ft_isprint.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 12:37:20 by yantoine #+# #+# */ +/* Updated: 2023/11/30 09:02:47 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (1); + return (0); +} diff --git a/lib/libft/ft_isprint.o b/lib/libft/ft_isprint.o new file mode 100644 index 0000000..fa1d564 Binary files /dev/null and b/lib/libft/ft_isprint.o differ diff --git a/lib/libft/ft_itoa.c b/lib/libft/ft_itoa.c new file mode 100755 index 0000000..e325b44 --- /dev/null +++ b/lib/libft/ft_itoa.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/22 15:16:11 by hexplor #+# #+# */ +/* Updated: 2023/11/30 07:44:52 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_n_digit(int n) +{ + long index; + + if (n == 0) + return (1); + index = 0; + while (n != 0) + { + n /= 10; + index++; + } + return (index); +} + +static int ft_pow(int n) +{ + long index; + + index = 1; + while (n != 0) + { + index *= 10; + n--; + } + return (index / 10); +} + +static void ft_set_number(char *tab) +{ + long index; + + index = 0; + while (index != 11) + { + tab[index] = index + '0'; + index++; + } + tab[index] = '\0'; +} + +static void ft_set_digit(long nbr_digit, long index, char *nbr, long n) +{ + char digit[15]; + long pow; + + if (n == 0) + { + *nbr = '0'; + *(nbr + 1) = 0; + return ; + } + ft_set_number(digit); + pow = ft_pow(nbr_digit); + while (nbr_digit != 0) + { + *(nbr + index++) = digit[(n / pow) % 10]; + nbr_digit--; + pow /= 10; + } + *(nbr + index++) = '\0'; +} + +char *ft_itoa(int n) +{ + char *nbr; + long index; + long n2; + long nbr_digit; + + n2 = (long) n; + nbr_digit = ft_n_digit(n); + index = 0; + if (n2 < 0) + { + nbr = ft_calloc((nbr_digit + 2), 1); + if (!nbr) + return (NULL); + *(nbr + index++) = '-'; + n2 *= -1; + } + else + { + nbr = ft_calloc((nbr_digit + 1), 1); + if (!nbr) + return (NULL); + } + ft_set_digit(nbr_digit, index, nbr, n2); + return (nbr); +} diff --git a/lib/libft/ft_itoa.o b/lib/libft/ft_itoa.o new file mode 100644 index 0000000..cde2cfa Binary files /dev/null and b/lib/libft/ft_itoa.o differ diff --git a/lib/libft/ft_memchr.c b/lib/libft/ft_memchr.c new file mode 100755 index 0000000..5e80b6a --- /dev/null +++ b/lib/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 09:03:40 by yantoine #+# #+# */ +/* Updated: 2023/11/13 16:24:52 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *p; + size_t index; + + p = (unsigned char *)s; + index = 0; + while (p[index] && index < n) + { + if (*(p + index) == (unsigned char) c) + return ((void *)(p + index)); + index++; + } + return (NULL); +} diff --git a/lib/libft/ft_memchr.o b/lib/libft/ft_memchr.o new file mode 100644 index 0000000..4074a63 Binary files /dev/null and b/lib/libft/ft_memchr.o differ diff --git a/lib/libft/ft_memcmp.c b/lib/libft/ft_memcmp.c new file mode 100755 index 0000000..16a42a6 --- /dev/null +++ b/lib/libft/ft_memcmp.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 10:08:42 by yantoine #+# #+# */ +/* Updated: 2023/11/13 16:23:41 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *p1; + unsigned char *p2; + size_t index; + + index = 0; + p1 = (unsigned char *)s1; + p2 = (unsigned char *)s2; + while (index < n) + { + if (*(p1 + index) != *(p2 + index)) + return ((*(p1 + index) - *(p2 + index))); + index++; + } + return (0); +} + +/*int main() +{ + ft_memcmp("001270", "coucou", 7); + return (0); +}*/ diff --git a/lib/libft/ft_memcmp.o b/lib/libft/ft_memcmp.o new file mode 100644 index 0000000..99bfa7f Binary files /dev/null and b/lib/libft/ft_memcmp.o differ diff --git a/lib/libft/ft_memcpy.c b/lib/libft/ft_memcpy.c new file mode 100755 index 0000000..030e42e --- /dev/null +++ b/lib/libft/ft_memcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 11:03:13 by yantoine #+# #+# */ +/* Updated: 2023/11/09 12:15:15 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t index; + + index = 0; + while (index < n) + { + *(unsigned char *)(dest + index) = *(unsigned char *)(src + index); + index++; + } + return (dest); +} diff --git a/lib/libft/ft_memcpy.o b/lib/libft/ft_memcpy.o new file mode 100644 index 0000000..ea83159 Binary files /dev/null and b/lib/libft/ft_memcpy.o differ diff --git a/lib/libft/ft_memmove.c b/lib/libft/ft_memmove.c new file mode 100755 index 0000000..1e79e41 --- /dev/null +++ b/lib/libft/ft_memmove.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/08 15:13:56 by hexplor #+# #+# */ +/* Updated: 2023/11/09 12:45:23 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t index; + int index2; + + if (dest > src) + { + index2 = n - 1; + while (index2 >= 0) + { + *(unsigned char *)(dest + index2) = \ + *(unsigned char *)(src + index2); + index2--; + } + } + else + { + index = 0; + while (index < n) + { + *(unsigned char *)(dest + index) = *(unsigned char *)(src + index); + index++; + } + } + return (dest); +} diff --git a/lib/libft/ft_memmove.o b/lib/libft/ft_memmove.o new file mode 100644 index 0000000..2d154b0 Binary files /dev/null and b/lib/libft/ft_memmove.o differ diff --git a/lib/libft/ft_memset.c b/lib/libft/ft_memset.c new file mode 100755 index 0000000..ee95790 --- /dev/null +++ b/lib/libft/ft_memset.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:18 by yantoine #+# #+# */ +/* Updated: 2023/11/09 14:55:20 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include +#include +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t index; + + index = 0; + while (index < n) + { + *(unsigned char *)(s + index) = c; + index++; + } + return (s); +} diff --git a/lib/libft/ft_memset.o b/lib/libft/ft_memset.o new file mode 100644 index 0000000..936618d Binary files /dev/null and b/lib/libft/ft_memset.o differ diff --git a/lib/libft/ft_putchar_fd.c b/lib/libft/ft_putchar_fd.c new file mode 100755 index 0000000..9666580 --- /dev/null +++ b/lib/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:08:31 by hexplor #+# #+# */ +/* Updated: 2023/11/23 15:04:00 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/lib/libft/ft_putchar_fd.o b/lib/libft/ft_putchar_fd.o new file mode 100644 index 0000000..786101f Binary files /dev/null and b/lib/libft/ft_putchar_fd.o differ diff --git a/lib/libft/ft_putendl_fd.c b/lib/libft/ft_putendl_fd.c new file mode 100755 index 0000000..4797c84 --- /dev/null +++ b/lib/libft/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:34:12 by hexplor #+# #+# */ +/* Updated: 2023/11/24 17:45:40 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/lib/libft/ft_putendl_fd.o b/lib/libft/ft_putendl_fd.o new file mode 100644 index 0000000..fedf787 Binary files /dev/null and b/lib/libft/ft_putendl_fd.o differ diff --git a/lib/libft/ft_putnbr_fd.c b/lib/libft/ft_putnbr_fd.c new file mode 100755 index 0000000..6e3cf3e --- /dev/null +++ b/lib/libft/ft_putnbr_fd.c @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:41:48 by hexplor #+# #+# */ +/* Updated: 2023/11/27 22:27:06 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_n_digit(int n) +{ + long index; + + index = 0; + while (n != 0) + { + n /= 10; + index++; + } + return (index); +} + +static int ft_pow(int n) +{ + long index; + + index = 1; + while (n != 0) + { + index *= 10; + n--; + } + return (index / 10); +} + +static void ft_set_number(char *tab) +{ + long index; + + index = 0; + while (index != 11) + { + tab[index] = index + '0'; + index++; + } + tab[index] = '\0'; +} + +static void ft_set_digit(long nbr_digit, long n, int fd) +{ + char digit[15]; + long pow; + + if (n == 0) + { + ft_putchar_fd('0', fd); + return ; + } + ft_set_number(digit); + pow = ft_pow(nbr_digit); + while (nbr_digit != 0) + { + ft_putchar_fd(digit[(n / pow) % 10], fd); + nbr_digit--; + pow /= 10; + } +} + +void ft_putnbr_fd(int n, int fd) +{ + long n2; + long nbr_digit; + + n2 = (long) n; + nbr_digit = ft_n_digit(n); + if (n2 < 0) + { + ft_putchar_fd('-', fd); + n2 *= -1; + } + ft_set_digit(nbr_digit, n2, fd); +} diff --git a/lib/libft/ft_putnbr_fd.o b/lib/libft/ft_putnbr_fd.o new file mode 100644 index 0000000..9ccbf82 Binary files /dev/null and b/lib/libft/ft_putnbr_fd.o differ diff --git a/lib/libft/ft_putstr_fd.c b/lib/libft/ft_putstr_fd.c new file mode 100755 index 0000000..e6cf7d7 --- /dev/null +++ b/lib/libft/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:24:20 by hexplor #+# #+# */ +/* Updated: 2023/11/23 14:32:00 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + unsigned int i; + + i = 0; + while (*(s + i)) + { + ft_putchar_fd(*(s + i), fd); + i++; + } +} diff --git a/lib/libft/ft_putstr_fd.o b/lib/libft/ft_putstr_fd.o new file mode 100644 index 0000000..0737168 Binary files /dev/null and b/lib/libft/ft_putstr_fd.o differ diff --git a/lib/libft/ft_split.c b/lib/libft/ft_split.c new file mode 100755 index 0000000..7ea16c3 --- /dev/null +++ b/lib/libft/ft_split.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 17:06:15 by hexplor #+# #+# */ +/* Updated: 2023/11/29 13:19:56 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t count_word(char *str, char c) +{ + int count; + + count = 0; + while (*str) + { + while (*str == c) + str++; + if (*str != c && *str) + count++; + while (*str && *str != c) + str++; + } + return (count); +} + +static size_t len_word(char *s, char c, size_t start) +{ + size_t i; + + i = 0; + while (s[start] && s[start] != c) + { + i++; + start++; + } + return (i); +} + +static void free_array(char **s1) +{ + size_t i; + + i = 0; + while (s1[i]) + { + free(s1[i]); + i++; + } + free(s1); +} + +static char **divisor(char *str1, char c, char **array, size_t len) +{ + size_t i; + size_t j; + + i = 0; + j = 0; + while (i < len) + { + while (str1[j] && str1[j] == c) + j++; + array[i] = ft_substr(str1, j, len_word(str1, c, j)); + if (!array[i]) + { + free_array(array); + return (NULL); + } + while (str1[j] && str1[j] != c) + j++; + i++; + } + array[i] = NULL; + return (array); +} + +char **ft_split(char const *s, char c) +{ + size_t words; + char **array; + + if (!s) + return (NULL); + words = count_word((char *)s, c); + array = (char **)malloc((words + 1) * (sizeof(char *))); + if (!array) + return (NULL); + array = divisor((char *)s, c, array, words); + return (array); +} +/* +int main() +{ + char **list; + + list = ft_split("--1-2--3---4----5-----42", '-'); + for (int i = 0; list[i] != NULL; ++i) + free(list[i]); + free(list); + return (0); +} +*/ diff --git a/lib/libft/ft_split.o b/lib/libft/ft_split.o new file mode 100644 index 0000000..dd1dc50 Binary files /dev/null and b/lib/libft/ft_split.o differ diff --git a/lib/libft/ft_strchr.c b/lib/libft/ft_strchr.c new file mode 100755 index 0000000..f16e965 --- /dev/null +++ b/lib/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 12:07:02 by hexplor #+# #+# */ +/* Updated: 2023/11/29 15:22:10 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + char *chaine; + + chaine = (char *)s; + while (*chaine) + { + if (*chaine == (unsigned char)c) + return (chaine); + chaine++; + } + if (c == '\0') + return (chaine); + return (NULL); +} diff --git a/lib/libft/ft_strchr.o b/lib/libft/ft_strchr.o new file mode 100644 index 0000000..3b2d3e8 Binary files /dev/null and b/lib/libft/ft_strchr.o differ diff --git a/lib/libft/ft_strdup.c b/lib/libft/ft_strdup.c new file mode 100755 index 0000000..562f9a7 --- /dev/null +++ b/lib/libft/ft_strdup.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/15 15:58:53 by hexplor #+# #+# */ +/* Updated: 2023/11/29 14:52:09 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s1) +{ + char *s2; + int index; + + s2 = (char *)ft_calloc(ft_strlen(s1) + 1, 1); + if (s2 == NULL) + return (NULL); + index = 0; + while (*(s1 + index)) + { + *(s2 + index) = *(s1 + index); + index++; + } + *(s2 + index) = '\0'; + return (s2); +} + +/*int main() +{ + char *dest; + + dest = ft_strdup("BONJOUR"); + dest = ft_strdup(""); + dest = ft_strdup("\0"); + return (0); +}*/ diff --git a/lib/libft/ft_strdup.o b/lib/libft/ft_strdup.o new file mode 100644 index 0000000..5b9fd48 Binary files /dev/null and b/lib/libft/ft_strdup.o differ diff --git a/lib/libft/ft_striteri.c b/lib/libft/ft_striteri.c new file mode 100755 index 0000000..68de181 --- /dev/null +++ b/lib/libft/ft_striteri.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 12:50:39 by hexplor #+# #+# */ +/* Updated: 2023/11/23 13:54:15 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (*s) + { + f(i, s); + i++; + s++; + } +} diff --git a/lib/libft/ft_striteri.o b/lib/libft/ft_striteri.o new file mode 100644 index 0000000..dfa4c5a Binary files /dev/null and b/lib/libft/ft_striteri.o differ diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c new file mode 100755 index 0000000..06d5c68 --- /dev/null +++ b/lib/libft/ft_strjoin.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 12:21:11 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:49:26 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t len; + char *str; + + len = ft_strlen(s1); + len += ft_strlen(s2); + str = (char *)ft_calloc((len + 1), 1); + if (!str) + return (NULL); + ft_memmove(str, s1, ft_strlen(s1)); + ft_memmove((str + ft_strlen(s1)), s2, ft_strlen(s2)); + return (str); +} diff --git a/lib/libft/ft_strjoin.o b/lib/libft/ft_strjoin.o new file mode 100644 index 0000000..2a7e2d4 Binary files /dev/null and b/lib/libft/ft_strjoin.o differ diff --git a/lib/libft/ft_strlcat.c b/lib/libft/ft_strlcat.c new file mode 100755 index 0000000..1e4b455 --- /dev/null +++ b/lib/libft/ft_strlcat.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 09:02:08 by hexplor #+# #+# */ +/* Updated: 2023/11/10 09:54:44 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t k; + + i = 0; + k = 0; + while (dest[i] && i < size) + i++; + while (src[k] && (i + k + 1) < size) + { + dest[i + k] = src[k]; + k++; + } + if (i < size) + dest[i + k] = '\0'; + return (i + ft_strlen(src)); +} + +/*int main() +{ + char mess1[10] = "oui"; + char mess2[10] = "non"; + + ft_strlcat(mess1, mess2, 3); + return (0); +}*/ diff --git a/lib/libft/ft_strlcat.o b/lib/libft/ft_strlcat.o new file mode 100644 index 0000000..7c2a842 Binary files /dev/null and b/lib/libft/ft_strlcat.o differ diff --git a/lib/libft/ft_strlcpy.c b/lib/libft/ft_strlcpy.c new file mode 100755 index 0000000..4cedd6b --- /dev/null +++ b/lib/libft/ft_strlcpy.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 17:27:30 by hexplor #+# #+# */ +/* Updated: 2023/11/09 20:22:10 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t c; + size_t i; + + c = 0; + while (src[c] != '\0') + c++; + i = 0; + if (size != 0) + { + while (src[i] != '\0' && i < (size - 1)) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + } + return (c); +} + +/*int main() +{ + char dest[10] = "oui"; + char src[3] = "non"; + + ft_strlcpy(dest, src, 10); + return (0); +}*/ diff --git a/lib/libft/ft_strlcpy.o b/lib/libft/ft_strlcpy.o new file mode 100644 index 0000000..a898350 Binary files /dev/null and b/lib/libft/ft_strlcpy.o differ diff --git a/lib/libft/ft_strlen.c b/lib/libft/ft_strlen.c new file mode 100755 index 0000000..7ed76b2 --- /dev/null +++ b/lib/libft/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:18:42 by yantoine #+# #+# */ +/* Updated: 2023/11/09 12:31:17 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strlen(const char *c) +{ + int index; + + index = 0; + while (c[index] != 0) + index += 1; + return (index); +} diff --git a/lib/libft/ft_strlen.o b/lib/libft/ft_strlen.o new file mode 100644 index 0000000..c9a6875 Binary files /dev/null and b/lib/libft/ft_strlen.o differ diff --git a/lib/libft/ft_strmapi.c b/lib/libft/ft_strmapi.c new file mode 100755 index 0000000..83db4d1 --- /dev/null +++ b/lib/libft/ft_strmapi.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 11:52:03 by hexplor #+# #+# */ +/* Updated: 2023/11/30 09:04:01 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + unsigned int i; + char *str; + + i = 0; + str = ft_calloc((ft_strlen(s) + 1), 1); + if (!str) + return (0); + while (*(s + i)) + { + *(str + i) = f(i, *(s + i)); + i++; + } + *(str + i) = '\0'; + return (str); +} diff --git a/lib/libft/ft_strmapi.o b/lib/libft/ft_strmapi.o new file mode 100644 index 0000000..c0c986a Binary files /dev/null and b/lib/libft/ft_strmapi.o differ diff --git a/lib/libft/ft_strncmp.c b/lib/libft/ft_strncmp.c new file mode 100755 index 0000000..4c48c8e --- /dev/null +++ b/lib/libft/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 08:46:16 by yantoine #+# #+# */ +/* Updated: 2023/11/30 09:28:36 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t index; + + index = 0; + while (*(unsigned char *)(s1 + index) && \ + *(unsigned char *)(s2 + index) && index < n) + { + if (*(s1 + index) != *(s2 + index)) + return (*(s1 + index) - *(s2 + index)); + index++; + } + return (0); +} diff --git a/lib/libft/ft_strncmp.o b/lib/libft/ft_strncmp.o new file mode 100644 index 0000000..0f00c4a Binary files /dev/null and b/lib/libft/ft_strncmp.o differ diff --git a/lib/libft/ft_strnstr.c b/lib/libft/ft_strnstr.c new file mode 100755 index 0000000..dc17b15 --- /dev/null +++ b/lib/libft/ft_strnstr.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/12 12:16:17 by yantoine #+# #+# */ +/* Updated: 2023/11/27 22:29:37 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t j; + char *b; + + b = (char *) big; + i = 0; + if (little[i] == '\0' || little == NULL) + return (b); + if (len == 0) + return (0); + while (b[i] != '\0' && i < len) + { + j = 0; + while (little[j] && (i + j) < len) + { + if (b[i + j] == little[j]) + j++; + else + break ; + } + if (little[j] == 0) + return (&b[i]); + i++; + } + return (0); +} +/*int main() +{ + ft_strnstr("aaabcabcd", "abcd", -1); + return (0); +}*/ diff --git a/lib/libft/ft_strnstr.o b/lib/libft/ft_strnstr.o new file mode 100644 index 0000000..fb033dd Binary files /dev/null and b/lib/libft/ft_strnstr.o differ diff --git a/lib/libft/ft_strrchr.c b/lib/libft/ft_strrchr.c new file mode 100755 index 0000000..dfc1be3 --- /dev/null +++ b/lib/libft/ft_strrchr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 08:02:01 by yantoine #+# #+# */ +/* Updated: 2023/11/29 14:34:30 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int len; + + len = 0; + while (*s) + { + len++; + s++; + } + if (c == '\0' && *s == '\0') + return ((char *)s); + while (len >= 0) + { + if (*s == (unsigned char)c) + return ((char *)s); + s--; + len--; + } + return (NULL); +} diff --git a/lib/libft/ft_strrchr.o b/lib/libft/ft_strrchr.o new file mode 100644 index 0000000..5525ac7 Binary files /dev/null and b/lib/libft/ft_strrchr.o differ diff --git a/lib/libft/ft_strtrim.c b/lib/libft/ft_strtrim.c new file mode 100755 index 0000000..d23003e --- /dev/null +++ b/lib/libft/ft_strtrim.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 13:48:16 by hexplor #+# #+# */ +/* Updated: 2023/11/29 13:09:29 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + int i; + int j; + + i = 0; + j = ft_strlen(s1) - 1; + while (s1[i] && ft_strchr(set, s1[i])) + i++; + while (s1[j] && ft_strchr(set, s1[j])) + j--; + return (ft_substr(s1, i, (j - i + 1))); +} diff --git a/lib/libft/ft_strtrim.o b/lib/libft/ft_strtrim.o new file mode 100644 index 0000000..f7acc25 Binary files /dev/null and b/lib/libft/ft_strtrim.o differ diff --git a/lib/libft/ft_substr.c b/lib/libft/ft_substr.c new file mode 100755 index 0000000..89ada2c --- /dev/null +++ b/lib/libft/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/15 20:04:44 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:45:42 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t i; + + if (!s) + return (NULL); + i = 0; + if (len > ft_strlen(s) - start) + { + len = ft_strlen(s) - start; + } + if (start >= ft_strlen(s)) + return (ft_strdup("")); + str = (char *)malloc(((sizeof(char) * (len + 1)))); + if (!str) + return (NULL); + while (i < len && s[start] != '\0') + { + str[i++] = s[start++]; + } + str[i] = '\0'; + return (str); +} +/* +int main() +{ + char *text; + + text = ft_substr("tripouille", 100, 1); + free(text); + return (0); +}*/ diff --git a/lib/libft/ft_substr.o b/lib/libft/ft_substr.o new file mode 100644 index 0000000..0ebec53 Binary files /dev/null and b/lib/libft/ft_substr.o differ diff --git a/lib/libft/ft_tolower.c b/lib/libft/ft_tolower.c new file mode 100755 index 0000000..604ca24 --- /dev/null +++ b/lib/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 10:09:46 by hexplor #+# #+# */ +/* Updated: 2023/11/10 10:13:40 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 97 - 32 && c <= 122 - 32) + return (c + 32); + return (c); +} diff --git a/lib/libft/ft_tolower.o b/lib/libft/ft_tolower.o new file mode 100644 index 0000000..9fde8fe Binary files /dev/null and b/lib/libft/ft_tolower.o differ diff --git a/lib/libft/ft_toupper.c b/lib/libft/ft_toupper.c new file mode 100755 index 0000000..1f09844 --- /dev/null +++ b/lib/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 10:05:42 by hexplor #+# #+# */ +/* Updated: 2023/11/10 10:09:20 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 97 && c <= 122) + return (c - 32); + return (c); +} diff --git a/lib/libft/ft_toupper.o b/lib/libft/ft_toupper.o new file mode 100644 index 0000000..374dad9 Binary files /dev/null and b/lib/libft/ft_toupper.o differ diff --git a/lib/libft/libft.a b/lib/libft/libft.a new file mode 100644 index 0000000..31846fd Binary files /dev/null and b/lib/libft/libft.a differ diff --git a/lib/libft/libft.h b/lib/libft/libft.h new file mode 100755 index 0000000..8291703 --- /dev/null +++ b/lib/libft/libft.h @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 09:46:33 by yantoine #+# #+# */ +/* Updated: 2023/11/23 14:41:28 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include + +void *ft_calloc(size_t count, size_t size); + +void ft_putnbr_fd(int n, int fd); + +void ft_putendl_fd(char *s, int fd); + +void ft_striteri(char *s, void (*f)(unsigned int, char*)); + +void *ft_memchr(const void *s, int c, size_t n); + +void *ft_memmove(void *dest, const void *src, size_t n); + +void ft_putchar_fd(char c, int fd); + +void ft_putstr_fd(char *s, int fd); + +void *ft_memset(void *s, int c, size_t n); + +void ft_bzero(void *s, size_t n); + +void *ft_memcpy(void *dest, const void *src, size_t n); + +size_t ft_strlcat(char *dest, const char *src, size_t size); + +size_t ft_strlcpy(char *dest, const char *src, size_t size); + +size_t ft_strlen(const char *c); + +char **ft_split(char const *s, char c); + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +char *ft_itoa(int n); + +char *ft_strtrim(char const *s1, char const *set); + +char *ft_strjoin(char const *s1, char const *s2); + +char *ft_substr(char const *s, unsigned int start, size_t len); + +char *ft_strdup(const char *s1); + +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); + +int ft_atoi(const char *str); + +int ft_memcmp(const void *s1, const void *s2, size_t n); + +int ft_strncmp(const char *s1, const char *s2, size_t n); + +int ft_toupper(int c); + +int ft_tolower(int c); + +int ft_isprint(int c); + +int ft_isalpha(int c); + +int ft_isdigit(int c); + +int ft_isalnum(int c); + +int ft_isascii(int c); + +#endif diff --git a/src/client/client.c b/src/client/client.c new file mode 100644 index 0000000..590bffd --- /dev/null +++ b/src/client/client.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* client.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/10 16:51:00 by yantoine #+# #+# */ +/* Updated: 2024/05/17 16:13:47 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minitalk.h" + +static void pausing(int signum) +{ + (void)signum; +} + +static void send_bits(int pid, char c) +{ + int bit; + + usleep(50); + bit = 0; + while (bit < 8) + { + if ((c & (0x01 << bit)) != 0) + kill(pid, SIGUSR1); + else + kill(pid, SIGUSR2); + signal(SIGUSR1, pausing); + pause(); + bit++; + } +} + +int main(int argc, char **argv) +{ + int i; + + if (argc != 3 || !ft_strlen(argv[2]) || ft_atoi(argv[1]) <= 0) + return (1); + i = 0; + while (argv[2][i] != '\0') + { + send_bits(ft_atoi(argv[1]), argv[2][i]); + i++; + } + send_bits(ft_atoi(argv[1]), '\n'); + send_bits(ft_atoi(argv[1]), '\0'); +} diff --git a/src/server/server.c b/src/server/server.c new file mode 100644 index 0000000..b96ea46 --- /dev/null +++ b/src/server/server.c @@ -0,0 +1,127 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* server.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/26 22:48:59 by yantoine #+# #+# */ +/* Updated: 2024/05/13 21:22:13 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minitalk.h" + +char *g_str; + +static void print_hello(void) +{ + ft_printf(" , ----.\n"); + ft_printf(" - - `\n"); + ft_printf(" ,__.,' \\\n"); + ft_printf(" .' *`\\\n"); + ft_printf(" / | | / **\\\n"); + ft_printf(" . / ****.\n"); + ft_printf(" | mm | ****|\n"); + ft_printf(" \\ | ****|\n"); + ft_printf(" ` ._______ \\ ****/\n"); + ft_printf(" \\ /`---'\n"); + ft_printf(" \\___(\n"); + ft_printf(" /~~~~\\\n"); + ft_printf(" / \\\n"); + ft_printf(" / | \\\n"); + ft_printf(" | | \\\n"); + ft_printf(" , ~~ . |, ~~ . | |\\\n"); + ft_printf(" ( |||| ) ( |||| )(,,,)`\n"); + ft_printf(" ( |||||| )-( |||||| ) | ^\n"); + ft_printf(" ( |||||| ) ( |||||| ) |'/\n"); + ft_printf(" ( |||||| )-( |||||| )___,'-\n"); + ft_printf(" ( |||| ) ( |||| )\n"); + ft_printf(" ` ~~ ' ` ~~ '\n"); +} + +char *ft_strcpy(char *dest, const char *src) +{ + int i; + + i = 0; + while (src[i] != '\0') + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} + +static char *add_char_to_string(char *str, char c) +{ + int len; + char *new_str; + + len = 0; + new_str = NULL; + if (str == NULL) + { + str = (char *)malloc(2 * sizeof(char)); + str[0] = c; + str[1] = '\0'; + } + else + { + len = ft_strlen(str); + new_str = (char *)malloc((len + 2) * sizeof(char)); + ft_strcpy(new_str, str); + new_str[len] = c; + new_str[len + 1] = '\0'; + free(str); + str = new_str; + } + return (str); +} + +static void action(int signum, siginfo_t *info, void *context) +{ + static int current_byte; + static int bit_count; + + (void)context; + if (signum == SIGUSR1) + current_byte |= (0x01 << bit_count); + bit_count++; + if (bit_count == 8) + { + if (current_byte == '\0') + { + ft_printf("%s", g_str); + free(g_str); + g_str = NULL; + kill(info->si_pid, SIGUSR1); + current_byte = 0; + bit_count = 0; + return ; + } + g_str = add_char_to_string(g_str, current_byte); + current_byte = 0; + bit_count = 0; + } + usleep(50); + kill(info->si_pid, SIGUSR1); +} + +int main(void) +{ + struct sigaction sa; + + print_hello(); + sa.sa_sigaction = action; + sa.sa_flags = SA_SIGINFO; + ft_printf("pid: %d\n", getpid()); + while (1) + { + sigaction(SIGUSR1, &sa, NULL); + sigaction(SIGUSR2, &sa, NULL); + pause(); + } + return (0); +} diff --git a/tester/bigTest.txt b/tester/bigTest.txt new file mode 100644 index 0000000..06aa4e9 --- /dev/null +++ b/tester/bigTest.txt @@ -0,0 +1 @@ +A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, and the breath of that universal love which bears and sustains us, as it floats around us in an eternity of bliss; and then, my friend, when darkness overspreads my eyes, and heaven and earth seem to dwell in my soul and absorb its power, like the form of a beloved mistress, then I often think with longing, Oh, would I could describe these conceptions, could impress upon paper all that is living so full and warm within me, that it might be the mirror of my soul, as my soul is the mirror of the infinite God! O my friend -- but it is too much for my strength -- I sink under the weight of the splendour of these visions! A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, and the breath of that universal love which bears and sustains us, as it floats around us in an eternity of bliss; and then, my friend, when darkness overspreads my eyes, and heaven and earth seem to dwell in my soul and absorb its power, like the form of a beloved mistress, then I often think with longing, Oh, would I could describe these conceptions, could impress upon paper all that is living so full and warm within me, that it might be the mirror of my soul, as my soul is the mirror of the infinite God! O my friend -- but it is too much for my strength -- I sink under the weight of the splendour of these visions! A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, and the breath of that universal love which bears and sustains us, as it floats around us in an eternity of bliss; and then, my friend, when darkness overspreads my eyes, and heaven and earth seem to dwell in my soul and absorb its power, like the form of a beloved mistress, then I often think with longing, Oh, would I could describe these conceptions, could impress upon paper all that is living so full and warm within me, that it might be the mirror of my soul, as my soul is the mirror of the infinite God! O my friend -- but it is too much for my strength -- I sink under the weight of the splendour of these visions! A wonderful serenity has taken possession of my entire sou \ No newline at end of file diff --git a/tester/minitalk_tester.sh b/tester/minitalk_tester.sh new file mode 100755 index 0000000..834bd59 --- /dev/null +++ b/tester/minitalk_tester.sh @@ -0,0 +1,231 @@ +#!/bin/bash + +################################################### +################# Minitalk Tester ################# + +echo -e "\n\033[1;34m========= MINITALK TESTER =========\033[0m\n" + +# Correct paths if needed +minitalk_path="../" + +results_path=results/ +client_file=results/client.out.txt +server_file=results/server.out.txt +error_file=results/error.log +KO="[\033[31mKO\033[0m]" +OK="[\033[32mOK\033[0m]" +ERROR="[\033[33mERROR\033[0m]" + +rm -rf $results_path 2> /dev/null +mkdir $results_path 2> /dev/null + +################################################### +################### Compilation ################### + +cd $minitalk_path +make re > /dev/null 2> /dev/null + +# check if a program have been correctly creates + +test_compile() { + ls $1 > /dev/null 2> /dev/null + if [ $? -eq 0 ] + then + echo -e "$1 \033[32m✔\033[0m" + else + echo -e "$1 \033[31mx\033[0m" + echo -e "Compilation $KO\n" + echo -e "\033[1mMinitalk failed ❌\033[0m\n" + make fclean > /dev/null 2> /dev/null + cd $tester_folder + exit 1 + fi +} + +test_compile client +test_compile server +echo "" + +cd - > /dev/null 2> /dev/null + +################################################### +#################### Execution #################### + +# Execution of server + +$minitalk_path/server > $server_file & server_pid=$! +sleep 1 + +# Check if the string has been received by the server + +check_string(){ + cat $server_file | grep "$@" > /dev/null 2> /dev/null + ret=$? + if [ $ret -eq 1 ] + then + test_ok=1 + elif [ $ret -eq 2 ] + then + test_ok=2 + else + test_ok=0 + fi +} + +# Execute client and check the transmission + +tester_ok=0 + +test_transmission() { + # test_ok=0 + $minitalk_path/client $server_pid "$@" > $client_file 2>> $client_file + check_string "$@" + if [ $test_ok -eq 0 ] + then + echo -en $OK + elif [ $test_ok -eq 1 ] + then + tester_ok=1 + echo -en $KO + else + echo -en $ERROR + fi +} + +################################################### +###################### Tests ###################### + +# Manual test +# Usage:./minitalk_tester.sh [string to pass] + +if [ $# -ne 0 ] +then + echo -e "\t\033[2m## Client output ##\033[0m" + str="$@" + $minitalk_path/client $server_pid "$str" + kill $server_pid 2> /dev/null + wait $server_pid 2> /dev/null + echo -e "\n\t\033[2m## Server output ##\033[0m" + cat $server_file + len=${#str} + echo -e "\n____________________________________" + echo -e "\nstring size = $len\n" + rm -rf $results_path 2> /dev/null + cd $minitalk_path + make fclean > /dev/null 2> /dev/null + exit 0 2> /dev/null +fi + +echo -e "\t\033[2m## Tests ##\033[0m\n" + +# Tests of 10 characters + +echo "10 characters:" + +test_transmission "Hello World" +test_transmission "0123456789" +test_transmission "qwertyuiop" +test_transmission "zxcvbnm,./" + +echo -e "\n" + +# Tests of 100 characters + +echo "100 characters:" + +test_transmission "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, to" +test_transmission "The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced" +test_transmission "Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musi" +test_transmission "A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring whi" + +echo -e "\n" + +# Tests of 1000 characters + +echo "1000 characters:" + +test_transmission "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. \ +Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec \ +quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec \ +pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, \ +venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. \ +Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat \ +vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra \ +nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur \ +ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, \ +sem quam semper libero, sit amet adipiscing sem neque sed ipsum. N" + +test_transmission "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his \ +bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see \ +his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover \ +it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest \ +of him, waved about helplessly as he looked. \"What's happened to me?\" he thought. It wasn't a dream. His room, \ +a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of \ +textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture \ +that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted \ +out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards t" + +test_transmission "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and \ +I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, \ +the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but \ +because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor \ +again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally \ +circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us \ +ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault \ +with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no \ +resultant pleasure? On the other hand, we denounc" + +test_transmission "The European languages are members of the same family. Their separate existence is a myth. For science, music, \ +sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their \ +most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive \ +translators. To achieve this, it would be necessary to have uniform grammar, pronunciation and more common words. If \ +several languages coalesce, the grammar of the resulting language is more simple and regular than that of the individual \ +languages. The new common language will be more simple and regular than the existing European languages. It will be as \ +simple as Occidental; in fact, it will be Occidental. To an English person, it will seem like simplified English, as a \ +skeptical Cambridge friend of mine told me what Occidental is. The European languages are members of the same family. \ +Their separate existence is a myth. For science, music, spo" + +echo -e "\n" + +# Test of a big string + +bigstr=`cat bigTest.txt` +len=${#bigstr} +echo "$len characters:" +$minitalk_path/client $server_pid "$bigstr" > $client_file 2>> $client_file +check_string "$bigstr" +if [ $test_ok -eq 0 ] +then + echo -e $OK +elif [ $test_ok -eq 1 ] +then + echo -e $KO + tester_ok=1 +else + echo -e $ERROR +fi +echo "" + +################################################### +######################## END ###################### + +# Stop the server + +kill $server_pid 2> /dev/null +wait $server_pid 2> /dev/null + +# Display result ans clean up + +if [ $tester_ok -ne 0 ] +then + echo -e "\033[1mMinitalk failed ❌\033[0m" + echo -e "Check \033[4m$server_file\033[0m\n" +else + echo -e "\033[1mMinitalk succeed ✅\033[0m\n" + rm -rf $results_path 2> /dev/null + cd $minitalk_path + make fclean > /dev/null 2> /dev/null + cd - > /dev/null 2> /dev/null +fi + +exit 0 diff --git a/tester/preview.png b/tester/preview.png new file mode 100644 index 0000000..dde556f Binary files /dev/null and b/tester/preview.png differ