Adding more protection to the parser, leaving it at this state for now whilst i branch out to work on a new parser
This commit is contained in:
parent
4a5c798b25
commit
bfb125f503
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/23 17:31:19 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);
|
void lm_initdata(t_lmdata *data);
|
||||||
int lm_getparams(t_lmdata *data);
|
int lm_getparams(t_lmdata *data);
|
||||||
void lm_clean_data(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);
|
t_ind **lst_indinit(t_lmdata *data);
|
||||||
int lst_indadd_link(t_lmdata *data, int n1, int n2);
|
int lst_indadd_link(t_lmdata *data, int n1, int n2);
|
||||||
t_ind *lst_indadd(t_ind **lst, int ind);
|
t_ind *lst_indadd(t_ind **lst, int ind);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/02 08:39:09 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);
|
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)
|
void lm_clear_unv(t_holder *holder)
|
||||||
{
|
{
|
||||||
t_temp *data;
|
t_temp *data;
|
||||||
@ -50,4 +68,4 @@ int lm_verify_cmd(t_syntax *synt, t_holder *holder, t_lmdata *data)
|
|||||||
return (1);
|
return (1);
|
||||||
lm_clear_unv(holder);
|
lm_clear_unv(holder);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/25 06:30:51 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)
|
void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = ft_strchr(line, '#');
|
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)
|
if (!synt->s_cmd)
|
||||||
{
|
{
|
||||||
@ -42,7 +44,7 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, ch
|
|||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
if (counter == 0)
|
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||||
{
|
{
|
||||||
value = lm_get_value(line);
|
value = lm_get_value(line);
|
||||||
if (value != -1)
|
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)
|
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||||
{
|
{
|
||||||
ft_strdel(&raw);
|
ft_strdel(&raw);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
lm_locate_cd(index, synt, raw);
|
lm_locate_cd(index, synt, raw);
|
||||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
||||||
{
|
{
|
||||||
ft_strdel(&raw);
|
ft_strdel(&raw);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
ft_strdel(&raw);
|
ft_strdel(&raw);
|
||||||
index++;
|
index++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/08 06:42:37 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/04 09:24:45 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
|
void lm_get_vert_link(int count, t_syntax *synt, t_lmdata *ldata
|
||||||
, t_holder *holder, char *line)
|
, t_holder *holder, char *line)
|
||||||
{
|
{
|
||||||
char *link_sign;
|
|
||||||
char *hash;
|
|
||||||
|
|
||||||
|
|
||||||
if (count > 0 && (count != synt->s_vert && count != synt->e_vert)
|
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))
|
||||||
{
|
{
|
||||||
link_sign = ft_strchr(line, '-');
|
if (lm_check_forbiden_chars(line, 0))
|
||||||
hash = ft_strchr(line, '#');
|
|
||||||
if (link_sign == NULL && hash == NULL)
|
|
||||||
{
|
{
|
||||||
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
||||||
{
|
{
|
||||||
synt->v_error = 1;
|
synt->v_error = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (link_sign != NULL && hash == NULL)
|
if (lm_check_forbiden_chars(line, 0))
|
||||||
{
|
{
|
||||||
if (!(lm_ext_conn(holder, ldata, line)))
|
if (!(lm_ext_conn(holder, ldata, line)))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user