no more leaks (checked with valgrind
This commit is contained in:
parent
c64cf9a5a4
commit
2684824c50
12 changed files with 71 additions and 79 deletions
BIN
fillit/fillit
BIN
fillit/fillit
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:38:16 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:38:16 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 16:51:11 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 11:00:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,9 +38,6 @@ typedef struct s_stack t_stack;
|
||||||
typedef struct s_ttmn t_ttmn;
|
typedef struct s_ttmn t_ttmn;
|
||||||
|
|
||||||
t_list *ft_parse(char *filename);
|
t_list *ft_parse(char *filename);
|
||||||
int ft_parse_line(char *line, int linenumber, t_list **list);
|
|
||||||
int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn);
|
|
||||||
int ft_parse_addttmn(int *j, int *k, t_ttmn ttmn, t_list **list);
|
|
||||||
|
|
||||||
int ft_solver(char **board, t_list *lttmn, int space, int size);
|
int ft_solver(char **board, t_list *lttmn, int space, int size);
|
||||||
int ft_solved(char **board);
|
int ft_solved(char **board);
|
||||||
|
|
@ -49,13 +46,11 @@ int ft_check_waste(char **board, t_list *lttmn, int space, int size);
|
||||||
int ft_fit_blob(
|
int ft_fit_blob(
|
||||||
char **board, t_list *lttmn, int space, int size);
|
char **board, t_list *lttmn, int space, int size);
|
||||||
int ft_floodfill_recursive(char **board, int size, int i, char c);
|
int ft_floodfill_recursive(char **board, int size, int i, char c);
|
||||||
int ft_floodfill_stack(char **board, int size, int i, char c);
|
|
||||||
|
|
||||||
void ft_board_print(char **board);
|
void ft_board_print(char **board);
|
||||||
char **ft_board_init(size_t size);
|
char **ft_board_init(size_t size);
|
||||||
char **ft_board_copy(char **board);
|
char **ft_board_copy(char **board);
|
||||||
void ft_board_fill(char **dst, char **src);
|
void ft_board_fill(char **dst, char **src);
|
||||||
void ft_board_free(char ***board);
|
|
||||||
void ft_board_replace(char **board, char a, char b);
|
void ft_board_replace(char **board, char a, char b);
|
||||||
void ft_board_remove(char **board, char *s);
|
void ft_board_remove(char **board, char *s);
|
||||||
int ft_board_add(char **board, t_ttmn ttmn, int i, int size);
|
int ft_board_add(char **board, t_ttmn ttmn, int i, int size);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 13:24:35 by jhalford #+# #+# */
|
/* Created: 2016/11/04 13:24:35 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 17:27:04 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:19:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:39:49 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:39:49 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 16:59:50 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:19:50 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,55 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:29:51 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:29:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 12:16:01 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 11:06:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
int g_target = 0;
|
int g_target = 2;
|
||||||
int g_ttmn = 0;
|
int g_ttmn = 0;
|
||||||
|
|
||||||
int ft_parse_line(char *line, int linenumber, t_list **list)
|
static int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn)
|
||||||
|
{
|
||||||
|
static int ref[2];
|
||||||
|
|
||||||
|
if (*k == 0)
|
||||||
|
{
|
||||||
|
ref[0] = *j / 4;
|
||||||
|
ref[1] = *j % 4;
|
||||||
|
ttmn->pos[0][0] = 0;
|
||||||
|
ttmn->pos[0][1] = 0;
|
||||||
|
}
|
||||||
|
else if (*k <= 3)
|
||||||
|
{
|
||||||
|
ttmn->pos[*k][0] = (*j) / 4 - ref[0];
|
||||||
|
ttmn->pos[*k][1] = (*j) % 4 - ref[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
|
*k += 1;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_parse_addttmn(int *j, int *k, t_ttmn ttmn, t_list **list)
|
||||||
|
{
|
||||||
|
static char id = 'A';
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
ttmn.id = id++;
|
||||||
|
if (*j != 16 || *k != 4)
|
||||||
|
return (1);
|
||||||
|
if (ft_ttmn_validate(ttmn))
|
||||||
|
return (1);
|
||||||
|
tmp = ft_lstnew(&ttmn, sizeof(t_ttmn));
|
||||||
|
ft_lsteadd(list, tmp);
|
||||||
|
*j = 0;
|
||||||
|
*k = 0;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_parse_line(char *line, int linenumber, t_list **list)
|
||||||
{
|
{
|
||||||
static t_ttmn ttmn;
|
static t_ttmn ttmn;
|
||||||
static int j = 0;
|
static int j = 0;
|
||||||
|
|
@ -44,46 +83,7 @@ int ft_parse_line(char *line, int linenumber, t_list **list)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn)
|
t_list *ft_parse(char *filename)
|
||||||
{
|
|
||||||
static int ref[2];
|
|
||||||
|
|
||||||
if (*k == 0)
|
|
||||||
{
|
|
||||||
ref[0] = *j / 4;
|
|
||||||
ref[1] = *j % 4;
|
|
||||||
ttmn->pos[0][0] = 0;
|
|
||||||
ttmn->pos[0][1] = 0;
|
|
||||||
}
|
|
||||||
else if (*k <= 3)
|
|
||||||
{
|
|
||||||
ttmn->pos[*k][0] = (*j) / 4 - ref[0];
|
|
||||||
ttmn->pos[*k][1] = (*j) % 4 - ref[1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return (1);
|
|
||||||
*k += 1;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_parse_addttmn(int *j, int *k, t_ttmn ttmn, t_list **list)
|
|
||||||
{
|
|
||||||
static char id = 'A';
|
|
||||||
t_list *tmp;
|
|
||||||
|
|
||||||
ttmn.id = id++;
|
|
||||||
if (*j != 16 || *k != 4)
|
|
||||||
return (1);
|
|
||||||
if (ft_ttmn_validate(ttmn))
|
|
||||||
return (1);
|
|
||||||
tmp = ft_lstnew(&ttmn, sizeof(t_ttmn));
|
|
||||||
ft_lsteadd(list, tmp);
|
|
||||||
*j = 0;
|
|
||||||
*k = 0;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_list *ft_parse(char *filename)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -98,13 +98,16 @@ t_list *ft_parse(char *filename)
|
||||||
while ((ret = get_next_line(fd, &line)))
|
while ((ret = get_next_line(fd, &line)))
|
||||||
{
|
{
|
||||||
if (ft_parse_line(line, linenumber++, &list))
|
if (ft_parse_line(line, linenumber++, &list))
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
if (ft_parse_line("", linenumber, &list))
|
if (ft_parse_line("", linenumber, &list))
|
||||||
return (0);
|
return (0);
|
||||||
g_target = 3;
|
|
||||||
g_ttmn = ft_lstsize(list);
|
g_ttmn = ft_lstsize(list);
|
||||||
while ((g_ttmn * 4) > (g_target) * (g_target))
|
while ((g_target) * (g_target) - g_ttmn * 4 < 0)
|
||||||
g_target++;
|
g_target++;
|
||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:36:27 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:36:27 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 17:26:58 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:54:50 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int ft_solved(char **board)
|
int ft_solved(char **board)
|
||||||
{
|
{
|
||||||
ft_board_remove(board, "^*");
|
ft_board_remove(board, "^*");
|
||||||
|
ft_sstrfree(g_sol);
|
||||||
g_sol = ft_board_copy(board);
|
g_sol = ft_board_copy(board);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:34:39 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:34:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 17:26:20 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:17:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:31:46 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:31:46 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 16:49:44 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:15:44 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,20 +40,6 @@ int ft_board_add(char **board, t_ttmn ttmn, int i, int size)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_board_free(char ***board)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((*board)[i])
|
|
||||||
{
|
|
||||||
free((*board)[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
free(*board);
|
|
||||||
*board = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_board_replace(char **board, char a, char b)
|
void ft_board_replace(char **board, char a, char b)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:32:01 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:32:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 12:14:50 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 15:31:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 17:31:13 by jhalford #+# #+# */
|
/* Created: 2016/11/03 17:31:13 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 17:26:50 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:46:17 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -41,5 +41,6 @@ int main(int ac, char **av)
|
||||||
}
|
}
|
||||||
ft_lstdel(<tmn, &ft_lst_cfree);
|
ft_lstdel(<tmn, &ft_lst_cfree);
|
||||||
ft_board_print(g_sol);
|
ft_board_print(g_sol);
|
||||||
|
ft_sstrfree(g_sol);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */
|
/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/08 17:09:26 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 10:38:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,9 +17,14 @@ void ft_sstrfree(char **sstr)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (sstr[i])
|
if (sstr)
|
||||||
{
|
{
|
||||||
|
while (sstr[i])
|
||||||
|
{
|
||||||
|
ft_strdel(sstr + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
ft_strdel(sstr + i);
|
ft_strdel(sstr + i);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
free(sstr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 12:45:02 by jhalford #+# #+# */
|
/* Created: 2016/11/04 12:45:02 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/04 13:43:29 by jhalford ### ########.fr */
|
/* Updated: 2016/11/14 11:06:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#define BUFF_SIZE 32
|
#define BUFF_SIZE 16
|
||||||
|
|
||||||
static char *ft_realloc(char *line, int size)
|
static char *ft_strrealloc(char *line, int size)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
|
@ -41,10 +41,11 @@ static int ft_loop_read(int fd, char **line, char (*save)[])
|
||||||
ft_strcat(*line, buf);
|
ft_strcat(*line, buf);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if ((*line = ft_realloc(*line, ret)) == NULL)
|
if ((*line = ft_strrealloc(*line, ret)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
ft_strcat(*line, buf);
|
ft_strcat(*line, buf);
|
||||||
}
|
}
|
||||||
|
free(*line);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue