forgot 3 files in last commitP
This commit is contained in:
Tanguy MAZE 2019-04-09 19:10:47 +02:00
parent 3b893147e5
commit fb66233265
3 changed files with 204 additions and 0 deletions

39
srcs/lm_data_utils.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lm_data_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/05 06:35:40 by mndhlovu #+# #+# */
/* Updated: 2019/04/08 16:40:15 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
t_rdata *lm_new_raw_line(char *raw)
{
t_rdata *line;
if (!(line = (t_rdata *)malloc(sizeof(t_rdata))))
return (NULL);
line->line = ft_strdup(raw);
line->next = NULL;
return (line);
}
void lm_append_line(t_rdata **line, char *raw)
{
if (*line)
{
if((*line)->next)
lm_append_line(&(*line)->next, raw);
else
(*line)->next = lm_new_raw_line(raw);
}
else
{
*line = lm_new_raw_line(raw);
}
}

View File

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lm_parser_error_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */
/* Updated: 2019/04/08 17:04:05 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int lm_chk_format_nbr(char *raw)
{
while (*raw)
{
if (*raw == '-' || *raw == '+')
raw++;
if (!ft_isdigit(*raw))
return (-1);
raw++;
}
return (0);
}
int lm_check_max(char *raw)
{
if (ft_atoi(raw) < INT_MIN || ft_atoi(raw) > INT_MAX)
return (-1);
return (0);
}
int lm_validate_name(char *name)
{
int index;
index = 0;
if (name[0] == 'L')
return (-1);
while (name[index])
{
if (name[index] == '-')
return (-1);
index++;
}
return (0);
}
int lm_validate_rooms(char *name, char *x, char *y)
{
if (lm_validate_name(name) == -1)
return (-1);
if (lm_chk_format_nbr(x) == -1 ||
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
(ft_atoi(x) == 0)) ||
ft_strlen(x) > 19)
return (0);
if (lm_chk_format_nbr(y) == -1 ||
lm_check_max(y) == -1 || (ft_atoi(y) > 0 &&
(ft_atoi(y) == 0)) ||
ft_strlen(y) > 19)
return (0);
return (1);
}
int lm_error_nbr(char *raw)
{
if (lm_chk_format_nbr(raw) == -1 || lm_check_max(raw) == -1 ||
(ft_atoi(raw) > 0 && (ft_atoi(raw) == 0)) ||
ft_strlen(raw) > 19)
return (-1);
return (0);
}

90
srcs/lm_utils_parser.c Normal file
View File

@ -0,0 +1,90 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lm_utils_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
/* Updated: 2019/04/08 16:51:51 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
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);
}
void lm_get_cmd_vert(int count, t_syntax *synt
, t_lmdata *ldata, char *line)
{
char *tmp;
if (synt->s_pos == count - 1)
{
tmp = ft_strchr(line, '#');
if (tmp == NULL && count != synt->e_vert)
{
synt->s_vert = count;
if (!(lm_add_vertex(ldata, line, 's', synt)))
synt->e_error = 1;
}
}
if (synt->e_pos == count - 1)
{
tmp = ft_strchr(line, '#');
if (tmp == NULL && count != synt->s_vert)
{
synt->e_vert = count;
if (!(lm_add_vertex(ldata, line, 'e', synt)))
synt->s_error = 1;
}
}
}
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_add_vertex(ldata, line, 'v', synt)))
{
synt->v_error = 1;
}
}
if (link_sign != NULL && hash == NULL)
{
if (!(lm_ext_conn(holder, ldata, line)))
{
synt->l_error = 1;
return ;
}
}
}
}