invalid maps

This commit is contained in:
Mthandazo Ndhlovu
2019-04-02 15:09:43 +02:00
parent 4e2fc9f19e
commit 1abb3fc566
127 changed files with 4946 additions and 131 deletions

View File

@@ -12,13 +12,15 @@
#include "lem_in.h"
void lm_init_data(t_syntax *synt, t_lmdata *ldata)
void lm_init_data(t_syntax *synt, t_lmdata *ldata,
t_holder *holder)
{
synt->s_cmd = 0;
synt->s_pos = 0;
synt->e_cmd = 0;
synt->e_pos = 0;
synt->gr_status = 0;
synt->error = 0;
synt->e_vert = 0;
synt->s_vert = 0;
synt->v_flag = 0;
@@ -27,36 +29,50 @@ void lm_init_data(t_syntax *synt, t_lmdata *ldata)
ldata->nodes_data = NULL;
ldata->nodes = NULL;
ldata->adj = NULL;
holder->count = 0;
holder->data = NULL;
}
void lm_add_vertex(t_lmdata *ldata, char *raw, char flag)
static void lm_add_vertex_sub(t_lmdata *ldata, t_node *new)
{
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)++;
}
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag,
t_syntax *synt)
{
char **tab;
t_node *room;
t_node *tmp;
t_node *new;
if (!(room = (t_node *)malloc(sizeof(t_node))))
return ;
if (!(new = (t_node *)malloc(sizeof(t_node))))
return (0);
tab = ft_strsplit(raw, ' ');
if (tab != NULL)
{
room->name = tab[0];
room->x = ft_atoi(tab[1]);
room->y = ft_atoi(tab[2]);
room->role = flag;
room->ind = ldata->nb_nodes;
room->next = NULL;
if (ldata->nodes_data == NULL)
ldata->nodes_data = room;
else
if (lm_check_room_before(tab, synt))
{
tmp = ldata->nodes_data;
while (tmp->next)
tmp = tmp->next;
tmp->next = room;
new->name = tab[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);
return (1);
}
(ldata->nb_nodes)++;
}
return (0);
}
int lm_find_index(t_lmdata *data, char *str)
@@ -64,14 +80,41 @@ int lm_find_index(t_lmdata *data, char *str)
t_node *nodes;
nodes = data->nodes_data;
if (nodes != NULL)
while (nodes)
{
while (nodes->next)
{
if (ft_strcmp(nodes->name, str))
return (nodes->ind);
nodes = nodes->next;
}
if (ft_strcmp(nodes->name, str) == 0)
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;
t_temp *new;
if (!(new = (t_temp *)malloc(sizeof(t_temp))))
return (0);
tab = ft_strsplit(raw, '-');
if (tab != NULL)
{
new->src_ind = lm_find_index(data, tab[0]);
new->dest_ind = lm_find_index(data, tab[1]);
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);
}