84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* lm_check_errors.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
|
|
/* Updated: 2019/04/29 12:06:41 by mndhlovu ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "lem_in.h"
|
|
|
|
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]))
|
|
return (1);
|
|
}
|
|
synt->v_error = 1;
|
|
return (0);
|
|
}
|
|
|
|
int lm_check_forbiden_chars(char *line, int flag)
|
|
{
|
|
char *hash;
|
|
char *dash;
|
|
|
|
if (line != NULL)
|
|
{
|
|
dash = ft_strchr(line, '-');
|
|
hash = ft_strchr(line, '#');
|
|
if (flag == 0 && dash == NULL && hash == NULL)
|
|
return (1);
|
|
if (flag == 1 && dash == NULL && hash != NULL)
|
|
return (1);
|
|
if (flag == 2 && dash == NULL
|
|
&& (hash == NULL || (hash != NULL && line[1] != '#')))
|
|
return (1);
|
|
if (flag == 3 && dash != NULL && hash == NULL)
|
|
return (1);
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
void lm_clear_unv(t_holder *holder)
|
|
{
|
|
t_temp *data;
|
|
t_temp *flush;
|
|
|
|
data = holder->data;
|
|
while (data)
|
|
{
|
|
flush = data;
|
|
data = data->next;
|
|
free(flush);
|
|
flush = NULL;
|
|
}
|
|
holder->data = NULL;
|
|
}
|
|
|
|
int lm_verify_links(t_holder *data, t_syntax *synt)
|
|
{
|
|
if (!synt->l_error || (synt->l_error && data->count > 0))
|
|
return (1);
|
|
return (0);
|
|
}
|
|
|
|
int lm_verify_cmd(t_syntax *synt, t_holder *holder
|
|
, t_lmdata *data)
|
|
{
|
|
if (synt->s_cmd && synt->e_cmd
|
|
&& !synt->e_error && !synt->s_error
|
|
&& !synt->v_error
|
|
&& synt->nb_state
|
|
&& lm_verify_links(holder, synt)
|
|
&& (data->nb_nodes > 0))
|
|
return (1);
|
|
lm_clear_unv(holder);
|
|
return (0);
|
|
}
|