segfaults have been eliminated
This commit is contained in:
BIN
srcs/.lm_parser.c.swp
Normal file
BIN
srcs/.lm_parser.c.swp
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)) ||
|
||||
|
@@ -6,30 +6,32 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user