/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* lem_in.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */ /* Updated: 2019/04/09 19:08:36 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "lem_in.h" int lm_error_exit(void) { ft_putendl_fd("ERROR", 2); return (1); } void ft_print_graph(t_graph *graph) { int v; t_ind *crawl; v = -1; while (++v < graph->v) { crawl = graph->array[v].head; printf("\n Adjacency list of vertex %d\n head", v); while (crawl) { printf("->%d",crawl->index); crawl = crawl->next; } printf("\n"); } } void lm_print_report(t_lmdata *ldata, t_syntax *synt, t_holder *holder) { t_node *nodes; t_temp *data; if (ldata != NULL) { nodes = ldata->nodes_data; while (nodes) { ft_printf("name: %s x: %d y: %d index: %d role: %c\n", nodes->name, nodes->x, nodes->y, nodes->ind, nodes->role); nodes = nodes->next; } } if (holder != NULL) { data = holder->data; while (data) { ft_printf("src: %d - dest: %d\n", data->src_ind, data->dest_ind); data = data->next; } } ft_printf("nb_state: %d\n s_cmd: %d\n e_cmd: %d\n s_error: %d\n e_rror: %d\n v_error: %d\n l_error: %d\n", synt->nb_state, synt->s_cmd, synt->e_cmd, synt->s_error, synt->e_error, synt->v_error, synt->l_error); } static int lem_in(t_syntax *synt, t_holder *holder, t_lmdata *lmdata) { if (!(lm_parser(synt, lmdata, holder))) return (0); if (!lst_indinit(lmdata)) return (0); if (!(lm_adj_parser(lmdata, holder))) return (0); return (1); } int main(int ac, char **av) { t_syntax synt; t_lmdata ldata; t_holder holder; t_ind **ret; t_node *it; t_node *start; t_node *end; t_ind *it2; int i; (void)av; i = 0; if (ac == 1) { lm_init_data(&synt, &holder, &ldata); if (!(lem_in(&synt, &holder, &ldata))) return (lm_error_exit()); it = ldata.nodes_data; start = NULL; end = NULL; while (it && (!start || !end)) { if (it->role == 's') start = it; else if (it->role == 'e') end = it; it = it->next; } ft_printf("data->adj: %p\n", ldata.adj); if ((!start) || (ret = edmunds_karp(&ldata, start->ind, end->ind)) == NULL) return (lm_error_exit()); if (ret != NULL) { i = 0; while (ret[i]) { it2 = ret[i]; while (it2) { ft_printf(" %d -> ", it2->index); it2 = it2->next; } ft_putchar('\n'); i++; } } push_ants(&ldata, ret, i); tablst_inddel(ret); i = 0; while (i < ldata.nb_nodes) { lst_inddel(&(ldata.adj[i])); i++; } ft_memdel((void**)&(ldata.adj)); return (0); } return (1); }