segfaults have been eliminated
This commit is contained in:
parent
ba1cea020d
commit
9a386b315b
@ -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/24 18:10:12 by tmaze ### ########.fr */
|
/* Updated: 2019/04/26 11:22:41 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2018/04/07 12:47:06 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_isascii.c \
|
||||||
ft_isprint.c \
|
ft_isprint.c \
|
||||||
ft_toupper.c \
|
ft_toupper.c \
|
||||||
|
ft_isnumeric.c \
|
||||||
ft_tolower.c \
|
ft_tolower.c \
|
||||||
ft_isupper.c \
|
ft_isupper.c \
|
||||||
ft_islower.c \
|
ft_islower.c \
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 00:12:36 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_atoi(const char *str);
|
||||||
int ft_isalpha(int c);
|
int ft_isalpha(int c);
|
||||||
int ft_isdigit(int c);
|
int ft_isdigit(int c);
|
||||||
|
int ft_isnumeric(char *str);
|
||||||
int ft_isalnum(int c);
|
int ft_isalnum(int c);
|
||||||
int ft_isascii(int c);
|
int ft_isascii(int c);
|
||||||
int ft_isprint(int c);
|
int ft_isprint(int c);
|
||||||
|
27
libft/srcs/ft_isnumeric.c
Normal file
27
libft/srcs/ft_isnumeric.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isnumeric.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
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> +#+ +:+ +#+ */
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/22 08:55:30 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 (tab[0] != NULL && tab[1] != NULL && tab[2] != NULL)
|
||||||
{
|
{
|
||||||
if (!lm_validate_rooms(tab[0], tab[1], tab[2]))
|
if (lm_validate_rooms(tab[0], tab[1], tab[2]))
|
||||||
{
|
return (1);
|
||||||
|
}
|
||||||
synt->v_error = 1;
|
synt->v_error = 1;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_check_forbiden_chars(char *line, int flag)
|
int lm_check_forbiden_chars(char *line, int flag)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/25 06:31:37 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/20 15:24:51 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;
|
char *tmp;
|
||||||
|
|
||||||
tmp = ft_strchr(line, '#');
|
tmp = ft_strchr(line, '#');
|
||||||
ft_printf("Bingo 1\n");
|
|
||||||
if ((!synt->s_cmd || !synt->e_cmd)
|
if ((!synt->s_cmd || !synt->e_cmd)
|
||||||
&& (tmp != NULL && line[1] == '#'
|
&& (tmp != NULL && line[1] == '#'
|
||||||
&& lm_check_forbiden_chars(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)
|
if (ft_strcmp(line, "##start") == 0)
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 2\n");
|
|
||||||
synt->s_cmd = 1;
|
synt->s_cmd = 1;
|
||||||
synt->s_pos = index;
|
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)
|
if (ft_strcmp(line, "##end") == 0)
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 3\n");
|
|
||||||
synt->e_cmd = 1;
|
synt->e_cmd = 1;
|
||||||
synt->e_pos = index;
|
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))
|
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||||
{
|
{
|
||||||
value = lm_get_value(line);
|
value = lm_get_value(line);
|
||||||
if (value != -1)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 4 %d\n", value);
|
|
||||||
ldata->nbants = value;
|
ldata->nbants = value;
|
||||||
synt->nb_state = 1;
|
synt->nb_state = 1;
|
||||||
return (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,
|
static int lm_get_vertices(int count, t_syntax *synt,
|
||||||
t_lmdata *data, t_holder *holder, char *line)
|
t_lmdata *data, t_holder *holder, char *line)
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 5\n");
|
|
||||||
lm_get_cmd_vert(count, synt, data, line);
|
lm_get_cmd_vert(count, synt, data, line);
|
||||||
if (!synt->s_error && !synt->e_error)
|
if (!synt->s_error && !synt->e_error)
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 6 %s\n", line);
|
|
||||||
lm_get_vert_link(count, synt, data, holder, line);
|
lm_get_vert_link(count, synt, data, holder, line);
|
||||||
if (!synt->v_error && !synt->l_error)
|
if (!synt->v_error && !synt->l_error)
|
||||||
return (1);
|
return (1);
|
||||||
@ -89,8 +83,7 @@ int lm_parser(t_syntax *synt, t_lmdata *ldata,
|
|||||||
ft_printf("%s\n", raw);
|
ft_printf("%s\n", raw);
|
||||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||||
{
|
{
|
||||||
ft_printf("banane\n");
|
//ft_strdel(&raw);
|
||||||
ft_strdel(&raw);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
lm_locate_cd(index, synt, raw);
|
lm_locate_cd(index, synt, raw);
|
||||||
|
@ -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/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)
|
int lm_validate_rooms(char *name, char *x, char *y)
|
||||||
{
|
{
|
||||||
if (lm_validate_name(name) == -1)
|
if (lm_validate_name(name) == -1)
|
||||||
return (-1);
|
return (0);
|
||||||
if (lm_chk_format_nbr(x) == -1 ||
|
if (lm_chk_format_nbr(x) == -1 ||
|
||||||
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
|
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
|
||||||
(ft_atoi(x) == 0)) ||
|
(ft_atoi(x) == 0)) ||
|
||||||
|
@ -6,30 +6,32 @@
|
|||||||
/* 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/24 09:47:29 by tmaze ### ########.fr */
|
/* Updated: 2019/04/26 11:51:12 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#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 lm_get_value(char *line)
|
||||||
{
|
{
|
||||||
int index;
|
|
||||||
|
|
||||||
if (line != NULL)
|
if (line != NULL)
|
||||||
{
|
return (lm_check_ant_no(line));
|
||||||
index = ft_atoi(line);
|
return (0);
|
||||||
if (index > INT_MIN && index < INT_MAX)
|
|
||||||
{
|
|
||||||
if (index > 0)
|
|
||||||
return (index);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_get_cmd_vert(int count, t_syntax *synt
|
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)
|
, t_holder *holder, char *line)
|
||||||
{
|
{
|
||||||
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 && line != NULL))
|
||||||
{
|
{
|
||||||
if (lm_check_forbiden_chars(line, 0))
|
if (lm_check_forbiden_chars(line, 0))
|
||||||
{
|
{
|
||||||
ft_printf("Bingo 7 %s\n", line);
|
|
||||||
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 (lm_check_forbiden_chars(line, 3))
|
if (lm_check_forbiden_chars(line, 3))
|
||||||
{
|
{
|
||||||
if (!(lm_ext_conn(holder, ldata, line)))
|
if (!(lm_ext_conn(holder, ldata, line)))
|
||||||
{
|
|
||||||
synt->l_error = 1;
|
synt->l_error = 1;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/24 17:35:29 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user