diff --git a/includes/lem_in.h b/includes/lem_in.h index 8e1631b..59a51ae 100644 --- a/includes/lem_in.h +++ b/includes/lem_in.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */ -/* Updated: 2019/04/24 18:10:12 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 11:22:41 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/Makefile b/libft/Makefile index e192ed6..5d27354 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/07 12:47:06 by tmaze #+# #+# # -# Updated: 2019/04/22 12:11:07 by mndhlovu ### ########.fr # +# Updated: 2019/04/26 11:54:46 by mndhlovu ### ########.fr # # # #******************************************************************************# @@ -32,6 +32,7 @@ SRCS = ft_memalloc.c \ ft_isascii.c \ ft_isprint.c \ ft_toupper.c \ + ft_isnumeric.c \ ft_tolower.c \ ft_isupper.c \ ft_islower.c \ diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 8efb2a0..53ad28a 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */ -/* Updated: 2019/03/20 16:46:41 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 10:36:51 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -266,6 +266,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n); int ft_atoi(const char *str); int ft_isalpha(int c); int ft_isdigit(int c); +int ft_isnumeric(char *str); int ft_isalnum(int c); int ft_isascii(int c); int ft_isprint(int c); diff --git a/libft/srcs/ft_isnumeric.c b/libft/srcs/ft_isnumeric.c new file mode 100644 index 0000000..146c3a7 --- /dev/null +++ b/libft/srcs/ft_isnumeric.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isnumeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mndhlovu +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/26 10:17:04 by mndhlovu #+# #+# */ +/* Updated: 2019/04/26 10:35:46 by mndhlovu ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isnumeric(char *str) +{ + int index; + + index = 0; + while (str[index] != '\0') + { + if (!ft_isdigit(str[index])) + return (0); + index++; + } + return (1); +} diff --git a/srcs/.lm_parser.c.swp b/srcs/.lm_parser.c.swp new file mode 100644 index 0000000..90f88e8 Binary files /dev/null and b/srcs/.lm_parser.c.swp differ diff --git a/srcs/lm_check_errors.c b/srcs/lm_check_errors.c index da23c7a..ba71a70 100644 --- a/srcs/lm_check_errors.c +++ b/srcs/lm_check_errors.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */ -/* Updated: 2019/04/24 09:49:38 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 11:50:56 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,11 @@ int lm_check_room_before(char **tab, t_syntax *synt) { if (tab[0] != NULL && tab[1] != NULL && tab[2] != NULL) { - if (!lm_validate_rooms(tab[0], tab[1], tab[2])) - { - synt->v_error = 1; - return (0); - } + if (lm_validate_rooms(tab[0], tab[1], tab[2])) + return (1); } - return (1); + synt->v_error = 1; + return (0); } int lm_check_forbiden_chars(char *line, int flag) diff --git a/srcs/lm_mem_utils.c b/srcs/lm_mem_utils.c index c42ef7d..911d713 100644 --- a/srcs/lm_mem_utils.c +++ b/srcs/lm_mem_utils.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */ -/* Updated: 2019/04/24 18:03:58 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 09:33:50 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/lm_parser.c b/srcs/lm_parser.c index d01c021..3ff1f6b 100644 --- a/srcs/lm_parser.c +++ b/srcs/lm_parser.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */ -/* Updated: 2019/04/24 09:45:04 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 11:58:52 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ void lm_locate_cd(int index, t_syntax *synt, char *line) char *tmp; tmp = ft_strchr(line, '#'); - ft_printf("Bingo 1\n"); if ((!synt->s_cmd || !synt->e_cmd) && (tmp != NULL && line[1] == '#' && lm_check_forbiden_chars(line, 1))) @@ -26,7 +25,6 @@ void lm_locate_cd(int index, t_syntax *synt, char *line) { if (ft_strcmp(line, "##start") == 0) { - ft_printf("Bingo 2\n"); synt->s_cmd = 1; synt->s_pos = index; } @@ -35,7 +33,6 @@ void lm_locate_cd(int index, t_syntax *synt, char *line) { if (ft_strcmp(line, "##end") == 0) { - ft_printf("Bingo 3\n"); synt->e_cmd = 1; synt->e_pos = index; } @@ -50,9 +47,8 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, char *line) if (counter == 0 && lm_check_forbiden_chars(line, 0)) { value = lm_get_value(line); - if (value != -1) + if (value > 0) { - ft_printf("Bingo 4 %d\n", value); ldata->nbants = value; synt->nb_state = 1; return (1); @@ -65,11 +61,9 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, char *line) static int lm_get_vertices(int count, t_syntax *synt, t_lmdata *data, t_holder *holder, char *line) { - ft_printf("Bingo 5\n"); lm_get_cmd_vert(count, synt, data, line); if (!synt->s_error && !synt->e_error) { - ft_printf("Bingo 6 %s\n", line); lm_get_vert_link(count, synt, data, holder, line); if (!synt->v_error && !synt->l_error) return (1); @@ -89,8 +83,7 @@ int lm_parser(t_syntax *synt, t_lmdata *ldata, ft_printf("%s\n", raw); if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0) { - ft_printf("banane\n"); - ft_strdel(&raw); + //ft_strdel(&raw); return (0); } lm_locate_cd(index, synt, raw); diff --git a/srcs/lm_parser_error_check.c b/srcs/lm_parser_error_check.c index 9f3aeb0..562a1d4 100644 --- a/srcs/lm_parser_error_check.c +++ b/srcs/lm_parser_error_check.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */ -/* Updated: 2019/04/20 13:29:12 by mndhlovu ### ########.fr */ +/* Updated: 2019/04/26 10:42:43 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ int lm_validate_name(char *name) int lm_validate_rooms(char *name, char *x, char *y) { if (lm_validate_name(name) == -1) - return (-1); + return (0); if (lm_chk_format_nbr(x) == -1 || lm_check_max(x) == -1 || (ft_atoi(x) > 0 && (ft_atoi(x) == 0)) || diff --git a/srcs/lm_utils_parser.c b/srcs/lm_utils_parser.c index 0166c72..bdccc14 100644 --- a/srcs/lm_utils_parser.c +++ b/srcs/lm_utils_parser.c @@ -6,30 +6,32 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */ -/* Updated: 2019/04/24 09:47:29 by tmaze ### ########.fr */ +/* Updated: 2019/04/26 11:51:12 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ #include "lem_in.h" +int lm_check_ant_no(char *line) +{ + int len; + + len = ft_strlen(line); + if (len > 0) + { + if (len == 1 && ft_isdigit(*line)) + return (*line - '0'); + else if (len > 1 && len < 19 && ft_isnumeric(line)) + return (ft_atoi(line)); + } + return (0); +} + int lm_get_value(char *line) { - int index; - if (line != NULL) - { - index = ft_atoi(line); - if (index > INT_MIN && index < INT_MAX) - { - if (index > 0) - return (index); - else - { - return (-1); - } - } - } - return (-1); + return (lm_check_ant_no(line)); + return (0); } void lm_get_cmd_vert(int count, t_syntax *synt @@ -63,23 +65,17 @@ void lm_get_vert_link(int count, t_syntax *synt, t_lmdata *ldata , t_holder *holder, char *line) { if (count > 0 && (count != synt->s_vert && count != synt->e_vert) - && (count != synt->s_pos && count != synt->e_pos)) + && (count != synt->s_pos && count != synt->e_pos && line != NULL)) { if (lm_check_forbiden_chars(line, 0)) { - ft_printf("Bingo 7 %s\n", line); if (!(lm_add_vertex(ldata, line, 'v', synt))) - { - synt->v_error = 1; - } + synt->v_error = 1; } if (lm_check_forbiden_chars(line, 3)) { if (!(lm_ext_conn(holder, ldata, line))) - { - synt->l_error = 1; - return ; - } + synt->l_error = 1; } } } diff --git a/srcs/print_map.c b/srcs/print_map.c index 110c512..a5bb42d 100644 --- a/srcs/print_map.c +++ b/srcs/print_map.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/24 17:35:29 by tmaze #+# #+# */ -/* Updated: 2019/04/26 11:36:27 by mndhlovu ### ########.fr */ +/* Updated: 2019/04/26 11:53:36 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */