84 lines
2.3 KiB
C
84 lines
2.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* lm_utils_parser.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
|
|
/* Updated: 2019/04/30 08:16:49 by mndhlovu ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "lem_in.h"
|
|
|
|
static 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)
|
|
{
|
|
if (line != NULL)
|
|
return (lm_check_ant_no(line));
|
|
return (0);
|
|
}
|
|
|
|
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->s_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->e_error = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void lm_get_vert_link(int count, t_lmdata *ldata
|
|
, t_syntax *syntax, t_holder *holder, char *line)
|
|
{
|
|
if (count > 0 && (count != syntax->s_vert
|
|
&& count != syntax->e_vert)
|
|
&& (count != syntax->s_pos
|
|
&& count != syntax->e_pos && line != NULL))
|
|
{
|
|
if (lm_check_forbiden_chars(line, 0))
|
|
{
|
|
if (!(lm_add_vertex(ldata, line, 'v', syntax)))
|
|
syntax->v_error = 1;
|
|
}
|
|
if (lm_check_forbiden_chars(line, 3))
|
|
{
|
|
if (!(lm_ext_conn(holder, ldata, line)))
|
|
syntax->l_error = 1;
|
|
}
|
|
}
|
|
}
|