intra to gitea

This commit is contained in:
lfirmin 2025-11-16 09:58:07 +01:00
commit 50c15b30e1
163 changed files with 12672 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# IDE - Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# IDE - JetBrains (IntelliJ, PyCharm, WebStorm, etc)
.idea/
*.iml
*.iws
.idea_modules/
# IDE - Eclipse
.classpath
.project
.settings/
.metadata/
# IDE - Sublime Text
*.sublime-workspace
*.sublime-project
# IDE - NetBeans
nbproject/
nbbuild/
dist/
nbdist/
.nb-gradle/
# Fichiers système
.DS_Store
Thumbs.db

97
Makefile Normal file
View File

@ -0,0 +1,97 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin lfirmim@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/12 07:07:31 by lfirmin #+# #+# #
# Updated: 2024/08/12 09:15:05 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
NAME = so_long
LIBFT = libft.a
GNL = gnl.a
FT_PRINTF_FD = libftprintf.a
SRC_FILES = main.c pars_map.c pars_map_2.c pars_map_3.c utils.c utils_2.c utils_3.c utils_4.c
INCLUDES_FILES = include/so_long.h
SRC_DIR = srcs/
SRC = $(addprefix $(SRC_DIR), $(SRC_FILES))
OBJ_DIR = obj/
OBJ = $(addprefix $(OBJ_DIR), $(SRC_FILES:.c=.o))
CC = cc
CFLAGS = -Wall -Werror -Wextra -g3
INCLUDE = -I include
RM = rm -rf
MKDIR = mkdir -p
GREEN = \033[0;32m
YELLOW = \033[0;33m
CYAN = \033[0;36m
RESET = \033[0m
BOLD = \033[1m
WHITE = \033[0;97m
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
define SO_LONG_ART
▗▄▄▖ ▗▄▖ ▗▖ ▗▄▖ ▗▖ ▗▖ ▗▄▄▖
▝▀▚▖▐▌ ▐▌ ▐▌ ▐▌ ▐▌▐▌ ▝▜▌▐▌▝▜▌
endef
export SO_LONG_ART
all: print_art $(NAME)
print_art:
@printf "$(YELLOW)%s$(RESET)\n" "$$SO_LONG_ART"
$(NAME): $(OBJ) $(INCLUDES_FILES)
@printf "$(BOLD)$(WHITE)Welcome to the $(GREEN)SO_LONG$(WHITE) compilation process.\nPlease hold on as we prepare your program.\n\n$(RESET)"
@make -s -C libft
@make -s -C minilibx-linux
@make -s -C gnl
@make -s -C ft_printf_fd
@printf "$(YELLOW)Compiling So_long, Please wait...$(RESET)"
@for char in $(LOADING_CHARS); do \
printf "\r$(YELLOW)Compiling So_long, Please wait... $$char$(RESET)"; \
sleep 0.1; \
done
@$(CC) $(CFLAGS) $(OBJ) $(INCLUDE) -L minilibx-linux -lmlx -lXext -lX11 -lm -lz libft/$(LIBFT) gnl/$(GNL) ft_printf_fd/$(FT_PRINTF_FD) -o $(NAME)
@printf "\r$(GREEN)Great news ! $(WHITE)SO_LONG compiled successfully ! $(RESET)\n\n"
@printf "$(BOLD)$(WHITE)Compilation complete !\n$(GREEN)So_long$(WHITE) is ready to use !\n"
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
@$(MKDIR) $(OBJ_DIR)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
clean:
@make clean -s -C libft
@make clean -s -C gnl
@make clean -s -C ft_printf_fd
@$(RM) $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)So_long.$(RESET)\n"
clean1:
@$(RM) $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)So_long$(RESET)\n"
fclean: clean1
@make fclean -s -C libft
@make fclean -s -C gnl
@make fclean -s -C ft_printf_fd
@$(RM) $(NAME)
@$(RM) $(PRINTF)
@$(RM) $(LIBFT)
@printf "$(WHITE)Full clean process completed for $(GREEN)So_long.$(RESET)\n"
re: fclean all
.PHONY: all clean fclean re print_art clean1 norminette
norminette:
norminette srcs/* include/* libft/*.c libft/*.h gnl/*/*.c gnl/*/*.h ft_printf_fd/*.c ft_printf_fd/*.h | grep "Error"

46
assets/collectible.xpm Normal file
View File

@ -0,0 +1,46 @@
/* XPM */
static char *result[] = {
/* columns rows colors chars-per-pixel */
"32 32 8 1 ",
" c #686868",
". c #747474",
"X c gray50",
"o c #3DE0E5",
"O c #65F5E3",
"+ c gray56",
"@ c #9EFEEB",
"# c #D5FFF6",
/* pixels */
"++++++++X...X.XXX. . ..X++X..XX",
"X+++X+XXXX...XXX... ..XXXXXXXXX",
"XX....X...XXX..X++X++X . .X...",
"+XXX.XXX...X..XX.X..XXX. X..X+",
"XX.. ... ...... @O X..X",
"++X.. #@+XX. ..X.XX @#@O+XXX",
"X...XX. Oo+XXX @O +XXX.+Ooo+..X",
".X++++++++++X @#@Oo+XX++++++.XX.",
"....X++. ..XX+Ooo+++++XX++...XX",
"X.XXXXX.... X++++X. +XX..XXXX",
"X++++X... @Oo .XX.. @O . .++",
"XX++XX @##@Oo X.. @#@oX......X",
"...X. O@#@@OOooo+++ O@Oo+XXXXXXX",
"X.....X+O@OooOo+X...Xoo+XX+++..X",
".... X+++++X......++.....XXX.",
"XX. . ......... .....XXXXXXX",
"X. @#@X..X..X+X @#O XX..X....X",
"X @#@OOo+++XXX @@##@Oo XXXXX..XX",
"XX+Oooo+.X.XX @O#@O@Ooo++XX++XXX",
"XX+++++X. ..X++OooOo++XX+++....",
". .XXXX. @@ . +++++XXX..X.. .X",
"XXXX... @#Oo+ ..XXXXXX ++XXX.",
"XXX..XXX+Oo++++X++XXX. Ooo ..X++",
"XXXXXXXXX++++XXXXX @@Ooo ...X",
".X..X...XX+XXX.. @##@@OOOoo+ ..",
"XXX. . +++XXX O@##@OOOooo+. .",
"X++++. O@ XX..XX.O@@Ooo++++X.+++",
"+++XX @#Oo+XXX....oOoo+..XX...X+",
"XX.X. Ooo++++...XX++++XX++++++++",
"X. .X+++++XXX...XXXXXXXXX+X+++X",
".XX...XXX.X.. .X+++++X.X.....X.",
"XX..XXXXXXXX.....XX++XXXXX..XXXX"
};

215
assets/exit.xpm Normal file
View File

@ -0,0 +1,215 @@
/* XPM */
static char *xpm_[] = {
/* columns rows colors chars-per-pixel */
"32 32 177 2 ",
" c #051003",
". c #0B110B",
"X c #0C1B0C",
"o c #10110D",
"O c #130E12",
"+ c #170F1A",
"@ c #0E1214",
"# c #0E1C11",
"$ c #0E1018",
"% c #141214",
"& c #141C14",
"* c #1B1D16",
"= c #171218",
"- c #1B141A",
"; c #1D1B1C",
": c #161518",
"> c #350F04",
", c #3D140D",
"< c #33120F",
"1 c #200E1D",
"2 c #2F1118",
"3 c #201D1E",
"4 c #23121E",
"5 c #3D1414",
"6 c #331019",
"7 c #3B1219",
"8 c #1E211E",
"9 c #161720",
"0 c #1D1C22",
"q c #1F1625",
"w c #231C23",
"e c #221628",
"r c #271C29",
"t c #281C2A",
"y c #391426",
"u c #3B172A",
"i c #3D1A27",
"p c #2A1C36",
"a c #2A1C3A",
"s c #301F37",
"d c #3F1933",
"f c #3A153E",
"g c #3F1B38",
"h c #36163C",
"j c #1E2224",
"k c #1C2D24",
"l c #212121",
"z c #2A2226",
"x c #20212A",
"c c #2B232C",
"v c #2B282D",
"b c #312C2E",
"n c #29322E",
"m c #2B2234",
"M c #252830",
"N c #262039",
"B c #2A2038",
"V c #2B2735",
"C c #322632",
"Z c #322C32",
"A c #382D34",
"S c #353134",
"D c #303933",
"F c #3A353D",
"G c #36343B",
"H c #431416",
"J c #5F1C14",
"K c #5C1E1D",
"L c #631E15",
"P c #5E201D",
"I c #6E2416",
"U c #63221A",
"Y c #6D241A",
"T c #69291E",
"R c #4C1B26",
"E c #4F1729",
"W c #471E29",
"Q c #4C1C2D",
"! c #511E28",
"~ c #5B1D22",
"^ c #541E3F",
"/ c #601F25",
"( c #4B242D",
") c #57232D",
"_ c #5C252B",
"` c #5D292E",
"' c #4D2536",
"] c #612126",
"[ c #6B2322",
"{ c #662927",
"} c #642629",
"| c #652A2A",
" . c #6B2A29",
".. c #712523",
"X. c #712E28",
"o. c #72302B",
"O. c #6F2638",
"+. c #602B3D",
"@. c #72263C",
"#. c #2A1D40",
"$. c #3C1641",
"%. c #322748",
"&. c #3A3442",
"*. c #3D3A44",
"=. c #3D354C",
"-. c #3B3350",
";. c #421645",
":. c #4E1F56",
">. c #521A5E",
",. c #413C46",
"<. c #5B2859",
"1. c #602259",
"2. c #6B245F",
"3. c #6A2547",
"4. c #401E6E",
"5. c #581764",
"6. c #561C64",
"7. c #5E1469",
"8. c #5B1D6B",
"9. c #641B6E",
"0. c #61166D",
"q. c #621673",
"w. c #701D77",
"e. c #731C7C",
"r. c #4C2D73",
"t. c #502D72",
"y. c #533075",
"u. c #65286C",
"i. c #684040",
"p. c #534969",
"a. c #5D5668",
"s. c #665D68",
"d. c #665F70",
"f. c #686868",
"g. c #6C6367",
"h. c #706B6D",
"j. c #656071",
"k. c #6D6676",
"l. c #6C6877",
"z. c #6D6778",
"x. c #747474",
"c. c #7F7F7F",
"v. c #83247D",
"b. c #7E1E8E",
"n. c #583685",
"m. c #7F288D",
"M. c #783BBF",
"N. c #787383",
"B. c #6045B5",
"V. c #7047B5",
"C. c #6752C2",
"Z. c #7051D1",
"A. c #7E57EC",
"S. c #7861E2",
"D. c #811E92",
"F. c #871D9B",
"G. c #812091",
"H. c #8B219A",
"J. c #9B2895",
"K. c #AC3092",
"L. c #B23294",
"P. c #9A24AA",
"I. c #9F26B4",
"U. c #A227A1",
"Y. c #CE38AB",
"T. c #D438AF",
"R. c #D13AA7",
"E. c #827487",
"W. c #8A35D6",
"Q. c #B728C5",
"!. c #BC29C9",
"~. c #BD27D2",
"^. c #C227CE",
"/. c #C428D5",
"(. c #C92AD5",
"). c gray56",
"_. c gray56",
/* pixels */
").).).).).).).).c.x.x.x.c.x.c.c.c.x.f.f.x.f.x.x.c.).).c.x.x.c.c.",
"c.).).).c.).c.c.c.c.x.x.x.c.c.c.x.x.x.f.f.x.x.c.c.c.c.c.c.c.c.c.",
"c.c.x.x.x.x.c.x.x.x.c.c.c.x.x.c.z F p.).).c.f.f.x.f.f.x.c.x.x.x.",
").c.c.c.x.c.c.c.x.x.x.c.x.x.v c b z S =.p.c.c.x.f.f.x.c.x.x.c.).",
"c.c.x.x.f.f.f.f.x.x.x.x.v b b Z S G m - %.x.x.c.c.c.c.c.c.x.x.c.",
").).c.x.x.f.f.x.f.f.0 c A Z C F Z r ; ; z A -.c.x.x.c.c.c.c.c.c.",
"c.x.x.x.c.c.x.x.x.c.O + w G V w ; 3 w w c C b #.d.c.x.f.f.x.x.c.",
"x.c.).).).).).).c.c.% % O ; w ; w w w w m c * p N.c.c.x.x.c.c.x.",
"x.x.x.x.c.).).x.f.f.= % % ; w w * * e % * w ; a z.).).x.x.x.c.c.",
"c.x.c.c.c.c.c.x.x.x.- O O * & & p 5.f . ; w 3 B k.c.x.x.c.c.c.c.",
"c.).).).).c.x.x.c.Z F C % X h H.F.e.f . ; w ; B a.f.x.f.f.x.).).",
"c.c.).).c.c.c.z b S C F D 6./.(.D.7.$. ; l ; B a.x.x.x.x.x.x.c.",
"x.x.x.c.x.c.,.O q Z F c # 9./.Q.b.9.;. ; w * p z.c.c.c.c.c.c.c.",
"c.x.x.x.x.x.F o O = r ; X 8.^.Q.b.7.$.. ; w ; B l.c.).).).x.x.c.",
"x.x.x.x.f.f.&.% % % w w X 9./.!.D.9.f . ; w ; m j.x.x.x.c.c.c.x.",
"c.c.c.x.x.f.&.% = - w w X 9.~.P.w.0.f ; l ; B d.c.c.c.c.c.c.c.",
"c.c.x.x.c.c.*.% O % 8 3 & >.U.L.v.q.$. ; w ; a d.x.c.x.x.x.x.c.",
"c.).).).).).,.% % % w l # 1.Y.R.v.7.;.. ; w ; N k.c.c.c.x.x.c.c.",
"c.c.c.).).c.,.% % % w w X 2.T.K.e.q.h . ; 0 - a E.c.c.).).c.c.c.",
"c.c.).).).).*.% % - w w # <.J.G.P.m.s . : w W | +.).).).x.x.x.x.",
"x.f.x.c.c.c.&.% % % j w & :.I.H.<.v M C W | .{ T | ' x.x.f.x.c.",
"c.c.c.c.x.i.- % % % w l & :.u.n k v Q } .| { | ` _ ~ O.c.c.c.x.",
"c.c.c.i T o.4 % % % w w ; x j v ( } | | | | ` ) / [ ] @.x.c.).).",
"c.c.c.> 7 R - $ % - w 0 9 t ( } | | | | ` ) ] [ [ [ U 3.x.x.x.c.",
"x.c.x., 5 5 6 1 $ @ 0 w W } | | | | ` ) ] [ [ [ Y I J V.f.f.x.x.",
"c.c.c., 5 5 H H 2 + i .X.| | | ` ) ] [ [ [ [ I L E 4.A.x.f.f.x.",
"c.).).y 5 , 5 5 H H 7 R _ | ` ) ] [ [ [ [ Y L E y.S.c.c.x.).).).",
").).).x.d y 5 , 5 5 5 7 6 ! ] [ [ [ [ I L E 6.W.x.c.c.x.x.x.c.).",
"c.c.x.c.x.h.g u 5 , 5 5 5 K ..[ [ Y U E r.B.c.c.).).).).).).).).",
"c.x.f.f.x.c.x.g.d u 5 , 5 P ..Y U Q t.Z.c.c.c.c.c.c.).c.).).).c.",
"x.c.c.x.x.x.c.c.c.s.d u < J U E 8.M.).).).).c.x.c.x.x.x.x.x.c.x.",
"c.c.x.x.c.c.c.c.c.c.c.c.^ Q n.C.x.c.c.).).c.c.c.c.c.x.x.c.c.c.c."
};

42
assets/floor.xpm Executable file
View File

@ -0,0 +1,42 @@
/* XPM */
static char *ea534f601fc548b8ddbc80a1baa83d2dTHcmw34tLSzWZjDk[] = {
/* columns rows colors chars-per-pixel */
"32 32 4 1 ",
" c #686868",
". c #747474",
"X c gray50",
"o c gray56",
/* pixels */
"ooooooooX...X.XXX. . ..XooX..XX",
"XoooXoXXXX...XXX... ..XXXXXXXXX",
"XX....X...XXX..XooXooX . .X...",
"oXXX.XXX...X..XX.X..XXX. .X..Xo",
"XX.. ..... .....XXXXXX..X",
"ooX.. . .XX. ....X.XXX..XXXXXX",
"X...XX...XXXXXXoooooXXX..X. ..X",
".XooooooXXooX..XXooXXXoooXX..XX.",
"....Xoo. ..XX..XXoooooXXoo...XX",
"X.XXXXX...XX..XXXooXXoooXX..XXXX",
"XooooX..XXXXXX..XX....X. . .oo",
"XXooXXXXXXX....XX.. . ......X",
"...X.XoooooX.Xooooo.....XXXXXXXX",
"X.......ooX...XoX... .XXXooo..X",
".... . .XX...X..XX.....XXX.",
"XXX.. . ........XXXX.....XXXXXXX",
"XX..XXX..X..XoooooooX.XX..X....X",
"XoooooXXoooXXXoooXX....XXXXX..XX",
"XXXooXX..X.XooXXooXX.XoooXXooXXX",
"XXooooXXXXX..XooXXXX...XXooo....",
". .XXXXX... . ..X..XXX..X.. .X",
"XXXX...XX.XX. ..XXXXXooooooXXX.",
"XXX..XXXXXoooooXooXXXXXXooX..Xoo",
"XXXXXXXXXooooXXXXX..X....XXX...X",
".X..X...XXoXXX.. .XXX. . ..",
"XXX. .XooooXXX..XXX..X. .... .",
"Xoooo.X...XX..XX...ooXXX..XX.ooo",
"oooXXX...XXXXX....XXX....XX...Xo",
"XX.X..XXooooo...XX..XXXXoooooooo",
"X. .X..XooXXX...XXXXXXXXXoXoooX",
".XX...XXX.X.. .XoooooX.X.....X.",
"XX..XXXXXXXX.....XXooXXXXX..XXXX"
};

216
assets/player.xpm Executable file
View File

@ -0,0 +1,216 @@
/* XPM */
static char *_472f46639e945e19be1c36ef31d5cc9[] = {
/* columns rows colors chars-per-pixel */
"32 32 178 2 ",
" c #3C2205",
". c #3E3519",
"X c #1D3233",
"o c #343529",
"O c #222F36",
"+ c #293737",
"@ c #481A00",
"# c #571A01",
"$ c #462A0D",
"% c #492C0F",
"& c #5E2201",
"* c #532606",
"= c #4D2F12",
"- c #402C11",
"; c #4C3013",
": c #42391E",
"> c #453215",
", c #523619",
"< c #5D3C1D",
"1 c #56391B",
"2 c #602402",
"3 c #622B0A",
"4 c #662804",
"5 c #762E09",
"6 c #72270B",
"7 c #7D350E",
"8 c #703614",
"9 c #713C1D",
"0 c #6A3615",
"q c #453D21",
"w c #593E21",
"e c #5D4023",
"r c #5E4A35",
"t c #4F5037",
"y c #644325",
"u c #674A2B",
"i c #6A4D2E",
"p c #654728",
"a c #604C36",
"s c #6B4E30",
"d c #634F3A",
"f c #7A4E35",
"g c #6C5032",
"h c #63503A",
"j c #725335",
"k c #735639",
"l c #7C5438",
"z c #76593B",
"x c #7E5535",
"c c #7B4B2D",
"v c #053A52",
"b c #2D4142",
"n c #314546",
"m c #36494A",
"M c #394C4D",
"N c #144B66",
"B c #1E5E7F",
"V c #22546D",
"C c #295E76",
"Z c #2B5F78",
"A c #265B73",
"S c #006869",
"D c #2D6079",
"F c #435758",
"G c #54585B",
"H c #685540",
"J c #7C5F41",
"K c #715B48",
"L c #7E6143",
"P c #76624D",
"I c #7D6456",
"U c #596B6C",
"Y c #686868",
"T c #747474",
"R c gray50",
"E c #737564",
"W c #843C17",
"Q c #884825",
"! c #944B24",
"~ c #99542D",
"^ c #825939",
"/ c #80563E",
"( c #985A36",
") c #A15932",
"_ c #AD663E",
"` c #8F5F43",
"' c #816446",
"] c #846749",
"[ c #85684A",
"{ c #8D6A51",
"} c #A66942",
"| c #AB6942",
" . c #AC7049",
".. c #A77453",
"X. c #AA7A57",
"o. c #B97A55",
"O. c #B46D4A",
"+. c #867462",
"@. c #A57F6B",
"#. c #7F827C",
"$. c #C3845E",
"%. c #C98962",
"&. c #C88A65",
"*. c #D58F69",
"=. c #D3926C",
"-. c #DB9369",
";. c #DE9B74",
":. c #DE9E79",
">. c #D79770",
",. c #E0A07F",
"<. c #004E80",
"1. c #055B8E",
"2. c #046283",
"3. c #12699D",
"4. c #1F76AA",
"5. c #2177AC",
"6. c #257AAD",
"7. c #277DB2",
"8. c #7C53BF",
"9. c #6441C8",
"0. c #7C6AE3",
"q. c #AE7BAF",
"w. c #B37FAF",
"e. c #9176D6",
"r. c #008E89",
"t. c #019C9D",
"y. c #029696",
"u. c #06928B",
"i. c #0C87AE",
"p. c #158AAF",
"a. c #09B0AB",
"s. c #6D8283",
"d. c #28AAD2",
"f. c #0FCAC6",
"g. c #10CBC7",
"h. c #10CCC9",
"j. c #15D3D0",
"k. c #3CC5EE",
"l. c #43CDF5",
"z. c gray56",
"x. c #899E9E",
"c. c #929D9E",
"v. c #BD94BB",
"b. c #B882A8",
"n. c #93A3A3",
"m. c #ECAB85",
"M. c #F4AA80",
"N. c #E9B38D",
"B. c #FFBA8E",
"V. c #EFB299",
"C. c #FBB792",
"Z. c #F7B995",
"A. c #FBBA95",
"S. c #F3B59A",
"D. c #F7BC9A",
"F. c #F8BC9F",
"G. c #D59CA1",
"H. c #FBC38F",
"J. c #FFC294",
"K. c #FDC39D",
"L. c #FFCA93",
"P. c #FFCBA5",
"I. c #FFC6A0",
"U. c #FFD3AD",
"Y. c #FEDBBB",
"T. c #AFC3C4",
"R. c #B6CACB",
"E. c #BDD1D2",
"W. c #C1D6D7",
"Q. c #C9DCDD",
"!. c #E0C0C6",
"~. c #FBDFC9",
"^. c #FFEED4",
"/. c #FFF6DD",
"(. c #CEC5EA",
"). c #C7C7FA",
"_. c #FDF9EF",
"`. c #FFFFFE",
/* pixels */
"z.z.z.z.z.z.z.z.R T T T R T R R R T Y Y T Y T T R z.z.R T T R R ",
"R z.z.z.R z.R R R R T T T R R R T T T Y Y T T R R R R R R R R R ",
"R R T T T T R T T T R R R T T R z.z.R z.z.R Y Y T Y Y T R T T T ",
"z.R R R T R R R T T T R T T R R T R T T R R R T Y Y T R T T R z.",
"R R T T Y Y Y Y T T T T T Y Y Y Y Y T T T T T R R R R R R T T R ",
"z.z.R T T Y Y T Y Y T R R T Y T T T T R T R R R T T R R R R R R ",
"R T T T R R T T T R R R R R R z.z.z.z.z.R R R T T R T Y Y T T R ",
"T R z.z.z.z.+.H r a h h a r r r r h h r r r h d K +.P T T R R T ",
"T T T T R z.w u u u u u u u u s s s i s s i i i p e w T T T R R ",
"R T R R R R % z ] ' ' ' ' ] J s g g g g g g s g y % < T R R R R ",
"R z.z.z.z.R ; k L J L L L J s < < < < < < < < < 1 = 0 Y Y T z.z.",
"R R z.z.R R = k ' J J J ] 1 x K.Z.A.A.A.A.Z.Z.K.=.& 8 T T T T R ",
"T T T R T R = k L L ] [ , { N.A.C.J.J.A.A.J.B.K.>.2 8 R R R R R ",
"R T T T T T ; k ] k 1 w X.P.Z.~.v.G.J.S.w.!.Y.=.2 8 z.z.T T R ",
"T T T T Y Y = z k j ^ ^ $ ..K.D.`.0.q.L.S.9.)./.*.2 8 T R R R T ",
"R R R T T Y = z , ^ P.K.y X.K.D._.e.b.H.V.8.(.^.*.2 8 R R R R R ",
"R R T T R R ; % ^ A.%.o.:.A.C.D.F.,.%.=.S.D.K.=.2 8 T T T T R ",
"R z.z.z.z.z.3 } o.&.:.=.*.m.P.I.P.%.} } } .m.U.:.2 8 R T T R R ",
"R R R z.z.R 4 ! ( ~ ! ! ! ) _ _ | W 5 7 7 5 ~ .~ & 9 z.z.R R R ",
"R R z.z.z.z.3 & # * q : : . . . . : q q q q - @ # 9 / z.T T T T ",
"T Y T R R R R l 6 t y.y.y.t.t.t.t.t.t.t.t.t.S o Q T R T T Y T R ",
"R R R R T T K ..m.$.> u.r.a.h.f.g.g.g.g.f.j.S E ;.I [ z.R R R T ",
"R R R T T R & o.K.-.* p.i.d.l.k.k.k.k.k.k.l.2.#.M.# f T T R z.z.",
"R R R R R R ( ( O.` O 1.1.3.5.4.7.6.5.4.4.6.<.G _ f @.R T T T R ",
"T R T T R T T f # o B V D D Z C v N A Z C D N + c Y Y T Y Y T T ",
"R R R T Y Y T R z.F n.x.R.W.W.R.b s.T.W.E.Q.U + Y T T T T Y Y T ",
"R z.z.z.z.T R T T + n n m m m m + b m m m M X U T T R R T z.z.z.",
"z.z.z.R R R T T T M M M m m m m M M m m m m F c.T R R T T T R z.",
"R R T R T T R R z.z.z.z.z.T T T R R T T R R R R z.z.z.z.z.z.z.z.",
"R T Y Y T R T T R z.z.R R R T T T R R R R R R R R R z.R z.z.z.R ",
"T R R T T T R R R T R T T Y Y T R z.z.z.z.z.R T R T T T T T R T ",
"R R T T R R R R R R R R T T T T T R R z.z.R R R R R T T R R R R "
};

43
assets/wall.xpm Normal file
View File

@ -0,0 +1,43 @@
/* XPM */
static char *result[] = {
/* columns rows colors chars-per-pixel */
"32 32 5 1 ",
" c #222222",
". c gray20",
"X c gray34",
"o c gray39",
"O c #979797",
/* pixels */
"XX..XX.XXXXXoooXXXXXXX.........X",
"X.........XoooooXOOOO....XX..XOO",
"...XooOOoOOoOO...oOOooooX. .XX..",
"..XooOOoXXoOOoX...oOOoXX. .XX.",
"X.... XX....XOOX.....XXoOOoXXXX",
". . .... ..XOOX.XXXXXoOOoOOo",
"XXX...XXX .oOOXXXX..........XX",
"XoooOOooXX. XXoXXXOOoX.....XOXXX",
"...OOo... ...XXXX..XoooX...X...",
"X. .OOXX...XOX.......ooooXooX.X",
"..XXooX......XXX. XXXXOOo.. ..",
"XoooOOXo..XooX.... .OOOo..... ",
"oooooooXXoXXooXooXXooooOOooOO X",
"oOoOOXXoooooOOooXX..XXooooOO....",
"OOOXXX.OOXOOOoXX... ..XXX..XXXX",
"XooX....XXXXOO. . .XXXooXXooXX",
"oooOOXX......XXXXoooOOooooOOOOXo",
"OOOOoooX...XXXXoOOoOOooXXOOOoooo",
"oXX... ....XooXXOOoX.....oOOOOo",
"X... . .XX..XX..XXXXXX...ooooo",
".ooOOo..XXoOOo.. ..oooOOooX....",
"oOOOo....oOOXXX .XXXOOOooooXX..",
" .OOX.. . .XXOOOOoXXXXoOOOOoo.",
"..XXXXXX. .XXoooOoooXXoOOOOoX..",
"XXX...XXOX.XX...OOOo...XX....XXX",
"XX......XXXX......XoX......XXXoo",
"ooOOoXXX. .X...XX... .XXooOOXO",
"oOOoXOOoOX ..XXX. . ...XXXoOOO",
"ooXXX.....XXX......XoOOooX.....X",
"XoooXXX..XXX....XXoOOoOOooX..XXX",
"OOX.... .oOOOX...Xooo. .....XX",
". . . .oOOooOOXXOooooX ..XXoo"
};

61
ft_printf_fd/Makefile Normal file
View File

@ -0,0 +1,61 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin lfirmim@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/12 07:07:31 by lfirmin #+# #+# #
# Updated: 2024/08/12 09:15:05 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
NAME = libftprintf.a
HEADER = ./
SRC = ft_putchar.c ft_put_ptr.c ft_conv_ith.c ft_hex_len.c \
ft_sorting.c ft_printf.c ft_print_ith.c ft_printchar.c \
ft_printstr.c ft_printpercent.c ft_print_unsigned.c \
ft_print_nbr.c ft_print_ptr.c ft_adrr_len.c ft_print_null.c \
ft_itoa.c ft_unsigned_itoa.c ft_count.c
CC = cc
CFLAGS = -Wall -Wextra -Werror
INCLUDE = -I $(HEADER)
OBJ_DIR = obj/
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
GREEN = \033[0;32m
YELLOW = \033[0;33m
RESET = \033[0m
WHITE = \033[0;97m
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
all: $(NAME)
$(NAME): $(OBJ)
@printf "$(YELLOW)Compiling ft_printf, Please wait...$(RESET)"
@for char in $(LOADING_CHARS); do \
printf "\r$(YELLOW)Compiling ft_print, Please wait... $$char$(RESET)"; \
sleep 0.1; \
done
@ar rc $(NAME) $(OBJ)``
@ranlib $(NAME)
@printf "\r$(GREEN)Great news ! $(WHITE)ft_printf compiled successfully ! $(RESET)\n"
$(OBJ_DIR)%.o: %.c
@mkdir -p $(OBJ_DIR)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
clean:
@rm -rf $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)Ft_printf.$(RESET)\n"
fclean: clean
@rm -f $(NAME)
@printf "$(WHITE)Full clean process completed for $(GREEN)Ft_printf.$(RESET)\n"
re: fclean all
.PHONY: all clean fclean re

48
ft_printf_fd/Readme.md Normal file
View File

@ -0,0 +1,48 @@
# ft_printf_fd
Your own implementation of the printf function with file descriptor support.
## 💡 About
The ft_printf_fd project is an extension of ft_printf that allows writing to any file descriptor. You will learn about file descriptors, variadic arguments and formatted output conversion. This project enhances the original printf functionality by adding the ability to choose the output destination.
## 🛠️ Supported Conversions
The function handles the following conversions:
* `%c` - Single character
* `%s` - String
* `%p` - Pointer address
* `%d` - Decimal (base 10) integer
* `%i` - Integer in base 10
* `%u` - Unsigned decimal (base 10) integer
* `%x` - Hexadecimal (base 16) integer lowercase
* `%X` - Hexadecimal (base 16) integer uppercase
* `%%` - Percentage sign
## 📋 Usage
```c
#include "ft_printf_fd.h"
int main(void)
{
// Write to stdout (fd 1)
ft_printf_fd(1, "Hello %s!\n", "world");
// Write to stderr (fd 2)
ft_printf_fd(2, "Error: %d\n", 42);
// Write to a file
int fd = open("output.txt", O_WRONLY | O_CREAT, 0644);
ft_printf_fd(fd, "Number: %d\n", 42);
close(fd);
return (0);
}
```
## ⚠️ Function Prototype
```c
int ft_printf_fd(int fd, const char *format, ...);
```
Returns the number of characters printed (excluding the null byte used to end output to strings).
## 📊 Expected Output
The function should work exactly like the original printf, handling all the specified conversions correctly, but writing to the specified file descriptor instead of stdout.

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_adrr_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 05:16:57 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:50:34 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_adrr_len(unsigned long long nbr)
{
int i;
if (nbr == 0)
return (1);
i = 0;
while (nbr != 0)
{
i++;
nbr = nbr / 16;
}
return (i);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_conv_ith.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:46:47 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:46:23 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
void ft_conv_ith(int fd, unsigned int nbr, const char str)
{
if (nbr >= 16)
{
ft_conv_ith(fd, (nbr / 16), str);
nbr = nbr % 16;
}
if (nbr <= 9)
ft_putchar(fd, nbr + '0');
else
{
if (str == 'x')
ft_putchar(fd, nbr - 10 + 'a');
else if (str == 'X')
ft_putchar(fd, nbr - 10 + 'A');
}
}

27
ft_printf_fd/ft_count.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_count.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:52:36 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:47:07 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
size_t ft_count(long long int n)
{
size_t c;
c = 0;
if (n <= 0)
c = 1;
while (n != 0)
{
n = n / 10;
c++;
}
return (c);
}

27
ft_printf_fd/ft_hex_len.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hex_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:45:50 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:49:59 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_hex_len(unsigned int nbr)
{
int i;
if (nbr == 0)
return (1);
i = 0;
while (nbr != 0)
{
i++;
nbr = nbr / 16;
}
return (i);
}

36
ft_printf_fd/ft_itoa.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:51:58 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:53:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
char *ft_itoa(int n)
{
char *str;
size_t size;
long int num;
num = n;
size = ft_count(num);
str = (char *)malloc(size + 1);
if (!str)
return (NULL);
str[size] = '\0';
if (num < 0)
num = -num;
while (size--)
{
str[size] = num % 10 + '0';
num = num / 10;
if (n < 0 && size == 0)
str[size] = '-';
}
return (str);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_ith.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:44:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:49:51 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_print_ith(int fd, unsigned int nbr, const char str)
{
if (nbr == 0)
return (write(fd, "0", 1));
ft_conv_ith(fd, nbr, str);
return (ft_hex_len(nbr));
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_nbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:44:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:52:47 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_print_nbr(int fd, int nb)
{
int len;
char *str;
str = ft_itoa(nb);
len = ft_printstr(fd, str);
free (str);
return (len);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_null.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 07:01:50 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:46:39 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_print_null(int fd)
{
write(fd, "(null)", 6);
return (6);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:44:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:51:10 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_print_ptr(int fd, unsigned long long ptr)
{
int print_length;
if (ptr == 0)
{
write(fd, "(nil)", 5);
return (5);
}
print_length = 2;
write(fd, "0x", 2);
{
ft_put_ptr(fd, ptr);
print_length = print_length + ft_adrr_len(ptr);
}
return (print_length);
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_unsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:50:53 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:51:31 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_print_unsigned(int fd, unsigned int nb)
{
int len;
char *str;
str = ft_unsigned_itoa(nb);
len = ft_printstr(fd, str);
free (str);
return (len);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:56:02 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:56:25 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_printchar(int fd, int c)
{
write (fd, &c, 1);
return (1);
}

39
ft_printf_fd/ft_printf.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:44:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:55:41 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_printf_fd(int fd, const char *str, ...)
{
int i;
va_list list;
int count;
i = 0;
count = 0;
va_start(list, str);
while (str[i])
{
if (str[i] == '%')
{
count += ft_sorting(list, str[i + 1], fd);
i++;
}
else
{
write (fd, &str[i], 1);
count++;
}
i++;
}
va_end(list);
return (count);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printpercent.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:47:38 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:50:08 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_printpercent(int fd)
{
ft_putchar(fd, '%');
return (1);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:55:08 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:46:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_printstr(int fd, char *s)
{
int i;
if (!s)
return (ft_print_null(fd));
i = 0;
while (s[i])
{
write (fd, &s[i], 1);
i++;
}
return (i);
}

28
ft_printf_fd/ft_put_ptr.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:54:06 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:46:52 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
void ft_put_ptr(int fd, unsigned long long num)
{
if (num >= 16)
{
ft_put_ptr(fd, num / 16);
ft_put_ptr(fd, num % 16);
}
else
{
if (num <= 9)
ft_putchar(fd, num + '0');
else
ft_putchar(fd, num - 10 + 'a');
}
}

17
ft_printf_fd/ft_putchar.c Normal file
View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:45:04 by lfirmin #+# #+# */
/* Updated: 2024/06/19 04:49:11 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
void ft_putchar(int fd, char c)
{
write(fd, &c, 1);
}

34
ft_printf_fd/ft_sorting.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sorting.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:56:45 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:51:17 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
int ft_sorting(va_list list, const char str, int fd)
{
int count;
count = 0;
if (str == 'c')
count += ft_printchar(fd, va_arg(list, int));
else if (str == 's')
count += ft_printstr(fd, va_arg(list, char *));
else if (str == 'p')
count += ft_print_ptr(fd, va_arg(list, unsigned long long));
else if (str == 'd' || str == 'i')
count += ft_print_nbr(fd, va_arg(list, int));
else if (str == 'u')
count += ft_print_unsigned(fd, va_arg(list, unsigned int));
else if (str == 'x' || str == 'X')
count += ft_print_ith(fd, va_arg(list, unsigned int), str);
else if (str == '%')
count += ft_printpercent(fd);
return (count);
}

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_unsigned_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:51:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:45:46 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftprintf.h"
char *ft_unsigned_itoa(unsigned int n)
{
char *str;
size_t size;
long int num;
num = n;
size = ft_count(num);
str = (char *)malloc(size + 1);
if (!str)
return (NULL);
str[size] = '\0';
if (num < 0)
num = -num;
while (size--)
{
str[size] = num % 10 + '0';
num = num / 10;
}
return (str);
}

43
ft_printf_fd/ftprintf.h Normal file
View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ftprintf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/19 04:44:27 by lfirmin #+# #+# */
/* Updated: 2024/06/19 07:49:08 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FTPRINTF_H
# define FTPRINTF_H
# include <stdarg.h>
# include <unistd.h>
# include <stdio.h>
# include "stdlib.h"
void ft_putchar(int fd, char c);
void ft_put_ptr(int fd, unsigned long long num);
void ft_conv_ith(int fd, unsigned int nbr, const char str);
int ft_hex_len(unsigned int nbr);
int ft_sorting(va_list list, const char str, int fd);
int ft_printf_fd(int fd, const char *str, ...);
int ft_print_ith(int fd, unsigned int nbr, const char str);
int ft_printchar(int fd, int c);
int ft_printstr(int fd, char *s);
int ft_printpercent(int fd);
int ft_print_unsigned(int fd, unsigned int nb);
int ft_print_nbr(int fd, int nb);
int ft_print_ptr(int fd, unsigned long long ptr);
int ft_adrr_len(unsigned long long nbr);
int ft_print_null(int fd);
char *ft_itoa(int n);
char *ft_unsigned_itoa(unsigned int n);
size_t ft_count(long long int n);
#endif

61
gnl/Makefile Normal file
View File

@ -0,0 +1,61 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin lfirmim@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/12 07:07:31 by lfirmin #+# #+# #
# Updated: 2024/08/12 09:15:05 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
NAME = gnl.a
SRCS_DIR = srcs/
INCS_DIR = includes/
OBJ_DIR = obj/
SRC = get_next_line.c get_next_line_utils.c
CC = cc
CFLAGS = -Wall -Wextra -Werror
INCLUDE = -I $(INCS_DIR)
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
# Colors
GREEN = \033[0;32m
YELLOW = \033[0;33m
RESET = \033[0m
WHITE = \033[0;97m
# Loading animation
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
all: $(NAME)
$(NAME): $(OBJ)
@printf "$(YELLOW)Compiling get_next_line, Please wait...$(RESET)"
@for char in $(LOADING_CHARS); do \
printf "\r$(YELLOW)Compiling get_next_line, Please wait... $$char$(RESET)"; \
sleep 0.1; \
done
@ar rc $(NAME) $(OBJ)
@ranlib $(NAME)
@printf "\r$(GREEN)fine ! $(WHITE)get_next_line compiled successfully ! $(RESET)\n"
$(OBJ_DIR)%.o: $(SRCS_DIR)%.c
@mkdir -p $(OBJ_DIR)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
clean:
@rm -rf $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)get_next_line.$(RESET)\n"
fclean: clean
@rm -f $(NAME)
@printf "$(WHITE)Full clean process completed for $(GREEN)get_next_line.$(RESET)\n"
re: fclean all
.PHONY: all clean fclean re

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 19:32:47 by abelghou #+# #+# */
/* Updated: 2024/07/23 20:47:15 by abelghou ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_H
# define GET_NEXT_LINE_H
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 10
# endif
# include <stdlib.h>
# include <unistd.h>
# include <stdio.h>
# include <fcntl.h>
char *ft_substr(char const *s, unsigned int start, size_t len);
int ft_strlen_g(const char *str);
char *ft_strchr(const char *s, int i);
char *ft_strdup_g(const char *s);
char *ft_strjoin(char const *s1, char const *s2);
char *get_next_line(int fd);
#endif

41
gnl/readme.md Normal file
View File

@ -0,0 +1,41 @@
# get_next_line
A function that reads a line from a file descriptor.
## 💡 About
The get_next_line project is a programming function that reads a line ending with a newline character from a file descriptor. When calling the function in a loop, it will then allow you to read the text file pointed to by the file descriptor, one line at a time until the end of the file.
## 🛠️ Function Prototype
```c
char *get_next_line(int fd);
```
## 📋 Usage
```c
#include "get_next_line.h"
#include <fcntl.h>
int main(void)
{
int fd;
char *line;
fd = open("test.txt", O_RDONLY);
while ((line = get_next_line(fd)) != NULL)
{
printf("%s", line);
free(line);
}
close(fd);
return (0);
}
```
## ⚠️ Return Value
* The line that was read when successful
* NULL if there is nothing else to read or if an error occurred
## 📊 Expected Behavior
* Repeated calls to get_next_line() should let you read the text file pointed to by the file descriptor, one line at a time
* The function should return the line that was read
* If there is nothing else to read or if an error occurred, it should return NULL
* The returned line should include the terminating \n character, except if the end of file was reached and does not end with a \n character

102
gnl/srcs/get_next_line.c Normal file
View File

@ -0,0 +1,102 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 21:31:24 by abelghou #+# #+# */
/* Updated: 2024/07/24 18:17:55 by abelghou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/get_next_line.h"
static char *sort_and_store(int fd, char *buf, char *backup)
{
int read_line;
char *char_temp;
read_line = 1;
while (read_line != 0)
{
read_line = read(fd, buf, BUFFER_SIZE);
if (read_line == -1)
return (0);
else if (read_line == 0)
break ;
buf[read_line] = '\0';
if (!backup)
backup = ft_strdup_g("");
if (!backup)
return (NULL);
char_temp = backup;
backup = ft_strjoin(char_temp, buf);
free(char_temp);
char_temp = NULL;
if (ft_strchr (buf, '\n'))
break ;
}
return (backup);
}
static char *extract(char *line)
{
size_t count;
char *backup;
count = 0;
while (line[count] != '\n' && line[count] != '\0')
count++;
if (line[count] == '\0' || line[1] == '\0')
return (0);
backup = ft_substr(line, count + 1, ft_strlen_g(line) - count);
if (!backup)
return (NULL);
if (*backup == '\0')
{
free (backup);
backup = NULL;
}
line[count + 1] = '\0';
return (backup);
}
char *get_next_line(int fd)
{
char *line;
char *buf;
char *temp;
static char *backup;
if (fd < 0 || BUFFER_SIZE <= 0)
return (free(backup), backup = NULL, NULL);
buf = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1));
if (!buf)
return (free(backup), backup = NULL, NULL);
line = sort_and_store(fd, buf, backup);
free(buf);
buf = NULL;
if (!line)
return (free(backup), backup = NULL, NULL);
backup = extract(line);
temp = ft_strdup_g(line);
free(line);
if (!temp)
return (free(backup), backup = NULL, NULL);
return (temp);
}
// int main()
// {
// int fd;
// char *line;
// fd = open("fd.txt", O_RDONLY);
// while((line = get_next_line(fd)) != NULL)
// {
// printf("%s", line);
// free(line);
// }
// line = get_next_line(fd);
// close(fd);
// }

View File

@ -0,0 +1,106 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 19:34:18 by abelghou #+# #+# */
/* Updated: 2024/07/23 20:06:41 by abelghou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/get_next_line.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t j;
char *str;
str = (char *)malloc(sizeof(*s) * (len + 1));
if (str == 0)
return (NULL);
i = 0;
j = 0;
while (s[i])
{
if (i >= start && j < len)
{
str[j] = s[i];
j++;
}
i++;
}
str[j] = '\0';
return (str);
}
int ft_strlen_g(const char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strchr(const char *s, int i)
{
while (*s)
{
if (*s == i)
return ((char *)s);
s++;
}
if (i == '\0')
return ((char *)s);
return (0);
}
char *ft_strdup_g(const char *s)
{
int i;
int j;
char *str;
i = 0;
j = ft_strlen_g(s);
str = (char *)malloc(sizeof(*str) * (j + 1));
if (!str)
return (NULL);
while (i < j)
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int j;
char *str;
i = 0;
j = 0;
str = (char *)malloc(sizeof(char) * (ft_strlen_g(s1) \
+ ft_strlen_g(s2) + 1));
if (str == NULL)
return (NULL);
while (s1[i] != '\0')
{
str[i] = s1[i];
i++;
}
while (s2[j] != '\0')
{
str[i + j] = s2[j];
j++;
}
str[i + j] = '\0';
return (str);
}

108
include/so_long.h Normal file
View File

@ -0,0 +1,108 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 11:00:04 by lfirmin #+# #+# */
/* Updated: 2024/11/17 13:53:20 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/17 10:00:00 by lfirmin #+# #+# */
/* Updated: 2024/03/17 10:00:00 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SO_LONG_H
# define SO_LONG_H
# define KEY_ESC 65307
# define KEY_W 119
# define KEY_A 97
# define KEY_S 115
# define KEY_D 100
# define KEY_UP 65362
# define KEY_LEFT 65361
# define KEY_DOWN 65364
# define KEY_RIGHT 65363
# include "../minilibx-linux/mlx.h"
# include "../gnl/include/get_next_line.h"
# include "../libft/libft.h"
# include "../ft_printf_fd/ftprintf.h"
# include <stdio.h>
typedef struct s_data
{
char **map;
int colect;
int e;
int p;
} t_data;
typedef struct s_game
{
void *mlx;
void *win;
void *img_floor;
void *img_wall;
void *img_player;
void *img_collect;
void *img_exit;
int player_x;
int player_y;
int moves;
int collectibles;
char **map;
int map_width;
int map_height;
int exit_x;
int exit_y;
t_data *data;
} t_game;
/* Utils functions */
t_data *init_data(void);
void clean_data(t_data *data);
int init_game(t_game *game);
int find_player_pos(t_game *game);
void draw_map(t_game *game);
int close_game(t_game *game);
void move_player(t_game *game, int new_x, int new_y);
int is_valid_move(t_game *game, int x, int y);
int key_hook(int keycode, t_game *game);
void find_exit_pos(t_game *game);
void draw_tile(t_game *game, char current, int x, int y);
int init_images(t_game *game);
int init_window(t_game *game);
int check_player(t_game *game, int x, int y, int *found);
void init_struct(t_game *game);
/* Map parsing functions */
int get_map(char *filename, t_data *data);
int ft_count_lines(char *file);
int check_close(t_data *data);
int check_rectangle(t_data *data);
int check_playable(t_data *data);
char **copy_map(char **original);
int play_check(char **map, int x, int y);
void free_map(char **map);
int is_playable(t_data *data, int x, int y);
int check_first_last_lines(t_data *data, int i);
int pars_map(t_data *data, char *file);
int have_require_item(t_data *data);
char *add_newline_if_needed(char *line);
int check_char(t_data *data);
int is_ber(char *file);
int get_map_2(int i, int nb_lines, t_data *data, int fd); /* in utils_4 */
#endif

65
libft/Makefile Normal file
View File

@ -0,0 +1,65 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/05/19 12:59:31 by lfirmin #+# #+# #
# Updated: 2024/05/22 15:18:38 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
HEADER = ./
SRC = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
ft_strlcat.c ft_strncmp.c ft_substr.c ft_atoi.c ft_isalpha.c \
ft_itoa.c ft_memcpy.c ft_putendl_fd.c ft_strchr.c ft_strlcpy.c \
ft_strnstr.c ft_tolower.c ft_bzero.c ft_isascii.c ft_strtrim.c \
ft_memmove.c ft_putnbr_fd.c ft_strdup.c ft_strlen.c ft_strrchr.c \
ft_toupper.c ft_calloc.c ft_isdigit.c ft_memchr.c ft_memset.c \
ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_striteri.c \
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
ft_atoll.c ft_print_array.c ft_strcat.c
CC = cc
CFLAGS = -Wall -Wextra -Werror -g3
INCLUDE = -I $(HEADER)
OBJ_DIR = obj/
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
GREEN = \033[0;32m
YELLOW = \033[0;33m
RESET = \033[0m
WHITE = \033[0;97m
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
all: $(NAME)
$(NAME): $(OBJ)
@printf "$(YELLOW)Compiling libft, Please wait...$(RESET)"
@for char in $(LOADING_CHARS); do \
printf "\r$(YELLOW)Compiling libft, Please wait... $$char$(RESET)"; \
sleep 0.1; \
done
@ar rc $(NAME) $(OBJ)
@ranlib $(NAME)
@printf "\r$(GREEN)Great news ! $(WHITE)Libft compiled successfully ! $(RESET)\n"
$(OBJ_DIR)%.o: %.c
@mkdir -p $(OBJ_DIR)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
clean:
@rm -rf $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)Libft.$(RESET)\n"
fclean: clean
@rm -f $(NAME)
@printf "$(WHITE)Full clean process completed for $(GREEN)Libft.$(RESET)\n"
re: fclean all
.PHONY: all clean fclean re

40
libft/ft_atoi.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 10:09:46 by lfirmin #+# #+# */
/* Updated: 2024/06/03 21:02:02 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int s;
int m;
i = 0;
s = 0;
m = 0;
while ((str[i] <= 13 && str[i] >= 9) || str[i] == 32)
i++;
while (str[i] == '-' || str[i] == '+')
{
s++;
if (s >= 2)
return (0);
if (str[i] == '-')
m++;
i++;
}
s = 0;
while (str[i] >= 48 && str[i] <= 57)
s = s * 10 + (str[i++] - 48);
if (m % 2 == 1)
s = s * -1;
return (s);
}

38
libft/ft_atoll.c Normal file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/03 17:25:06 by lfirmin #+# #+# */
/* Updated: 2024/11/03 17:25:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long long ft_atoll(const char *str)
{
long long result;
int sign;
result = 0;
sign = 1;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
if (result > INT_MAX || result < INT_MIN)
return (2147483648);
result = result * 10 + (*str - '0');
str++;
}
return (result * sign);
}

24
libft/ft_bzero.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 00:20:00 by lfirmin #+# #+# */
/* Updated: 2024/05/30 19:49:23 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_bzero(void *b, size_t len)
{
size_t i;
unsigned char *r;
r = (unsigned char *)b;
i = 0;
while (i < len)
r[i++] = '\0';
return (b);
}

31
libft/ft_calloc.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 11:14:02 by lfirmin #+# #+# */
/* Updated: 2024/06/03 18:15:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t c, size_t s)
{
void *ptr;
long long int tmp1;
long long int tmp2;
tmp1 = (long long int)c;
tmp2 = (long long int)s;
if ((c > 4294967295 || s > 4294967295) && (tmp1 < 0 && tmp2 < 0))
return (NULL);
if (tmp1 * tmp2 < 0)
return (NULL);
ptr = malloc(c * s);
if (!ptr)
return (NULL);
ft_bzero(ptr, c * s);
return (ptr);
}

19
libft/ft_isalnum.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:29:49 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if ((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 65 && c <= 90))
return (1);
return (0);
}

19
libft/ft_isalpha.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 01:55:52 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
return (1);
return (0);
}

19
libft/ft_isascii.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:36:17 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}

19
libft/ft_isdigit.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:31:51 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
if (c >= 48 && c <= 57)
return (1);
return (0);
}

19
libft/ft_isprint.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:38:24 by lfirmin #+# #+# */
/* Updated: 2024/05/23 06:21:54 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
if (((c >= 0 && c <= 31) || c >= 127 || c == EOF))
return (0);
return (1);
}

51
libft/ft_itoa.c Normal file
View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 12:59:00 by lfirmin #+# #+# */
/* Updated: 2024/05/29 10:31:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_count(long int n)
{
size_t c;
c = 0;
if (n <= 0)
c = 1;
while (n != 0)
{
n = n / 10;
c++;
}
return (c);
}
char *ft_itoa(int n)
{
char *str;
size_t size;
long int num;
num = n;
size = ft_count(num);
str = (char *)malloc(size + 1);
if (!str)
return (NULL);
str[size] = '\0';
if (num < 0)
num = -num;
while (size--)
{
str[size] = num % 10 + '0';
num = num / 10;
if (n < 0 && size == 0)
str[size] = '-';
}
return (str);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 02:01:18 by lfirmin #+# #+# */
/* Updated: 2024/06/03 15:59:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *last;
if (!new)
return ;
if (!lst || !*lst)
{
*lst = new;
return ;
}
last = ft_lstlast(*lst);
last->next = new;
}

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 20:34:57 by lfirmin #+# #+# */
/* Updated: 2024/05/31 20:41:34 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (lst && new)
{
new->next = *lst;
*lst = new;
}
}

28
libft/ft_lstclear_bonus.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 20:46:07 by lfirmin #+# #+# */
/* Updated: 2024/06/01 20:51:07 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *t;
if (lst)
{
while (*lst)
{
t = (*lst)->next;
ft_lstdelone(*lst, del);
(*lst) = t;
}
(*lst) = NULL;
}
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 20:32:56 by lfirmin #+# #+# */
/* Updated: 2024/06/01 20:32:56 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void*))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}

23
libft/ft_lstiter_bonus.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 21:05:12 by lfirmin #+# #+# */
/* Updated: 2024/06/01 21:05:12 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

23
libft/ft_lstlast_bonus.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 01:52:09 by lfirmin #+# #+# */
/* Updated: 2024/06/01 01:57:22 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
while (lst)
{
if (!lst->next)
return (lst);
lst = lst->next;
}
return (lst);
}

41
libft/ft_lstmap_bonus.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/02 18:21:09 by lfirmin #+# #+# */
/* Updated: 2024/06/03 15:53:13 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new;
t_list *save;
if (!lst || !del || !f)
return (NULL);
new = ft_lstnew(lst->content);
if (!new)
return (NULL);
new->content = f(new->content);
save = new;
lst = lst->next;
while (lst)
{
new->next = ft_lstnew(lst->content);
if (!new->next)
{
ft_lstclear(&save, del);
return (NULL);
}
new->next->content = f(new->next->content);
new = new->next;
lst = lst->next;
}
new->next = NULL;
return (save);
}

24
libft/ft_lstnew_bonus.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 18:41:23 by lfirmin #+# #+# */
/* Updated: 2024/05/31 20:33:26 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *new;
new = (t_list *)malloc(sizeof(*new));
if (!new)
return (NULL);
new->content = content;
new->next = NULL;
return (new);
}

27
libft/ft_lstsize_bonus.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 22:00:49 by lfirmin #+# #+# */
/* Updated: 2024/05/31 22:12:17 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *count;
count = lst;
i = 0;
while (count)
{
count = count->next;
i++;
}
return (i);
}

26
libft/ft_memchr.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 07:40:39 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *str;
str = (unsigned char *)s;
while (n--)
{
if (*str == (unsigned char)c)
return (str);
str++;
}
return (NULL);
}

30
libft/ft_memcmp.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 07:57:58 by lfirmin #+# #+# */
/* Updated: 2024/05/22 11:34:35 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num)
{
unsigned char *pt1;
unsigned char *pt2;
size_t i;
pt1 = (unsigned char *)ptr1;
pt2 = (unsigned char *)ptr2;
i = 0;
while (i < num)
{
if (pt1[i] != pt2[i])
return (pt1[i] - pt2[i]);
i++;
}
return (0);
}

31
libft/ft_memcpy.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 01:08:31 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:46:00 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t len)
{
size_t i;
unsigned char *r;
unsigned char *s;
i = 0;
r = (unsigned char *)dest;
s = (unsigned char *)src;
if (dest == (void *)0 && src == (void *)0)
return (dest);
while (i < len)
{
r[i] = s[i];
i++;
}
return (dest);
}

39
libft/ft_memmove.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmov.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 01:26:13 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *s1, const void *s2, size_t len)
{
unsigned char *dest;
unsigned char *src;
unsigned int i;
dest = (unsigned char *)s1;
src = (unsigned char *)s2;
i = 0;
if (dest == NULL && src == NULL)
return (NULL);
if (dest < src)
{
while (i < len)
{
dest[i] = src[i];
i++;
}
}
else
{
while (0 < len--)
dest[len] = src[len];
}
return (dest);
}

24
libft/ft_memset.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:42:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
size_t i;
unsigned char *r;
i = 0;
r = (unsigned char *)b;
while (i < len)
r[i++] = (unsigned char)c;
return (b);
}

39
libft/ft_print_array.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 02:29:54 by lfirmin #+# #+# */
/* Updated: 2024/11/05 02:29:54 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void put_str(char *str)
{
if (!str)
return ;
while (*str)
write(1, str++, 1);
}
void ft_print_str_array(char **array)
{
int i;
if (array == NULL)
{
put_str("Tableau invalide\n");
return ;
}
i = 0;
put_str("Contenu du tableau:\n");
while (array[i])
{
put_str(array[i]);
write(1, "\n", 1);
i++;
}
}

17
libft/ft_putchar_fd.c Normal file
View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:17:45 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:20:42 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

18
libft/ft_putendl_fd.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:35:44 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:38:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

31
libft/ft_putnbr_fd.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:42:38 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:56:04 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
long int nb;
nb = n;
if (nb < 0)
{
nb = -nb;
ft_putchar_fd('-', fd);
}
if (nb >= 10)
{
ft_putnbr_fd(nb / 10, fd);
ft_putnbr_fd(nb % 10, fd);
}
else
ft_putchar_fd(nb + '0', fd);
}

24
libft/ft_putstr_fd.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:27:05 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:33:18 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
int i;
i = 0;
while (s[i])
{
ft_putchar_fd(s[i], fd);
i++;
}
}

59
libft/ft_split.c Normal file
View File

@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 05:56:37 by lfirmin #+# #+# */
/* Updated: 2024/06/04 12:08:51 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_countword(char const *s, char c)
{
size_t count;
if (!*s)
return (0);
count = 0;
while (*s)
{
while (*s == c)
s++;
if (*s)
count++;
while (*s != c && *s)
s++;
}
return (count);
}
char **ft_split(char const *s, char c)
{
char **lst;
size_t word_len;
int i;
lst = (char **)malloc((ft_countword(s, c) + 1) * sizeof(char *));
if (!s || !lst)
return (0);
i = 0;
while (*s)
{
while (*s == c && *s)
s++;
if (*s)
{
if (!ft_strchr(s, c))
word_len = ft_strlen(s);
else
word_len = ft_strchr(s, c) - s;
lst[i++] = ft_substr(s, 0, word_len);
s += word_len;
}
}
lst[i] = NULL;
return (lst);
}

82
libft/ft_strcat.c Normal file
View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 02:21:14 by lfirmin #+# #+# */
/* Updated: 2024/11/05 08:19:47 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int should_add_space(char *dest, char *src)
{
size_t dest_len;
size_t src_len;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (dest_len > 0 && src_len > 0)
{
if (dest[dest_len - 1] != ' ' && src[0] != ' ')
return (1);
}
return (0);
}
char *create_new_str(char *dest, char *src, int add_space)
{
size_t dest_len;
size_t src_len;
char *new_str;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (add_space == 1)
new_str = malloc(sizeof(char) * (dest_len + src_len + 2));
else
new_str = malloc(sizeof(char) * (dest_len + src_len + 1));
if (!new_str)
return (NULL);
return (new_str);
}
void fill_new_str(char *new_str, char *dest, char *src, int add_space)
{
size_t dest_len;
size_t src_len;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (add_space == 1)
{
ft_memset(new_str, 0, dest_len + src_len + 2);
ft_strlcpy(new_str, dest, dest_len + 1);
new_str[dest_len] = ' ';
ft_strlcpy(new_str + dest_len + 1, src, src_len + 1);
}
else
{
ft_memset(new_str, 0, dest_len + src_len + 1);
ft_strlcpy(new_str, dest, dest_len + 1);
ft_strlcpy(new_str + dest_len, src, src_len + 1);
}
}
char *ft_strcat(char *dest, char *src)
{
char *new_str;
int add_space;
if (!dest || !src)
return (NULL);
add_space = should_add_space(dest, src);
new_str = create_new_str(dest, src, add_space);
if (!new_str)
return (NULL);
fill_new_str(new_str, dest, src, add_space);
free(dest);
return (new_str);
}

26
libft/ft_strchr.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:46:40 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:51:25 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(char const *str, int c)
{
while (*str)
{
if (*str == (char)c)
return ((char *)str);
str++;
}
if (*str == (char)c)
return ((char *)str);
else
return (NULL);
}

22
libft/ft_strcmp.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/19 21:01:26 by lfirmin #+# #+# */
/* Updated: 2024/10/19 21:01:26 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
i++;
return (s1[i] - s2[i]);
}

34
libft/ft_strdup.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 05:28:24 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *dest;
int i;
int size;
size = 0;
while (src[size] != '\0')
size++;
dest = malloc(sizeof(char) * (size + 1));
if (dest == NULL)
return (NULL);
i = 0;
while (i != size)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

27
libft/ft_striteri.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 10:54:40 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:12:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
int i;
i = 0;
if (s)
{
while (s[i])
{
f(i, &s[i]);
++i;
}
}
}

34
libft/ft_strjoin.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 01:00:14 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:49:06 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *res;
int i;
int j;
i = 0;
j = 0;
if (s1 == NULL && s2 == NULL)
return (NULL);
res = (char *) malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (!res)
return (NULL);
while (s1[i])
res[j++] = s1[i++];
i = 0;
while (s2[i])
res[j++] = s2[i++];
res[j] = 0;
return (res);
}

32
libft/ft_strlcat.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 03:55:25 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t r;
size_t s;
i = 0;
r = ft_strlen(dst);
s = ft_strlen(src);
if (size <= r)
return (s + size);
while (r + i < size - 1 && src[i] != '\0')
{
dst[r + i] = src[i];
i++;
}
dst[r + i] = '\0';
return (r + s);
}

34
libft/ft_strlcpy.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 02:18:17 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:36:18 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dsts)
{
size_t srcs;
size_t i;
ft_strlen(src);
if (!src || !dst)
return (0);
srcs = ft_strlen(src);
i = 0;
if (dsts != 0)
{
while (src[i] != '\0' && i < (dsts - 1))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
return (srcs);
}

22
libft/ft_strlen.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 23:16:45 by lfirmin #+# #+# */
/* Updated: 2024/05/23 07:36:59 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return ((size_t)i);
}

32
libft/ft_strmapi.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 15:10:42 by lfirmin #+# #+# */
/* Updated: 2024/05/28 17:00:27 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int i;
if (!s)
return (NULL);
str = (char *)malloc(ft_strlen(s) + 1);
if (!str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
++i;
}
str[i] = '\0';
return (str);
}

32
libft/ft_strncmp.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:55:09 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:47:59 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, unsigned int n)
{
unsigned int i;
unsigned char c1;
unsigned char c2;
i = 0;
if (n == 0)
return (0);
while (i < n)
{
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
if (c1 != c2 || c1 == '\0' || c2 == '\0')
return (c1 - c2);
i++;
}
return (0);
}

36
libft/ft_strnstr.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:22:59 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *hay, const char *need, size_t len)
{
size_t i;
size_t n;
i = 0;
if (need[0] == '\0')
return ((char *)hay);
while (hay[i] != '\0')
{
n = 0;
while (hay[i + n] == need[n] && (i + n) < len)
{
if (hay[i + n] == '\0' && need[n] == '\0')
return ((char *)&hay[i]);
n++;
}
if (need[n] == '\0')
return ((char *)hay + i);
i++;
}
return (0);
}

35
libft/ft_strrchr.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:42:38 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:30:00 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
int i;
int last_occurrence;
ft_strlen(str);
i = 0;
last_occurrence = -1;
if (str == NULL)
return (NULL);
while (str[i])
{
if (str[i] == (char)c)
last_occurrence = i;
i++;
}
if ((char)c == '\0')
return ((char *)&str[i]);
if (last_occurrence != -1)
return ((char *)&str[last_occurrence]);
return (NULL);
}

68
libft/ft_strtrim.c Normal file
View File

@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 21:32:01 by lfirmin #+# #+# */
/* Updated: 2024/05/31 02:04:11 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_in_set(char c, const char *set)
{
while (*set)
{
if (c == *set)
{
return (1);
}
set++;
}
return (0);
}
static char *ft_strncpy(char *dest, const char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (src[i] != '\0' && i < n)
{
dest[i] = src[i];
++i;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}
char *ft_strtrim(const char *s1, const char *set)
{
size_t s;
size_t e;
size_t len;
char *str;
if (!s1 || !set)
return (NULL);
s = 0;
while (s1[s] && is_in_set(s1[s], set))
s++;
e = ft_strlen(s1);
while (e > s && is_in_set(s1[e - 1], set))
e--;
len = e - s;
str = (char *)malloc(sizeof(char) * (len + 1));
if (!str)
return (NULL);
ft_strncpy(str, s1 + s, len);
str[len] = '\0';
return (str);
}

34
libft/ft_substr.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 00:15:54 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:28:01 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *sub;
size_t i;
if ((ft_strlen(s) - start) < len)
len = ft_strlen(s) - start;
if (ft_strlen(s) < start)
return (ft_strdup(""));
i = 0;
sub = (char *) malloc(len + 1);
if (!sub)
return (NULL);
while (len > 0)
{
sub[i++] = s[start++];
len--;
}
sub[i] = '\0';
return (sub);
}

19
libft/ft_tolower.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 04:50:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 11:09:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if (c >= 65 && c <= 90)
return (c + 32);
return (c);
}

19
libft/ft_toupper.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 04:50:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if (c >= 97 && c <= 122)
return (c - 32);
return (c);
}

82
libft/libft.h Normal file
View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 11:19:08 by lfirmin #+# #+# */
/* Updated: 2024/06/02 21:12:47 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stdlib.h>
# include <string.h>
# include <stddef.h>
# include <stdio.h>
# include <unistd.h>
# include <limits.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
int ft_atoi(const char *str);
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num);
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
int ft_toupper(int c);
int ft_tolower(int c);
int ft_lstsize(t_list *lst);
int ft_strcmp(char *s1, char *s2);
long long ft_atoll(const char *str);
size_t ft_strlen(const char *s);
size_t ft_strlcat(char *dst, const char *src, size_t size);
size_t ft_strlcpy(char *dst, const char *src, size_t dsts);
void *ft_bzero(void *s, size_t n);
void *ft_calloc(size_t count, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t len);
void *ft_memset(void *b, int c, size_t len);
void *ft_memmove(void *s1, const void *s2, size_t len);
void *ft_memset(void *str, int c, size_t n);
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);
void ft_striteri(char *s, void (*f)(unsigned int, char*));
void ft_lstadd_front(t_list **lst, t_list *new);
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void*));
void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_print_str_array(char **array);
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), \
void (*del)(void *));
char *ft_strchr(char const *str, int c);
char *ft_strdup(const char *src);
char *ft_strjoin(const char *s1, const char *s2);
char *ft_strnstr(const char *hay, const char *need, size_t len);
char *ft_strrchr(const char *str, int c);
char *ft_strtrim(char const *s1, char const *set);
char *ft_substr(char const *s, unsigned int start, size_t len);
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_strcat(char *dest, char *src);
t_list *ft_lstnew(void *content);
t_list *ft_lstlast(t_list *lst);
#endif

0
maps/invalid/empty.ber Normal file
View File

3
maps/invalid/not_ber.txt Normal file
View File

@ -0,0 +1,3 @@
1111111111111111111
10P0000C0000C0000E1
1111111111111111111

View File

@ -0,0 +1,3 @@
1111111111111111111
10P0000C0000C0000E1
1111111110111111111

View File

@ -0,0 +1,3 @@
1111111111111111111
10P0000C0000C0010E1
1111111111111111111

View File

@ -0,0 +1,3 @@
1111111111111111111
10P0000C0000C0E0111
11111111111111111

36
maps/invalid/too_big.ber Normal file
View File

@ -0,0 +1,36 @@
1111111111111111111111111111111111111111
1001010001000001000100000000000000000001
100001000000C010000010000101010100000001
100010000100C000000001001000010000000111
1000001010000110000100000110101000010011
10C0000000000000001010101000100010000011
10C1001001000010010000100000100001000101
1100000010000000110000101011000000C00001
1000100000000000010010000000000000000001
1000000100000001000000011010000000000001
1000100110001000000010010010000C00000001
1000100000010010000010000000101000000001
1000100000001111011010100001110001100001
1000000000011010100000011000000000000101
10110C0100011000000000000000000011101001
10100000C1000100000000000010010010000001
10000000001000000111010110000001000000P1
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
1000000C00000100000000110001010001000001
1001010000000001C00001000001010100010001
1010000000000010110000110000000111000001
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
10000000000010011001000C0000110010001011
1110100001001000100100000001001010000101
110010001100000CC000001010100E1000000001
11000000000000000000000110100C0100010001
1000000000100000010001000000000000000001
1100100000000000000010001000000100110011
1101100000100010000000010100100000001001
10000C0000000100000111100100010000000001
1111111111111111111111111111111111111111

11
maps/valid/crep.ber Normal file
View File

@ -0,0 +1,11 @@
111111111111
10C00C000001
10P00000C001
100110011001
100110011001
10CC00CCC0C1
10C001100001
100C1111C001
10C01C0100E1
10C00C000001
111111111111

19
maps/valid/hard.ber Normal file
View File

@ -0,0 +1,19 @@
1111111111111111111111111111111111111111
1E00000000000001111111000C000000000C0001
1011110111110101000000011111111111111101
1010010100010101011111100000000000000101
1010010111110101010000101011111111110101
1010000000000101000110101010000000010101
101111111111010101011C101010111111010101
1000000000010101010110101010100001010101
1011111111110101010110101C10101101010101
101000CCC0000101010110101010101101010101
1010111111111101010110101010101101010101
10100000000000010101101010101C11C1010101
1011111111111111010110101010101101010101
1000000000000000010110101010101101010101
1111111111111111110110101010101101010101
100000C0000CCC00000000101000000000000101
1111111111111111111110101111111111111101
1P00000000000000000000100000000CCCCCCCC1
1111111111111111111111111111111111111111

6
maps/valid/map1.ber Normal file
View File

@ -0,0 +1,6 @@
1111111111111111111111111111111111111111
1000000000000000000000001000000000000001
100000000000000000C000001000C00010000001
1000000000000000000000001000000010000001
100000000P0000000000000000C00000100000E1
1111111111111111111111111111111111111111

3
maps/valid/map2.ber Normal file
View File

@ -0,0 +1,3 @@
1111111111111111111
10P0000C0000C0000E1
1111111111111111111

88
minilibx-linux/.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,88 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ${{ matrix.os }}
env:
DISPLAY: ":99"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Install mlx dependencies
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update -qq
sudo apt-get install -y -qq gcc make xorg libxext-dev libbsd-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xquartz
echo "/usr/X11/bin" >> $GITHUB_PATH
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Setup x11 headless testing environment
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install xvfb xdotool valgrind
Xvfb $DISPLAY -screen 0 1280x1024x24 &
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xdotool
defaults write org.x.X11 enable_test_extensions -boolean true
sudo Xvfb $DISPLAY -screen 0 1280x1024x24 &
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Run ./configure
run: ./configure
- name: make check Linux
if: matrix.os == 'ubuntu-latest'
run: make -f Makefile.gen check
- name: make check MacOS
continue-on-error: true
if: matrix.os == 'macos-latest'
run: make -f Makefile.gen check
# Didn't find a way to simulate inputs on Macos. libxdo seem to no longer work on macos.
# It can be partially fixed writing proper unit-tests, thus avoiding the need of libxdo.
- name: Check leaks from binary "test/mlx-test"
run: |
cd test
if [ "$RUNNER_OS" == "Linux" ]; then
echo "Info: Still reachable doesn't matter. Valgrind will return success on thoses reports.
It is fine, we searching for lost pointers. Valgrind will return exit status 42 if any block is lost."
valgrind --leak-check=full --show-leak-kinds=definite,indirect,possible --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=42 ./mlx-test > /dev/null &
PID=$!
sleep 30
xdotool search --name Title3 windowfocus key Escape
xdotool search --name Title2 windowfocus key Escape
wait $PID
elif [ "$RUNNER_OS" == "macOS" ]; then
MallocStackLoggingNoCompact=1
./mlx-test &
sleep 30
leaks mlx-test
pkill mlx-test
fi
- name: Norminette, just for fun
continue-on-error: true
run: |
pip3 install Norminette
norminette *.c *.h
norminette --version

67
minilibx-linux/.gitignore vendored Normal file
View File

@ -0,0 +1,67 @@
## Mlx related
Makefile.gen
/test/mlx-test
## Editor
.vscode/*
*~
\#*\#
## Other
.DS_STORE
## Template from https://github.com/github/gitignore
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

25
minilibx-linux/LICENSE Normal file
View File

@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) 2021, Ecole 42
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

22
minilibx-linux/Makefile Normal file
View File

@ -0,0 +1,22 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
## Made by Olivier Crouzet
## Login <ol@epitech.net>
##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
##
## Please use configure script
all : do_configure
do_configure :
./configure
clean :
./configure clean
re : clean all

View File

@ -0,0 +1,66 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
## Made by Olivier Crouzet
## Login <ol@epitech.net>
##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
##
## Please use configure script
INC =%%%%
UNAME = $(shell uname)
CC = gcc
ifeq ($(UNAME),FreeBSD)
CC = clang
endif
NAME = libmlx.a
NAME_UNAME = libmlx_$(UNAME).a
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
mlx_new_image.c mlx_get_data_addr.c \
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
mlx_destroy_display.c
OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
CFLAGS = -O3 -I$(INC)
all : $(NAME)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
$(NAME) : $(OBJ)
ar -r $(NAME) $(OBJ)
ranlib $(NAME)
cp $(NAME) $(NAME_UNAME)
check: all
@test/run_tests.sh
show:
@printf "NAME : $(NAME)\n"
@printf "NAME_UNAME : $(NAME_UNAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean :
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
.PHONY: all check show clean

55
minilibx-linux/README.md Executable file
View File

@ -0,0 +1,55 @@
[![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml)
This is the MinilibX, a simple X-Window (X11R6) programming API
in C, designed for students, suitable for X-beginners.
Contents
- source code in C to create the mlx library
- man pages (in man/ directory)
- a test program (in test/ directory) is built
with the library
- a public include file mlx.h
- a tiny configure script to generate an appropriate Makefile.gen
Requirements for Linux
- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
- gcc
- make
- X11 include files (package xorg)
- XShm extension must be present (package libxext-dev)
- Utility functions from BSD systems - development files (package libbsd-dev)
- **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)**
Requirements for MacOS
- [Xquartz](https://www.xquartz.org/)
```bash
➜ ~ Brew install Xquartz
➜ ~ reboot
➜ ~ xeyes # run an hello world X11 app
```
MlX Color Opacity / Transparency / Alpha (32 bits depth)
- 0xFF (fully transparent) or 0x00 (fully opaque)
Compile MinilibX
- run ./configure or make
both will make a few tests, create Makefile.gen
and then automatically run make on this generated Makefile.gen .
libmlx.a and libmlx_$(HOSTTYPE).a are created.
test/mlx-test binary is also created.
Install MinilibX
- no installation script is provided. You may want to install
- libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib
- mlx.h in /usr/X11/include or /usr/local/include
- man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3
Olivier CROUZET - 2014-01-06 -

126
minilibx-linux/configure vendored Executable file
View File

@ -0,0 +1,126 @@
#!/usr/bin/env sh
set -e
BOLD="\033[1m"
RESET="\033[0m"
LIGHT_RED="\033[91m"
LIGHT_GREEN="\033[92m"
LIGHT_CYAN="\033[96m"
logging(){
local type=$1; shift
printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*"
}
log_info(){
logging "${LIGHT_GREEN}info${RESET}" "$@"
}
log_error(){
logging "${LIGHT_RED}error${RESET}" "$@" >&2
}
# find and print x11 header path
get_xlib_include_path(){
local result=""
for inc in \
/usr/X11/include \
/usr/X11R6/include \
/usr/X11R5/include \
/usr/X11R4/include \
\
/usr/include \
/usr/include/X11 \
/usr/include/X11R6 \
/usr/include/X11R5 \
/usr/include/X11R4 \
\
/usr/local/X11/include \
/usr/local/X11R6/include \
/usr/local/X11R5/include \
/usr/local/X11R4/include \
\
/usr/local/include/X11 \
/usr/local/include/X11R6 \
/usr/local/include/X11R5 \
/usr/local/include/X11R4 \
\
/usr/X386/include \
/usr/x386/include \
/usr/XFree86/include/X11 \
\
/usr/local/include \
/usr/athena/include \
/usr/local/x11r5/include \
/usr/lpp/Xamples/include \
\
/usr/openwin/include \
/usr/openwin/share/include
do
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
result=$inc
break
fi
done
echo $result
}
show_help(){
cat <<EOF
Usage :
$0 Auto-configure and make MinilibX
$0 clean Execute the clean rule of both Makefile.gen
EOF
}
clean(){
log_info 'Execute "make clean" from "makefile.gen"'
${MAKE} -f Makefile.gen clean
log_info 'Execute "make clean" from "test/makefile.gen"'
${MAKE} -f Makefile.gen -C test/ --no-print-directory clean
}
parse_args(){
case "$1" in
--help | -h)
show_help
exit 0;;
clean)
clean
exit 0;;
"") return;;
*)
log_error "unknown command \"$1\"\nRun \"./configure --help\" for usage."
exit 1;;
esac
}
main(){
local xlib_inc="$(get_xlib_include_path)"
case $(uname) in
FreeBSD) MAKE=gmake ;;
*) MAKE=make ;;
esac
parse_args "$@"
if [ -z "$xlib_inc" ]; then
log_error "Can't find a suitable X11 include directory."
exit 1
fi
log_info "Found X11 include path directory: $xlib_inc"
log_info 'Generate "makefile.gen" from template "makefile.mk"'
echo "INC=$xlib_inc" > Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen
log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"'
echo "INC=$xlib_inc" > test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
log_info 'Execute "make all" from file "makefile.gen"'
${MAKE} -f Makefile.gen all
log_info 'Execute "make all" from file "test/makefile.gen"'
(cd test ; ${MAKE} -f Makefile.gen all )
}
main "$@"

Some files were not shown because too many files have changed in this diff Show More