diff --git a/includes/lem_in.h b/includes/lem_in.h index 459643d..32c90e1 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/14 12:18:02 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 13:18:46 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,7 +121,7 @@ int lm_verify_cmd(t_syntax *synt, t_holder *holder void lm_initdata(t_lmdata *data); int lm_getparams(t_lmdata *data); void lm_clean_data(t_lmdata *data); - +int lm_check_forbiden_chars(char *line, int flag); t_ind **lst_indinit(t_lmdata *data); int lst_indadd_link(t_lmdata *data, int n1, int n2); t_ind *lst_indadd(t_ind **lst, int ind); diff --git a/srcs/lm_check_errors.c b/srcs/lm_check_errors.c index dba9d15..51c276c 100644 --- a/srcs/lm_check_errors.c +++ b/srcs/lm_check_errors.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/02 08:39:09 by mndhlovu #+# #+# */ -/* Updated: 2019/04/11 12:48:13 by mndhlovu ### ########.fr */ +/* Updated: 2019/04/20 13:18:54 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,24 @@ int lm_check_room_before(char **tab, t_syntax *synt) return (1); } +int lm_check_forbiden_chars(char *line, int flag) +{ + char *hash; + char *dash; + + dash = ft_strchr(line, '-'); + hash = ft_strchr(line, '#'); + if (flag == 0 && dash == NULL && hash == NULL) + return (1); + if (flag = 1 && dash == NULL && hash != NULL) + return (1); + if (flag == 2 && dash == NULL && (hash == NULL || (hash != NULL && line[1] != '#'))) + return (1); + if (flag == 3 && dash != NULL && (hash == NULL || (hash != NULL && line[1] != '#'))) + return (1); + return (0); +} + void lm_clear_unv(t_holder *holder) { t_temp *data; @@ -50,4 +68,4 @@ int lm_verify_cmd(t_syntax *synt, t_holder *holder, t_lmdata *data) return (1); lm_clear_unv(holder); return (0); -} \ No newline at end of file +} diff --git a/srcs/lm_parser.c b/srcs/lm_parser.c index fd816cd..003ef52 100644 --- a/srcs/lm_parser.c +++ b/srcs/lm_parser.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/25 06:30:51 by mndhlovu #+# #+# */ -/* Updated: 2019/04/11 09:51:29 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 13:08:01 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,12 @@ void lm_locate_cd(int index, t_syntax *synt, char *line) { - char *tmp; + char *tmp; tmp = ft_strchr(line, '#'); - if ((!synt->s_cmd || !synt->e_cmd) && (tmp != NULL && line[1] == '#')) + if ((!synt->s_cmd || !synt->e_cmd) + && (tmp != NULL && line[1] == '#' + && lm_check_forbiden_chars(line, 1))) { if (!synt->s_cmd) { @@ -42,7 +44,7 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, ch { int value; - if (counter == 0) + if (counter == 0 && lm_check_forbiden_chars(line, 0)) { value = lm_get_value(line); if (value != -1) @@ -82,13 +84,13 @@ int lm_parser(t_syntax *synt, t_lmdata *ldata, if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0) { ft_strdel(&raw); - return (0); + return (0); } lm_locate_cd(index, synt, raw); if (!(lm_get_vertices(index, synt, ldata, holder, raw))) { ft_strdel(&raw); - return (0); + return (0); } ft_strdel(&raw); index++; diff --git a/srcs/lm_parser_error_check.c b/srcs/lm_parser_error_check.c index ae8c136..9f3aeb0 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/08 17:04:05 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 13:29:12 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/lm_utils_parser.c b/srcs/lm_utils_parser.c index b88db9b..946c5f6 100644 --- a/srcs/lm_utils_parser.c +++ b/srcs/lm_utils_parser.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */ -/* Updated: 2019/04/08 16:51:51 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 13:25:57 by mndhlovu ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,23 +62,17 @@ void lm_get_cmd_vert(int count, t_syntax *synt void lm_get_vert_link(int count, t_syntax *synt, t_lmdata *ldata , t_holder *holder, char *line) { - char *link_sign; - char *hash; - - if (count > 0 && (count != synt->s_vert && count != synt->e_vert) && (count != synt->s_pos && count != synt->e_pos)) { - link_sign = ft_strchr(line, '-'); - hash = ft_strchr(line, '#'); - if (link_sign == NULL && hash == NULL) + if (lm_check_forbiden_chars(line, 0)) { if (!(lm_add_vertex(ldata, line, 'v', synt))) { synt->v_error = 1; } } - if (link_sign != NULL && hash == NULL) + if (lm_check_forbiden_chars(line, 0)) { if (!(lm_ext_conn(holder, ldata, line))) {