diff --git a/includes/fillit.h b/includes/fillit.h index e2c1368..90fafa5 100644 --- a/includes/fillit.h +++ b/includes/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 12:13:35 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 12:34:30 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,5 +34,6 @@ void print_test(char *test); char *read_file(char *file); void ft_display_error(char *s, int fd); +int ft_file_errors(char *file); #endif diff --git a/samples/1tetri b/samples/1tetri new file mode 100644 index 0000000..3f1734a --- /dev/null +++ b/samples/1tetri @@ -0,0 +1,4 @@ +...# +...# +...# +...# diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c index 3ba9595..dedfac7 100644 --- a/srcs/handle_errors.c +++ b/srcs/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 12:06:40 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 12:35:46 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,25 @@ void ft_display_error(char *s, int fd) write(fd, s, strlen(s)); } +int ft_file_errors(char *file) +{ + int line_nbr; + + line_nbr = 0; + while (*file) + { + if (*file == '\n') + line_nbr++; + file++; + } + /*less than 4 lines or more than 104 (26 tetri) + 25 = 129 lines*/ + if (line_nbr < 4 || line_nbr > 129) + return (1); + return (0); +} + /* -int ft_tetri_erros() +int ft_tetri_errors() { } diff --git a/srcs/main.c b/srcs/main.c index 6a379c7..f14e429 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 12:13:42 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 12:44:14 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,22 +17,28 @@ int main(int argc, char **argv) char *input; short i; - if (argc == 2) + if (argc != 2) { - if (!(input = read_file(argv[1]))) - ft_display_error("Error: Could not read file.\n", 2); -// else if (/*Elements in file not valid*/) -// ft_display_error("Error: Invalid file.\n", 2); - /* - Transform input to tetriminos - Check if every tetrimino is valid - Backtracking for smallest square - Transform tetriminos with letters - Print result - */ - print_test(input); - } - else ft_display_error("Error: Please submit a file.\n", 2); - return 0; + return (0); + } + else if (!(input = read_file(argv[1]))) + { + ft_display_error("Error: Could not read file.\n", 2); + return (0); + } + else if (ft_file_errors(input)) + { + ft_display_error("Error: Invalid file.\n", 2); + return (0); + } + /* + Check if every tetrimino is valid + Transform input to tetriminos + Backtracking for smallest square + Transform tetriminos with letters + Print result + */ + print_test(input); + return (0); }