diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 21b4873..70d361f 100644 --- a/f_bonus_opti.c +++ b/f_bonus_opti.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ -/* Updated: 2019/05/28 17:00:32 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:46:56 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,6 +51,21 @@ int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b) 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 */ @@ -61,7 +76,8 @@ int check_same_tetri(t_fillist *list, int num) t_fillist *next_tetri; int i; - curr_tetri = list; + curr_tetri = clean_list_memory(list, list); +// curr_tetri = list; while (curr_tetri != NULL) { i = 0; diff --git a/f_bonus_print.c b/f_bonus_print.c index a6034c8..1dfd9d4 100644 --- a/f_bonus_print.c +++ b/f_bonus_print.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */ -/* Updated: 2019/06/01 14:00:58 by vmanzoni ### ########.fr */ +/* Updated: 2019/05/29 16:25:52 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ t_fillist *print_tetri(t_fillist *list) print = tmp->tetribit; print <<= 16; print_sized_map(&print, tmp->width, tmp->height, tmp->letter); - if (tmp->same) + if (tmp->same && list->dope[1]) { print = tmp->same->tetribit; print <<= 16; diff --git a/f_handle_errors.c b/f_handle_errors.c index 47f2a8e..dc27add 100644 --- a/f_handle_errors.c +++ b/f_handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/05/29 13:56:55 by vmanzoni ### ########.fr */ +/* Updated: 2019/05/29 15:55:03 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,9 +23,7 @@ void print_error(char *str) } /* -** Function that display error message *s on fd -** with more informations -** and exit program +** Function that display error message *s on fd with more informations */ void print_error_extended(int error, int *dope) @@ -35,13 +33,16 @@ void print_error_extended(int error, int *dope) if (error == 1) print_error("error: File contains char other than '.','#' and '\\n'\n"); if (error == 2) - print_error("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) + print_error("error: File contains more than 2 '\\n' in a row\n"); + if (error == 4) print_error("error: File contains less than 1 tetrimino " "or more than 26\n"); - if (error == 4) - print_error("error: Tetrimino has more or less than 4 #\n"); if (error == 5) + print_error("error: Tetrimino has more or less than 4 #\n"); + if (error == 6) print_error("error: Tetrimino # are not all connected\n"); print_error("error\n"); } @@ -67,14 +68,14 @@ void check_file_errors(char *file, int *dope) else if (file[i] == '\n') line_nbr++; if (file[i] == '\n' && line_nbr % 5 == 0 && file[i-1] != '\n') - print_error("error\n"); + print_error_extended(2, dope); if (file[i] == '\n' && file[i+1] != '\0' && \ file[i+2] != '.' && file[i+2] != '#') - print_error_extended(2, dope); + print_error_extended(3, dope); i++; } if (line_nbr < 4 || line_nbr > 129) - print_error_extended(3, dope); + print_error_extended(4, dope); } /* @@ -101,7 +102,7 @@ int check_tetri_errors(char *tetri) i++; } if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri)) - return (4 + check_tetri_errors_proxy(tetri)); + return (5 + check_tetri_errors_proxy(tetri)); return (0); } diff --git a/f_parse_input.c b/f_parse_input.c index dd58683..5b90a63 100644 --- a/f_parse_input.c +++ b/f_parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/05/28 19:05:05 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:32:38 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/f_read_file.c b/f_read_file.c index 2e2ef58..0157491 100644 --- a/f_read_file.c +++ b/f_read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/05/28 18:36:35 by hulamy ### ########.fr */ +/* Updated: 2019/05/29 16:10:58 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ char *read_file(char *file) { char buf[BUFF_SIZE]; int fd; - size_t rv; + int rv; int i; char *result; diff --git a/f_search_map.c b/f_search_map.c index 9cb1713..00bb44e 100644 --- a/f_search_map.c +++ b/f_search_map.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/05/29 13:37:51 by vmanzoni ### ########.fr */ +/* Updated: 2019/06/01 13:38:26 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -165,5 +165,6 @@ int search_map(t_fillist *list) map[num] = 0; i = fill_map(map, list, size++); } + free(map); return (print_binary_map(map, size, list->dope)); } diff --git a/fillit.dSYM/Contents/Info.plist b/fillit.dSYM/Contents/Info.plist new file mode 100644 index 0000000..96bfe2d --- /dev/null +++ b/fillit.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.fillit + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/fillit.h b/fillit.h index a73a692..984b987 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/05/29 13:31:37 by vmanzoni ### ########.fr */ +/* Updated: 2019/06/01 13:44:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,6 +94,7 @@ int print_flags_usage(void); */ int check_same_tetri(t_fillist *list, int num); int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b); +t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp); int check_tetri_memory(t_fillist *list, int pos); /* @@ -101,6 +102,7 @@ int check_tetri_memory(t_fillist *list, int pos); */ int main(int argc, char **argv); int *create_dope(char *av, int mdp); +void clean_list(t_fillist *list, t_fillist *tmp); int is_mdp(int ac, char **av); /* diff --git a/main.c b/main.c index 5cf1d0c..c1f6a82 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/05/29 13:27:14 by vmanzoni ### ########.fr */ +/* Updated: 2019/06/01 13:41:46 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,22 @@ int is_mdp(int ac, char **av) return (1); } +/* +** Function that free the list +*/ + +void clean_list(t_fillist *list, t_fillist *tmp) +{ + tmp = list; + while (list) + { + list = tmp->next; + free(tmp->memory); + free(tmp); + tmp = list; + } +} + /* ** Main function */ @@ -87,8 +103,11 @@ int main(int ac, char **av) check_file_errors(input, dope); size = parse_input(input, &list, dope); print_final_map(list, size); + free(input); + clean_list(list, list); } else print_error("usage: Please submit a file.\n> ./fillit file.fillit\n"); + free(dope); return (0); }