lem_in/srcs/lem_in.c
Tanguy MAZE 0a9d7b816d Merge branch 'tmaze'
merging algorithm to master of project
2019-04-05 14:06:42 +02:00

65 lines
2.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lem_in.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
/* Updated: 2019/04/05 13:43:21 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int lm_error_exit(int flag)
{
if (flag == 0)
ft_printf("Invalid Map\n");
if (flag == 1)
ft_printf("Usage ./lem_in < map-file\n");
if (flag == 2)
ft_printf("Error opening the Map file\n");
return (1);
}
int main(int ac, char **av)
{
t_syntax synt;
//t_graph graph;
t_lmdata ldata;
t_holder holder;
int fd;
t_list *it;
t_node *start;
t_node *end;
if (ac == 2)
{
if ((fd = open (av[1], O_RDONLY)) < -1)
return (lm_error_exit(2));
lm_init_data(&synt, &ldata, &holder);
lm_parser(fd, &synt, &ldata, &holder);
if (lm_validate(&synt, &ldata))
{
//validation works
ft_printf("Success\n");
it = ldata.nodes;
while (it && ((t_node*)(it->content))->role != 's')
{
ft_printf("=== node ===\nindex: %d\nrole: %c\n\n", ((t_node*)(it->content))->ind, ((t_node*)(it->content))->role);
it = it->next;
}
start = it->content;
it = ldata.nodes;
while (it && ((t_node*)(it->content))->role != 'e')
it = it->next;
end = it->content;
edmunds_karp(&ldata, start->ind, end->ind);
}
else
ft_printf("Fail\n");
}
return (0);
}