Bonus: Best Error Handler (more details about the error)

This commit is contained in:
Manzovince
2019-05-03 19:13:48 +02:00
parent 8d9b314781
commit 1cf791746c
5 changed files with 35 additions and 11 deletions

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/04/27 15:06:26 by vmanzoni ### ########.fr */
/* Updated: 2019/05/03 19:11:02 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,6 +22,27 @@ void print_error(char *s)
exit(1);
}
/*
** Function that display error message *s on fd
** with more informations
** and exit program
*/
void print_error_extended(int error)
{
if (error == 1)
ft_putstr("error: File contains char other than . # \\n found.\n");
if (error == 2)
ft_putstr("error: File contains more than 2 \\n in a row.\n");
if (error == 3)
ft_putstr("error: File contains less than 1 tetrimino or more than 26.\n");
if (error == 4)
ft_putstr("\n\nerror: This tetrimino has more or less than 4 #.\n");
if (error == 5)
ft_putstr("\n\nerror: This tetrimino # are not well connected.\n");
exit(1);
}
/*
** Function to see if there if an error if the file
** - less than 4 lines
@@ -44,11 +65,11 @@ int check_file_errors(char *file)
line_nbr++;
if (file[i] == '\n' && file[i+1] != '\0' && \
file[i+2] != '.' && file[i+2] != '#')
return (1);
return (2);
i++;
}
if (line_nbr < 4 || line_nbr > 129)
return (1);
return (3);
return (0);
}
@@ -76,7 +97,7 @@ int check_tetri_errors(char *tetri)
i++;
}
if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri))
return (1);
return (4 + check_tetri_errors_proxy(tetri));
return (0);
}