code cleaning done on 80 percent of the parser functions, whats left is to re structure the syntax struct and do furthure tests to eliminate level 0 errors

This commit is contained in:
Mthandazo Ndhlovu
2019-04-29 12:47:14 +02:00
parent 6ad8cd2d95
commit a51c8ad81d
17 changed files with 389 additions and 355 deletions

View File

@@ -6,13 +6,13 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */
/* Updated: 2019/04/26 10:42:43 by mndhlovu ### ########.fr */
/* Updated: 2019/04/29 12:06:08 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int lm_chk_format_nbr(char *raw)
static int lm_chk_format_nbr(char *raw)
{
while (*raw)
{
@@ -25,16 +25,16 @@ int lm_chk_format_nbr(char *raw)
return (0);
}
int lm_check_max(char *raw)
static int lm_check_max(char *raw)
{
if (ft_atoi(raw) < INT_MIN || ft_atoi(raw) > INT_MAX)
return (-1);
return (0);
}
int lm_validate_name(char *name)
static int lm_validate_name(char *name)
{
int index;
int index;
index = 0;
if (name[0] == 'L')
@@ -48,28 +48,29 @@ int lm_validate_name(char *name)
return (0);
}
int lm_validate_rooms(char *name, char *x, char *y)
int lm_validate_rooms(char *name, char *x, char *y)
{
if (lm_validate_name(name) == -1)
return (0);
if (lm_chk_format_nbr(x) == -1 ||
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
(ft_atoi(x) == 0)) ||
ft_strlen(x) > 19)
if (lm_chk_format_nbr(x) == -1
|| lm_check_max(x) == -1
|| (ft_atoi(x) > 0 && (ft_atoi(x) == 0))
|| ft_strlen(x) > 19)
return (0);
if (lm_chk_format_nbr(y) == -1 ||
lm_check_max(y) == -1 || (ft_atoi(y) > 0 &&
(ft_atoi(y) == 0)) ||
ft_strlen(y) > 19)
if (lm_chk_format_nbr(y) == -1
|| lm_check_max(y) == -1
|| (ft_atoi(y) > 0 && (ft_atoi(y) == 0))
|| ft_strlen(y) > 19)
return (0);
return (1);
}
int lm_error_nbr(char *raw)
int lm_error_nbr(char *raw)
{
if (lm_chk_format_nbr(raw) == -1 || lm_check_max(raw) == -1 ||
(ft_atoi(raw) > 0 && (ft_atoi(raw) == 0)) ||
ft_strlen(raw) > 19)
if (lm_chk_format_nbr(raw) == -1
|| lm_check_max(raw) == -1
|| (ft_atoi(raw) > 0 && (ft_atoi(raw) == 0))
|| ft_strlen(raw) > 19)
return (-1);
return (0);
}