Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa8a80b831 | ||
|
|
0e52943b34 | ||
|
|
602ebf070d | ||
|
|
f1471562f3 | ||
|
|
58490cfb56 | ||
|
|
214dc0dc5c | ||
|
|
47fcd0ec91 | ||
|
|
ee2620e540 | ||
|
|
26a9c9cbac | ||
|
|
d7dc746779 | ||
|
|
c81b7515be | ||
|
|
c007a8299a | ||
|
|
fd696fc499 | ||
|
|
bfe7658388 | ||
|
|
5bdc944da9 | ||
|
|
482861a3c9 | ||
|
|
5d4de7718e | ||
|
|
f29d9d8e60 | ||
|
|
2d06dcf837 | ||
|
|
0c48e90449 | ||
|
|
68bac851e2 | ||
|
|
f79d3812d0 | ||
|
|
56ca478503 | ||
|
|
27afcbe7e9 | ||
|
|
04a4fef38b | ||
|
|
e7e944f1ac | ||
|
|
819a14407d | ||
|
|
2bc1f50b46 | ||
|
|
7a07d84d6c | ||
|
|
0236573b6d | ||
|
|
fb1a41e94f | ||
|
|
6ca294272f | ||
|
|
bfd23d6211 | ||
|
|
fa5f2e7f00 | ||
|
|
246906a490 | ||
|
|
eea8110abd | ||
|
|
79a5fb188c | ||
|
|
59d2be2756 | ||
|
|
c82ba9bccb | ||
|
|
ed06e3eb8e | ||
|
|
2dfe395a9b | ||
|
|
77656ba113 | ||
|
|
a9e62833bb | ||
|
|
6b9936b0cd | ||
|
|
1a16e305d3 | ||
|
|
1811268725 | ||
|
|
184981a28d | ||
|
|
c2e87b7303 | ||
|
|
2dbd5b7320 | ||
|
|
0912e52a7a | ||
|
|
f4b1da414c | ||
|
|
a639da4ac5 | ||
|
|
b9bdc14db7 | ||
|
|
8a62783a6b | ||
|
|
1c6e41e8bf | ||
|
|
3977a73682 | ||
|
|
4a7ad39626 | ||
|
|
fe191054c9 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,4 +12,4 @@ a\.out
|
|||||||
|
|
||||||
fillit
|
fillit
|
||||||
|
|
||||||
test_fillit\.c
|
\.DS_Store
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# 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/17 17:11:53 by hulamy ### ########.fr #
|
# Updated: 2019/06/01 16:57:51 by hulamy ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,7 @@ Le but de ce projet est d’agencer les Tetriminos entre eux pour former le plus
|
|||||||
|
|
||||||
## BONUS
|
## BONUS
|
||||||
- [x] Best error handler (more details on why there is an error.)
|
- [x] Best error handler (more details on why there is an error.)
|
||||||
- [ ] Optimisation
|
- [x] Optimisation (skip when tetri with same shape was already tested on map)
|
||||||
- [ ] Add colors to tetri when printing result map
|
- [x] Add colors to tetri when printing result map
|
||||||
|
- [x] Flag for debbuging (print every step in backtracking)
|
||||||
|
- [x] Adding flags (and password for blocking more args on moulinette)
|
||||||
|
|||||||
106
f_bonus_opti.c
Normal file
106
f_bonus_opti.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* bonus.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/06/01 14:11:32 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Test optimisation for not testing wrong maps when tetri are identical
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_tetri_memory(t_fillist *list, int pos)
|
||||||
|
{
|
||||||
|
t_fillist *tetri;
|
||||||
|
unsigned int mask;
|
||||||
|
|
||||||
|
tetri = list;
|
||||||
|
mask = 1 << ((pos % 32) - 1);
|
||||||
|
if (!tetri->same && !tetri->memory)
|
||||||
|
return(1);
|
||||||
|
if (tetri->same)
|
||||||
|
{
|
||||||
|
if (!(tetri->same->memory[pos / 32] & mask))
|
||||||
|
return (tetri->same->memory[pos / 32] |= mask);
|
||||||
|
}
|
||||||
|
else if (tetri->memory)
|
||||||
|
{
|
||||||
|
if (!(tetri->memory[pos / 32] & mask))
|
||||||
|
return (tetri->memory[pos / 32] |= mask);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Test optimisation for not testing wrong maps when tetri are identical
|
||||||
|
*/
|
||||||
|
|
||||||
|
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
|
||||||
|
{
|
||||||
|
if (tetri_a->same)
|
||||||
|
return (0);
|
||||||
|
if (tetri_a->tetribit != tetri_b->tetribit)
|
||||||
|
return (0);
|
||||||
|
if (tetri_a->width != tetri_b->width)
|
||||||
|
return (0);
|
||||||
|
if (tetri_a->height != tetri_b->height)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that free the list->memory each time it's malloc
|
||||||
|
*/
|
||||||
|
|
||||||
|
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp)
|
||||||
|
{
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
if (tmp->memory)
|
||||||
|
free(tmp->memory);
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Test optimisation for not testing wrong maps when tetri are identical
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_same_tetri(t_fillist *list, int num)
|
||||||
|
{
|
||||||
|
t_fillist *curr_tetri;
|
||||||
|
t_fillist *next_tetri;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
curr_tetri = clean_list_memory(list, list);
|
||||||
|
while (curr_tetri != NULL)
|
||||||
|
{
|
||||||
|
next_tetri = curr_tetri->next;
|
||||||
|
while (next_tetri != NULL)
|
||||||
|
{
|
||||||
|
if (compare_tetri(curr_tetri, next_tetri))
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
if (!(curr_tetri->memory =
|
||||||
|
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
|
||||||
|
return (0);
|
||||||
|
while (i < num)
|
||||||
|
curr_tetri->memory[i++] = 0;
|
||||||
|
next_tetri->same = curr_tetri;
|
||||||
|
}
|
||||||
|
next_tetri = next_tetri->next;
|
||||||
|
}
|
||||||
|
curr_tetri->position = 0;
|
||||||
|
curr_tetri->total_num = num;
|
||||||
|
curr_tetri = curr_tetri->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
79
f_bonus_print.c
Normal file
79
f_bonus_print.c
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* f_bonus_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/06/01 16:26:09 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that print the given tetris if flag p is present
|
||||||
|
*/
|
||||||
|
|
||||||
|
t_fillist *print_tetri(t_fillist *list, int num)
|
||||||
|
{
|
||||||
|
unsigned int print;
|
||||||
|
t_fillist *tmp;
|
||||||
|
|
||||||
|
tmp = list;
|
||||||
|
if (list->dope[2])
|
||||||
|
{
|
||||||
|
check_same_tetri(list, 1);
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
print = tmp->tetribit;
|
||||||
|
print <<= 16;
|
||||||
|
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
|
||||||
|
if (tmp->same && list->dope[1])
|
||||||
|
{
|
||||||
|
ft_putstr("same --> ");
|
||||||
|
ft_put_tetri_color(tmp->same->letter);
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
|
if (list->dope[1] && tmp->memory)
|
||||||
|
ft_putendl("have a copy");
|
||||||
|
ft_putchar('\n');
|
||||||
|
tmp->total = num;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that print the map in binary if flag p is present
|
||||||
|
** it returns anyway the size of the map for main to print it
|
||||||
|
*/
|
||||||
|
|
||||||
|
int print_binary_map(unsigned int *map, int size, int *dope)
|
||||||
|
{
|
||||||
|
size--;
|
||||||
|
if (dope[2])
|
||||||
|
{
|
||||||
|
ft_putendl("result in binary :");
|
||||||
|
print_sized_map(map, size, size, '#');
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
|
free(map);
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that print the flags usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
int print_flags_usage(void)
|
||||||
|
{
|
||||||
|
ft_putendl("flags usage :");
|
||||||
|
ft_putendl("d : debug print (print the map during the backtracking)");
|
||||||
|
ft_putendl("o : optimisation ultra fast but with some errors still");
|
||||||
|
ft_putendl("p : print the tetri and the map in different formats");
|
||||||
|
ft_putendl("e : error msgs more precise AND no error for too much tetri\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* handle_errors.c :+: :+: :+: */
|
/* f_handle_errors.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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/05/03 19:11:02 by vmanzoni ### ########.fr */
|
/* Updated: 2019/06/01 15:53:31 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,31 +16,36 @@
|
|||||||
** Function that display error message *s on fd and exit program
|
** Function that display error message *s on fd and exit program
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void print_error(char *s)
|
void print_error(char *str)
|
||||||
{
|
{
|
||||||
write(2, s, strlen(s));
|
write(1, str, ft_strlen(str));
|
||||||
exit(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function that display error message *s on fd
|
** Function that display error message *s on fd with more informations
|
||||||
** with more informations
|
|
||||||
** and exit program
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void print_error_extended(int error)
|
void print_error_extended(int error, int *dope)
|
||||||
{
|
{
|
||||||
|
if (!dope[3])
|
||||||
|
print_error("error\n");
|
||||||
if (error == 1)
|
if (error == 1)
|
||||||
ft_putstr("error: File contains char other than . # \\n found.\n");
|
print_error("error: File contains char other than '.','#' and '\\n'\n");
|
||||||
if (error == 2)
|
if (error == 2)
|
||||||
ft_putstr("error: File contains more than 2 \\n in a row.\n");
|
print_error("error: File contains two tetriminos not"
|
||||||
|
"separated by a '\\n'\n");
|
||||||
if (error == 3)
|
if (error == 3)
|
||||||
ft_putstr("error: File contains less than 1 tetrimino or more than 26.\n");
|
print_error("error: File contains more than 2 '\\n' in a row\n");
|
||||||
if (error == 4)
|
if (error == 4)
|
||||||
ft_putstr("\n\nerror: This tetrimino has more or less than 4 #.\n");
|
print_error("error: File contains less than 1 tetrimino\n");
|
||||||
if (error == 5)
|
if (error == 5)
|
||||||
ft_putstr("\n\nerror: This tetrimino # are not well connected.\n");
|
print_error("error: File contains more than 26 tetriminos\n");
|
||||||
exit(1);
|
if (error == 6)
|
||||||
|
print_error("error: Tetrimino has more or less than 4 #\n");
|
||||||
|
if (error == 7)
|
||||||
|
print_error("error: Tetrimino # are not all connected\n");
|
||||||
|
print_error("error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -50,7 +55,7 @@ void print_error_extended(int error)
|
|||||||
** - two \n in a row
|
** - two \n in a row
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int check_file_errors(char *file)
|
void check_file_errors(char *file, int *dope)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int line_nbr;
|
int line_nbr;
|
||||||
@@ -60,17 +65,22 @@ int check_file_errors(char *file)
|
|||||||
while (file[i])
|
while (file[i])
|
||||||
{
|
{
|
||||||
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
|
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
|
||||||
return (1);
|
print_error_extended(1, dope);
|
||||||
if (file[i] == '\n')
|
else if (file[i] == '\n')
|
||||||
line_nbr++;
|
line_nbr++;
|
||||||
if (file[i] == '\n' && file[i+1] != '\0' && \
|
if (file[i] == '\n' && line_nbr % 5 == 0 && file[i - 1] != '\n')
|
||||||
file[i+2] != '.' && file[i+2] != '#')
|
print_error_extended(2, dope);
|
||||||
return (2);
|
if (file[i] == '\n' && file[i + 1] != '\0' && \
|
||||||
|
file[i + 2] != '.' && file[i + 2] != '#')
|
||||||
|
print_error_extended(3, dope);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (line_nbr < 4 || line_nbr > 129)
|
if (file[i - 1] == '\n')
|
||||||
return (3);
|
print_error_extended(3, dope);
|
||||||
return (0);
|
if (line_nbr < 4)
|
||||||
|
print_error_extended(4, dope);
|
||||||
|
if (!dope[3] && line_nbr > 129)
|
||||||
|
print_error_extended(5, dope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -97,7 +107,7 @@ int check_tetri_errors(char *tetri)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri))
|
if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri))
|
||||||
return (4 + check_tetri_errors_proxy(tetri));
|
return (6 + check_tetri_errors_proxy(tetri));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,17 +118,21 @@ int check_tetri_errors(char *tetri)
|
|||||||
int check_tetri_errors_proxy(char *tetri)
|
int check_tetri_errors_proxy(char *tetri)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
j = 0;
|
||||||
while (tetri[i])
|
while (tetri[i])
|
||||||
{
|
{
|
||||||
if (tetri[i] == '.' || tetri[i] == '\n')
|
if (i < 19 && tetri[i] == '#' && tetri[i + 1] == '#')
|
||||||
i++;
|
j++;
|
||||||
else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#'
|
if (i > 0 && tetri[i] == '#' && tetri[i - 1] == '#')
|
||||||
|| tetri[i + 5] == '#' || tetri[i - 5] == '#'))
|
j++;
|
||||||
i++;
|
if (i < 15 && tetri[i] == '#' && tetri[i + 5] == '#')
|
||||||
else
|
j++;
|
||||||
return (1);
|
if (i > 4 && tetri[i] == '#' && tetri[i - 5] == '#')
|
||||||
|
j++;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return ((j < 6) ? 1 : 0);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/16 15:30:57 by hulamy ### ########.fr */
|
/* Updated: 2019/06/01 13:32:38 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -44,10 +44,7 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
|
|||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
|
|
||||||
// cree un mask avec des 1 a gauche sur la largeur du tetriminos
|
|
||||||
mask = ~0u << (32 - width) >> 16;
|
mask = ~0u << (32 - width) >> 16;
|
||||||
// fabrique la ligne pour le tetriminos de la bonne largeur
|
|
||||||
tmp = tetri;
|
|
||||||
tmp = (mask & tetri);
|
tmp = (mask & tetri);
|
||||||
tmp |= ((mask & tetri << 4) >> width);
|
tmp |= ((mask & tetri << 4) >> width);
|
||||||
tmp |= ((mask & tetri << 8) >> (2 * width));
|
tmp |= ((mask & tetri << 8) >> (2 * width));
|
||||||
@@ -58,18 +55,27 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
|
|||||||
/*
|
/*
|
||||||
** Function that transforme a tetriminos char* into a short of 16 bites
|
** Function that transforme a tetriminos char* into a short of 16 bites
|
||||||
** and then fills it and its reversed into the list
|
** and then fills it and its reversed into the list
|
||||||
|
**
|
||||||
|
** 1) transforme la ligne de . et # en un short de 0 et 1
|
||||||
|
** 2) cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
|
||||||
|
** 3) utilise le mask pour trouver la largeur que prend le tetriminos
|
||||||
|
** 4) deplace le tetriminos tout en haut a gauche
|
||||||
|
** (i - list->width = le nombre de colonne vide a gauche)
|
||||||
|
** 5) trouve la hauteur du tetri
|
||||||
|
** 6) fabrique la ligne pour le tetriminos de la bonne largeur
|
||||||
|
**
|
||||||
|
** list->test is used to debug the backtracking, allowing to print the
|
||||||
|
** map each time without the previous tries
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fill_list(char line[], t_fillist *list)
|
void fill_list(char line[], t_fillist *list)
|
||||||
{
|
{
|
||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// transforme la ligne de . et # en un short de 0 et 1
|
|
||||||
list->tetribit = tab_to_bin(line);
|
list->tetribit = tab_to_bin(line);
|
||||||
// cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
|
list->memory = 0;
|
||||||
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
|
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
|
||||||
// utilise le mask pour trouver la largeur que prend le tetriminos
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (!(mask & list->tetribit) && i++ < 4)
|
while (!(mask & list->tetribit) && i++ < 4)
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
@@ -77,20 +83,16 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
while (mask & list->tetribit && ++i < 4)
|
while (mask & list->tetribit && ++i < 4)
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
list->width = i - list->width;
|
list->width = i - list->width;
|
||||||
// deplace le tetriminos tout en haut a gauche
|
|
||||||
//(i - list->width = le nombre de colonne vide a gauche)
|
|
||||||
list->tetribit <<= (i - list->width);
|
list->tetribit <<= (i - list->width);
|
||||||
while (!(list->tetribit & (~0u << 12)))
|
while (!(list->tetribit & (~0u << 12)))
|
||||||
list->tetribit <<= 4;
|
list->tetribit <<= 4;
|
||||||
// trouve la hauteur du tetri
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
|
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
|
||||||
i++;
|
i++;
|
||||||
list->height = i;
|
list->height = i;
|
||||||
// fabrique la ligne pour le tetriminos de la bonne largeur
|
|
||||||
list->tetribit = reduce_tetri(list->tetribit, list->width);
|
list->tetribit = reduce_tetri(list->tetribit, list->width);
|
||||||
list->position = 0;
|
list->same = NULL;
|
||||||
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
|
list->test = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -98,7 +100,7 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
** linked each time needed
|
** linked each time needed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int add_to_list(char *line, t_fillist **list, char letter)
|
int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
|
||||||
{
|
{
|
||||||
t_fillist *tmp;
|
t_fillist *tmp;
|
||||||
t_fillist *test;
|
t_fillist *test;
|
||||||
@@ -106,17 +108,20 @@ int add_to_list(char *line, t_fillist **list, char letter)
|
|||||||
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
|
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
|
||||||
return (0);
|
return (0);
|
||||||
tmp->next = NULL;
|
tmp->next = NULL;
|
||||||
test = *list;
|
test = *lst;
|
||||||
if (!test)
|
if (!test)
|
||||||
*list = tmp;
|
*lst = tmp;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while(test->next)
|
while (test->next)
|
||||||
test = test->next;
|
test = test->next;
|
||||||
test->next = tmp;
|
test->next = tmp;
|
||||||
}
|
}
|
||||||
fill_list(line, tmp);
|
fill_list(line, tmp);
|
||||||
tmp->letter = letter;
|
tmp->letter = letter;
|
||||||
|
tmp->dope = dope;
|
||||||
|
tmp->start = *lst;
|
||||||
|
tmp->memory = NULL;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,13 +129,13 @@ int add_to_list(char *line, t_fillist **list, char letter)
|
|||||||
** Function that parse a file and put each tetrimino in a linked list
|
** Function that parse a file and put each tetrimino in a linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void parse_input(char *input)
|
int parse_input(char *input, t_fillist **list, int *dope)
|
||||||
{
|
{
|
||||||
static t_fillist *list = NULL;
|
|
||||||
char tetri[20];
|
char tetri[20];
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int letter;
|
int letter;
|
||||||
|
int size;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
letter = 'A';
|
letter = 'A';
|
||||||
@@ -141,14 +146,11 @@ void parse_input(char *input)
|
|||||||
tetri[j++] = input[i++];
|
tetri[j++] = input[i++];
|
||||||
tetri[19] = '\0';
|
tetri[19] = '\0';
|
||||||
if (check_tetri_errors(tetri))
|
if (check_tetri_errors(tetri))
|
||||||
{
|
print_error_extended(check_tetri_errors(tetri), dope);
|
||||||
ft_putstr(tetri);
|
add_to_list(tetri, list, letter++, dope);
|
||||||
print_error_extended(check_tetri_errors(tetri));
|
|
||||||
//print_error("\n\nerror: This tetrimino is not valid.\n");
|
|
||||||
}
|
|
||||||
add_to_list(tetri, &list, letter++);
|
|
||||||
while (input[i] && input[i] != '.' && input[i] != '#')
|
while (input[i] && input[i] != '.' && input[i] != '#')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
search_map(list);
|
size = search_map(*list);
|
||||||
|
return (size);
|
||||||
}
|
}
|
||||||
122
f_print.c
Normal file
122
f_print.c
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* f_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/06/01 13:56:50 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that print a map of height and width
|
||||||
|
** useful to print tetris
|
||||||
|
*/
|
||||||
|
|
||||||
|
void print_sized_map(unsigned int *tab, int width, int height, char letter)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned int mask;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
mask = 0;
|
||||||
|
while (i++ < width)
|
||||||
|
mask = (mask >> 1) | ((mask | 1) << 31);
|
||||||
|
i = 0;
|
||||||
|
while (i < width * height)
|
||||||
|
{
|
||||||
|
if (i && !(i % width))
|
||||||
|
ft_putchar('\n');
|
||||||
|
if (tab[i / 32] & (1 << (31 - i % 32)))
|
||||||
|
ft_put_tetri_color(letter);
|
||||||
|
else
|
||||||
|
ft_putchar('.');
|
||||||
|
ft_putchar(' ');
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
write(1, "\n", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Print the final map with the letters
|
||||||
|
** if flag value is 0 -> print moulinette version
|
||||||
|
** if flag value is p -> print in color
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *init_print_map(t_fillist *list, int size)
|
||||||
|
{
|
||||||
|
char *map;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
if (!(map = (char *)malloc(sizeof(*map) * (size * size + 1))))
|
||||||
|
return (NULL);
|
||||||
|
map[size * size] = '\0';
|
||||||
|
i = -1;
|
||||||
|
while (++i < size * size)
|
||||||
|
map[i] = '.';
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
i = -1;
|
||||||
|
while (++i < list->width * list->height)
|
||||||
|
{
|
||||||
|
if (i && i % list->width == 0)
|
||||||
|
j += size - list->width;
|
||||||
|
if (1 << (15 - i) & list->tetribit && list->test == 1)
|
||||||
|
map[list->position + i + j - 1] = list->letter;
|
||||||
|
}
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return (map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that print the map with color if flag = 1
|
||||||
|
** or for moulinette if flag = 0;
|
||||||
|
*/
|
||||||
|
|
||||||
|
void print_letter_map(t_fillist *list, int size, int flag)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *map;
|
||||||
|
|
||||||
|
map = init_print_map(list, size);
|
||||||
|
i = -1;
|
||||||
|
while (++i < size * size)
|
||||||
|
{
|
||||||
|
if (i && i % size == 0)
|
||||||
|
ft_putchar('\n');
|
||||||
|
if (flag == 0)
|
||||||
|
ft_putchar(map[i]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_put_tetri_color(map[i]);
|
||||||
|
ft_putchar(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ft_putchar('\n');
|
||||||
|
free(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that print the map
|
||||||
|
*/
|
||||||
|
|
||||||
|
void print_final_map(t_fillist *list, int size)
|
||||||
|
{
|
||||||
|
if (list->dope[2])
|
||||||
|
{
|
||||||
|
ft_putendl("result for humans :");
|
||||||
|
print_letter_map(list, size, 1);
|
||||||
|
ft_putchar('\n');
|
||||||
|
ft_putendl("result for moulinette :");
|
||||||
|
}
|
||||||
|
print_letter_map(list, size, 0);
|
||||||
|
if (list->dope[2])
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
@@ -6,73 +6,46 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/05/03 20:27:22 by vmanzoni #+# #+# */
|
/* Created: 2019/05/03 20:27:22 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/04 19:15:35 by vmanzoni ### ########.fr */
|
/* Updated: 2019/06/01 14:27:30 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
void ft_putchar(char c)
|
void ft_putchar_color(char c, char color)
|
||||||
{
|
{
|
||||||
write(1, &c, 1);
|
if (color == 'R')
|
||||||
}
|
write(1, RED, 5);
|
||||||
|
else if (color == 'B')
|
||||||
void ft_putchar_red(char c)
|
write(1, BLU, 5);
|
||||||
{
|
else if (color == 'G')
|
||||||
write(1, RED, 5);
|
write(1, GRN, 5);
|
||||||
ft_putchar(c);
|
else if (color == 'Y')
|
||||||
write(1, RESET, 5);
|
write(1, YEL, 5);
|
||||||
}
|
else if (color == 'M')
|
||||||
|
write(1, MAG, 5);
|
||||||
void ft_putchar_blue(char c)
|
else if (color == 'C')
|
||||||
{
|
write(1, CYN, 5);
|
||||||
write(1, BLU, 5);
|
else if (color == 'W' || !c)
|
||||||
ft_putchar(c);
|
write(1, RESET, 5);
|
||||||
write(1, RESET, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putchar_green(char c)
|
|
||||||
{
|
|
||||||
write(1, GRN, 5);
|
|
||||||
ft_putchar(c);
|
|
||||||
write(1, RESET, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putchar_yellow(char c)
|
|
||||||
{
|
|
||||||
write(1, YEL, 5);
|
|
||||||
ft_putchar(c);
|
|
||||||
write(1, RESET, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putchar_magenta(char c)
|
|
||||||
{
|
|
||||||
write(1, MAG, 5);
|
|
||||||
ft_putchar(c);
|
|
||||||
write(1, RESET, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putchar_cyan(char c)
|
|
||||||
{
|
|
||||||
write(1, CYN, 5);
|
|
||||||
ft_putchar(c);
|
ft_putchar(c);
|
||||||
write(1, RESET, 5);
|
write(1, RESET, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_put_tetri_color(char c)
|
void ft_put_tetri_color(char c)
|
||||||
{
|
{
|
||||||
if (c == 'A' || c == 'G' || c == 'M' || c == 'S')
|
if (c == 'A' || c == 'G' || c == 'M' || c == 'S' || c == 'Y')
|
||||||
ft_putchar_red(c);
|
ft_putchar_color(c, 'R');
|
||||||
else if (c == 'B' || c == 'H' || c == 'N' || c == 'T' || c == 'Y')
|
else if (c == 'B' || c == 'H' || c == 'N' || c == 'T' || c == 'Z')
|
||||||
ft_putchar_blue(c);
|
ft_putchar_color(c, 'B');
|
||||||
else if (c == 'C' || c == 'I' || c == 'O' || c == 'U' || c == 'Z')
|
else if (c == 'C' || c == 'I' || c == 'O' || c == 'U')
|
||||||
ft_putchar_green(c);
|
ft_putchar_color(c, 'G');
|
||||||
else if (c == 'D' || c == 'J' || c == 'P' || c == 'V')
|
else if (c == 'D' || c == 'J' || c == 'P' || c == 'V')
|
||||||
ft_putchar_yellow(c);
|
ft_putchar_color(c, 'Y');
|
||||||
else if (c == 'E' || c == 'K' || c == 'Q' || c == 'W')
|
else if (c == 'E' || c == 'K' || c == 'Q' || c == 'W')
|
||||||
ft_putchar_magenta(c);
|
ft_putchar_color(c, 'M');
|
||||||
else if (c == 'F' || c == 'L' || c == 'R' || c == 'X')
|
else if (c == 'F' || c == 'L' || c == 'R' || c == 'X')
|
||||||
ft_putchar_cyan(c);
|
ft_putchar_color(c, 'C');
|
||||||
else
|
else
|
||||||
ft_putchar(c);
|
ft_putchar(c);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/22 15:16:18 by vmanzoni ### ########.fr */
|
/* Updated: 2019/06/01 15:12:03 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,17 +18,17 @@
|
|||||||
|
|
||||||
char *read_file(char *file)
|
char *read_file(char *file)
|
||||||
{
|
{
|
||||||
char buf[BUFF_SIZE];
|
char buf[BUFF_SIZE];
|
||||||
int fd;
|
int fd;
|
||||||
int rv;
|
int rv;
|
||||||
int i;
|
int i;
|
||||||
char *result;
|
char *result;
|
||||||
|
|
||||||
if (((fd = open(file, O_RDONLY)) < 0) \
|
if (((fd = open(file, O_RDONLY)) < 0) \
|
||||||
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|
||||||
|| !(result = malloc(sizeof(char) * rv)))
|
|| !(result = malloc(sizeof(char) * rv)))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
buf[rv] = '\0';
|
buf[rv - 1] = '\0';
|
||||||
i = -1;
|
i = -1;
|
||||||
while (buf[++i])
|
while (buf[++i])
|
||||||
result[i] = buf[i];
|
result[i] = buf[i];
|
||||||
@@ -36,3 +36,15 @@ char *read_file(char *file)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that init num and size for search_map
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init_num_and_size(int num, int *size, t_fillist *tmp)
|
||||||
|
{
|
||||||
|
while ((tmp = tmp->next))
|
||||||
|
num++;
|
||||||
|
while (*size * *size < num * 4)
|
||||||
|
(*size)++;
|
||||||
|
}
|
||||||
247
f_search_map.c
Normal file
247
f_search_map.c
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* f_search_map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/06/01 15:12:08 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that look if a tretri fit in a place
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int sze, int i)
|
||||||
|
{
|
||||||
|
unsigned int tmp;
|
||||||
|
unsigned int mask;
|
||||||
|
unsigned int tetri;
|
||||||
|
int n;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
n = lst->num;
|
||||||
|
r = lst->rank;
|
||||||
|
i = lst->height;
|
||||||
|
tetri = lst->tetribit << 16 >> lst->width;
|
||||||
|
tmp = 0;
|
||||||
|
mask = ~0u << (32 - lst->width);
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
if (tmp & tetri)
|
||||||
|
return (0);
|
||||||
|
if (r >= 32 && ++n)
|
||||||
|
r -= 32;
|
||||||
|
tmp = (mask & (map[n] << r));
|
||||||
|
if (n + 1 < lst->total_num)
|
||||||
|
tmp |= (mask & (map[n + 1] >> (32 - r)));
|
||||||
|
tetri <<= lst->width;
|
||||||
|
r += sze;
|
||||||
|
}
|
||||||
|
return (!(tmp & tetri));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that look for the first place in the map for a tetri
|
||||||
|
*/
|
||||||
|
|
||||||
|
int find_place(unsigned int *map, t_fillist *list, int size)
|
||||||
|
{
|
||||||
|
int limit;
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
pos = list->position;
|
||||||
|
list->place = pos % size;
|
||||||
|
list->rank = pos % 32;
|
||||||
|
list->num = pos / 32;
|
||||||
|
limit = (size - list->height + 1) * size;
|
||||||
|
while (pos < limit)
|
||||||
|
{
|
||||||
|
if (list->rank >= 32 && ++list->num)
|
||||||
|
list->rank -= 32;
|
||||||
|
if (list->place > size - list->width)
|
||||||
|
{
|
||||||
|
list->place = -1;
|
||||||
|
pos += list->width - 2;
|
||||||
|
list->rank += list->width - 2;
|
||||||
|
}
|
||||||
|
else if (fit_in_place(map, list, size, 0))
|
||||||
|
return ((list->position = pos + 1));
|
||||||
|
pos++;
|
||||||
|
list->place++;
|
||||||
|
list->rank++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** function that add or remove a tetri on the map
|
||||||
|
*/
|
||||||
|
|
||||||
|
void add_remove(unsigned int *map, t_fillist *list, int size)
|
||||||
|
{
|
||||||
|
unsigned int msk;
|
||||||
|
unsigned short tetri;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
tetri = list->tetribit;
|
||||||
|
msk = ~0u << (32 - list->width);
|
||||||
|
i = (list->height - 1) * list->width;
|
||||||
|
j = (list->height - 1) * size + list->position;
|
||||||
|
while (j >= list->position)
|
||||||
|
{
|
||||||
|
map[(j - 1) / 32] ^= (msk & tetri << (16 + i)) >> (j - 1);
|
||||||
|
if ((j - 1) / 32 + 1 < list->total_num)
|
||||||
|
map[(j - 1) / 32 + 1] ^= (msk & tetri << (16 + i)) << (32 - j) << 1;
|
||||||
|
j -= size;
|
||||||
|
i -= list->width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that try to place every tetri in the left places
|
||||||
|
** to know if it worth it to continue to check in this order
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_others(unsigned int *map, t_fillist *list, int size, int num)
|
||||||
|
{
|
||||||
|
t_fillist *tmp;
|
||||||
|
int dots;
|
||||||
|
int total;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
dots = 0;
|
||||||
|
i = -1;
|
||||||
|
num *= 4;
|
||||||
|
total = size * size;
|
||||||
|
while (++i < total && dots <= total - num)
|
||||||
|
{
|
||||||
|
tmp = list->next;
|
||||||
|
j = 1;
|
||||||
|
while (1 << (i % 32) & map[i % 32])
|
||||||
|
i++;
|
||||||
|
while (j && tmp)
|
||||||
|
{
|
||||||
|
if (tmp->width > (size - i % size) || (total - i) <= (tmp->height * size))
|
||||||
|
tmp = tmp->next;
|
||||||
|
else if (!fit_in_place(map, list, size, i))
|
||||||
|
tmp = tmp->next;
|
||||||
|
else
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
if (j)
|
||||||
|
dots++;
|
||||||
|
}
|
||||||
|
return (dots > total - num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that supress the memory of already placed tetri
|
||||||
|
** when a next one is placed before them
|
||||||
|
** because then they might fit where they already tried
|
||||||
|
*/
|
||||||
|
|
||||||
|
void clean_memory(t_fillist *list, int pos, int mem)
|
||||||
|
{
|
||||||
|
t_fillist *tmp;
|
||||||
|
unsigned int mask;
|
||||||
|
|
||||||
|
tmp = list->start;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
if (tmp->memory)
|
||||||
|
{
|
||||||
|
pos = mem;
|
||||||
|
while (pos >= list->position)
|
||||||
|
{
|
||||||
|
mask = ~(1 << ((pos % 32) - 1));
|
||||||
|
tmp->memory[pos / 32] &= mask;
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that recursively try to fill the map with the tetris
|
||||||
|
*/
|
||||||
|
|
||||||
|
int fill_map(unsigned int *map, t_fillist *list, int size)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return (1);
|
||||||
|
pos = list->position;
|
||||||
|
list->position = 0;
|
||||||
|
while (find_place(map, list, size))
|
||||||
|
{
|
||||||
|
if (list->position < pos)
|
||||||
|
clean_memory(list, pos, pos);
|
||||||
|
add_remove(map, list, size);
|
||||||
|
list->test = 1;
|
||||||
|
if (list->dope[0])
|
||||||
|
{
|
||||||
|
print_letter_map(list->start, size, 1);
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
|
if (list->dope[1])
|
||||||
|
if (check_tetri_memory(list, list->position))
|
||||||
|
// if (check_others(map, list, size, list->total))
|
||||||
|
if (fill_map(map, list->next, size))
|
||||||
|
return (1);
|
||||||
|
if (!list->dope[1])
|
||||||
|
if (fill_map(map, list->next, size))
|
||||||
|
return (1);
|
||||||
|
add_remove(map, list, size);
|
||||||
|
list->test = 0;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that send to "fill_map" a map of a certain size
|
||||||
|
** and increment its size untill it's solved
|
||||||
|
*/
|
||||||
|
|
||||||
|
int search_map(t_fillist *list)
|
||||||
|
{
|
||||||
|
t_fillist *tmp;
|
||||||
|
unsigned int *map;
|
||||||
|
int size;
|
||||||
|
int num;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
size = 2;
|
||||||
|
|
||||||
|
num = 1;
|
||||||
|
tmp = list;
|
||||||
|
while ((tmp = tmp->next))
|
||||||
|
num++;
|
||||||
|
|
||||||
|
tmp = print_tetri(list, num);
|
||||||
|
init_num_and_size(1, &size, tmp);
|
||||||
|
i = 0;
|
||||||
|
while (!i)
|
||||||
|
{
|
||||||
|
num = (size * size) / 32 + 1;
|
||||||
|
if (!(map = (unsigned int *)malloc(sizeof(*map) * num)))
|
||||||
|
return (0);
|
||||||
|
check_same_tetri(list, num);
|
||||||
|
if (list->dope[2])
|
||||||
|
ft_putnbrendl(size);
|
||||||
|
while (num--)
|
||||||
|
map[num] = 0;
|
||||||
|
i = fill_map(map, list, size++);
|
||||||
|
if (!i)
|
||||||
|
free(map);
|
||||||
|
}
|
||||||
|
return (print_binary_map(map, size, list->dope));
|
||||||
|
}
|
||||||
20
fillit.dSYM/Contents/Info.plist
Normal file
20
fillit.dSYM/Contents/Info.plist
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?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>
|
||||||
134
fillit.h
134
fillit.h
@@ -6,19 +6,19 @@
|
|||||||
/* 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/05/17 17:03:35 by hulamy ### ########.fr */
|
/* Updated: 2019/06/01 15:12:00 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FILLIT_H
|
#ifndef FILLIT_H
|
||||||
# define FILLIT_H
|
# define FILLIT_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#include <unistd.h> // for system call write
|
# include <unistd.h>
|
||||||
#include <fcntl.h> // for system call open
|
# include <fcntl.h>
|
||||||
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
# include <stdbool.h>
|
||||||
|
|
||||||
#include "libft/includes/libft.h"
|
# include "libft/includes/libft.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DEFINE
|
** DEFINE
|
||||||
@@ -26,19 +26,33 @@
|
|||||||
|
|
||||||
# define BUFF_SIZE 1024
|
# define BUFF_SIZE 1024
|
||||||
|
|
||||||
#define RED "\x1B[31m"
|
# define RED "\x1B[31m"
|
||||||
#define GRN "\x1B[32m"
|
# define GRN "\x1B[32m"
|
||||||
#define YEL "\x1B[33m"
|
# define YEL "\x1B[33m"
|
||||||
#define BLU "\x1B[34m"
|
# define BLU "\x1B[34m"
|
||||||
#define MAG "\x1B[35m"
|
# define MAG "\x1B[35m"
|
||||||
#define CYN "\x1B[36m"
|
# define CYN "\x1B[36m"
|
||||||
#define RESET "\x1B[0m"
|
# define RESET "\x1B[0m"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** STRUCTURE
|
** STRUCTURE
|
||||||
|
** tetribit : tetri ecrit en binaire dans un short de 16 bits
|
||||||
|
** width : largeur du tetri
|
||||||
|
** height : hauteur du tetri
|
||||||
|
** position : memorise la position d tetri bit a bit
|
||||||
|
** place : position sur l'axe des abscisses de la map (position % size)
|
||||||
|
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
|
||||||
|
** num : memorise dans quel int du tableau on se trouve (position / 32)
|
||||||
|
** total_num: memorise le nombre d'int dans le tableau
|
||||||
|
** test :
|
||||||
|
** letter : letter of the tetrimino for printing final map
|
||||||
|
** dope : flags for details, optimisation, printing and error
|
||||||
|
** memory : positions already tested by a tetrimino in bitwise
|
||||||
|
** same : pointer to previous identical tetrimino
|
||||||
|
** next : pointer to next tetrimino
|
||||||
|
** start : pointer to first tetrimino of input file
|
||||||
*/
|
*/
|
||||||
|
typedef struct s_fillist
|
||||||
typedef struct s_fillist
|
|
||||||
{
|
{
|
||||||
unsigned short tetribit;
|
unsigned short tetribit;
|
||||||
int width;
|
int width;
|
||||||
@@ -47,29 +61,85 @@ typedef struct s_fillist
|
|||||||
int place;
|
int place;
|
||||||
int rank;
|
int rank;
|
||||||
int num;
|
int num;
|
||||||
|
int total_num;
|
||||||
int test;
|
int test;
|
||||||
|
int total;
|
||||||
char letter;
|
char letter;
|
||||||
|
int *dope;
|
||||||
|
unsigned int *memory;
|
||||||
|
struct s_fillist *same;
|
||||||
struct s_fillist *next;
|
struct s_fillist *next;
|
||||||
} t_fillist;
|
struct s_fillist *start;
|
||||||
|
} t_fillist;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** FUNCTIONS
|
** bonus_opti.c
|
||||||
*/
|
*/
|
||||||
|
int check_tetri_memory(t_fillist *list, int pos);
|
||||||
|
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b);
|
||||||
|
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp);
|
||||||
|
int check_same_tetri(t_fillist *list, int num);
|
||||||
|
|
||||||
char *read_file(char *file);
|
/*
|
||||||
void print_error(char *s);
|
** bonus_print.c
|
||||||
void print_error_extended(int error);
|
*/
|
||||||
void parse_input(char *input);
|
t_fillist *print_tetri(t_fillist *list, int num);
|
||||||
int check_file_errors(char *file);
|
int print_binary_map(unsigned int *map, int size, int *dope);
|
||||||
int check_tetri_errors(char *tetri);
|
int print_flags_usage(void);
|
||||||
int check_tetri_errors_proxy(char *tetri);
|
|
||||||
int add_to_list(char *square, t_fillist **list, char letter);
|
/*
|
||||||
void fill_list(char line[], t_fillist *list);
|
** main.c
|
||||||
void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL
|
*/
|
||||||
void print_tetri(unsigned int bits, int size); //TO DELETE BEFORE EVAL
|
int *create_dope(char *av, int mdp);
|
||||||
int search_map(t_fillist *list);
|
int is_mdp(int ac, char **av);
|
||||||
void print_map(unsigned int *tab, int width, int height, char letter);
|
void clean_list(t_fillist *list, t_fillist *tmp);
|
||||||
void print_final_map(t_fillist *list, int size);
|
int main(int argc, char **argv);
|
||||||
void ft_put_tetri_color(char c);
|
|
||||||
|
/*
|
||||||
|
** read_file.c
|
||||||
|
*/
|
||||||
|
char *read_file(char *file);
|
||||||
|
void init_num_and_size(int num, int *size, t_fillist *tmp);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** handle_errors.c
|
||||||
|
*/
|
||||||
|
void print_error(char *s);
|
||||||
|
void print_error_extended(int error, int *dope);
|
||||||
|
void check_file_errors(char *file, int *dope);
|
||||||
|
int check_tetri_errors(char *tetri);
|
||||||
|
int check_tetri_errors_proxy(char *tetri);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** parse_input.c
|
||||||
|
*/
|
||||||
|
unsigned short tab_to_bin(char line[]);
|
||||||
|
unsigned short reduce_tetri(unsigned short tetri, int width);
|
||||||
|
void fill_list(char line[], t_fillist *list);
|
||||||
|
int add_to_list(char *sqr, t_fillist **lst, char lett, int *dope);
|
||||||
|
int parse_input(char *input, t_fillist **list, int *dope);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** search_map.c
|
||||||
|
*/
|
||||||
|
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int siz, int i);
|
||||||
|
int find_place(unsigned int *map, t_fillist *list, int size);
|
||||||
|
void add_remove(unsigned int *map, t_fillist *list, int size);
|
||||||
|
int fill_map(unsigned int *map, t_fillist *list, int size);
|
||||||
|
int search_map(t_fillist *list);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** print.c
|
||||||
|
*/
|
||||||
|
void print_sized_map(unsigned int *tab, int wdth, int hgt, char ltr);
|
||||||
|
char *init_print_map(t_fillist *list, int size);
|
||||||
|
void print_letter_map(t_fillist *list, int size, int flag);
|
||||||
|
void print_final_map(t_fillist *list, int size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** print_map_with_colors.c
|
||||||
|
*/
|
||||||
|
void ft_putchar_color(char c, char color);
|
||||||
|
void ft_put_tetri_color(char c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
223
libft/Makefile
Normal file
223
libft/Makefile
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
##
|
||||||
|
# # ------------------------------------------------------
|
||||||
|
# # utiliser le makefile pour creer une librairie statique
|
||||||
|
# # ------------------------------------------------------
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## - - - - - - - -
|
||||||
|
## compiler des .o
|
||||||
|
## - - - - - - - -
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## quand on ecrit un programme il contient un main et les
|
||||||
|
## fonctions dont le main a besoin (ex ft_putchar) :
|
||||||
|
##
|
||||||
|
### #include <unistd.h>
|
||||||
|
###
|
||||||
|
### void ft_putchar(char c)
|
||||||
|
### {
|
||||||
|
### write(1, &c, 1);
|
||||||
|
### }
|
||||||
|
###
|
||||||
|
### int main()
|
||||||
|
### {
|
||||||
|
### ft_putchar('0');
|
||||||
|
### return (0);
|
||||||
|
### }
|
||||||
|
##
|
||||||
|
## on peut compiler ce fichier avec gcc en faisant :
|
||||||
|
## gcc file.c
|
||||||
|
## et ca sort un executable a.out
|
||||||
|
## si on l'execute "./a.out" ca ecrit 0 dans la console
|
||||||
|
##
|
||||||
|
## mais pour ne pas reecrire a chaque fois ft_putchar
|
||||||
|
## on peut la mettre dans une librairie qu'on inclue dans
|
||||||
|
## le fichier qui l'utilise...
|
||||||
|
## si on sort ft_putchar du fichier :
|
||||||
|
##
|
||||||
|
### int main()
|
||||||
|
### {
|
||||||
|
### ft_putchar('0');
|
||||||
|
### return (0);
|
||||||
|
### }
|
||||||
|
##
|
||||||
|
## et qu'on l'execute "gcc file.c" on va avoir une erreur
|
||||||
|
## car file.c utilise ft_putchar mais gcc ne sait pas ce
|
||||||
|
## que c'est, donc il faut qu'on le rajoute a la compilation
|
||||||
|
## on peut par exemple l'ecrire dans un fichier ft_putchar.c
|
||||||
|
##
|
||||||
|
### #include <unistd.h>
|
||||||
|
###
|
||||||
|
### void ft_putchar(char c)
|
||||||
|
### {
|
||||||
|
### write(1, &c, 1);
|
||||||
|
### }
|
||||||
|
##
|
||||||
|
## et compiler les deux :
|
||||||
|
## gcc file.c ft_putchar.c
|
||||||
|
##
|
||||||
|
## ca fonctionne mais gcc doit a chaque fois recompiler
|
||||||
|
## ft_putchar.c alors qu'il n'est pas modifie, donc on peut
|
||||||
|
## le compiler une bonne fois pour toute et le rajouter a la
|
||||||
|
## compilation finale quand on en a besoin sans que l'ordi
|
||||||
|
## ait a tout retraduire dans son langage
|
||||||
|
##
|
||||||
|
## mais si on essaye de compiler ft_putchar seul
|
||||||
|
## gcc ft_putchar.c
|
||||||
|
## ca nous donne une erreur car pour compiler, gcc a besoin
|
||||||
|
## de trouver un main !
|
||||||
|
##
|
||||||
|
## on va donc utiliser l'option -c pour
|
||||||
|
## creer une fichier objet .o qui est deja traduit en langue
|
||||||
|
## d'ordinateur et pret a etre rajoute a la compilation :
|
||||||
|
## gcc -c ft_putchar.c --> donne ft_putchar.o
|
||||||
|
## qu'on peut compiler avec le fichier qui contient le main :
|
||||||
|
##
|
||||||
|
## gcc file.c ft_putchar.o
|
||||||
|
##
|
||||||
|
## on a nos bouts de codes comme ft_putchar.o dans des fichiers
|
||||||
|
## objets prets a etre ajoutes a la compilation du main
|
||||||
|
##
|
||||||
|
## on va maintenant voir comment faire une libraire qui contien
|
||||||
|
## tous nos fichiers objets
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## - - - - - - - -
|
||||||
|
## creer une lib.a
|
||||||
|
## - - - - - - - -
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## pour mettre tous les fichiers .o dans un seul fichier .a
|
||||||
|
## on utilise un programme d'archive ar avec les options rc
|
||||||
|
## r indique d'inserer les .o en remplacant si necessaire
|
||||||
|
## c de creer une nouvelle archive
|
||||||
|
## le nom de l'archive doit commencer par lib et finir en .a :
|
||||||
|
## ar rc nom_de_l'archive fichier_1.o fichier_2.o etc
|
||||||
|
##
|
||||||
|
## ar rc libtest.a ft_putchar.o
|
||||||
|
##
|
||||||
|
## on obtient un fichier libtest.a qui contient les fichiers
|
||||||
|
## objets .o
|
||||||
|
##
|
||||||
|
## on peut l'utiliser a la compilation de cette manniere :
|
||||||
|
##
|
||||||
|
## gcc file.c -L. -ltest
|
||||||
|
##
|
||||||
|
## -L indique ou est la librairie (ici elle est dans le
|
||||||
|
## dossier courant .)
|
||||||
|
## -l indique son nom ("test" car on n'indique pas lib et .a)
|
||||||
|
##
|
||||||
|
##
|
||||||
|
# # -----------------------------------------------
|
||||||
|
# # ecrire un make file pour aider a la compilation
|
||||||
|
# # -----------------------------------------------
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## exemple d'un makefilede basic
|
||||||
|
##
|
||||||
|
### NAME = libtest.h
|
||||||
|
### CC = gcc
|
||||||
|
### CFLAGS = -I. -c
|
||||||
|
### SRCS = example01.c \
|
||||||
|
### example02.c
|
||||||
|
### OBJ = $(SRCS:.c=.o) |ecrit les fichiers .c en .o
|
||||||
|
###
|
||||||
|
### all: $(NAME) |make execute sa premiere regle NAME
|
||||||
|
### $(NAME): $(OBJ) |NAME execute d'abord OBJ
|
||||||
|
### ar -rc $@ $< |
|
||||||
|
##
|
||||||
|
## Make a des built-in pattern rules :
|
||||||
|
## https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
|
||||||
|
## par exemple pour construire des .o a partir de .c
|
||||||
|
## qui sont utilisees par défaut si les variables
|
||||||
|
## sont bien nomee (genre CC ou CFLAGS)
|
||||||
|
##
|
||||||
|
## cependant si on veut mettre les fichiers .o dans un
|
||||||
|
## sous-fichier BUILDS il n'y a pas de built-in pattern
|
||||||
|
## il faut donc l'ecrire nous-meme :
|
||||||
|
##
|
||||||
|
### NAME = libtest.h
|
||||||
|
### CC = gcc
|
||||||
|
### CFLAGS = -I.
|
||||||
|
### SRCS = example01.c \
|
||||||
|
### example02.c
|
||||||
|
### ODIR = ./builds
|
||||||
|
### OBJS = $(addprefix $(ODIR)/, $(SRCS:.c=.o))
|
||||||
|
###
|
||||||
|
### all: $(NAME)
|
||||||
|
### $(NAME): $(OBJS)
|
||||||
|
### ar -rc $@ $<
|
||||||
|
###
|
||||||
|
### $(ODIR)/%.o : %.c
|
||||||
|
### $(COMPILE.c) -o $@ $<
|
||||||
|
##
|
||||||
|
## cette regle est appellee par $(OBJS) puisque
|
||||||
|
## cette variable appelle la regle $(ODIR/file.o)
|
||||||
|
##
|
||||||
|
## COMPILE est une built-in variable qui execute
|
||||||
|
## les regles CC et CFLAGS avec l'option -c
|
||||||
|
##
|
||||||
|
## % = "tout"
|
||||||
|
## $@ = "la valeur a gauche de :"
|
||||||
|
## $< = "la premiere valeur a droite de :"
|
||||||
|
## $^ = "toutes les valeurs a droite de :"
|
||||||
|
##
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------- #
|
||||||
|
# #
|
||||||
|
# variables modifiables #
|
||||||
|
# #
|
||||||
|
# ----------------------------------------------------------- #
|
||||||
|
|
||||||
|
NAME = libft.a
|
||||||
|
|
||||||
|
DEPS = libft.h
|
||||||
|
|
||||||
|
SDIR = ./src
|
||||||
|
ODIR = ./build
|
||||||
|
IDIR = ./includes
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall -Wextra -Werror -I$(IDIR)
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------- #
|
||||||
|
# #
|
||||||
|
# ne pas modifier en dessous #
|
||||||
|
# #
|
||||||
|
# ----------------------------------------------------------- #
|
||||||
|
|
||||||
|
## SUB_SDIR sera utilise pour creer les sous dossiers :
|
||||||
|
## avec mkdir -p ODIR/subdir1 ODIR/subdir2 ODIR/subdir3 etc...
|
||||||
|
## find $(SDIR) cherche recursivement tous le contenu de SDIR
|
||||||
|
## -type d ne trouve que les dossiers, pas les fichiers
|
||||||
|
## -mindepth 1 ne liste pas le dossier SDIR
|
||||||
|
## subst transform arg1 en arg2 dans arg3
|
||||||
|
|
||||||
|
SUB_SDIR = $(shell find $(SDIR) -mindepth 1 -type d)
|
||||||
|
SRC = $(shell find $(SDIR) -type f -not -name '.*' -name '*.c')
|
||||||
|
OBJ = $(subst $(SDIR), $(ODIR), $(SRC:.c=.o))
|
||||||
|
|
||||||
|
all: $(ODIR) $(NAME)
|
||||||
|
|
||||||
|
$(ODIR):
|
||||||
|
mkdir -p $(subst $(SDIR), $(ODIR), $(SUB_SDIR))
|
||||||
|
|
||||||
|
$(ODIR)/%.o: $(SDIR)/%.c
|
||||||
|
$(COMPILE.c) -o $@ $<
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
ar -rc $@ $^
|
||||||
|
@ranlib $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
/bin/rm -rf $(ODIR)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
/bin/rm -f $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
101
libft/includes/libft.h
Normal file
101
libft/includes/libft.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:22:07 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/04/07 14:22:04 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
# include <string.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int ft_atoi(const char *str);
|
||||||
|
void ft_bzero(void *s, size_t n);
|
||||||
|
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);
|
||||||
|
void *ft_memccpy(void *dst, const void *restrict src,
|
||||||
|
int c, size_t n);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||||
|
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||||
|
void *ft_memset(void *b, int c, size_t len);
|
||||||
|
char *ft_strcat(char *s1, const char *s2);
|
||||||
|
char *ft_strchr(const char *s, int c);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
char *ft_strcpy(char *dst, const char *src);
|
||||||
|
char *ft_strdup(const char *s1);
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
size_t ft_strlen(const char *str);
|
||||||
|
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||||
|
char *ft_strnstr(const char *big, const char *little,
|
||||||
|
size_t len);
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
char *ft_strstr(const char *big, const char *little);
|
||||||
|
int ft_tolower(int c);
|
||||||
|
int ft_toupper(int c);
|
||||||
|
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
void *ft_memalloc(size_t size);
|
||||||
|
void ft_memdel(void **ap);
|
||||||
|
void ft_putchar(char c);
|
||||||
|
void ft_putchar_fd(char c, int fd);
|
||||||
|
void ft_putendl(char const *str);
|
||||||
|
void ft_putendl_fd(char const *s, int fd);
|
||||||
|
void ft_putnbr(int nbr);
|
||||||
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
void ft_putstr(char const *str);
|
||||||
|
void ft_putstr_fd(char const *s, int fd);
|
||||||
|
void ft_strclr(char *s);
|
||||||
|
void ft_strdel(char **as);
|
||||||
|
int ft_strequ(char const *s1, char const *s2);
|
||||||
|
void ft_striter(char *s, void (*f)(char *));
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strjoinfree(char *s1, char *s2);
|
||||||
|
char *ft_strmap(char const *s, char (*f)(char));
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
|
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||||
|
char *ft_strnew(size_t size);
|
||||||
|
char **ft_strsplit(char const *s, char c);
|
||||||
|
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strtrim(char const *s);
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
size_t content_size;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
t_list *ft_lstnew(const void *content, size_t content_size);
|
||||||
|
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||||
|
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||||
|
void ft_lstadd(t_list **alst, t_list *n);
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||||
|
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||||
|
|
||||||
|
void ft_putnbrbase(int nbr, char *base);
|
||||||
|
int ft_atoibase(char *str, char *base);
|
||||||
|
char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
||||||
|
char **ft_strmultisplit(char *str, char *charset);
|
||||||
|
int ft_any(char **tab, int (*f)(char*));
|
||||||
|
void ft_foreach(int *tab, int length, void (*f)(int));
|
||||||
|
int ft_issort(int *tab, int length, int (*f)(int, int));
|
||||||
|
int *ft_arraymap(int *tab, int length, int(*f)(int));
|
||||||
|
void ft_putnbrendl(int n);
|
||||||
|
void ft_putnbrendl_fd(int n, int fd);
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
libft/libft.a
Normal file
BIN
libft/libft.a
Normal file
Binary file not shown.
18
libft/src/is/ft_isalnum.c
Normal file
18
libft/src/is/ft_isalnum.c
Normal 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/src/is/ft_isalpha.c
Normal file
18
libft/src/is/ft_isalpha.c
Normal 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/src/is/ft_isascii.c
Normal file
18
libft/src/is/ft_isascii.c
Normal 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/src/is/ft_isdigit.c
Normal file
18
libft/src/is/ft_isdigit.c
Normal 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/src/is/ft_isprint.c
Normal file
18
libft/src/is/ft_isprint.c
Normal 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/src/is/ft_issort.c
Normal file
26
libft/src/is/ft_issort.c
Normal 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);
|
||||||
|
}
|
||||||
19
libft/src/lst/ft_lstadd.c
Normal file
19
libft/src/lst/ft_lstadd.c
Normal 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/src/lst/ft_lstdel.c
Normal file
20
libft/src/lst/ft_lstdel.c
Normal 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/src/lst/ft_lstdelone.c
Normal file
20
libft/src/lst/ft_lstdelone.c
Normal 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/src/lst/ft_lstiter.c
Normal file
22
libft/src/lst/ft_lstiter.c
Normal 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/src/lst/ft_lstmap.c
Normal file
35
libft/src/lst/ft_lstmap.c
Normal 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/src/lst/ft_lstnew.c
Normal file
35
libft/src/lst/ft_lstnew.c
Normal 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/src/mem/ft_memalloc.c
Normal file
27
libft/src/mem/ft_memalloc.c
Normal 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/src/mem/ft_memccpy.c
Normal file
36
libft/src/mem/ft_memccpy.c
Normal 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/src/mem/ft_memchr.c
Normal file
30
libft/src/mem/ft_memchr.c
Normal 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/src/mem/ft_memcmp.c
Normal file
32
libft/src/mem/ft_memcmp.c
Normal 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/src/mem/ft_memcpy.c
Normal file
31
libft/src/mem/ft_memcpy.c
Normal 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/src/mem/ft_memdel.c
Normal file
26
libft/src/mem/ft_memdel.c
Normal 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/src/mem/ft_memmove.c
Normal file
35
libft/src/mem/ft_memmove.c
Normal 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/src/mem/ft_memset.c
Normal file
29
libft/src/mem/ft_memset.c
Normal 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);
|
||||||
|
}
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* print_fillit.c :+: :+: :+: */
|
/* ft_putchar.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:35:48 by vmanzoni #+# #+# */
|
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/04/16 16:41:46 by vmanzoni ### ########.fr */
|
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "libft.h"
|
||||||
|
|
||||||
/*
|
void ft_putchar(char c)
|
||||||
void ft_print_fillit()
|
|
||||||
{
|
{
|
||||||
|
write(1, &c, 1);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
18
libft/src/put/ft_putchar_fd.c
Normal file
18
libft/src/put/ft_putchar_fd.c
Normal 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/src/put/ft_putendl.c
Normal file
19
libft/src/put/ft_putendl.c
Normal 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/src/put/ft_putendl_fd.c
Normal file
19
libft/src/put/ft_putendl_fd.c
Normal 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/src/put/ft_putnbr.c
Normal file
18
libft/src/put/ft_putnbr.c
Normal 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/src/put/ft_putnbr_fd.c
Normal file
28
libft/src/put/ft_putnbr_fd.c
Normal 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/src/put/ft_putnbrbase.c
Normal file
59
libft/src/put/ft_putnbrbase.c
Normal 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/src/put/ft_putnbrendl.c
Normal file
18
libft/src/put/ft_putnbrendl.c
Normal 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/src/put/ft_putnbrendl_fd.c
Normal file
29
libft/src/put/ft_putnbrendl_fd.c
Normal 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/src/put/ft_putstr.c
Normal file
22
libft/src/put/ft_putstr.c
Normal 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/src/put/ft_putstr_fd.c
Normal file
19
libft/src/put/ft_putstr_fd.c
Normal 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/src/str/ft_strcat.c
Normal file
32
libft/src/str/ft_strcat.c
Normal 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/src/str/ft_strchr.c
Normal file
33
libft/src/str/ft_strchr.c
Normal 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/src/str/ft_strclr.c
Normal file
23
libft/src/str/ft_strclr.c
Normal 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/src/str/ft_strcmp.c
Normal file
28
libft/src/str/ft_strcmp.c
Normal 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/src/str/ft_strcpy.c
Normal file
28
libft/src/str/ft_strcpy.c
Normal 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/src/str/ft_strdel.c
Normal file
26
libft/src/str/ft_strdel.c
Normal 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/src/str/ft_strdup.c
Normal file
32
libft/src/str/ft_strdup.c
Normal 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/src/str/ft_strequ.c
Normal file
24
libft/src/str/ft_strequ.c
Normal 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/src/str/ft_striter.c
Normal file
23
libft/src/str/ft_striter.c
Normal 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++);
|
||||||
|
}
|
||||||
26
libft/src/str/ft_striteri.c
Normal file
26
libft/src/str/ft_striteri.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striteri.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:17:04 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:21:27 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** apply function f to each element of string s with index specified
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s && *s && f)
|
||||||
|
f(i++, s++);
|
||||||
|
}
|
||||||
54
libft/src/str/ft_strjoin.c
Normal file
54
libft/src/str/ft_strjoin.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:17:12 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:31:03 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string by concatenating the two strings s1 and s2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static char *ft_doit(char const *s1, char const *s2, char *dest)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
while (s1[j] != '\0')
|
||||||
|
{
|
||||||
|
dest[i] = s1[j];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
|
while (s2[j] != '\0')
|
||||||
|
{
|
||||||
|
dest[i] = s2[j];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (NULL);
|
||||||
|
if (!(str = (char *)malloc(sizeof(char) *
|
||||||
|
(ft_strlen(s1) + ft_strlen(s2) + 1))))
|
||||||
|
return (NULL);
|
||||||
|
str = ft_doit(s1, s2, str);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
28
libft/src/str/ft_strjoinfree.c
Normal file
28
libft/src/str/ft_strjoinfree.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoinfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/05 15:05:28 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:22:28 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string by concatenating the two strings s1
|
||||||
|
** and s2 then freeing them
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoinfree(char *s1, char *s2)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!(str = ft_strjoin(s1, s2)))
|
||||||
|
return (NULL);
|
||||||
|
free(s1);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
@@ -1,35 +1,38 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* get_smallest_square.c :+: :+: :+: */
|
/* ft_strlcat.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */
|
/* Created: 2018/11/14 21:17:22 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/04/27 15:04:46 by vmanzoni ### ########.fr */
|
/* Updated: 2019/03/25 15:22:42 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function to bruteforce with backtracking for smallest square
|
** append src to sized dest and return size of final dest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int *get_smallest_square(t_fillist list, int size, unsigned int map[])
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||||
{
|
{
|
||||||
unsigned int mask;
|
size_t i;
|
||||||
int i;
|
size_t j;
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
mask = map[size];
|
j = 0;
|
||||||
while (list.tetribit != NULL)
|
while (dest[i] && i < size)
|
||||||
{
|
|
||||||
mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32)));
|
|
||||||
if (!(tetri & mask))
|
|
||||||
return (1);
|
|
||||||
i++;
|
i++;
|
||||||
|
while (src[j])
|
||||||
|
{
|
||||||
|
if (j + i < size - 1 && size)
|
||||||
|
{
|
||||||
|
dest[i + j] = src[j];
|
||||||
|
dest[i + j + 1] = '\0';
|
||||||
|
}
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (i + j);
|
||||||
}
|
}
|
||||||
27
libft/src/str/ft_strlen.c
Normal file
27
libft/src/str/ft_strlen.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:17:32 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:23:00 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return length of of string
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *str)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
32
libft/src/str/ft_strmap.c
Normal file
32
libft/src/str/ft_strmap.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:17:49 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:23:12 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new array with the result of function f on every element of s
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmap(char const *s, char (*f)(char))
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
if (!(str = ft_strnew(ft_strlen(s))))
|
||||||
|
return (NULL);
|
||||||
|
i = -1;
|
||||||
|
while (s[++i])
|
||||||
|
str[i] = f(s[i]);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
33
libft/src/str/ft_strmapi.c
Normal file
33
libft/src/str/ft_strmapi.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:18:03 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:28:21 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new array with the result of function f
|
||||||
|
** on every element of s by index i
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
if (!(str = ft_strnew(ft_strlen(s))))
|
||||||
|
return (NULL);
|
||||||
|
i = -1;
|
||||||
|
while (s[++i])
|
||||||
|
str[i] = f(i, s[i]);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
83
libft/src/str/ft_strmultisplit.c
Normal file
83
libft/src/str/ft_strmultisplit.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmultisplit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:18:29 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:23:57 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return an array of string with each word found in str
|
||||||
|
** with any character of charset difining a separator
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int ft_is_separator(char c, char *charset, int i)
|
||||||
|
{
|
||||||
|
while (charset[i])
|
||||||
|
{
|
||||||
|
if (c == charset[i])
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
c = charset[i];
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_count(char *str, int word, char **tab, char *charset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
k = 0;
|
||||||
|
i = 0;
|
||||||
|
while (ft_is_separator(str[k], charset, 0) == 1)
|
||||||
|
k++;
|
||||||
|
while (str[k] != '\0' && i != word)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (!ft_is_separator(str[k + j], charset, 0) && str[k + j] != '\0')
|
||||||
|
{
|
||||||
|
if (word == -2)
|
||||||
|
tab[i][j] = str[k + j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
k += j;
|
||||||
|
while (ft_is_separator(str[k], charset, 0))
|
||||||
|
k++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (word == -1)
|
||||||
|
return (i);
|
||||||
|
return (j);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_strmultisplit(char *str, char *charset)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
k = 0;
|
||||||
|
tab = 0;
|
||||||
|
i = ft_count(str, -1, tab, charset);
|
||||||
|
if (!(tab = (char**)malloc(sizeof(tab) * (i + 1))))
|
||||||
|
return (NULL);
|
||||||
|
tab[i] = 0;
|
||||||
|
while (k < i)
|
||||||
|
{
|
||||||
|
j = ft_count(str, k + 1, tab, charset);
|
||||||
|
tab[k] = (char*)malloc(sizeof(*tab) * (j + 1));
|
||||||
|
tab[k][j] = '\0';
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
ft_count(str, -2, tab, charset);
|
||||||
|
return (tab);
|
||||||
|
}
|
||||||
32
libft/src/str/ft_strncat.c
Normal file
32
libft/src/str/ft_strncat.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:18:24 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:24:11 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** append n character of src to dest and return dest
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strncat(char *dest, const char *src, size_t nb)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (dest[i])
|
||||||
|
i++;
|
||||||
|
while (src[j] && j < nb)
|
||||||
|
dest[i++] = src[j++];
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
32
libft/src/str/ft_strncmp.c
Normal file
32
libft/src/str/ft_strncmp.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:18:34 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:24:35 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** compare size first character of two null terminated strings
|
||||||
|
** and return value of difference between first two different character
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
res = 0;
|
||||||
|
while (s1[i] && s1[i] == s2[i] && i < n - 1)
|
||||||
|
i++;
|
||||||
|
if (n != 0)
|
||||||
|
res = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
30
libft/src/str/ft_strncpy.c
Normal file
30
libft/src/str/ft_strncpy.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:18:44 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:24:59 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy n characters from string src to dst including '\0'
|
||||||
|
** if space remain it's filled zith '\0', and return dst
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strncpy(char *dest, const char *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (++i < n && src[i])
|
||||||
|
dest[i] = src[i];
|
||||||
|
while (i < n)
|
||||||
|
dest[i++] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
25
libft/src/str/ft_strnequ.c
Normal file
25
libft/src/str/ft_strnequ.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnequ.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:18:55 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:25:20 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return 0 if n first character of strings s1 and s2 are identical
|
||||||
|
** and 1 if not
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||||
|
{
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (0);
|
||||||
|
return (ft_strncmp(s1, s2, n) == 0);
|
||||||
|
}
|
||||||
27
libft/src/str/ft_strnew.c
Normal file
27
libft/src/str/ft_strnew.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnew.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:08 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:25:38 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string of length size, fill with zero, and return pointer to it
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strnew(size_t size)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!(str = (char *)malloc(sizeof(char) * (size + 1))))
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(str, size + 1);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
42
libft/src/str/ft_strnstr.c
Normal file
42
libft/src/str/ft_strnstr.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:16 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:25:57 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** locate the first occurence of the string little in len first characters
|
||||||
|
** of big and return a pointer to this occurence if found
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
if (!ft_strlen(little))
|
||||||
|
return ((char *)big);
|
||||||
|
while (i == 0 && j <= len)
|
||||||
|
{
|
||||||
|
while (little[i] == big[j + i] && little[i] && j + i <= len)
|
||||||
|
i++;
|
||||||
|
if (little[i])
|
||||||
|
{
|
||||||
|
j++;
|
||||||
|
if (!big[j] || j >= len)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((char *)big + j);
|
||||||
|
}
|
||||||
32
libft/src/str/ft_strrchr.c
Normal file
32
libft/src/str/ft_strrchr.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strrchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:23 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:26:21 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** locate the last occurence of character c in string s
|
||||||
|
** and return pointer to its location
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strrchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
i++;
|
||||||
|
while (i--)
|
||||||
|
if (s[i] == c)
|
||||||
|
return ((char *)s + i);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
62
libft/src/str/ft_strsplit.c
Normal file
62
libft/src/str/ft_strsplit.c
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strsplit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:36 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:26:39 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return an array of string with each word found in str, with c as separator
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int ft_count_word(char const *s, char c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
len = 0;
|
||||||
|
while (s[++i])
|
||||||
|
if (s[i] != c)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
while (s[i] && s[i] != c)
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_strsplit(char const *s, char c)
|
||||||
|
{
|
||||||
|
char **array;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
j = 0;
|
||||||
|
if (!s || !c)
|
||||||
|
return (0);
|
||||||
|
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
|
||||||
|
return (NULL);
|
||||||
|
while (s[++i])
|
||||||
|
{
|
||||||
|
if (s[i] != c)
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
while (s[i + len] && s[i + len] != c)
|
||||||
|
len++;
|
||||||
|
array[j++] = ft_strsub(s, i, len);
|
||||||
|
i = i + len - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array[j] = 0;
|
||||||
|
return (array);
|
||||||
|
}
|
||||||
42
libft/src/str/ft_strstr.c
Normal file
42
libft/src/str/ft_strstr.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:45 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:26:59 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** locate the first occurence of the string little in big
|
||||||
|
** and return a pointer to this occurence if found
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strstr(const char *str, const char *to_find)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
if (!ft_strlen(to_find))
|
||||||
|
return ((char *)str);
|
||||||
|
while (i == 0)
|
||||||
|
{
|
||||||
|
while (to_find[i] && to_find[i] == str[j + i])
|
||||||
|
i++;
|
||||||
|
if (to_find[i])
|
||||||
|
{
|
||||||
|
j++;
|
||||||
|
if (str[j] == '\0' && to_find[i])
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((char *)str + j);
|
||||||
|
}
|
||||||
32
libft/src/str/ft_strsub.c
Normal file
32
libft/src/str/ft_strsub.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strsub.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:19:52 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:27:14 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a copy of a portion of s, begining at start and of length len
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
if (!(str = ft_strnew(len)))
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < len)
|
||||||
|
str[i++] = s[start++];
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
35
libft/src/str/ft_strtrim.c
Normal file
35
libft/src/str/ft_strtrim.c
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtrim.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:20:09 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:12:04 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a copy of s without the firsts and lasts empty characters
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strtrim(char const *s)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
while (*s == ' ' || *s == '\t' || *s == '\n')
|
||||||
|
s++;
|
||||||
|
len = ft_strlen(s) - 1;
|
||||||
|
while (len >= 0 && (s[len] == ' ' || s[len] == '\t' || s[len] == '\n'))
|
||||||
|
len--;
|
||||||
|
len++;
|
||||||
|
if (!(str = ft_strsub(s, 0, len)))
|
||||||
|
return (NULL);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
26
libft/src/tab/ft_any.c
Normal file
26
libft/src/tab/ft_any.c
Normal 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/src/tab/ft_arraymap.c
Normal file
28
libft/src/tab/ft_arraymap.c
Normal 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);
|
||||||
|
}
|
||||||
22
libft/src/tab/ft_foreach.c
Normal file
22
libft/src/tab/ft_foreach.c
Normal 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++]);
|
||||||
|
}
|
||||||
39
libft/src/trsf/ft_atoi.c
Normal file
39
libft/src/trsf/ft_atoi.c
Normal 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/src/trsf/ft_atoibase.c
Normal file
75
libft/src/trsf/ft_atoibase.c
Normal 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/src/trsf/ft_bzero.c
Normal file
27
libft/src/trsf/ft_bzero.c
Normal 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/src/trsf/ft_convertbase.c
Normal file
86
libft/src/trsf/ft_convertbase.c
Normal 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));
|
||||||
|
}
|
||||||
35
libft/src/trsf/ft_itoa.c
Normal file
35
libft/src/trsf/ft_itoa.c
Normal 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);
|
||||||
|
}
|
||||||
20
libft/src/trsf/ft_tolower.c
Normal file
20
libft/src/trsf/ft_tolower.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:20:19 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:20:20 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
return (c + 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
20
libft/src/trsf/ft_toupper.c
Normal file
20
libft/src/trsf/ft_toupper.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:20:26 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:20:27 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'a' && c <= 'z')
|
||||||
|
return (c - 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
109
main.c
109
main.c
@@ -6,30 +6,109 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/03 19:12:47 by vmanzoni ### ########.fr */
|
/* Updated: 2019/06/01 15:27:22 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
/*
|
||||||
{
|
** Function that put the flags for bonus into a tab of int
|
||||||
char *input;
|
**
|
||||||
|
** d : debug print (print the map during the backtracking)
|
||||||
|
** o : optimisation ultra fast but with some errors still
|
||||||
|
** p : print extended (print the tetri and the map in different formats)
|
||||||
|
** e : error extended (message more precise AND no error if too much tetri)
|
||||||
|
*/
|
||||||
|
|
||||||
if (argc == 2)
|
int *create_dope(char *av, int mdp)
|
||||||
|
{
|
||||||
|
char *comp;
|
||||||
|
int *dope;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
comp = "dope";
|
||||||
|
if (!(dope = (int*)malloc(sizeof(*dope) * 4)))
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (i < 4)
|
||||||
|
dope[i++] = 0;
|
||||||
|
if (!mdp)
|
||||||
|
return (dope);
|
||||||
|
i = -1;
|
||||||
|
while (++i < 4 && (j = -1))
|
||||||
|
while (av[++j])
|
||||||
|
if (comp[i] == av[j])
|
||||||
|
dope[i] = 1;
|
||||||
|
return (dope);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that check if the password is good to unlock the flags
|
||||||
|
*/
|
||||||
|
|
||||||
|
int is_mdp(int ac, char **av)
|
||||||
|
{
|
||||||
|
char *mdp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (ac < 3 || ac > 4)
|
||||||
|
return (0);
|
||||||
|
mdp = "trompette";
|
||||||
|
i = 0;
|
||||||
|
while (av[2][i] && mdp[i] && mdp[i] == av[2][i])
|
||||||
|
i++;
|
||||||
|
if (av[2][i] || mdp[i])
|
||||||
|
return (0);
|
||||||
|
if (ac == 3)
|
||||||
|
return (print_flags_usage());
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that free the list
|
||||||
|
*/
|
||||||
|
|
||||||
|
void clean_list(t_fillist *list, t_fillist *tmp)
|
||||||
|
{
|
||||||
|
tmp = list;
|
||||||
|
while (list)
|
||||||
{
|
{
|
||||||
if (!(input = read_file(argv[1])))
|
list = tmp->next;
|
||||||
print_error("error: Could not read file.\n");
|
free(tmp->memory);
|
||||||
if (check_file_errors(input))
|
free(tmp);
|
||||||
print_error_extended(check_file_errors(input));
|
tmp = list;
|
||||||
// print_error("error: Invalid file.\n");
|
}
|
||||||
parse_input(input);
|
}
|
||||||
/*
|
|
||||||
Backtracking for smallest square
|
/*
|
||||||
Transform tetriminos with letters & Print result
|
** Main function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
t_fillist *list;
|
||||||
|
char *input;
|
||||||
|
int *dope;
|
||||||
|
int size;
|
||||||
|
int mdp;
|
||||||
|
|
||||||
|
list = NULL;
|
||||||
|
mdp = is_mdp(ac, av);
|
||||||
|
dope = create_dope(av[3], mdp);
|
||||||
|
if (ac == 2 || mdp)
|
||||||
|
{
|
||||||
|
if (!(input = read_file(av[1])))
|
||||||
|
print_error(dope[3] ? "error: Could not read file.\n" : "error\n");
|
||||||
|
check_file_errors(input, dope);
|
||||||
|
size = parse_input(input, &list, dope);
|
||||||
|
print_final_map(list, size);
|
||||||
|
free(input);
|
||||||
|
clean_list(list, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");
|
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");
|
||||||
|
free(dope);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
124
print.c
124
print.c
@@ -1,124 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* print.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
|
|
||||||
/* Updated: 2019/05/16 15:52:52 by hulamy ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "fillit.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
|
||||||
** Prints a ligne of size bits
|
|
||||||
*/
|
|
||||||
|
|
||||||
void print_bits(unsigned int bits, int size)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
|
|
||||||
mask = 1 << (size - 1);
|
|
||||||
while (mask)
|
|
||||||
{
|
|
||||||
(bits & mask) ? write(1, "#", 1) : write(1, ".", 1);
|
|
||||||
write(1, " ", 1);
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
write(1, "\n", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
|
||||||
** Prints a tetri from its bit form
|
|
||||||
*/
|
|
||||||
|
|
||||||
void print_tetri(unsigned int bits, int size)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
short i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
mask = 1 << (size - 1);
|
|
||||||
while (mask)
|
|
||||||
{
|
|
||||||
if (i % 4 == 0)
|
|
||||||
write(1, "\n", 1);
|
|
||||||
(bits & mask) ? write(1, "#", 1) : write(1, ".", 1);
|
|
||||||
write(1, " ", 1);
|
|
||||||
mask >>= 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
write(1, "\n", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
|
||||||
** Print a map of height and width
|
|
||||||
*/
|
|
||||||
|
|
||||||
void print_map(unsigned int *tab, int width, int height, char letter)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
unsigned int mask;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
mask = 0;
|
|
||||||
while (i++ < width)
|
|
||||||
mask = (mask >> 1) | ((mask | 1) << 31);
|
|
||||||
i = 0;
|
|
||||||
while (i < width * height)
|
|
||||||
{
|
|
||||||
if (i && !(i % width))
|
|
||||||
ft_putchar('\n');
|
|
||||||
tab[i / 32] & (1 << (31 - i % 32)) ? ft_put_tetri_color(letter) : ft_putchar('.');
|
|
||||||
ft_putchar(' ');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
write(1, "\n", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Print the final map with the letters
|
|
||||||
*/
|
|
||||||
|
|
||||||
void print_final_map(t_fillist *list, int size)
|
|
||||||
{
|
|
||||||
// unsigned int print; // DEBUG
|
|
||||||
t_fillist *tmp;
|
|
||||||
char *map;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
map = (char *)malloc(sizeof(*map) * (size * size + 1));
|
|
||||||
map[size*size] = '\0';
|
|
||||||
i = -1;
|
|
||||||
while (++i < size * size)
|
|
||||||
map[i] = '.';
|
|
||||||
tmp = list;
|
|
||||||
while (tmp)
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
i = -1;
|
|
||||||
while (++i < tmp->width * tmp->height)
|
|
||||||
{
|
|
||||||
if (i && i % tmp->width == 0)
|
|
||||||
j += size - tmp->width;
|
|
||||||
if (1 << (15 - i) & tmp->tetribit/* && tmp->test == 1*/) // DEBUG "&& tmp->position != -1" pour imprimer les bonnes lettres au coours du debug
|
|
||||||
map[tmp->position + i + j - 1] = tmp->letter;
|
|
||||||
}
|
|
||||||
tmp = tmp->next;
|
|
||||||
}
|
|
||||||
i = -1;
|
|
||||||
while (++i < size * size)
|
|
||||||
{
|
|
||||||
if (i && i % size == 0)
|
|
||||||
ft_putchar('\n');
|
|
||||||
ft_put_tetri_color(map[i]);
|
|
||||||
ft_putchar(' ');
|
|
||||||
}
|
|
||||||
ft_putchar('\n');
|
|
||||||
}
|
|
||||||
79
samples/16square
Normal file
79
samples/16square
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
129
samples/26square
Normal file
129
samples/26square
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
19
samples/4square
Normal file
19
samples/4square
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
24
samples/5square
Normal file
24
samples/5square
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
44
samples/9square
Normal file
44
samples/9square
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
89
samples/debug/jdugoudr
Normal file
89
samples/debug/jdugoudr
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
84
samples/debug/jdugoudr1
Normal file
84
samples/debug/jdugoudr1
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
84
samples/debug/jdugoudr10
Normal file
84
samples/debug/jdugoudr10
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
84
samples/debug/jdugoudr11
Normal file
84
samples/debug/jdugoudr11
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
84
samples/debug/jdugoudr12
Normal file
84
samples/debug/jdugoudr12
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
.##.
|
||||||
|
##..
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
#...
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
#...
|
||||||
|
....
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user