23 Commits

Author SHA1 Message Date
Hugo LAMY
a602b3a78c a la norme et avec le dossier fillit de robin 2019-06-04 10:09:02 +02:00
Hugo LAMY
1aa695c85a mise a la racine des sous dossiers de libt 2019-06-03 22:01:27 +02:00
Hugo LAMY
700fb91632 a la norme et sans erreur 2019-06-03 13:00:46 +02:00
Hugo LAMY
d86dc433dc jsais pas ce qui a change 2019-06-03 09:54:19 +02:00
Hugo LAMY
9aa1acafe4 synchro maison ecole 2019-06-03 09:22:29 +02:00
pia Lepetit
602ebf070d ajout de l'effacement selectif lors de l'opti, pas ouf ouf 2019-06-03 08:16:18 +02:00
Hugo LAMY
f1471562f3 makefile lance la libft aussi 2019-06-01 17:00:52 +02:00
Hugo LAMY
58490cfb56 pret a rendre 2019-06-01 16:27:26 +02:00
Hugo LAMY
214dc0dc5c tout foncioooooone 2019-06-01 16:25:29 +02:00
Manzovince
47fcd0ec91 free bonus print 2019-06-01 16:25:28 +02:00
Hugo LAMY
ee2620e540 tout foncioooooone 2019-06-01 16:23:27 +02:00
Hugo LAMY
26a9c9cbac merge a la main c pas bien 2019-06-01 16:05:47 +02:00
Hugo LAMY
d7dc746779 catastrophe merge 2019-06-01 16:00:49 +02:00
Hugo LAMY
c81b7515be clean pour merge 2019-06-01 15:58:31 +02:00
Manzovince
c007a8299a handle error correct 2019-06-01 15:53:43 +02:00
Manzovince
fd696fc499 oubli dans le main.c 2019-06-01 15:27:46 +02:00
Manzovince
bfe7658388 Merge remote-tracking branch 'origin/ralentit' 2019-06-01 15:17:58 +02:00
Manzovince
482861a3c9 Auto stash before merge of "master" and "origin/ralentit" 2019-06-01 14:54:12 +02:00
Manzovince
5d4de7718e Merge remote-tracking branch 'origin/ralentit' 2019-06-01 14:52:37 +02:00
Hugo LAMY
2d06dcf837 merging ralentit branch 2019-06-01 14:08:35 +02:00
Manzovince
0c48e90449 Merge branch 'ralentit' 2019-06-01 14:04:23 +02:00
Manzovince
68bac851e2 free(map) in print_binary_map - Auto stash before rebase of "origin/master" 2019-06-01 14:03:37 +02:00
Hugo LAMY
27afcbe7e9 tentative d'enlever les leaks en cours 2019-06-01 12:36:34 +02:00
128 changed files with 5898 additions and 59 deletions

4
.gitignore vendored
View File

@@ -12,8 +12,4 @@ a\.out
fillit fillit
test_fillit\.c
libft
\.DS_Store \.DS_Store

View File

@@ -6,14 +6,10 @@
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ # # By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
# Updated: 2019/05/29 14:03:03 by vmanzoni ### ########.fr # # Updated: 2019/06/03 21:55:31 by hulamy ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
# - - - - - - - - - - - - - - - #
# VARIABLES #
# - - - - - - - - - - - - - - - #
NAME = fillit NAME = fillit
CC = gcc CC = gcc
@@ -23,13 +19,17 @@ CFLAGS += -Wall -Wextra -Werror
LDFLAGS = -L./libft/ LDFLAGS = -L./libft/
LDLIBS = -lft LDLIBS = -lft
SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') SRCS = main.c \
f_bonus_opti.c \
f_bonus_print.c \
f_handle_errors.c \
f_parse_input.c \
f_print.c \
f_print_map_with_colors.c \
f_read_file.c \
f_search_map.c
TRASH = $(shell find . -depth 1 -name '*.dSYM') OBJS = $(SRCS:.c=.o)
TRASH += $(shell find . -depth 1 -type f -name '*.o')
TRASH += $(shell find . -depth 1 -type f -name '*.swp')
TRASH += $(shell find . -depth 1 -type f -name '*.swo')
TRASH += $(shell find . -depth 1 -type f -name '*.swn')
# - - - - - - - - - - - - - - - # # - - - - - - - - - - - - - - - #
# RULES # # RULES #
@@ -37,19 +37,16 @@ TRASH += $(shell find . -depth 1 -type f -name '*.swn')
all: $(NAME) all: $(NAME)
$(NAME): $(SRCS) $(NAME): $(OBJS)
make -C ./libft/
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME)
debug: $(SRCS)
$(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME)
lib:
make -C ./libft/
clean: clean:
/bin/rm -rf $(TRASH) make clean -C libft/
/bin/rm -rf $(OBJS)
fclean: clean fclean: clean
make fclean -C libft/
/bin/rm -rf $(NAME) /bin/rm -rf $(NAME)
re: fclean all re: fclean all

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ /* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
/* Updated: 2019/06/01 14:11:32 by hulamy ### ########.fr */ /* Updated: 2019/06/03 12:51:22 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* f_bonus_print.c :+: :+: :+: */ /* f_bonus_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */ /* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */
/* Updated: 2019/06/01 15:00:01 by hulamy ### ########.fr */ /* Updated: 2019/06/01 16:26:09 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 14:49:01 by hulamy ### ########.fr */ /* Updated: 2019/06/01 19:44:08 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -75,7 +75,9 @@ void check_file_errors(char *file, int *dope)
print_error_extended(3, dope); print_error_extended(3, dope);
i++; i++;
} }
if (line_nbr < 4) if (file[i - 1] == '\n')
print_error_extended(3, dope);
if (line_nbr < 3)
print_error_extended(4, dope); print_error_extended(4, dope);
if (!dope[3] && line_nbr > 129) if (!dope[3] && line_nbr > 129)
print_error_extended(5, dope); print_error_extended(5, dope);

View File

@@ -1,7 +1,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* print.c :+: :+: :+: */ /* f_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
@@ -13,8 +13,8 @@
#include "fillit.h" #include "fillit.h"
/* /*
** function that print a map of height and width ** Function that print a map of height and width
** usefull to print tetris ** useful to print tetris
*/ */
void print_sized_map(unsigned int *tab, int width, int height, char letter) void print_sized_map(unsigned int *tab, int width, int height, char letter)
@@ -44,7 +44,7 @@ void print_sized_map(unsigned int *tab, int width, int height, char letter)
/* /*
** Print the final map with the letters ** Print the final map with the letters
** if flag value is 0 -> print moulinette version ** if flag value is 0 -> print moulinette version
** if flag value is 0 -> print in color ** if flag value is p -> print in color
*/ */
char *init_print_map(t_fillist *list, int size) char *init_print_map(t_fillist *list, int size)
@@ -53,7 +53,8 @@ char *init_print_map(t_fillist *list, int size)
int i; int i;
int j; int j;
map = (char *)malloc(sizeof(*map) * (size * size + 1)); if (!(map = (char *)malloc(sizeof(*map) * (size * size + 1))))
return (NULL);
map[size * size] = '\0'; map[size * size] = '\0';
i = -1; i = -1;
while (++i < size * size) while (++i < size * size)

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/06/01 15:12:08 by hulamy ### ########.fr */ /* Updated: 2019/06/03 13:00:28 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -157,6 +157,8 @@ int search_map(t_fillist *list)
if (!(map = (unsigned int *)malloc(sizeof(*map) * num))) if (!(map = (unsigned int *)malloc(sizeof(*map) * num)))
return (0); return (0);
check_same_tetri(list, num); check_same_tetri(list, num);
if (list->dope[2])
ft_putnbrendl(size);
while (num--) while (num--)
map[num] = 0; map[num] = 0;
i = fill_map(map, list, size++); i = fill_map(map, list, size++);

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.fillit</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 15:12:00 by hulamy ### ########.fr */ /* Updated: 2019/06/03 21:53:09 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -18,7 +18,7 @@
# include <fcntl.h> # include <fcntl.h>
# include <stdbool.h> # include <stdbool.h>
# include "libft/includes/libft.h" # include "libft/libft.h"
/* /*
** DEFINE ** DEFINE

34
fillit_roduquen/Makefile Executable file
View File

@@ -0,0 +1,34 @@
CC = gcc
CFLAGS = -Wall -Wextra -Werror
NAME = fillit
SRCDIR = ./
INCLDIR = ./
SRCS = $(SRCDIR)main.c $(SRCDIR)check_square.c $(SRCDIR)check_square2.c \
$(SRCDIR)fillit.c $(SRCDIR)full_square.c $(SRCDIR)check_hole.c\
$(SRCDIR)full_square2.c $(SRCDIR)remove_square.c $(SRCDIR)utilitys.c \
$(SRCDIR)do_i_fillit.c $(SRCDIR)count_island.c \
$(SRCDIR)check_count_island.c $(SRCDIR)init.c \
$(SRCDIR)check_count_island2.c
OBJS_ = $(SRCS:.c=.o)
OBJS = $(notdir $(OBJS_))
all : $(NAME)
$(NAME) : $(SRCS)
@make $(OBJS)
@$(CC) $(CFLAGS) -I $(INCLDIR) $^ -o $@
@echo "\n\033[36mCreation :\033[0m \033[35;4m$(NAME)\033[0m\n"
%.o : %.c
@$(CC) $(CFLAGS) -c -I $(INCLDIR) $^
@echo "\033[36mCompilation :\033[0m \033[32m$*\033[0m"
clean :
@rm -rf $(OBJS)
@echo "\n\033[36mDeletion :\033[0m \033[32mObjects\033[0m\n"
fclean : clean
@rm -rf $(NAME)
@echo "\033[36mDeletion :\033[0m \033[35;4m$(NAME)\033[0m\n"
re : fclean all

View File

@@ -0,0 +1,54 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,64 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....
....
.#..
###.
....
..##
.##.
....
....

View File

@@ -0,0 +1,34 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....

View File

@@ -0,0 +1,44 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....

39
fillit_roduquen/TEST/test_I.txt Executable file
View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

119
fillit_roduquen/TEST/test_J.txt Executable file
View File

@@ -0,0 +1,119 @@
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_J2.txt Executable file
View File

@@ -0,0 +1,119 @@
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_L.txt Executable file
View File

@@ -0,0 +1,119 @@
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###

44
fillit_roduquen/TEST/test_O.txt Executable file
View File

@@ -0,0 +1,44 @@
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##

59
fillit_roduquen/TEST/test_S.txt Executable file
View File

@@ -0,0 +1,59 @@
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#

119
fillit_roduquen/TEST/test_T.txt Executable file
View File

@@ -0,0 +1,119 @@
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#

59
fillit_roduquen/TEST/test_Z.txt Executable file
View File

@@ -0,0 +1,59 @@
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

View File

@@ -0,0 +1,24 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....

View File

@@ -0,0 +1,129 @@
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,38 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
..##
...#
...#

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
....
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,64 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....

View File

@@ -0,0 +1,79 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....
##..
.#..
.#..
....
##..
#...
#...
....
.##.
##..
....
....

View File

@@ -0,0 +1,44 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....

1
fillit_roduquen/auteur Executable file
View File

@@ -0,0 +1 @@
roduquen;scarpent

View File

@@ -0,0 +1,121 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:16:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square(int i, t_type *square, char nbr)
{
if (i < square->size)
{
if (i == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square2(i, square, nbr));
}
return (ft_check_square3(i, square, nbr));
}
int ft_check_square2(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - 1] == nbr
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square3(int i, t_type *square, char nbr)
{
if (i < square->size * (square->size - 1))
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.')
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square4(i, square, nbr));
}
return (ft_check_square5(i, square, nbr));
}
int ft_check_square4(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - 1] == nbr || square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square5(int i, t_type *square, char nbr)
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
return (ft_check_square6(i, square, nbr));
}

View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:15:21 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square6(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr
|| square->isl[i - 1] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
return (SUCCESS);
}
return (ERROR);
}

41
fillit_roduquen/check_hole.c Executable file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_hole.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:10 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:11 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_hole(t_type *square, char tetri[], int to_test)
{
if (count_island(square, 0, tetri, to_test) > square->hole)
return (ERROR);
return (SUCCESS);
}
int i_fillit_the_power(t_type *square, char tetri[], int pos)
{
int i;
int j;
i = 0;
j = -1;
while (i < pos)
{
if (tetri[i] == tetri[pos])
j = i;
i++;
}
if (j == -1)
return (0);
i = 0;
while (square->str[i] != j + 'A')
i++;
return (i);
}

158
fillit_roduquen/check_square.c Executable file
View File

@@ -0,0 +1,158 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:12 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:14:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int check_square(t_type *square, char tetri, int pos)
{
if (tetri == -9
&& square->str[pos] == '.' && (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -8
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2 * square->size] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -7
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
return (check_square2(square, tetri, pos));
}
int check_square2(t_type *square, char tetri, int pos)
{
if (tetri == -6
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 2 * square->size + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -5
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == -4
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square3(square, tetri, pos));
}
int check_square3(t_type *square, char tetri, int pos)
{
if (tetri == -3
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -2
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -1
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& (pos + 3) % square->size != 0
&& pos + 3 < square->size * square->size
&& square->str[pos] == '.' && square->str[pos + 1] == '.'
&& square->str[pos + 3] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
return (check_square4(square, tetri, pos));
}
int check_square4(t_type *square, char tetri, int pos)
{
if (tetri == 0
&& (pos + 1) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == 1
&& pos + 3 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 3 * square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 2
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square5(square, tetri, pos));
}
int check_square5(t_type *square, char tetri, int pos)
{
if (tetri == 3
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 1 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 4
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 5
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
return (check_square6(square, tetri, pos));
}

55
fillit_roduquen/check_square2.c Executable file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:15 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:26:45 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_square6(t_type *square, char tetri, int pos)
{
if (tetri == 6
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 7
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
if (tetri == 8
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square7(square, tetri, pos));
}
int check_square7(t_type *square, char tetri, int pos)
{
if (tetri == 9
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 2] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (ERROR);
}

126
fillit_roduquen/count_island.c Executable file
View File

@@ -0,0 +1,126 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:17 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:13:25 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int count_island(t_type *square, int i, char tetri[], int to_test)
{
char nbr;
ft_memset(square->isl, '.', 170);
nbr = 'a';
while (1)
{
i = 0;
while (square->str[i])
{
if (square->isl[i] == '.' && square->str[i] == '.')
break ;
i++;
}
if (square->str[i])
square->isl[i] = nbr;
else
return (count_hole(square, nbr, tetri, to_test));
full_count_island_square(square, nbr);
nbr++;
}
return (ERROR);
}
void full_count_island_square(t_type *square, char nbr)
{
int i;
int j;
i = 0;
while (i < square->size * 2)
{
j = 0;
while (square->str[j])
{
if (square->str[j] == '.' && square->isl[j] == '.')
ft_check_square(j, square, nbr);
j++;
}
i++;
}
}
int count_hole(t_type *square, char nbr, char tetri[], int to_test)
{
int i;
int nbr_hole;
int total;
total = 0;
while (nbr >= 'a')
{
i = 0;
nbr_hole = 0;
while (i < square->size * square->size)
{
if (square->isl[i] == nbr)
nbr_hole++;
i++;
}
if (nbr_hole == 4)
total += check_new_possibility(square, nbr, tetri, to_test);
else
total += nbr_hole % 4;
nbr--;
}
return (total);
}
int check_if_placing_tetri_is_possible(t_type *square, char tetri[],
int to_test, int i)
{
while (tetri[to_test] != 42)
{
if (tetri[to_test] == -9 || tetri[to_test] == -7
|| tetri[to_test] == -6 || tetri[to_test] == -4
|| tetri[to_test] == -3 || tetri[to_test] == -1
|| tetri[to_test] == 0 || tetri[to_test] == 1
|| tetri[to_test] == 3 || tetri[to_test] == 5
|| tetri[to_test] == 6 || tetri[to_test] == 7
|| tetri[to_test] == 8)
{
if (check_square(square, tetri[to_test], i) == SUCCESS)
return (0);
}
else if (tetri[to_test] == -8 || tetri[to_test] == -5
|| tetri[to_test] == -2 || tetri[to_test] == 2
|| tetri[to_test] == 4)
{
if (check_square(square, tetri[to_test], i - 1) == SUCCESS)
return (0);
}
else if (check_square(square, tetri[to_test], i - 2) == SUCCESS)
return (0);
to_test++;
}
return (4);
}
int check_new_possibility(t_type *square, char nbr, char tetri[],
int to_test)
{
int i;
i = 0;
while (square->isl[i] != nbr)
i++;
return (check_if_placing_tetri_is_possible(square, tetri, to_test, i));
}

103
fillit_roduquen/do_i_fillit.c Executable file
View File

@@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_i_fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:19 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:27:29 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "fillit.h"
#include <unistd.h>
int do_i_fillit(char tetri[], int nbr)
{
int i;
t_type *square;
i = 0;
if (!(square = (t_type*)malloc(sizeof(t_type))))
return (ERROR);
while (i * i < nbr * 4)
i++;
if (!(square->str = (char*)malloc(sizeof(char) * (i * i + 1))))
return (free_error(square));
square->size = i;
full_square_hole(square, nbr);
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
return (do_i_fillit2(tetri, square));
}
int do_i_fillit2(char tetri[], t_type *square)
{
int i;
while (fillit(tetri, square) == ERROR)
{
free(square->str);
square->size++;
square->hole += square->size * 2 - 1;
if (!(square->str = (char*)malloc(sizeof(char) * (square->size
* square->size + 1))))
return (free_error(square));
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
}
free(square->str);
free(square);
return (SUCCESS);
}
int free_error(void *ptr)
{
free(ptr);
return (ERROR);
}
void print_tab(t_type *square)
{
int i;
i = 0;
while (i < square->size * square->size)
{
if (i != 0 && i % square->size == 0)
write(1, "\n", 1);
write(1, &square->str[i], 1);
i++;
}
write(1, "\n", 1);
}
void full_square_hole(t_type *square, int nbr)
{
if (nbr == 1 || nbr == 4 || nbr == 9 || nbr == 16 || nbr == 25)
square->hole = 0;
else if (nbr == 2 || nbr == 6 || nbr == 12 || nbr == 20)
square->hole = 1;
else if (nbr == 3 || nbr == 8 || nbr == 15 || nbr == 24)
square->hole = 4;
else if (nbr == 5 || nbr == 11 || nbr == 19)
square->hole = 5;
else if (nbr == 7 || nbr == 14 || nbr == 23)
square->hole = 8;
else if (nbr == 10 || nbr == 18)
square->hole = 9;
else if (nbr == 13 || nbr == 22)
square->hole = 12;
else if (nbr == 17)
square->hole = 13;
else if (nbr == 21)
square->hole = 16;
else
square->hole = 17;
}

564
fillit_roduquen/external_file.txt Executable file
View File

@@ -0,0 +1,564 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

127
fillit_roduquen/fillit.c Executable file
View File

@@ -0,0 +1,127 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:23 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:28:16 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int full_tetri(char tetri[], char buffer[], char bufftest[], int fd)
{
int i;
if (fd == 26)
return (FILE_ERROR);
i = ft_strstr(buffer, bufftest);
if (i == 0 || i == 21 || i == 42 || i == 63)
tetri[fd] = -1;
if (i == 84 || i == 105 || i == 126 || i == 147)
tetri[fd] = 1;
if (i == 168 || i == 189 || i == 210 || i == 231 || i == 252 || i == 273)
tetri[fd] = -8;
if (i == 294 || i == 315 || i == 336 || i == 357 || i == 378 || i == 399)
tetri[fd] = 7;
if (i == 420 || i == 441 || i == 462 || i == 483 || i == 504 || i == 525)
tetri[fd] = -7;
if (i == 546 || i == 567 || i == 588 || i == 609 || i == 630 || i == 651)
tetri[fd] = 8;
if (i == 672 || i == 693 || i == 714 || i == 735 || i == 756 || i == 777)
tetri[fd] = -6;
if (i == 798 || i == 819 || i == 840 || i == 861 || i == 882 || i == 903)
tetri[fd] = 6;
if (i == 924 || i == 945 || i == 966 || i == 987 || i == 1008 || i == 1029)
tetri[fd] = -9;
return (full_tetri2(i, tetri, fd));
}
int full_tetri2(int i, char tetri[], int fd)
{
if (i == 1050 || i == 1071 || i == 1092 || i == 1113 || i == 1134
|| i == 1155)
tetri[fd] = 9;
if (i == 1176 || i == 1197 || i == 1218 || i == 1239 || i == 1260
|| i == 1281 || i == 1302 || i == 1323 || i == 1344)
tetri[fd] = 0;
if (i == 1365 || i == 1386 || i == 1407 || i == 1428 || i == 1449
|| i == 1470)
tetri[fd] = -5;
if (i == 1491 || i == 1512 || i == 1533 || i == 1554 || i == 1575
|| i == 1596)
tetri[fd] = 5;
if (i == 1617 || i == 1638 || i == 1659 || i == 1680 || i == 1701
|| i == 1722)
tetri[fd] = 3;
if (i == 1743 || i == 1764 || i == 1785 || i == 1806 || i == 1827
|| i == 1848)
tetri[fd] = -3;
if (i == 1869 || i == 1890 || i == 1911 || i == 1932 || i == 1953
|| i == 1974)
tetri[fd] = 2;
if (i == 1995 || i == 2016 || i == 2037 || i == 2058 || i == 2079
|| i == 2100)
tetri[fd] = -2;
return (full_tetri3(i, tetri, fd));
}
int full_tetri3(int i, char tetri[], int fd)
{
if (i == 2121 || i == 2142 || i == 2163 || i == 2184 || i == 2205
|| i == 2226)
tetri[fd] = -4;
if (i == 2247 || i == 2268 || i == 2289 || i == 2310 || i == 2331
|| i == 2352)
tetri[fd] = 4;
if (tetri[fd] == 42)
return (FILE_ERROR);
return (SUCCESS);
}
int fillit(char tetri[], t_type *square)
{
int i;
int j;
i = 0;
j = 0;
while (j >= 0)
{
if (check_square(square, tetri[j], i) == SUCCESS)
{
if (fillit2(square, tetri, &j, &i) == SUCCESS)
return (SUCCESS);
}
else if (square->str[i])
i++;
else
{
j--;
if (j >= 0)
i = remove_square(square, j + 'A', tetri[j]);
}
}
return (ERROR);
}
int fillit2(t_type *square, char tetri[], int *j, int *i)
{
full_square(square, tetri[*j], *j + 'A', *i);
if (tetri[*j + 1] != 42 && check_hole(square, tetri, *j + 1) != SUCCESS)
*i = remove_square(square, *j + 'A', tetri[*j]);
else
{
*i = i_fillit_the_power(square, tetri, *j + 1);
*j += 1;
}
if (tetri[*j] == 42)
{
print_tab(square);
return (SUCCESS);
}
return (CONTINUE);
}

91
fillit_roduquen/fillit.h Executable file
View File

@@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:28:32 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:01:09 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
/*
** MACROS
*/
# define SUCCESS 0
# define ERROR -1
# define READ_ERROR -2
# define OPEN_ERROR -3
# define FILE_ERROR -4
# define CONTINUE 1
# define BUFF_SIZE 2372
/*
** TYPEDEF && STRUCTURES
*/
typedef struct s_type
{
int size;
int hole;
char *str;
char isl[170];
} t_type;
/*
** PROTOTYPES
*/
int fillit(char tetri[], t_type *square);
int fillit2(t_type *square, char tetri[], int *j, int *i);
void full_square(t_type *square, char tetri, char nbr, int pos);
void full_square2(t_type *square, char tetri, char nbr, int pos);
void full_square3(t_type *square, char tetri, char nbr, int pos);
void full_square4(t_type *square, char tetri, char nbr, int pos);
void full_square5(t_type *square, char tetri, char nbr, int pos);
void full_square6(t_type *square, char tetri, char nbr, int pos);
int check_square(t_type *square, char tetri, int pos);
int check_square2(t_type *square, char tetri, int pos);
int check_square3(t_type *square, char tetri, int pos);
int check_square4(t_type *square, char tetri, int pos);
int check_square5(t_type *square, char tetri, int pos);
int check_square6(t_type *square, char tetri, int pos);
int check_square7(t_type *square, char tetri, int pos);
int remove_square(t_type *square, char nbr, char type);
int i_fillit_the_power(t_type *square, char tetri[], int pos);
int i_got_a_fillit(int check_fd);
int check_file(char bufftest[], char tetri[], char buffer[],
int fd);
int free_error(void *ptr);
int do_i_fillit(char tetri[], int nbr);
int do_i_fillit2(char tetri[], t_type *square);
void print_tab(t_type *square);
int full_tetri(char tetri[], char buffer[], char bufftest[],
int fd);
int full_tetri2(int i, char tetri[], int fd);
int full_tetri3(int i, char tetri[], int fd);
int ft_strstr(char haystack[], char needle[]);
int chose_type(char type, int ret);
int check_hole(t_type *square, char tetri[], int to_test);
void full_square_hole(t_type *square, int nbr);
int ft_check_square(int i, t_type *square, char nbr);
int ft_check_square2(int i, t_type *square, char nbr);
int ft_check_square3(int i, t_type *square, char nbr);
int ft_check_square4(int i, t_type *square, char nbr);
int ft_check_square5(int i, t_type *square, char nbr);
int ft_check_square6(int i, t_type *square, char nbr);
int count_island(t_type *square, int i, char tetri[],
int to_test);
void full_count_island_square(t_type *square, char nbr);
int count_hole(t_type *square, char nbr, char tetri[],
int to_test);
void ft_memset(void *ptr, char c, int len);
int check_new_possibility(t_type *square, char nbr,
char tetri[], int to_test);
#endif

148
fillit_roduquen/full_square.c Executable file
View File

@@ -0,0 +1,148 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:25 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:29:03 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -9)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -8)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else
full_square2(square, tetri, nbr, pos);
}
void full_square2(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -6)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -5)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == -4)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square3(square, tetri, nbr, pos);
}
void full_square3(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -3)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == -2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -1)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + 3] = nbr;
}
else
full_square4(square, tetri, nbr, pos);
}
void full_square4(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 0)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 1)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size * 2] = nbr;
square->str[pos + 3 * square->size] = nbr;
}
else if (tetri == 2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square5(square, tetri, nbr, pos);
}
void full_square5(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 3)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 4)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == 5)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else
full_square6(square, tetri, nbr, pos);
}

38
fillit_roduquen/full_square2.c Executable file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:29 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:30 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square6(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 6)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
}
else if (tetri == 7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else if (tetri == 8 || tetri == 9)
{
square->str[(tetri == 8 ? pos : pos + 2)] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
}

53
fillit_roduquen/init.c Executable file
View File

@@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:31 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:32 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <fcntl.h>
#include <unistd.h>
int i_got_a_fillit(int check_fd)
{
int fd;
char buffer[BUFF_SIZE];
char bufftest[21];
char tetri[27];
int ret;
ft_memset(bufftest, 42, 21);
ft_memset(tetri, 42, 27);
bufftest[20] = 0;
if ((fd = open("external_file.txt", O_RDONLY)) < 0)
return (OPEN_ERROR);
if (read(fd, buffer, BUFF_SIZE) <= 0)
return (READ_ERROR);
fd = 0;
while ((ret = read(check_fd, bufftest, 20)) > 0)
{
if (ret != 20 || check_file(bufftest, tetri, buffer, fd) != SUCCESS)
return (FILE_ERROR);
if (read(check_fd, bufftest, 1) > 0 && bufftest[0] != '\n')
return (FILE_ERROR);
tetri[++fd] = 42;
}
if (ret < 0 || fd == 0 || bufftest[0] == '\n')
return (FILE_ERROR);
return (do_i_fillit(tetri, fd));
}
int check_file(char bufftest[], char tetri[], char buffer[], int fd)
{
if (bufftest[0] != '.' && bufftest[0] != '#')
return (FILE_ERROR);
if (full_tetri(tetri, buffer, bufftest, fd) != SUCCESS)
return (FILE_ERROR);
return (SUCCESS);
}

42
fillit_roduquen/main.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:34 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:35 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <unistd.h>
#include <fcntl.h>
int main(int ac, char **av)
{
int fd;
if (ac != 2 || (fd = open(av[1], O_DIRECTORY | O_RDONLY)) >= 0)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
if ((fd = open(av[1], O_RDONLY)) == -1)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
else
{
if ((fd = i_got_a_fillit(fd)) < 0)
{
if (fd == FILE_ERROR || fd == ERROR)
write(1, "error\n", 6);
if (fd == OPEN_ERROR || fd == READ_ERROR)
write(2, "Something went wrong, please try again\n", 39);
}
}
return (fd);
}

46
fillit_roduquen/remove_square.c Executable file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* remove_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:36 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:38 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int remove_square(t_type *square, char nbr, char type)
{
int i;
int ret;
i = 0;
ret = -1;
while (square->str[i])
{
if (square->str[i] == nbr)
{
if (ret == -1)
ret = i;
square->str[i] = '.';
}
i++;
}
return (chose_type(type, ret));
}
int chose_type(char type, int ret)
{
if (type == -9 || type == -7 || type == -6 || type == -4
|| type == -3 || type == -1 || type == 0 || type == 1
|| type == 3 || type == 5 || type == 6 || type == 7
|| type == 8)
return (ret + 1);
else if (type == 9)
return (ret - 1);
else
return (ret);
}

42
fillit_roduquen/utilitys.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilitys.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:39 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:50 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_strstr(char haystack[], char needle[])
{
int i;
int j;
i = 0;
while (i < BUFF_SIZE)
{
j = 0;
while (i + j < BUFF_SIZE && needle[j] && needle[j] == haystack[i + j])
j++;
if (!needle[j])
return (i);
i++;
}
return (ERROR);
}
void ft_memset(void *ptr, char c, int len)
{
int i;
unsigned char *str;
i = 0;
str = (unsigned char*)ptr;
while (i < len)
str[i++] = c;
}

46
libft/Makefile Normal file
View File

@@ -0,0 +1,46 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: hulamy <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/06/03 21:52:28 by hulamy #+# #+# #
# Updated: 2019/06/03 21:52:33 by hulamy ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
CFLAGS = -Wall -Wextra -Werror -I.
SRCS = ft_isdigit.c ft_memccpy.c ft_putnbr.c ft_strcpy.c ft_strmapi.c ft_strsub.c \
ft_any.c ft_isprint.c ft_memchr.c ft_putnbr_fd.c ft_strdel.c ft_strmultisplit.c ft_strtrim.c \
ft_arraymap.c ft_issort.c ft_memcmp.c ft_putnbrbase.c ft_strdup.c ft_strncat.c ft_tolower.c \
ft_atoi.c ft_itoa.c ft_memcpy.c ft_putnbrendl.c ft_strequ.c ft_strncmp.c ft_toupper.c \
ft_atoibase.c ft_lstadd.c ft_memdel.c ft_putnbrendl_fd.c ft_striter.c ft_strncpy.c \
ft_bzero.c ft_lstdel.c ft_memmove.c ft_putstr.c ft_striteri.c ft_strnequ.c \
ft_convertbase.c ft_lstdelone.c ft_memset.c ft_putstr_fd.c ft_strjoin.c ft_strnew.c \
ft_foreach.c ft_lstiter.c ft_putchar.c ft_strcat.c ft_strjoinfree.c ft_strnstr.c \
ft_isalnum.c ft_lstmap.c ft_putchar_fd.c ft_strchr.c ft_strlcat.c ft_strrchr.c \
ft_isalpha.c ft_lstnew.c ft_putendl.c ft_strclr.c ft_strlen.c ft_strsplit.c \
ft_isascii.c ft_memalloc.c ft_putendl_fd.c ft_strcmp.c ft_strmap.c ft_strstr.c
OBJS = $(SRCS:.c=.o)
all: $(NAME)
$(NAME): $(SRCS)
@gcc $(CFLAGS) -c $(SRCS)
@ar -rc $(NAME) $(OBJS)
@ranlib $(NAME)
clean:
@/bin/rm -f $(OBJS)
fclean: clean
@/bin/rm -f $(NAME)
re: fclean all

26
libft/ft_any.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_any.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_any(char **tab, int (*f)(char*))
{
int i;
i = -1;
if (!tab)
return (0);
while (tab[++i])
if (f(tab[i]) == 1)
return (1);
return (0);
}

28
libft/ft_arraymap.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arraymap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int *ft_arraymap(int *tab, int length, int (*f)(int))
{
int i;
int *newtab;
i = -1;
if (!tab)
return (NULL);
if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1))))
return (NULL);
while (++i < length)
newtab[i] = (*f)(tab[i]);
return (newtab);
}

39
libft/ft_atoi.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:04 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:38:12 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long long nbr;
int i;
int n;
i = 0;
n = 1;
nbr = 0;
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '-')
n = -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
if ((nbr >= 922337203685477580
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
return ((n > 0) ? -1 : 0);
else
nbr = nbr * 10 + (str[i++] - '0');
}
return (nbr * n);
}

75
libft/ft_atoibase.c Normal file
View File

@@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoibase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_valid_base(char *base, int i, int j)
{
while (base[i])
{
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (0);
j++;
}
if (base[i] == '-' || base[i] == '+')
return (0);
i++;
}
if (i >= 2)
return (1);
return (0);
}
static int skip(int i, char *str, int *n)
{
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
*n = -1;
i++;
}
return (i);
}
int ft_atoibase(char *str, char *base)
{
int i;
int j;
int length;
int res;
int n;
length = 0;
res = 0;
n = 1;
if (!is_valid_base(base, 0, 0))
return (0);
while (base[length])
length++;
i = skip(0, str, &n);
while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+')
{
j = 0;
while (str[i] != base[j] && base[j])
j++;
if (base[j] == '\0')
return (0);
res = (res * length) + j;
i++;
}
return (res * n);
}

27
libft/ft_bzero.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:19 by hulamy #+# #+# */
/* Updated: 2018/11/15 21:43:05 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
size_t i;
unsigned char *ptr;
if (n)
{
ptr = (unsigned char *)s;
i = 0;
while (i < n)
ptr[i++] = '\0';
}
}

86
libft/ft_convertbase.c Normal file
View File

@@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_convertbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:15:55 by hulamy #+# #+# */
/* Updated: 2019/04/17 17:09:35 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_malloc_size(int decimal, int length, int i)
{
if (decimal <= 0)
i++;
while (decimal)
{
decimal /= length;
i++;
}
return (i);
}
static char *ft_decimal_to_base(int decimal, char *base, char *res, int size)
{
long nb;
int i;
nb = decimal;
i = 0;
while (base[i])
i++;
if (nb < 0)
nb = -nb;
while (--size >= 0)
{
res[size] = base[nb % i];
nb /= i;
}
return (res);
}
static int ft_base_to_decimal(char *nbr, char *base, int length, int i)
{
long decimal;
int j;
decimal = 0;
if (nbr[i] == '-')
i++;
while (nbr[i])
{
j = 0;
while (nbr[i] != base[j] && base[j])
j++;
decimal = (decimal * length) + j;
i++;
}
if (nbr[0] == '-')
decimal = -decimal;
return (decimal);
}
char *ft_convertbase(char *nbr, char *base_from, char *base_to)
{
int length;
int size;
int decimal;
char *res;
res = 0;
length = 0;
while (base_from[length])
length++;
decimal = ft_base_to_decimal(nbr, base_from, length, 0);
length = 0;
while (base_to[length])
length++;
size = ft_malloc_size(decimal, length, 0);
res = (char *)malloc(sizeof(char) * (size + 1));
res[size] = '\0';
return (ft_decimal_to_base(decimal, base_to, res, size));
}

22
libft/ft_foreach.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_foreach.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_foreach(int *tab, int length, void (*f)(int))
{
int i;
i = 0;
while (i < length && tab && tab[i])
(*f)(tab[i++]);
}

18
libft/ft_isalnum.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:33 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:37 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isalpha(c) || ft_isdigit(c));
}

18
libft/ft_isalpha.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:44 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}

18
libft/ft_isascii.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:53 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:55 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
return (c >= 0 && c <= 127);
}

18
libft/ft_isdigit.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:01 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:10:05 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
return (c >= '0' && c <= '9');
}

18
libft/ft_isprint.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:19 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:10:20 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
return (c >= 32 && c < 127);
}

26
libft/ft_issort.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_issort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_issort(int *tab, int length, int (*f)(int, int))
{
int i;
i = -1;
if (!tab)
return (0);
while (++i < length - 1)
if (f(tab[i], tab[i + 1]) > 0)
return (0);
return (1);
}

35
libft/ft_itoa.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:25 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:36:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *str;
int len;
long int nbis;
len = (n < 0) ? 2 : 1;
nbis = n;
while (nbis /= 10)
len++;
nbis = n;
nbis *= (nbis < 0) ? -1 : 1;
if (!(str = ft_strnew(len)))
return (NULL);
str[--len] = nbis % 10 + '0';
while (nbis /= 10)
str[--len] = nbis % 10 + '0';
if (n < 0)
str[0] = '-';
return (str);
}

19
libft/ft_lstadd.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:33 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:58:54 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd(t_list **alst, t_list *new)
{
new->next = *alst;
*alst = new;
}

20
libft/ft_lstdel.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:49 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:59:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
if ((*alst)->next)
ft_lstdel(&(*alst)->next, del);
ft_lstdelone(alst, del);
}

20
libft/ft_lstdelone.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:59 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:59:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
{
del((*alst)->content, (*alst)->content_size);
free(*alst);
*alst = NULL;
}

22
libft/ft_lstiter.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:14 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
{
if (!lst)
return ;
if (lst->next)
ft_lstiter(lst->next, f);
f(lst);
}

35
libft/ft_lstmap.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:20 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:23 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *new;
t_list *tmp;
if (!lst)
return (NULL);
tmp = f(lst);
new = tmp;
while (lst->next)
{
lst = lst->next;
if (!(tmp->next = f(lst)))
{
free(tmp->next);
return (NULL);
}
tmp = tmp->next;
}
return (new);
}

35
libft/ft_lstnew.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:42 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:36 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *lst;
if (!(lst = (t_list *)malloc(sizeof(*lst))))
return (NULL);
if (!content)
{
lst->content = NULL;
lst->content_size = 0;
}
else
{
if (!(lst->content = malloc(content_size)))
return (NULL);
ft_memcpy(lst->content, content, content_size);
lst->content_size = content_size;
}
lst->next = NULL;
return (lst);
}

27
libft/ft_memalloc.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:58 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:42:06 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** allocate size byte of memory and return a pointer to the allocated memory
*/
#include "libft.h"
void *ft_memalloc(size_t size)
{
void *tmp;
if (!(tmp = malloc(size)))
return (NULL);
ft_bzero(tmp, size);
return (tmp);
}

36
libft/ft_memccpy.c Normal file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:12:10 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:42:41 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy string until character is found and place cursor in dst
** after last byte copied
*/
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
unsigned char *dest;
unsigned char *sourc;
size_t i;
i = -1;
dest = (unsigned char *)dst;
sourc = (unsigned char *)src;
while (++i < n)
{
dest[i] = sourc[i];
if (sourc[i] == (unsigned char)c)
return (dst + i + 1);
}
return (NULL);
}

30
libft/ft_memchr.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:12:32 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate character in string and return its position
*/
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *sbis;
size_t i;
sbis = (unsigned char *)s;
i = -1;
while (++i < n)
if (sbis[i] == (unsigned char)c)
return ((void *)sbis + i);
return (NULL);
}

32
libft/ft_memcmp.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:04 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:41 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** compare two bytes strings (doesnt recognize a null terminated string)
** and return value of difference between first two different character
*/
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *frst;
unsigned char *scnd;
size_t i;
i = 0;
frst = (unsigned char *)s1;
scnd = (unsigned char *)s2;
while (i < n && frst[i] == scnd[i])
i++;
return ((i == n) ? 0 : frst[i] - scnd[i]);
}

31
libft/ft_memcpy.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:17 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:56 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n characters from src to dst and return dst
*/
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
char *ptr;
char *ptr2;
ptr = (char *)dst;
ptr2 = (char *)src;
i = -1;
while (++i < n)
ptr[i] = ptr2[i];
return (dst);
}

26
libft/ft_memdel.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** free memory
*/
#include "libft.h"
void ft_memdel(void **ap)
{
if (ap && *ap)
{
free(*ap);
*ap = 0;
}
}

35
libft/ft_memmove.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:34 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:28 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n characters from src to dst in a non destructive way and return dst
*/
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
int i;
char *source;
char *dest;
i = -1;
source = (char *)src;
dest = (char *)dst;
if (source < dest)
while ((int)(--len) >= 0)
dest[len] = source[len];
else
while (++i < (int)len)
dest[i] = source[i];
return (dst);
}

29
libft/ft_memset.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:41 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:44 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n time a character in a string and return the string
*/
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
char *ptr;
size_t i;
ptr = (char *)b;
i = 0;
while (i < len)
ptr[i++] = c;
return (b);
}

18
libft/ft_putchar.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}

18
libft/ft_putchar_fd.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:14 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

19
libft/ft_putendl.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl(char const *s)
{
ft_putstr(s);
ft_putchar('\n');
}

19
libft/ft_putendl_fd.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:47 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:48 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char const *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

18
libft/ft_putnbr.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
ft_putnbr_fd(n, 1);
}

28
libft/ft_putnbr_fd.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:09 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
long l;
l = n;
if (l < 0)
{
ft_putchar_fd('-', fd);
l *= -1;
}
if (l >= 10)
ft_putnbr_fd(l / 10, fd);
ft_putchar_fd((l % 10) + '0', fd);
}

59
libft/ft_putnbrbase.c Normal file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int check(char *base)
{
int i;
int j;
i = 0;
while (base[i])
{
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (0);
j++;
}
if (base[i] == '-' || base[i] == '+')
return (0);
i++;
}
if (i >= 2)
return (1);
return (0);
}
void ft_putnbrbase(int nbr, char *base)
{
int i;
long n;
i = 0;
n = nbr;
if (check(base))
{
if (n < 0)
{
ft_putchar('-');
n = -n;
}
while (base[i])
i++;
if (n >= i)
ft_putnbrbase(n / i, base);
ft_putchar(base[n % i]);
}
}

18
libft/ft_putnbrendl.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */
/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbrendl(int n)
{
ft_putnbrendl_fd(n, 1);
}

29
libft/ft_putnbrendl_fd.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */
/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbrendl_fd(int n, int fd)
{
long l;
l = n;
if (l < 0)
{
ft_putchar_fd('-', fd);
l *= -1;
}
if (l >= 10)
ft_putnbr_fd(l / 10, fd);
ft_putchar_fd((l % 10) + '0', fd);
ft_putchar_fd('\n', fd);
}

22
libft/ft_putstr.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr(char const *s)
{
int i;
i = 0;
while (s && s[i])
ft_putchar(s[i++]);
}

19
libft/ft_putstr_fd.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:31 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:32 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char const *s, int fd)
{
while (s && *s)
ft_putchar_fd(*s++, fd);
}

32
libft/ft_strcat.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:40 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:12:58 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** append src to dest (dest must have sufficient space) and return dest
*/
#include "libft.h"
char *ft_strcat(char *dest, const char *src)
{
int i;
int j;
i = 0;
j = 0;
while (dest[i])
i++;
while (src[j])
dest[i++] = src[j++];
dest[i] = '\0';
return (dest);
}

33
libft/ft_strchr.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:48 by hulamy #+# #+# */
/* Updated: 2019/04/16 17:28:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate the first occurence of character c in string s
** and return pointer to its location
*/
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
int i;
int j;
i = 0;
j = -1;
while (s[i])
i++;
while (++j < i + 1)
if (s[j] == c)
return ((char *)s + j);
return (NULL);
}

23
libft/ft_strclr.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:58 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:17:42 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** fill string with zeros
*/
#include "libft.h"
void ft_strclr(char *s)
{
if (s)
ft_bzero(s, ft_strlen(s));
}

28
libft/ft_strcmp.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:08 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:18:30 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** compare two null terminated strings and return value
** of difference between first two different character
*/
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
int i;
i = 0;
while (s1[i] && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}

28
libft/ft_strcpy.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:17 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:19:19 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy string src to dst including '\0' and return dst
*/
#include "libft.h"
char *ft_strcpy(char *dest, const char *src)
{
int i;
i = -1;
while (src[++i])
dest[i] = src[i];
dest[i] = '\0';
return (dest);
}

26
libft/ft_strdel.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:25 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:19:54 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** free memory
*/
#include "libft.h"
void ft_strdel(char **as)
{
if (as && *as)
{
free(*as);
*as = 0;
}
}

32
libft/ft_strdup.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:32 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:20:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** save a copy of string src by allocating memory and return pointer to copy
*/
#include "libft.h"
char *ft_strdup(const char *src)
{
int i;
char *str;
i = 0;
while (src[i] != '\0')
i++;
if (!(str = (char*)malloc(sizeof(*str) * (i + 1))))
return (NULL);
while (i-- >= 0)
str[i + 1] = src[i + 1];
return (str);
}

24
libft/ft_strequ.c Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:44 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:21:02 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return 0 if strings s1 and s2 are identical and 1 if not
*/
#include "libft.h"
int ft_strequ(char const *s1, char const *s2)
{
if (!s1 || !s2)
return (0);
return (ft_strcmp(s1, s2) == 0);
}

23
libft/ft_striter.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:53 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:21:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** apply function f to each element of string s
*/
#include "libft.h"
void ft_striter(char *s, void (*f)(char *))
{
while (s && *s && f)
f(s++);
}

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