code cleaning done on 80 percent of the parser functions, whats left is to re structure the syntax struct and do furthure tests to eliminate level 0 errors
This commit is contained in:
Binary file not shown.
@@ -6,79 +6,36 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 13:21:09 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:40:52 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
static t_node *get_node_role(t_lmdata *data, char role)
|
||||
{
|
||||
t_node *it;
|
||||
|
||||
it = data->nodes_data;
|
||||
while (it)
|
||||
{
|
||||
if (it->role == role)
|
||||
return (it);
|
||||
it = it->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int get_nb_paths(t_ind **ret)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (ret[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void get_nb_paths_max(t_lmdata *data, int start, int end)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
t_ind *it;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
it = data->adj[start];
|
||||
while (it && ++i)
|
||||
it = it->next;
|
||||
it = data->adj[end];
|
||||
while (it && ++j)
|
||||
it= it->next;
|
||||
data->nb_paths_max = (i > j) ? j : i;
|
||||
}
|
||||
|
||||
static int lem_in(t_syntax *synt, t_holder *holder,
|
||||
t_lmdata *lmdata, t_ind ***ret)
|
||||
{
|
||||
lm_parser(synt, lmdata, holder);
|
||||
if (!(lm_verify_cmd(synt, holder, lmdata)))
|
||||
if (!lm_verify_cmd(synt, holder, lmdata))
|
||||
return (0);
|
||||
print_map(lmdata);
|
||||
if (!lst_indinit(lmdata))
|
||||
return (0);
|
||||
lm_adj_parser(lmdata, holder);
|
||||
if ((lm_adj_parser(lmdata, holder) == 0))
|
||||
return (0);
|
||||
//print_map(lmdata);
|
||||
lm_clear_unv(holder);
|
||||
get_nb_paths_max(lmdata, get_node_role(lmdata, 's')->ind
|
||||
, get_node_role(lmdata, 'e')->ind);
|
||||
if ((*ret = edmonds_karp(lmdata, get_node_role(lmdata, 's')->ind
|
||||
, get_node_role(lmdata, 'e')->ind)) == NULL)
|
||||
{
|
||||
ft_printf("plop\n");
|
||||
return (0);
|
||||
}
|
||||
if (!push_ants(lmdata, *ret, get_nb_paths(*ret)))
|
||||
return (0);
|
||||
tablst_inddel(*ret);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int lm_error_exit(void)
|
||||
static int lm_error_exit(void)
|
||||
{
|
||||
ft_putendl_fd("ERROR", 2);
|
||||
return (1);
|
||||
|
@@ -6,52 +6,49 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 13:35:05 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:06:41 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
int lm_check_room_before(char **tab, t_syntax *synt)
|
||||
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]))
|
||||
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);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_check_forbiden_chars(char *line, int flag)
|
||||
int lm_check_forbiden_chars(char *line, int flag)
|
||||
{
|
||||
char *hash;
|
||||
char *dash;
|
||||
char *hash;
|
||||
char *dash;
|
||||
|
||||
if (line != NULL)
|
||||
{
|
||||
dash = ft_strchr(line, '-');
|
||||
hash = ft_strchr(line, '#');
|
||||
if (flag == 0 && dash == NULL
|
||||
&& hash == NULL)
|
||||
if (flag == 0 && dash == NULL && hash == NULL)
|
||||
return (1);
|
||||
if (flag == 1 && dash == NULL
|
||||
&& hash != NULL)
|
||||
if (flag == 1 && dash == NULL && hash != NULL)
|
||||
return (1);
|
||||
if (flag == 2 && dash == NULL
|
||||
if (flag == 2 && dash == NULL
|
||||
&& (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||
return (1);
|
||||
if (flag == 3 && dash != NULL
|
||||
&& hash == NULL)
|
||||
if (flag == 3 && dash != NULL && hash == NULL)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void lm_clear_unv(t_holder *holder)
|
||||
void lm_clear_unv(t_holder *holder)
|
||||
{
|
||||
t_temp *data;
|
||||
t_temp *flush;
|
||||
t_temp *data;
|
||||
t_temp *flush;
|
||||
|
||||
data = holder->data;
|
||||
while (data)
|
||||
@@ -64,24 +61,22 @@ void lm_clear_unv(t_holder *holder)
|
||||
holder->data = NULL;
|
||||
}
|
||||
|
||||
int lm_verify_links(t_holder *data, t_syntax *synt)
|
||||
int lm_verify_links(t_holder *data, t_syntax *synt)
|
||||
{
|
||||
if (!synt->l_error || (synt->l_error && data->count > 0))
|
||||
{
|
||||
ft_printf("Bingo\n");
|
||||
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)
|
||||
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
|
||||
&& synt->nb_state
|
||||
&& lm_verify_links(holder, synt)
|
||||
&& (data->nb_nodes > 0))
|
||||
&& (data->nb_nodes > 0))
|
||||
return (1);
|
||||
lm_clear_unv(holder);
|
||||
return (0);
|
||||
|
@@ -6,40 +6,40 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/05 06:35:40 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/23 11:01:37 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:06:18 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
t_rdata *lm_new_raw_line(char *raw)
|
||||
t_rdata *lm_new_raw_line(char *raw)
|
||||
{
|
||||
t_rdata *line;
|
||||
t_rdata *line;
|
||||
|
||||
if (!(line = (t_rdata *)malloc(sizeof(t_rdata))))
|
||||
return (NULL);
|
||||
line->line = ft_strdup(raw);
|
||||
line->next = NULL;
|
||||
return (line);
|
||||
if (!(line = (t_rdata *)malloc(sizeof(t_rdata))))
|
||||
return (NULL);
|
||||
line->line = ft_strdup(raw);
|
||||
line->next = NULL;
|
||||
return (line);
|
||||
}
|
||||
|
||||
void lm_append_line(t_rdata **line, char *raw)
|
||||
void lm_append_line(t_rdata **line, char *raw)
|
||||
{
|
||||
if (*line)
|
||||
{
|
||||
if((*line)->next)
|
||||
lm_append_line(&(*line)->next, raw);
|
||||
else
|
||||
(*line)->next = lm_new_raw_line(raw);
|
||||
}
|
||||
else
|
||||
*line = lm_new_raw_line(raw);
|
||||
if (*line)
|
||||
{
|
||||
if ((*line)->next)
|
||||
lm_append_line(&(*line)->next, raw);
|
||||
else
|
||||
(*line)->next = lm_new_raw_line(raw);
|
||||
}
|
||||
else
|
||||
*line = lm_new_raw_line(raw);
|
||||
}
|
||||
|
||||
void lm_clean_data(t_lmdata *data)
|
||||
void lm_clean_data(t_lmdata *data)
|
||||
{
|
||||
t_node *tmp;
|
||||
int i;
|
||||
t_node *tmp;
|
||||
int i;
|
||||
|
||||
while (data->nodes_data)
|
||||
{
|
||||
|
@@ -6,15 +6,16 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/29 07:17:06 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 12:15:47 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:05:52 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
static int is_link_in(t_lmdata *data, int src, int dest)
|
||||
static int is_link_in(t_lmdata *data, int src, int dest)
|
||||
{
|
||||
t_ind *it;
|
||||
t_ind *it;
|
||||
|
||||
if (src < data->nb_nodes)
|
||||
{
|
||||
it = data->adj[src];
|
||||
@@ -28,15 +29,13 @@ static int is_link_in(t_lmdata *data, int src, int dest)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder)
|
||||
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder)
|
||||
{
|
||||
t_temp *data;
|
||||
t_temp *data;
|
||||
|
||||
ft_printf("=== lm_adj_parser ===\nholder: %p\n\n", holder);
|
||||
if (holder != NULL)
|
||||
{
|
||||
data = holder->data;
|
||||
ft_printf("data: %p\n\n", data);
|
||||
if (data != NULL)
|
||||
{
|
||||
while (data)
|
||||
|
@@ -6,15 +6,44 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/23 17:43:34 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/22 12:44:00 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:08:36 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void lm_initdata(t_lmdata *data)
|
||||
void lm_initdata(t_lmdata *data)
|
||||
{
|
||||
data->nbants = 0;
|
||||
data->nodes_data = NULL;
|
||||
data->adj = NULL;
|
||||
}
|
||||
|
||||
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
|
||||
, char *raw)
|
||||
{
|
||||
int s;
|
||||
int d;
|
||||
char **tab;
|
||||
|
||||
if (raw != NULL)
|
||||
{
|
||||
tab = ft_strsplit(raw, '-');
|
||||
if (tab != NULL)
|
||||
{
|
||||
s = lm_find_index(data, tab[0]);
|
||||
d = lm_find_index(data, tab[1]);
|
||||
if (s == -1 || d == -1)
|
||||
{
|
||||
ft_del_words_tables(&tab);
|
||||
return (0);
|
||||
}
|
||||
*src = s;
|
||||
*dest = d;
|
||||
ft_del_words_tables(&tab);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
ft_del_words_tables(&tab);
|
||||
return (0);
|
||||
}
|
||||
|
@@ -6,131 +6,121 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 12:15:05 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:07:09 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void lm_init_data(t_syntax *synt, t_holder *holder, t_lmdata *ldata)
|
||||
void lm_init_data(t_syntax *synt, t_holder *holder, t_lmdata *ldata)
|
||||
{
|
||||
synt->nb_state = 0;
|
||||
synt->s_cmd = 0;
|
||||
synt->e_cmd = 0;
|
||||
synt->s_error = 0;
|
||||
synt->e_error = 0;
|
||||
synt->v_error = 0;
|
||||
synt->l_error = 0;
|
||||
synt->s_vert = 0;
|
||||
synt->e_vert = 0;
|
||||
synt->gr_status = 0;
|
||||
synt->s_pos = 0;
|
||||
synt->e_pos = 0;
|
||||
synt->v_flag = 0;
|
||||
holder->count = 0;
|
||||
holder->data = NULL;
|
||||
ldata->nbants = 0;
|
||||
ldata->nb_nodes = 0;
|
||||
ldata->nodes_data = NULL;
|
||||
synt->nb_state = 0;
|
||||
synt->s_cmd = 0;
|
||||
synt->e_cmd = 0;
|
||||
synt->s_error = 0;
|
||||
synt->e_error = 0;
|
||||
synt->v_error = 0;
|
||||
synt->l_error = 0;
|
||||
synt->s_vert = 0;
|
||||
synt->e_vert = 0;
|
||||
synt->gr_status = 0;
|
||||
synt->s_pos = 0;
|
||||
synt->e_pos = 0;
|
||||
synt->v_flag = 0;
|
||||
holder->count = 0;
|
||||
holder->data = NULL;
|
||||
ldata->nbants = 0;
|
||||
ldata->nb_nodes = 0;
|
||||
ldata->nodes_data = NULL;
|
||||
ldata->adj = NULL;
|
||||
ldata->map = NULL;
|
||||
}
|
||||
|
||||
static void lm_add_vertex_sub(t_lmdata *ldata, t_node *new)
|
||||
static void lm_add_vertex_sub(t_lmdata *ldata, t_node *new)
|
||||
{
|
||||
t_node *tmp;
|
||||
t_node *tmp;
|
||||
|
||||
if (ldata->nodes_data == NULL)
|
||||
ldata->nodes_data = new;
|
||||
else
|
||||
{
|
||||
tmp = ldata->nodes_data;
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
(ldata->nb_nodes)++;
|
||||
if (ldata->nodes_data == NULL)
|
||||
ldata->nodes_data = new;
|
||||
else
|
||||
{
|
||||
tmp = ldata->nodes_data;
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
(ldata->nb_nodes)++;
|
||||
}
|
||||
|
||||
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag,
|
||||
t_syntax *synt)
|
||||
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag,
|
||||
t_syntax *synt)
|
||||
{
|
||||
char **tab;
|
||||
t_node *new;
|
||||
char **tab;
|
||||
t_node *new;
|
||||
|
||||
if (!(new = (t_node *)ft_memalloc(sizeof(t_node))))
|
||||
return (0);
|
||||
tab = ft_strsplit(raw, ' ');
|
||||
if (tab != NULL)
|
||||
{
|
||||
if (lm_check_room_before(tab, synt))
|
||||
{
|
||||
if ((new->name = ft_strdup(tab[0])) == NULL)
|
||||
if (!(new = (t_node *)ft_memalloc(sizeof(t_node))))
|
||||
return (0);
|
||||
tab = ft_strsplit(raw, ' ');
|
||||
if (tab != NULL)
|
||||
{
|
||||
if (lm_check_room_before(tab, synt))
|
||||
{
|
||||
if ((new->name = ft_strdup(tab[0])) == NULL)
|
||||
ft_del_words_tables(&tab);
|
||||
if (new->name == NULL)
|
||||
return (0);
|
||||
new->x = ft_atoi(tab[1]);
|
||||
new->y = ft_atoi(tab[2]);
|
||||
new->role = flag;
|
||||
new->ind = ldata->nb_nodes;
|
||||
new->next = NULL;
|
||||
lm_add_vertex_sub(ldata, new);
|
||||
new->x = ft_atoi(tab[1]);
|
||||
new->y = ft_atoi(tab[2]);
|
||||
new->role = flag;
|
||||
new->ind = ldata->nb_nodes;
|
||||
new->next = NULL;
|
||||
lm_add_vertex_sub(ldata, new);
|
||||
ft_del_words_tables(&tab);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_find_index(t_lmdata *data, char *str)
|
||||
{
|
||||
t_node *nodes;
|
||||
|
||||
nodes = data->nodes_data;
|
||||
while (nodes)
|
||||
{
|
||||
if (ft_strequ(nodes->name, str))
|
||||
return (nodes->ind);
|
||||
nodes = nodes->next;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw)
|
||||
{
|
||||
char **tab;
|
||||
t_temp *temp;
|
||||
int src;
|
||||
int dest;
|
||||
t_temp *new;
|
||||
|
||||
if (!(new = (t_temp *)ft_memalloc(sizeof(t_temp))))
|
||||
return (0);
|
||||
tab = ft_strsplit(raw, '-');
|
||||
if (tab != NULL)
|
||||
{
|
||||
src = lm_find_index(data, tab[0]);
|
||||
dest = lm_find_index(data, tab[1]);
|
||||
if (src == -1 || dest == -1)
|
||||
{
|
||||
ft_del_words_tables(&tab);
|
||||
return 0;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_find_index(t_lmdata *data, char *str)
|
||||
{
|
||||
t_node *nodes;
|
||||
|
||||
nodes = data->nodes_data;
|
||||
while (nodes)
|
||||
{
|
||||
if (ft_strequ(nodes->name, str))
|
||||
return (nodes->ind);
|
||||
nodes = nodes->next;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw)
|
||||
{
|
||||
t_temp *temp;
|
||||
t_temp *new;
|
||||
int src;
|
||||
int dest;
|
||||
|
||||
if (!(new = (t_temp *)ft_memalloc(sizeof(t_temp))))
|
||||
return (0);
|
||||
if (lm_init_src_dest(&src, &dest, data, raw))
|
||||
{
|
||||
new->src_ind = src;
|
||||
new->dest_ind = dest;
|
||||
new->next = NULL;
|
||||
if (holder->data == NULL)
|
||||
holder->data = new;
|
||||
else
|
||||
{
|
||||
temp = holder->data;
|
||||
while (temp->next)
|
||||
temp = temp->next;
|
||||
temp->next = new;
|
||||
}
|
||||
(holder->count)++;
|
||||
ft_del_words_tables(&tab);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
new->next = NULL;
|
||||
if (holder->data == NULL)
|
||||
holder->data = new;
|
||||
else
|
||||
{
|
||||
temp = holder->data;
|
||||
while (temp->next)
|
||||
temp = temp->next;
|
||||
temp->next = new;
|
||||
}
|
||||
(holder->count)++;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
148
srcs/lm_parser.c
148
srcs/lm_parser.c
@@ -6,97 +6,97 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 13:05:45 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:45:25 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||
static void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||
{
|
||||
char *tmp;
|
||||
char *tmp;
|
||||
|
||||
tmp = ft_strchr(line, '#');
|
||||
if ((!synt->s_cmd || !synt->e_cmd)
|
||||
tmp = ft_strchr(line, '#');
|
||||
if ((!synt->s_cmd || !synt->e_cmd)
|
||||
&& (tmp != NULL && line[1] == '#'
|
||||
&& lm_check_forbiden_chars(line, 1)))
|
||||
{
|
||||
if (!synt->s_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##start") == 0)
|
||||
{
|
||||
synt->s_cmd = 1;
|
||||
synt->s_pos = index;
|
||||
}
|
||||
}
|
||||
if (!synt->e_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##end") == 0)
|
||||
{
|
||||
synt->e_cmd = 1;
|
||||
synt->e_pos = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, char *line)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
value = lm_get_value(line);
|
||||
if (value > 0)
|
||||
{
|
||||
ldata->nbants = value;
|
||||
synt->nb_state = 1;
|
||||
return (1);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int lm_get_vertices(int count, t_syntax *synt,
|
||||
t_lmdata *data, t_holder *holder, char *line)
|
||||
{
|
||||
lm_get_cmd_vert(count, synt, data, line);
|
||||
if (!synt->s_error && !synt->e_error)
|
||||
{
|
||||
lm_get_vert_link(count, synt, data, holder, line);
|
||||
if (!synt->v_error && !synt->l_error)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_parser(t_syntax *synt, t_lmdata *ldata,
|
||||
t_holder *holder)
|
||||
{
|
||||
char *raw;
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
while (ft_getline(&raw) > 0 && raw[0] != '\0')
|
||||
{
|
||||
ft_printf("%s\n", raw);
|
||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||
if (!synt->s_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##start") == 0)
|
||||
{
|
||||
synt->s_cmd = 1;
|
||||
synt->s_pos = index;
|
||||
}
|
||||
}
|
||||
if (!synt->e_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##end") == 0)
|
||||
{
|
||||
synt->e_cmd = 1;
|
||||
synt->e_pos = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int lm_get_ant_(int counter, t_lmdata *ldata
|
||||
, t_syntax *synt, char *line)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
value = lm_get_value(line);
|
||||
if (value > 0)
|
||||
{
|
||||
ldata->nbants = value;
|
||||
synt->nb_state = 1;
|
||||
return (1);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int lm_get_vertices(int count, t_syntax *synt
|
||||
, t_lmdata *data, t_holder *holder, char *line)
|
||||
{
|
||||
lm_get_cmd_vert(count, synt, data, line);
|
||||
if (!synt->s_error && !synt->e_error)
|
||||
{
|
||||
lm_get_vert_link(count, synt, data, holder, line);
|
||||
if (!synt->v_error && !synt->l_error)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_parser(t_syntax *synt
|
||||
, t_lmdata *ldata, t_holder *holder)
|
||||
{
|
||||
char *raw;
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
while (ft_getline(&raw) > 0 && raw[0] != '\0')
|
||||
{
|
||||
if ((add_line_map(ldata, raw)))
|
||||
return (0);
|
||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||
{
|
||||
//ft_strdel(&raw);
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
lm_locate_cd(index, synt, raw);
|
||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
||||
lm_locate_cd(index, synt, raw);
|
||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
||||
{
|
||||
ft_strdel(&raw);
|
||||
return (0);
|
||||
}
|
||||
ft_strdel(&raw);
|
||||
index++;
|
||||
}
|
||||
ft_printf("final raw: %s\n", raw);
|
||||
index++;
|
||||
}
|
||||
ft_strdel(&raw);
|
||||
ft_putchar('\n');
|
||||
return (1);
|
||||
return (1);
|
||||
}
|
||||
|
@@ -6,13 +6,13 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 10:42:43 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:06:08 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
int lm_chk_format_nbr(char *raw)
|
||||
static int lm_chk_format_nbr(char *raw)
|
||||
{
|
||||
while (*raw)
|
||||
{
|
||||
@@ -25,16 +25,16 @@ int lm_chk_format_nbr(char *raw)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_check_max(char *raw)
|
||||
static int lm_check_max(char *raw)
|
||||
{
|
||||
if (ft_atoi(raw) < INT_MIN || ft_atoi(raw) > INT_MAX)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_validate_name(char *name)
|
||||
static int lm_validate_name(char *name)
|
||||
{
|
||||
int index;
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
if (name[0] == 'L')
|
||||
@@ -48,28 +48,29 @@ int lm_validate_name(char *name)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_validate_rooms(char *name, char *x, char *y)
|
||||
int lm_validate_rooms(char *name, char *x, char *y)
|
||||
{
|
||||
if (lm_validate_name(name) == -1)
|
||||
return (0);
|
||||
if (lm_chk_format_nbr(x) == -1 ||
|
||||
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
|
||||
(ft_atoi(x) == 0)) ||
|
||||
ft_strlen(x) > 19)
|
||||
if (lm_chk_format_nbr(x) == -1
|
||||
|| lm_check_max(x) == -1
|
||||
|| (ft_atoi(x) > 0 && (ft_atoi(x) == 0))
|
||||
|| ft_strlen(x) > 19)
|
||||
return (0);
|
||||
if (lm_chk_format_nbr(y) == -1 ||
|
||||
lm_check_max(y) == -1 || (ft_atoi(y) > 0 &&
|
||||
(ft_atoi(y) == 0)) ||
|
||||
ft_strlen(y) > 19)
|
||||
if (lm_chk_format_nbr(y) == -1
|
||||
|| lm_check_max(y) == -1
|
||||
|| (ft_atoi(y) > 0 && (ft_atoi(y) == 0))
|
||||
|| ft_strlen(y) > 19)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int lm_error_nbr(char *raw)
|
||||
int lm_error_nbr(char *raw)
|
||||
{
|
||||
if (lm_chk_format_nbr(raw) == -1 || lm_check_max(raw) == -1 ||
|
||||
(ft_atoi(raw) > 0 && (ft_atoi(raw) == 0)) ||
|
||||
ft_strlen(raw) > 19)
|
||||
if (lm_chk_format_nbr(raw) == -1
|
||||
|| lm_check_max(raw) == -1
|
||||
|| (ft_atoi(raw) > 0 && (ft_atoi(raw) == 0))
|
||||
|| ft_strlen(raw) > 19)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
54
srcs/lm_utils_algo.c
Normal file
54
srcs/lm_utils_algo.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lm_utils_algo.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/29 11:50:04 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/29 12:10:09 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
t_node *get_node_role(t_lmdata *data, char role)
|
||||
{
|
||||
t_node *it;
|
||||
|
||||
it = data->nodes_data;
|
||||
while (it)
|
||||
{
|
||||
if (it->role == role)
|
||||
return (it);
|
||||
it = it->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int get_nb_paths(t_ind **ret)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
while (ret[index])
|
||||
index++;
|
||||
return (index);
|
||||
}
|
||||
|
||||
void get_nb_paths_max(t_lmdata *data, int start, int end)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
t_ind *it;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
it = data->adj[start];
|
||||
while (it && ++i)
|
||||
it = it->next;
|
||||
it = data->adj[end];
|
||||
while (it && ++j)
|
||||
it = it->next;
|
||||
data->nb_paths_max = (i > j) ? j : i;
|
||||
}
|
@@ -6,15 +6,15 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 13:35:09 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:05:40 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
int lm_check_ant_no(char *line)
|
||||
static int lm_check_ant_no(char *line)
|
||||
{
|
||||
int len;
|
||||
int len;
|
||||
|
||||
len = ft_strlen(line);
|
||||
if (len > 0)
|
||||
@@ -27,55 +27,56 @@ int lm_check_ant_no(char *line)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_get_value(char *line)
|
||||
int lm_get_value(char *line)
|
||||
{
|
||||
if (line != NULL)
|
||||
if (line != NULL)
|
||||
return (lm_check_ant_no(line));
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void lm_get_cmd_vert(int count, t_syntax *synt
|
||||
, t_lmdata *ldata, char *line)
|
||||
void lm_get_cmd_vert(int count, t_syntax *synt
|
||||
, t_lmdata *ldata, char *line)
|
||||
{
|
||||
char *tmp;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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_syntax *synt, t_lmdata *ldata
|
||||
, t_holder *holder, char *line)
|
||||
void lm_get_vert_link(int count, t_syntax *synt
|
||||
, t_lmdata *ldata, t_holder *holder, char *line)
|
||||
{
|
||||
if (count > 0 && (count != synt->s_vert && count != synt->e_vert)
|
||||
&& (count != synt->s_pos && count != synt->e_pos && line != NULL))
|
||||
{
|
||||
if (lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
||||
synt->v_error = 1;
|
||||
}
|
||||
if (lm_check_forbiden_chars(line, 3))
|
||||
{
|
||||
if (!(lm_ext_conn(holder, ldata, line)))
|
||||
synt->l_error = 1;
|
||||
}
|
||||
}
|
||||
if (count > 0 && (count != synt->s_vert && count != synt->e_vert)
|
||||
&& (count != synt->s_pos
|
||||
&& count != synt->e_pos && line != NULL))
|
||||
{
|
||||
if (lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
||||
synt->v_error = 1;
|
||||
}
|
||||
if (lm_check_forbiden_chars(line, 3))
|
||||
{
|
||||
if (!(lm_ext_conn(holder, ldata, line)))
|
||||
synt->l_error = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/24 17:35:29 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/26 11:53:36 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:40:25 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user