lem_in/srcs/lm_utils_parser.c
Mthandazo Ndhlovu 56537c0917 Semi Final Parser
Parser working fine with valid maps.
only a few adjustments are yet to be made.
The adjustments will not affect the output
of the adjacency list.
FYI leaks like a garden pipe.
2019-04-08 15:27:09 +02:00

91 lines
2.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lm_utils_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
/* Updated: 2019/04/08 15:14:34 by mndhlovu ### ########.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 ;
}
}
}
}