From c671539661fe2d38c8be894430da51ff56ac7888 Mon Sep 17 00:00:00 2001 From: Maelys Date: Tue, 10 Sep 2024 16:27:06 +0200 Subject: [PATCH] wip_parsing --- MacroLibX | 1 + Makefile | 47 ++++++++++++++++++ cub3D | Bin 0 -> 17400 bytes include/cub3d.h | 28 +++++++++++ include/mess_err.h | 24 +++++++++ libft/Ft_Printf/ft_printf.c | 66 +++++++++++++++++++++++++ libft/Ft_Printf/ft_printf_utils.c | 63 +++++++++++++++++++++++ libft/Ft_Printf/ft_putnbr_hexa.c | 60 ++++++++++++++++++++++ libft/Ft_Printf/ft_putnbr_uns_int.c | 31 ++++++++++++ libft/Makefile | 67 +++++++++++++++++++++++++ libft/compile_commands.json | 0 libft/gnl/get_next_line.c | 74 ++++++++++++++++++++++++++++ libft/includes/ft_printf.h | 30 +++++++++++ libft/includes/libft.h | 69 ++++++++++++++++++++++++++ libft/is/ft_is_space.c | 20 ++++++++ libft/is/ft_isalnum.c | 21 ++++++++ libft/is/ft_isalpha.c | 20 ++++++++ libft/is/ft_isascii.c | 20 ++++++++ libft/is/ft_isdigit.c | 20 ++++++++ libft/is/ft_isprint.c | 20 ++++++++ libft/mem/ft_bzero.c | 19 +++++++ libft/mem/ft_calloc.c | 30 +++++++++++ libft/mem/ft_memchr.c | 29 +++++++++++ libft/mem/ft_memcmp.c | 31 ++++++++++++ libft/mem/ft_memcpy.c | 28 +++++++++++ libft/mem/ft_memmove.c | 40 +++++++++++++++ libft/mem/ft_memset.c | 26 ++++++++++ libft/put/ft_putchar_fd.c | 18 +++++++ libft/put/ft_putendl_fd.c | 28 +++++++++++ libft/put/ft_putnbr_fd.c | 38 ++++++++++++++ libft/put/ft_putstr_fd.c | 27 ++++++++++ libft/str/ft_atoi.c | 40 +++++++++++++++ libft/str/ft_atoll.c | 40 +++++++++++++++ libft/str/ft_count_word.c | 33 +++++++++++++ libft/str/ft_itoa.c | 64 ++++++++++++++++++++++++ libft/str/ft_split.c | 71 ++++++++++++++++++++++++++ libft/str/ft_strchr.c | 31 ++++++++++++ libft/str/ft_strcmp.c | 27 ++++++++++ libft/str/ft_strdup.c | 31 ++++++++++++ libft/str/ft_striteri.c | 27 ++++++++++ libft/str/ft_strjoin.c | 41 +++++++++++++++ libft/str/ft_strlcat.c | 36 ++++++++++++++ libft/str/ft_strlcpy.c | 30 +++++++++++ libft/str/ft_strlen.c | 23 +++++++++ libft/str/ft_strmapi.c | 32 ++++++++++++ libft/str/ft_strncmp.c | 27 ++++++++++ libft/str/ft_strnstr.c | 38 ++++++++++++++ libft/str/ft_strrchr.c | 31 ++++++++++++ libft/str/ft_strtrim.c | 31 ++++++++++++ libft/str/ft_substr.c | 47 ++++++++++++++++++ libft/str/ft_tolower.c | 20 ++++++++ libft/str/ft_toupper.c | 20 ++++++++ obj/src/main.o | Bin 0 -> 2120 bytes obj/src/parsing/check_arg.o | Bin 0 -> 2416 bytes obj/src/utils/mess_error.o | Bin 0 -> 1560 bytes src/main.c | 44 +++++++++++++++++ src/parsing/check_arg.c | 46 +++++++++++++++++ src/parsing/check_id_text.c | 0 src/parsing/check_map.c | 0 src/parsing/check_rgb.c | 0 src/parsing/memo_parsing | 18 +++++++ src/utils/mess_error.c | 20 ++++++++ 62 files changed, 1863 insertions(+) create mode 160000 MacroLibX create mode 100644 Makefile create mode 100755 cub3D create mode 100644 include/cub3d.h create mode 100644 include/mess_err.h create mode 100644 libft/Ft_Printf/ft_printf.c create mode 100644 libft/Ft_Printf/ft_printf_utils.c create mode 100644 libft/Ft_Printf/ft_putnbr_hexa.c create mode 100644 libft/Ft_Printf/ft_putnbr_uns_int.c create mode 100644 libft/Makefile create mode 100644 libft/compile_commands.json create mode 100644 libft/gnl/get_next_line.c create mode 100644 libft/includes/ft_printf.h create mode 100644 libft/includes/libft.h create mode 100644 libft/is/ft_is_space.c create mode 100644 libft/is/ft_isalnum.c create mode 100644 libft/is/ft_isalpha.c create mode 100644 libft/is/ft_isascii.c create mode 100644 libft/is/ft_isdigit.c create mode 100644 libft/is/ft_isprint.c create mode 100644 libft/mem/ft_bzero.c create mode 100644 libft/mem/ft_calloc.c create mode 100644 libft/mem/ft_memchr.c create mode 100644 libft/mem/ft_memcmp.c create mode 100644 libft/mem/ft_memcpy.c create mode 100644 libft/mem/ft_memmove.c create mode 100644 libft/mem/ft_memset.c create mode 100644 libft/put/ft_putchar_fd.c create mode 100644 libft/put/ft_putendl_fd.c create mode 100644 libft/put/ft_putnbr_fd.c create mode 100644 libft/put/ft_putstr_fd.c create mode 100644 libft/str/ft_atoi.c create mode 100644 libft/str/ft_atoll.c create mode 100644 libft/str/ft_count_word.c create mode 100644 libft/str/ft_itoa.c create mode 100644 libft/str/ft_split.c create mode 100644 libft/str/ft_strchr.c create mode 100644 libft/str/ft_strcmp.c create mode 100644 libft/str/ft_strdup.c create mode 100644 libft/str/ft_striteri.c create mode 100644 libft/str/ft_strjoin.c create mode 100644 libft/str/ft_strlcat.c create mode 100644 libft/str/ft_strlcpy.c create mode 100644 libft/str/ft_strlen.c create mode 100644 libft/str/ft_strmapi.c create mode 100644 libft/str/ft_strncmp.c create mode 100644 libft/str/ft_strnstr.c create mode 100644 libft/str/ft_strrchr.c create mode 100644 libft/str/ft_strtrim.c create mode 100644 libft/str/ft_substr.c create mode 100644 libft/str/ft_tolower.c create mode 100644 libft/str/ft_toupper.c create mode 100644 obj/src/main.o create mode 100644 obj/src/parsing/check_arg.o create mode 100644 obj/src/utils/mess_error.o create mode 100644 src/main.c create mode 100644 src/parsing/check_arg.c create mode 100644 src/parsing/check_id_text.c create mode 100644 src/parsing/check_map.c create mode 100644 src/parsing/check_rgb.c create mode 100644 src/parsing/memo_parsing create mode 100644 src/utils/mess_error.c diff --git a/MacroLibX b/MacroLibX new file mode 160000 index 0000000..5a09ebb --- /dev/null +++ b/MacroLibX @@ -0,0 +1 @@ +Subproject commit 5a09ebb179f8f20afa8405a6d1e29845f0952c46 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c6c2120 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +NAME = cub3D + +CC = cc + +OBJSDIR = obj/ + +SRCDIR = src/ + +I_DIR = includes/ + +LIBFT_DIR = libft/ + +INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) + +SRCS = src/main.c \ + src/parsing/check_arg.c \ + src/utils/mess_error.c + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o)) + +FLAGS = -Wall -Werror -Wextra +LIB = libft/libft.a + +$(NAME): $(OBJS) + @make -s -C libft + @$(CC) $(FLAGS) $(OBJS) $(LIB) -o $(NAME) + @echo "✅ Compiled" + +$(OBJSDIR)%.o: %.c + @mkdir -p $(@D) + @$(CC) $(INCLUDE) $(FLAGS) $< -c -o $@ + +all: $(NAME) + +clean: + @make -s -C libft clean + @rm -f $(OBJS) + +fclean: clean + @make -s -C libft fclean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @echo "🧹 Cleaned" + +re: fclean all + +.PHONY: clean all re fclean diff --git a/cub3D b/cub3D new file mode 100755 index 0000000000000000000000000000000000000000..01dbd1fedf1538dd11c733c030643bb596268ecd GIT binary patch literal 17400 zcmeHPeQ;dWb-ycHSb%NG#I6knynGm(fEW1-1h$L(@yv5#gKMk_WT20gw6Zp=c9q?? z!D6DsK{(^hqQr%1;-(BS%^#3Sry(Q|po}A9W7!NfhEh-(lM2QptI7}&4A~IF_IK_* z=k429EoIvDKi!$tx%YQI?!D)p`|;lH)z_>I>uN$FC25lSOGTyd41+W?qiF?aK$=yP znufpg)cNW(lqYM<@S6<**QBAEN?OPGBv8_uLz!{txdv83rG-REuUgtY#c+hG22&=z zTFP=cNDoglazcgg)fYB=6`)JGF+%-%a%~bTLNP4?jZ#U}+9is*z z2^D`*Gw9RA{tVJaQbH0M)azuuAYE(Jlu)XJ(v5Gr?f;wlHnE-^)@D?YK5t+pRO?F$p}WOm!aZB17$ymDzIlZq_XO`vv# z@u8Ty?)nx5GXsRN8&%DAQxgI8{v+UFe1hp302c;9DmzZbjkewHv~}L@bVTC`)sc?H zR5})ISE=q;QguZWiBucJ5Fl+Nn|7V9Xgmp|ZCljoh$o|o_?W*~WjVThP z(794ww_*M2HO}J5QZKipoLwAQrkwR#HahLGbZl!p!3TK%sB6}0N^mI;U2AZPVSjuN`*4{{Bw6s`VvF!GAATkQoQgi2 z=8L2~jMFwju`20dA5Qa7(jz`x?;p%~!iSrAXcz-NoVOy)ION0OP%jLdIW0x+|L2Bfsa+wZvBhQq}bdVc)v|OeG*2q7U%XF|Bxwl-V z1J%e~Ub!^?deq)gKX0wl^_S-VCQ@1cb)fu8pnN1yJ{TzP4U`|RC@*?zeeT7-wsUXT zeaFW(ZLt;&EIMrWugs&{rCIku^khe*e%{?^G#uE!@<||ef9<10t}eQ>;My-!953i+ItUv?LfPk&_R#_WA>Uu*9xPO?J>?H50CXTpHR2I@+~#t))T{@=cm z*eZKji`}>KLdx2?H{Gdre&r=76rTL3R4TN?n+I#pLpgLSbiMjXf8-7@DboTy1Vf{p z>m9Q5*3e#Rsht~qf@tA&*vVPP^Vad)VBsnp!tI<@*h^#o3;I*I7sC!{%{r^&T%}=NdPB4iF6dEgKl5wq9cQZ+si@ZY@l{>{m+Ef$0@BXP&8qGjw zc*j6bJ@o^0iV5Od2)65gY!#luOext{Ka*k3YL7!b_%UqgFzxFtDs*4Ba-L7*8RUyR z6Ml|Wj*7m{^_|d7%w>-cTBk_a^sQy|V&4$;PpzR)pdhw$6bgU*pj7I!PKA6jdc5F+ zL!M;+v=#)9Q8)yJ(a^4P#W!NoH(^K)A^HbU=OKk4&RYZ2r+sMVh#s20-T{L{Y_RY{ z!e66CH8MKaqsL?P+l4k!= zjHI34NKuXKbBN2GH5l-tAs-(gdU*u8Lt6K8=nWxiQB@08u$BS4e`X+3kIv{t9QQMyrP^VOW(qF`H~z6aDws(BO#}ot(MVI+Qy}>#?cD?JtRU889nZdiHkN0BH_~ML zz@T-^*d8Wg2A+pxA>ylkZ_5ER@sL@$Z^Oz>gSdMyy?>#xd=Tr4Ho4_<-ajJ9ZX6F;$11(C8H?A|)^Pnjb7(=Jk*|ytTBoqm1V(Rim64kn9Jv)|WM3W!yPfn$ zFRkF@Td;bQFNbB8kdRprf+3Q9)>|YXO+gM*m-&}}K>q!)964Ab^r~(4RoaSm3?$yy z-7ng-QRz7_rYEI)8k{mVO3Mhg{=vdp$OS_j%U!PbL|^X-we9q;_ns)h-CyPKdk40B zM~kb>s)0&t+vcN|9Ru|{9wialLd^O-Q;XED1$*SXx+SxkNR)hK0(g4G>dY1GG@{cg zMVBFFR)n(DhvI0bouBsB#pJ3JzE$_9?@_#-?CU+LzBb3yauA!@0SHompQWga*!fvM z)tV;}ro5=sK1d=s44#PzS5);oHY0+9t{H#!o9*CC)K)MnA8#>TXeJi8TubG6WBR+x zDG)}nZx@5xIV}!n6YgI{NCiP!ZHdYLyka$}jENRZ9qit4sP@2ItRTKUhR>CHR_N84 zrv~~oq})w<*&o(^^p<_><=(Q7eV!tm+RMweOEY}P#u3K8+A5|8^crFKX7L`TaoGQd z@yW%y}dUQrVm$y!qot1Avfu^0;%0BBPmI|MU z8Kc7HmyF_(L2pE)kZ(D@v%ws6sB_D$q3rAEc;VLl`dJ8Wtt&sR zQKu%-gaI+0t2LGmr#iyX^ww-wEa_&L2p3?f94%^+tsz_T>Y6P z7hgy)>ED9S0_e+kaDuzYgn@Sxz=`U*2cIZ>w~sJudc!wr)=WFC<_WaOwB;WG*TAP& z`T0rB)@`M6IUD@f{rs9CPyYn)e+NHT!Qbxjr=s6$Fh(o<{7l*Y<={Ku(|4*~`@U4> zZvejs{2%!FHQ)2>C%``ieoqCzTl2}U_kiDm*q~VQ>|1@4CY=*9l>jC`{fy)gE4L%> z$o@o)zF927hw}f4#@Q z1^hpOPdlX7&PiwKN~j-S0sno(@$l`i-5+caDI;c4)5;P3GBYrf*? z9|Qkw@b9bOf79ci0zZnmv)a$^G4=_XNE05I@W6xzCOk0Vfe8;xcwoWAPQ&Y6^i|K3NX6qO(0 z=bu_CAT@C2G*eVV%-0Wnz@BAXetSpHf0Sk!;{9bcwUdAEh9jm<4>P6bB1-rYP$&9b zD5Wv3Snx(JOS=cOlv47WI;sDB#zhW~e7b+|tA_A;PM62He|QHce65McEnR+v`8W>i zvh;(^|JjKAzB_2JkslJ9nQmfw8`Ey4+nMfS8np92mFt>~#C2=dToYc<(wa@W+3=zz zk;Re5g^QPDb$RKh8TlAv6t|PrJEfoqjZX-id)R?t7NBos$CIb=tHG~SH}UUCSzLt~ z-yXo1FfQ{)DmKgIxc3#8PSil=lZ$mQ!Og6Cme73LO)quB! z@R}J)_A}A?f|i$3nP%C}w|JwYc}S^`@gCk6R~uOMSF!VbmVbi+3`xHO1N})A`DcJr zzf?0xm(vTt!{wrv`!(hXl zD9i6)`3r$JVE%@i8DMgV?T2~&)bB9CyOiaFm<$>46_-{EL^t(6U3C2S_F0ZqlJAsowgYEnV@G#5x$sXVr`T@@WGuf}f zsVcBv?js!F-Q3O|mVbfq49`>j?v8jjwx!)gkrXaxL|fyI8{Mh^WZY~=N2E=aFLF3; zmxC)I$yf%G?I~w#BGnpAIPGpKopGYsZK^HR)t!jBvGz#g_!4xrB<@7h>1dCGm-Fc! z+)Rmf#hmtRS62^Id?g2xZiOh_P(gdzI%Bxng7^E#cf~RpCq}REQRr}Stt6d@kr482 z`jU&ucW2#LvOVE+w0m-2OlfPR)SZaCz_-R+CmGx3;#N#DhH@+VA4{VvWGsclgmXtK z%?4WUjHOeatwdXQk5_2VcAI=xtSb{E!;Z6V^Qw)OV_m=2!IhV_H($SMn7vl;M?RJtn)~)Tn0(SuaO;WgIIN$@Fx&(N<75ZD^Q<3t%8f;~CbN<5H2Rcwdwfu9HjWE~@pgt*tzN&776>ig8O?O6NPABbRT%1~ z4F`djiKmhk1qZxzED zbP)>lOep%aA5jw8Xo}unIll^UB{F_}`aY17(BN@W_Gcrd6g^k?_2s!nXjlZ92KDJ& zg|C28(tdgF7Ap12b9b=)QRve%x9AUX`-L{K!>Emv6@7U=jsqhV(U<3Zq4Hc05uJkm z{}NDoW)^*UP8Q1BB;Qdj*CX;@g+4ulOIe=7g*NM2jgS59XIS+kLp~LKc`qPzfCYp8 zlm35~^;ff;yk`*luuq?Kg8q9D7`036d*=u~PssZhHly1rd7}5@)Wg+^m$Qa8r1()K!45!Mo{RvJRil3#E+EU zL}ofZA|~$@fo{D|U*7BOS_lwHkt7W_jnD0ZcOc^;PkJ0SmGfYuL6 zq9^0{BVgn|(U!S-9z( +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:48:56 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_H +# define CUB3D_H + +# include "../libft/includes/libft.h" +# include "mess_err.h" +# include +# include +# include +# include + +int check_format_file(char *file); +int check_err_arg(int argc, char **argv); + +int err_mess(char *str); + +#endif diff --git a/include/mess_err.h b/include/mess_err.h new file mode 100644 index 0000000..5dc0585 --- /dev/null +++ b/include/mess_err.h @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mess_err.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */ +/* Updated: 2024/09/07 19:13:20 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +//for argurments + +#define ERR_ARGS "Wrong number of arguments" +#define ERR_TYPE "Wrong type of file" +#define EMPTY "Empty file" + +//for map + +#define NOT_CLOSE "The map isn't closed" +#define ERR_PLAYER "Incorrect number of players" + +//for permission diff --git a/libft/Ft_Printf/ft_printf.c b/libft/Ft_Printf/ft_printf.c new file mode 100644 index 0000000..faf9baa --- /dev/null +++ b/libft/Ft_Printf/ft_printf.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/13 14:38:09 by madumerg #+# #+# */ +/* Updated: 2024/07/09 17:54:17 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static int ft_conversions(va_list args, char c) +{ + int print; + + print = 0; + if (c == 'c') + print += ft_putchar(va_arg(args, int)); + else if (c == 's') + print += ft_putstr(va_arg(args, char *)); + else if (c == 'p') + print += ft_print_ptr(va_arg(args, void *)); + else if (c == 'd') + print += ft_putnbr(va_arg(args, int)); + else if (c == 'i') + print += ft_putnbr(va_arg(args, int)); + else if (c == 'u') + print += ft_putnbr_uns_int(va_arg(args, unsigned int)); + else if (c == 'x') + print += ft_putnbr_hexa_low(va_arg(args, unsigned int)); + else if (c == 'X') + print += ft_putnbr_hexa_upp(va_arg(args, unsigned int)); + else if (c == '%') + print += ft_putchar('%'); + return (print); +} + +int ft_printf(const char *str, ...) +{ + va_list args; + int print; + + if (!str) + return (-1); + va_start(args, str); + print = 0; + while (*str) + { + if (*str == '%') + { + ++str; + if (*str) + print += ft_conversions(args, *str); + else + return (-1); + } + else + print += ft_putchar(*str); + str++; + } + va_end(args); + return (print); +} diff --git a/libft/Ft_Printf/ft_printf_utils.c b/libft/Ft_Printf/ft_printf_utils.c new file mode 100644 index 0000000..fc73f4d --- /dev/null +++ b/libft/Ft_Printf/ft_printf_utils.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 10) + { + i += ft_putnbr(n / 10); + i += ft_putnbr(n % 10); + } + return (i); +} + +int ft_putstr(char *str) +{ + int i; + + i = 0; + if (!str) + return (ft_putstr("(null)")); + while (str[i] != '\0') + { + write(1, &str[i], 1); + i++; + } + return (i); +} diff --git a/libft/Ft_Printf/ft_putnbr_hexa.c b/libft/Ft_Printf/ft_putnbr_hexa.c new file mode 100644 index 0000000..0cd72dd --- /dev/null +++ b/libft/Ft_Printf/ft_putnbr_hexa.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_hexa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 10) + { + i += ft_putnbr_hexa_low(n / 16); + i += ft_putnbr_hexa_low(n % 16); + } + return (i); +} + +int ft_putnbr_hexa_upp(unsigned int n) +{ + unsigned int i; + + i = 0; + if (n < 16) + { + i += ft_putchar("0123456789ABCDEF"[n % 16]); + return (i); + } + else if (n >= 10) + { + i += ft_putnbr_hexa_upp(n / 16); + i += ft_putnbr_hexa_upp(n % 16); + } + return (i); +} + +int ft_print_ptr(void *ptr) +{ + int i; + + if (!ptr) + i = ft_putstr("(nil)"); + else + i = ft_putstr("0x") + ft_putnbr_hexa_low((size_t)ptr); + return (i); +} diff --git a/libft/Ft_Printf/ft_putnbr_uns_int.c b/libft/Ft_Printf/ft_putnbr_uns_int.c new file mode 100644 index 0000000..2340bb0 --- /dev/null +++ b/libft/Ft_Printf/ft_putnbr_uns_int.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_uns_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/17 13:18:12 by madumerg #+# #+# */ +/* Updated: 2023/11/28 12:16:03 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_putnbr_uns_int(unsigned int n) +{ + unsigned int i; + + i = 0; + if (n < 10) + { + i += ft_putchar(n + '0'); + return (i); + } + else if (n >= 10) + { + i += ft_putnbr(n / 10); + i += ft_putnbr(n % 10); + } + return (i); +} diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..fbb39b2 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,67 @@ +NAME = libft.a + +SRCS = is/ft_isalpha.c \ + is/ft_isalnum.c \ + is/ft_isascii.c \ + is/ft_isdigit.c \ + is/ft_isprint.c \ + is/ft_is_space.c \ + str/ft_strlen.c \ + str/ft_toupper.c \ + str/ft_tolower.c \ + str/ft_strchr.c \ + str/ft_strrchr.c \ + str/ft_strncmp.c \ + str/ft_strnstr.c \ + str/ft_atoi.c \ + mem/ft_memset.c \ + mem/ft_memmove.c \ + mem/ft_memcpy.c \ + mem/ft_memchr.c \ + mem/ft_memcmp.c \ + mem/ft_bzero.c \ + mem/ft_calloc.c \ + str/ft_strlcpy.c \ + str/ft_strlcat.c \ + put/ft_putchar_fd.c \ + put/ft_putendl_fd.c \ + put/ft_putstr_fd.c \ + put/ft_putnbr_fd.c \ + str/ft_strdup.c \ + str/ft_strjoin.c \ + str/ft_substr.c \ + str/ft_strtrim.c \ + str/ft_itoa.c \ + str/ft_striteri.c \ + str/ft_strmapi.c \ + str/ft_split.c \ + str/ft_atoll.c \ + Ft_Printf/ft_printf_utils.c \ + Ft_Printf/ft_printf.c \ + Ft_Printf/ft_putnbr_hexa.c \ + Ft_Printf/ft_putnbr_uns_int.c \ + gnl/get_next_line.c \ + str/ft_count_word.c \ + str/ft_strcmp.c + +OBJS = ${SRCS:.c=.o} + +HEADERS = includes/ + +all : ${NAME} + +${OBJS} : + @gcc -Wall -Wextra -Werror -I ${HEADERS} -c ${@:.o=.c} -o $@ + +${NAME} : ${OBJS} + @ar rcs ${NAME} ${OBJS} + +clean : + @rm -f ${OBJS} + +fclean : clean + @rm -f ${NAME} + +re : fclean all + +.PHONY : all clean fclean re diff --git a/libft/compile_commands.json b/libft/compile_commands.json new file mode 100644 index 0000000..e69de29 diff --git a/libft/gnl/get_next_line.c b/libft/gnl/get_next_line.c new file mode 100644 index 0000000..8827b3c --- /dev/null +++ b/libft/gnl/get_next_line.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/24 11:51:12 by madumerg #+# #+# */ +/* Updated: 2024/09/04 15:59:19 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/libft.h" + +char ft_end_of_line(char *line, char *buffer) +{ + int i; + int j; + + i = 0; + j = 0; + while (line[i] && line[i] != '\n') + i++; + if (line[i] == '\n') + { + i++; + while (line[i]) + { + buffer[j] = line[i]; + i++; + j++; + } + buffer[j] = '\0'; + line[i - j] = '\0'; + return (1); + } + return (0); +} + +char *ft_verif(char **buffer, char *line) +{ + free(*buffer); + *buffer = NULL; + if (line[0] != '\0') + return (line); + free(line); + return (NULL); +} + +char *get_next_line(int fd) +{ + static char *buffer; + char *line; + int read_nb; + + if (fd < 0 || fd > 1023 || BUFFER_SIZE <= 0) + return (NULL); + line = ft_calloc(1, 1); + if (!buffer) + buffer = ft_calloc(sizeof(char), (BUFFER_SIZE + 1)); + while (buffer && line) + { + line = ft_strjoin(line, buffer); + if (!line) + return (NULL); + if (ft_end_of_line(line, buffer) == 1) + return (line); + read_nb = read(fd, buffer, BUFFER_SIZE); + if (read_nb < 1) + return (ft_verif(&buffer, line)); + buffer[read_nb] = '\0'; + } + return (NULL); +} diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h new file mode 100644 index 0000000..c4cd386 --- /dev/null +++ b/libft/includes/ft_printf.h @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +# include +# include +# include + +int ft_printf(const char *str, ...); +int ft_putchar(char c); +int ft_putstr(char *str); +int ft_putnbr(int n); +int ft_putnbr_uns_int(unsigned int n); +int ft_putnbr_hexa_low(size_t n); +int ft_putnbr_hexa_upp(unsigned int n); +int ft_print_ptr(void *ptr); + +#endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h new file mode 100644 index 0000000..f5bf4db --- /dev/null +++ b/libft/includes/libft.h @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 13:02:45 by madumerg #+# #+# */ +/* Updated: 2024/09/04 16:24:48 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include + +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 1 +# endif + +int ft_atoi(const char *str); +int ft_isalnum(int i); +int ft_isalpha(int i); +int ft_isascii(int i); +int ft_isdigit(int i); +int ft_isprint(int i); +char *ft_strchr(const char *str, int p); +char *ft_strdup(const char *s); +size_t ft_strlen(const char *str); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strrchr(const char *str, int p); +int ft_tolower(int i); +int ft_toupper(int i); +char *ft_strnstr(const char *str, const char *to_find, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +void *ft_memset(void *ptr, int v, size_t count); +void *ft_memmove(void *dest, const void *src, size_t n); +void ft_bzero(void *s, size_t count); +void *ft_memcpy(void *dest, const void *src, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memchr(const void *s, int c, size_t n); +size_t ft_strlcpy(char *dest, const char *src, size_t size); +void *ft_calloc(size_t nmemb, size_t size); +size_t ft_strlcat(char *dest, const char *src, size_t destsize); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_itoa(int n); +char *ft_substr(char const *s, unsigned int start, size_t len); +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); +long long int ft_atoll(const char *str); +int ft_is_space(char c); +char ft_end_of_line(char *line, char *buffer); +char *ft_verif(char **buffer, char *line); +char *get_next_line(int fd); +int ft_count_word(const char *str, char sep); +int ft_count_len(const char *str, char sep); +void *ft_free(char **s); +int ft_strcmp(char *s1, char *s2); + +#endif diff --git a/libft/is/ft_is_space.c b/libft/is/ft_is_space.c new file mode 100644 index 0000000..9905b93 --- /dev/null +++ b/libft/is/ft_is_space.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_space.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && c <= 13)) + return (1); + return (0); +} diff --git a/libft/is/ft_isalnum.c b/libft/is/ft_isalnum.c new file mode 100644 index 0000000..cbc5ce4 --- /dev/null +++ b/libft/is/ft_isalnum.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 13:03:43 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:15 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int i) +{ + if ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'z') + || (i >= 'A' && i <= 'Z')) + return (1); + return (0); +} diff --git a/libft/is/ft_isalpha.c b/libft/is/ft_isalpha.c new file mode 100644 index 0000000..3168959 --- /dev/null +++ b/libft/is/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 12:35:26 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:21 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int i) +{ + if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')) + return (1); + return (0); +} diff --git a/libft/is/ft_isascii.c b/libft/is/ft_isascii.c new file mode 100644 index 0000000..6939b4b --- /dev/null +++ b/libft/is/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 13:32:37 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:27 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int i) +{ + if (i >= 0 && i <= 127) + return (1); + return (0); +} diff --git a/libft/is/ft_isdigit.c b/libft/is/ft_isdigit.c new file mode 100644 index 0000000..cf0edb7 --- /dev/null +++ b/libft/is/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = '0' && i <= '9') + return (1); + return (0); +} diff --git a/libft/is/ft_isprint.c b/libft/is/ft_isprint.c new file mode 100644 index 0000000..0e3708c --- /dev/null +++ b/libft/is/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:08:46 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:37 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int i) +{ + if (i < 32 || i > 126) + return (0); + return (1); +} diff --git a/libft/mem/ft_bzero.c b/libft/mem/ft_bzero.c new file mode 100644 index 0000000..69b71a4 --- /dev/null +++ b/libft/mem/ft_bzero.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 17:15:50 by madumerg #+# #+# */ +/* Updated: 2023/11/02 13:48:10 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_bzero(void *s, size_t count) +{ + ft_memset(s, 0, count); +} diff --git a/libft/mem/ft_calloc.c b/libft/mem/ft_calloc.c new file mode 100644 index 0000000..7291b9b --- /dev/null +++ b/libft/mem/ft_calloc.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:05 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:18:08 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t ct, size_t size) +{ + char *str; + + if (size == 0 || ct == 0) + return (malloc(1)); + if ((int)size < 0 && (int)ct < 0) + return (NULL); + if ((unsigned long long)(size * ct) > UINT_MAX) + return (NULL); + str = malloc(size * ct); + if (!str) + return (NULL); + ft_bzero(str, size * ct); + return (str); +} diff --git a/libft/mem/ft_memchr.c b/libft/mem/ft_memchr.c new file mode 100644 index 0000000..a60e616 --- /dev/null +++ b/libft/mem/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:18 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:24:27 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + + i = 0; + if (!s) + return (0); + while (i < n) + { + if (*(unsigned char *)(s + i) == (unsigned char)c) + return ((void *)(s + i)); + i++; + } + return (0); +} diff --git a/libft/mem/ft_memcmp.c b/libft/mem/ft_memcmp.c new file mode 100644 index 0000000..aa1de19 --- /dev/null +++ b/libft/mem/ft_memcmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:37 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:11:43 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + unsigned char *ptr1; + unsigned char *ptr2; + + ptr1 = (unsigned char *) s1; + ptr2 = (unsigned char *) s2; + i = 0; + while (i < n) + { + if (ptr1[i] != ptr2[i]) + return (ptr1[i] - ptr2[i]); + i++; + } + return (0); +} diff --git a/libft/mem/ft_memcpy.c b/libft/mem/ft_memcpy.c new file mode 100644 index 0000000..876bb95 --- /dev/null +++ b/libft/mem/ft_memcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:45 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:21:18 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + + i = 0; + if (!dest) + return (NULL); + while (i != n) + { + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + i++; + } + return (dest); +} diff --git a/libft/mem/ft_memmove.c b/libft/mem/ft_memmove.c new file mode 100644 index 0000000..d1e2c2f --- /dev/null +++ b/libft/mem/ft_memmove.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:28 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:24:06 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t size) +{ + size_t i; + + i = 0; + if (!dest && !src) + return (NULL); + if (dest > src) + { + i = size; + while (i > 0) + { + i--; + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + } + } + else + { + while (i != size) + { + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + i++; + } + } + return (dest); +} diff --git a/libft/mem/ft_memset.c b/libft/mem/ft_memset.c new file mode 100644 index 0000000..641f9c0 --- /dev/null +++ b/libft/mem/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:15 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:11:59 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *ptr, int v, size_t count) +{ + size_t i; + + i = 0; + while (i != count) + { + *(unsigned char *)(ptr + i) = (unsigned char)v; + i++; + } + return (ptr); +} diff --git a/libft/put/ft_putchar_fd.c b/libft/put/ft_putchar_fd.c new file mode 100644 index 0000000..cf6738b --- /dev/null +++ b/libft/put/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:32:56 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:52:19 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/put/ft_putendl_fd.c b/libft/put/ft_putendl_fd.c new file mode 100644 index 0000000..54d1ea4 --- /dev/null +++ b/libft/put/ft_putendl_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:06 by madumerg #+# #+# */ +/* Updated: 2024/04/04 17:11:24 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + i = 0; + if (!s) + return ; + while (s[i] != '\0') + { + write(fd, &s[i], 1); + i++; + } + write(fd, "\n", 1); +} diff --git a/libft/put/ft_putnbr_fd.c b/libft/put/ft_putnbr_fd.c new file mode 100644 index 0000000..53845e7 --- /dev/null +++ b/libft/put/ft_putnbr_fd.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:42 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:58:11 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + ft_putchar_fd('-', fd); + ft_putchar_fd('2', fd); + n = 147483648; + } + if (n < 0) + { + ft_putchar_fd('-', fd); + n *= -1; + } + if (n < 10) + { + ft_putchar_fd((n + '0'), fd); + return ; + } + else if (n >= 10) + { + ft_putnbr_fd((n / 10), fd); + ft_putnbr_fd((n % 10), fd); + } +} diff --git a/libft/put/ft_putstr_fd.c b/libft/put/ft_putstr_fd.c new file mode 100644 index 0000000..a352e32 --- /dev/null +++ b/libft/put/ft_putstr_fd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:15 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:26:33 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + if (!s) + return ; + while (s[i] != '\0') + { + write(fd, &s[i], 1); + i++; + } +} diff --git a/libft/str/ft_atoi.c b/libft/str/ft_atoi.c new file mode 100644 index 0000000..4d11419 --- /dev/null +++ b/libft/str/ft_atoi.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && str[i] <= 13)) + i++; + if (str[i] == '-' || str[i] == '+') + { + if (str[i] == '-') + s = -1; + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + r = r * 10 + str[i] - '0'; + i++; + } + return (r *= s); +} diff --git a/libft/str/ft_atoll.c b/libft/str/ft_atoll.c new file mode 100644 index 0000000..6fee091 --- /dev/null +++ b/libft/str/ft_atoll.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoll.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && str[i] <= 13)) + i++; + if (str[i] == '-' || str[i] == '+') + { + if (str[i] == '-') + s = -1; + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + r = r * 10 + str[i] - '0'; + i++; + } + return (r *= s); +} diff --git a/libft/str/ft_count_word.c b/libft/str/ft_count_word.c new file mode 100644 index 0000000..11ac9ef --- /dev/null +++ b/libft/str/ft_count_word.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/29 00:04:58 by madumerg #+# #+# */ +/* Updated: 2024/05/29 00:05:09 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_count_word(const char *str, char sep) +{ + int i; + int count; + + i = 0; + count = 0; + if (!str || !str[0]) + return (0); + if (str[i++] != sep) + count++; + while (str[i]) + { + if (str[i - 1] == sep && str[i] != sep) + count++; + i++; + } + return (count); +} diff --git a/libft/str/ft_itoa.c b/libft/str/ft_itoa.c new file mode 100644 index 0000000..dbc432e --- /dev/null +++ b/libft/str/ft_itoa.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:14:32 by madumerg #+# #+# */ +/* Updated: 2023/11/08 10:22:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_len(int n) +{ + int cpt; + unsigned int nb; + + cpt = 0; + if (n < 0) + { + cpt++; + nb = -n; + } + else + nb = n; + while (nb >= 10) + { + nb /= 10; + cpt++; + } + cpt++; + return (cpt); +} + +char *ft_itoa(int n) +{ + char *str; + int cpt; + long long int nb; + int i; + + i = 0; + nb = n; + cpt = ft_len(n); + str = ft_calloc((cpt + 1), sizeof(char)); + if (!str) + return (NULL); + if (n < 0) + { + str[0] = '-'; + i = 1; + nb *= -1; + } + cpt--; + while (cpt >= i) + { + str[cpt] = (nb % 10) + '0'; + nb /= 10; + cpt--; + } + return (str); +} diff --git a/libft/str/ft_split.c b/libft/str/ft_split.c new file mode 100644 index 0000000..fbf3889 --- /dev/null +++ b/libft/str/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/08 12:11:54 by gadelbes #+# #+# */ +/* Updated: 2024/05/29 00:04:26 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_free(char **s) +{ + int i; + + i = 0; + while (s[i]) + { + free(s[i]); + i++; + } + free(s); + return (NULL); +} + +int ft_count_len(const char *str, char sep) +{ + int i; + int len; + + i = 0; + len = 0; + while (str[i] && str[i] != sep) + { + len++; + i++; + } + return (len); +} + +char **ft_split(char const *s, char c) +{ + char **str; + int i; + int w; + int l; + + i = 0; + w = 0; + if (!s) + return (NULL); + str = ft_calloc((ft_count_word((char *)s, c) + 1), sizeof(char *)); + if (!str) + return (NULL); + while (w < ft_count_word(s, c)) + { + while (s[i] == c) + i++; + l = ft_count_len((s + i), c); + str[w] = ft_calloc(l + 1, sizeof(char)); + if (!str[w]) + return (ft_free(str)); + ft_strlcpy(str[w], s + i, l + 1); + w++; + i += l; + } + return (str); +} diff --git a/libft/str/ft_strchr.c b/libft/str/ft_strchr.c new file mode 100644 index 0000000..78e91b0 --- /dev/null +++ b/libft/str/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 16:16:43 by madumerg #+# #+# */ +/* Updated: 2023/11/07 17:50:18 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *str, int p) +{ + int i; + + i = 0; + if (!str) + return (NULL); + while (str[i] != '\0') + { + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + i++; + } + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + return (0); +} diff --git a/libft/str/ft_strcmp.c b/libft/str/ft_strcmp.c new file mode 100644 index 0000000..aa3c328 --- /dev/null +++ b/libft/str/ft_strcmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/06 12:58:01 by madumerg #+# #+# */ +/* Updated: 2024/06/24 14:42:39 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while (s1[i] != '\0' || s2[i] != '\0') + { + if (s2[i] != s1[i]) + return (s1[i] - s2[i]); + i++; + } + return (0); +} diff --git a/libft/str/ft_strdup.c b/libft/str/ft_strdup.c new file mode 100644 index 0000000..ebac695 --- /dev/null +++ b/libft/str/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:11:13 by madumerg #+# #+# */ +/* Updated: 2024/07/11 20:14:23 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *src) +{ + int size; + char *dest; + + size = 0; + dest = ft_calloc(sizeof(char), (ft_strlen(src) + 1)); + if (dest == NULL) + return (NULL); + while (src[size]) + { + dest[size] = src[size]; + size++; + } + dest[size] = '\0'; + return (dest); +} diff --git a/libft/str/ft_striteri.c b/libft/str/ft_striteri.c new file mode 100644 index 0000000..eced53f --- /dev/null +++ b/libft/str/ft_striteri.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:34:05 by madumerg #+# #+# */ +/* Updated: 2023/11/07 18:13:31 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + unsigned int i; + + i = 0; + if (!s || !f) + return ; + while (s[i]) + { + f(i, &s[i]); + i++; + } +} diff --git a/libft/str/ft_strjoin.c b/libft/str/ft_strjoin.c new file mode 100644 index 0000000..5ad80ab --- /dev/null +++ b/libft/str/ft_strjoin.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/27 17:26:43 by madumerg #+# #+# */ +/* Updated: 2024/07/09 15:36:26 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t len; + size_t i; + size_t j; + char *str; + + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + len = ft_strlen(s1) + ft_strlen(s2); + str = malloc(sizeof(char) * (len + 1)); + if (!str) + return (NULL); + i = 0; + while (s1[i] != '\0') + { + str[i] = s1[i]; + i++; + } + j = 0; + while (s2[j] != '\0') + str[i++] = s2[j++]; + str[i] = '\0'; + return (str); +} diff --git a/libft/str/ft_strlcat.c b/libft/str/ft_strlcat.c new file mode 100644 index 0000000..301c50a --- /dev/null +++ b/libft/str/ft_strlcat.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:26 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:21:31 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t sdst; + size_t ssrc; + size_t i; + size_t j; + + sdst = ft_strlen(dest); + ssrc = ft_strlen(src); + i = 0; + j = sdst; + if (sdst > size || size == 0) + return (ssrc + size); + while (src[i] && (i < size) && (sdst < size - 1)) + { + dest[sdst] = src[i]; + i++; + sdst++; + } + dest[sdst] = '\0'; + return (ssrc + j); +} diff --git a/libft/str/ft_strlcpy.c b/libft/str/ft_strlcpy.c new file mode 100644 index 0000000..5276331 --- /dev/null +++ b/libft/str/ft_strlcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:08:10 by madumerg #+# #+# */ +/* Updated: 2023/11/03 12:30:11 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t destsize) +{ + size_t i; + + i = 0; + if (destsize > 0) + { + while (src[i] && i < destsize - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + } + return (ft_strlen(src)); +} diff --git a/libft/str/ft_strlen.c b/libft/str/ft_strlen.c new file mode 100644 index 0000000..12a6ce0 --- /dev/null +++ b/libft/str/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:07:38 by madumerg #+# #+# */ +/* Updated: 2024/07/09 17:00:57 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str && str[i]) + i++; + return (i); +} diff --git a/libft/str/ft_strmapi.c b/libft/str/ft_strmapi.c new file mode 100644 index 0000000..46118e2 --- /dev/null +++ b/libft/str/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:40 by madumerg #+# #+# */ +/* Updated: 2023/11/08 09:42:37 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + unsigned int i; + char *str; + + i = 0; + if (!s || !f) + return (NULL); + str = ft_calloc(ft_strlen(s) + 1, sizeof(char)); + if (!str) + return (NULL); + while (s[i]) + { + str[i] = f(i, s[i]); + i++; + } + return (str); +} diff --git a/libft/str/ft_strncmp.c b/libft/str/ft_strncmp.c new file mode 100644 index 0000000..eb22cb1 --- /dev/null +++ b/libft/str/ft_strncmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *str, const char *to_find, size_t len) +{ + size_t i; + int j; + + i = 0; + j = 0; + if (!str) + return (NULL); + if (to_find[0] == '\0') + return ((char *) &str[i]); + while (str[i] && i < len) + { + while (str[i + j] == to_find[j] && i + j < len) + { + j++; + if (to_find[j] == '\0') + return ((char *) &str[i]); + } + j = 0; + i++; + } + return (0); +} diff --git a/libft/str/ft_strrchr.c b/libft/str/ft_strrchr.c new file mode 100644 index 0000000..2749134 --- /dev/null +++ b/libft/str/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 16:42:24 by madumerg #+# #+# */ +/* Updated: 2023/11/03 15:59:52 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *str, int p) +{ + int i; + + i = 0; + while (str[i] != '\0') + i++; + while (i > 0) + { + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + i--; + } + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + return (0); +} diff --git a/libft/str/ft_strtrim.c b/libft/str/ft_strtrim.c new file mode 100644 index 0000000..c24a76f --- /dev/null +++ b/libft/str/ft_strtrim.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:52 by madumerg #+# #+# */ +/* Updated: 2023/11/07 17:51:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t start; + size_t len; + char *str; + + if (!s1) + return (NULL); + len = ft_strlen(s1); + start = 0; + while (ft_strchr(set, s1[start]) != 0) + start++; + while (ft_strrchr(set, s1[len]) != 0) + len--; + str = ft_substr(s1, start, (len - start) + 1); + return (str); +} diff --git a/libft/str/ft_substr.c b/libft/str/ft_substr.c new file mode 100644 index 0000000..3db5abc --- /dev/null +++ b/libft/str/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:14:21 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:27:51 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_min(int lenb, int len) +{ + if (len < lenb) + return (len); + return (lenb); +} + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t lenb; + size_t i; + size_t j; + + if (!s) + return (NULL); + if (start > ft_strlen(s)) + return (ft_calloc(1, 1)); + lenb = ft_strlen(s) - start; + str = malloc(sizeof(char) * ft_min(lenb, len) + 1); + if (!str) + return (NULL); + i = start; + j = 0; + while (s[i] && j < len) + { + str[j] = s[i]; + i++; + j++; + } + str[j] = '\0'; + return (str); +} diff --git a/libft/str/ft_tolower.c b/libft/str/ft_tolower.c new file mode 100644 index 0000000..3edc7c8 --- /dev/null +++ b/libft/str/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:21:25 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:59:56 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int i) +{ + if (i >= 'A' && i <= 'Z') + i += 32; + return (i); +} diff --git a/libft/str/ft_toupper.c b/libft/str/ft_toupper.c new file mode 100644 index 0000000..199bfd1 --- /dev/null +++ b/libft/str/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:21:13 by madumerg #+# #+# */ +/* Updated: 2023/11/02 15:00:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int i) +{ + if (i >= 'a' && i <= 'z') + i -= 32; + return (i); +} diff --git a/obj/src/main.o b/obj/src/main.o new file mode 100644 index 0000000000000000000000000000000000000000..9fd5597fb3a5493b6c2cc5c6c28f122836c1f3b4 GIT binary patch literal 2120 zcmbu9&1(}u6u{r6pK7a76vT=I4_d*l{SYigC0N!jDuP19i>#aNHi=C(VLz}Hib_FP za`EWJKf$v-Ri%g8f1va#R0z~V#7mGueQ$Oq8JEpPAI!{~-@K36c{BS`yLUUKC?G_E zo6wmF3NYB$(X&j=!Y~ZMuVd$a=k)NqzWQTa4_9{dy0)`U>w37kMq`7zP}{9*yWu9A z=%LnFryQTC6R4@Lt~4Q-W=?wry`F1etfn4rW2BBzU2BN>-x1Nh0l`=DSwD<%g%xIN zMS-Fyl2=`8ZEZ*&kPcV&^)P5+?q*#>b(?2iZ7IRP8trzkkL_=31LkIDXELL?eBk&& zW@1X6RL93Arvf&=dWjQ&UUW)hqvM;qpMw;@XJS3rNKQrrC@&s@vXoXvh6V=TVy3gm zsgZo4PCJ@@lbRjwPpzRvw0501$~Ef5y2F-N?*h{`qE;%->TV}ajWtN`rKC6}-Sa5B&;?>F}AFOiKvspZ_ing_A*sg1sZUHj` zoM(M>Kj=Q}A4GCR;&f*Or|%{q+kR|2?Q3r?WcTr8yPFN4Y=*hOQ(H7j;|FaM)t&{@Go zwUH&uCoLJGPPVd);Dl6^IELwXBEAsEmyuJ< zfAyb0Uy3=7O%{>=q6|?N`NcRRG1=4*1~N>ry@QPIzkIjIRHL{*z1eu}5J8&5d74PV V!?wwB)RO$)@%@+EmXQ+o{{!H1DMSDO literal 0 HcmV?d00001 diff --git a/obj/src/parsing/check_arg.o b/obj/src/parsing/check_arg.o new file mode 100644 index 0000000000000000000000000000000000000000..251970bb3d6fc37c88a0b72afb25e96ebd1afa1c GIT binary patch literal 2416 zcmbu9&1(}u6u@WGZ|z4aMTAP(gH}uJ(hrrYMWSWf1*=FQ){|kAZko2)Y}w30D+Gn0 zxP)SFdh;s&0a`prpn~)wJqq@sREShW@lvH4-`kx@hb6t}gUNgE_da%Z-%ReP6JsGs zB3vYLk?eV#67sEX&yILzgtU?t@}sTmS5$L9Y56bxZf;X^osDU&P<#9&Ru zHbb;STlN}g?wb-;e}0JZg1VvQi;Y?VQhk1}=(Gn?w`YXBS6B?mtEjzBuDX@aZIzwQ zg1W_;1RHc~%U8cb_~ikw_$^Cw)zV%~K`m*8=+3m(+u`k<)_L96*Mt|8H8%%YkjXma zOOmVZ7SvrWvEgxPqwP5vi8~X>9&5|j%K~0__u%+r(qQbv0dlA>-yT1 zZDnTUjAOx6~x8!>jU0QLU literal 0 HcmV?d00001 diff --git a/obj/src/utils/mess_error.o b/obj/src/utils/mess_error.o new file mode 100644 index 0000000000000000000000000000000000000000..c95786297e1e712ef4c65c72bdaf6c1342c3ddc8 GIT binary patch literal 1560 zcmbtSO=}Zj5S~qI8?}v51ci$1#V@cg{W_?K1Vii|#6uzHut_!+Z8l-|4YX46P!NI$ zJ@z+v^5{tl9>kk}Lh#^4yod;Oo@6H7zNQx)n9R)c&NDNa*%y_E4|1MIDjwaV!$?u0 zz1*Q+8n`7Y&@BBpbNN>_=zj@zz7>Q1^PlgL7rZ`!l%W6d>%hLM2rj@obolh4k|dqv z6wzwAe8<0Dt@mQv^B0%Rl3AEvTJ8{UR0_qHx$^8($_a>%5llKs-w(z;PmJ9ZW*PkbBa{M1=Q8<& z85q03ivRPMw4*ewMc9yO5Zf96YS~)1XQQ~eQEN59xhO=e9Xt4aFce>K>;}^)zIY7o z3ywO_k(hL=ZNoa5)Fwl_u3i#tgvLgjmP|9WA(=W)Xp+t_Xmr}`DCW1gV7{oJ+2C_-=(C}wmOb=``_eu)cjXI?u?p8ZppFspJqQRZvWf-2y7vn#Qu)N z*Bo5=YVY&A`q|Vs*&yS)xoiA}8QuBc3da|#M)$Ar6LwJ3<$sohTbd}=<>M)i1vhk1wlpx9wBGh8^`x$emlw>IxhbY Dv^<3^ literal 0 HcmV?d00001 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..816e15b --- /dev/null +++ b/src/main.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ +/* Updated: 2024/09/07 19:12:04 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../include/cub3d.h" + +char **ft_parse_map(char *map) +{ + int fd; + char **parse_map; + char *save; + char *join; + + fd = open(map, O_RDONLY); + save = get_next_line(fd); + join = ft_calloc(1, 1); + if (!join) + return (NULL); + while (save != NULL) + { + join = ft_strjoin(join, save); + free(save); + save = get_next_line(fd); + } + parse_map = ft_split(join, '\n'); + free(join); + close(fd); + return (parse_map); +} + +int main(int ac, char **av) +{ + if (check_err_arg(ac, av) == 1) + return (1); + return (0); +} diff --git a/src/parsing/check_arg.c b/src/parsing/check_arg.c new file mode 100644 index 0000000..f17f593 --- /dev/null +++ b/src/parsing/check_arg.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check_arg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 21:33:35 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:57:29 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../include/cub3d.h" + +int check_err_arg(int ac, char **av) +{ + int fd; + int rd; + char buf[10]; + + if (ac != 2) + return (err_mess(ERR_ARGS)); + if (check_format_file(av[1]) == 0) + return (err_mess(ERR_TYPE)); + fd = open(av[1], O_RDONLY); + if (fd == -1) + { + close(fd); + return (err_mess(EMPTY)); + } + rd = read(fd, buf, 10); + close(fd); + return (rd); +} + +int check_format_file(char *file) +{ + int len; + + len = ft_strlen(file) - 1; + if (file[len] == 'b' && file[len - 1] == 'u' && \ + file[len - 2] == 'c' && file[len - 3] == '.') + return (1); + return (0); +} + diff --git a/src/parsing/check_id_text.c b/src/parsing/check_id_text.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/check_map.c b/src/parsing/check_map.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/check_rgb.c b/src/parsing/check_rgb.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/memo_parsing b/src/parsing/memo_parsing new file mode 100644 index 0000000..41fa973 --- /dev/null +++ b/src/parsing/memo_parsing @@ -0,0 +1,18 @@ + char **map = ft_parse_map(av[1]); + int i = 0; + while (map[i]) + { + ft_putchar_fd('*', 2); + ft_putstr_fd(map[i], 2); + ft_putchar_fd('*', 2); + ft_putchar_fd('\n', 2); + i++; + } + //envoyer de 0 a 3 inclus dans check id texture + //envoyer de 4 a 5 inclus dans check rgb format + //envoyer de 6 a jusqu a la fin dans check map + + struct typedef s_pars + { + + } t_pars; diff --git a/src/utils/mess_error.c b/src/utils/mess_error.c new file mode 100644 index 0000000..41446eb --- /dev/null +++ b/src/utils/mess_error.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mess_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/07 17:35:14 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:40:57 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../include/cub3d.h" + +int err_mess(char *str) +{ + ft_putendl_fd("Error\n", 2); + ft_putendl_fd(str, 2); + return (1); +}