modify map printing system
added functions to create, print and clear map when it's valid corrected map del in print_map
This commit is contained in:
parent
fe1c85371f
commit
0b4c310374
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
|
||||
# Updated: 2019/04/22 12:10:47 by mndhlovu ### ########.fr #
|
||||
# Updated: 2019/04/24 18:00:14 by tmaze ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
@ -51,6 +51,7 @@ SRC = lm_parser.c \
|
||||
push_ants.c \
|
||||
push_ants_utils.c \
|
||||
score_utils.c \
|
||||
print_map.c \
|
||||
lem_in.c
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/22 12:48:54 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/24 18:10:12 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -32,15 +32,6 @@ typedef struct s_ind
|
||||
struct s_ind *next;
|
||||
} t_ind;
|
||||
|
||||
typedef struct s_lmdata
|
||||
{
|
||||
int nbants;
|
||||
int nb_nodes;
|
||||
int nb_paths_max;
|
||||
t_node *nodes_data;
|
||||
t_ind **adj;
|
||||
} t_lmdata;
|
||||
|
||||
typedef struct s_bfs
|
||||
{
|
||||
int parent;
|
||||
@ -95,6 +86,16 @@ typedef struct s_rdata
|
||||
struct s_rdata *next;
|
||||
} t_rdata;
|
||||
|
||||
typedef struct s_lmdata
|
||||
{
|
||||
int nbants;
|
||||
int nb_nodes;
|
||||
int nb_paths_max;
|
||||
t_node *nodes_data;
|
||||
t_ind **adj;
|
||||
t_rdata *map;
|
||||
} t_lmdata;
|
||||
|
||||
int lm_error_exit(void);
|
||||
int lm_validate(t_syntax *synt, t_lmdata *lmdata);
|
||||
int lm_parser(t_syntax *synt, t_lmdata *ldata
|
||||
@ -143,4 +144,8 @@ void print_paths(t_lmdata *data, t_ind **ret);
|
||||
int push_ants(t_lmdata *data, t_ind **paths
|
||||
, int nb_paths);
|
||||
|
||||
void del_map(t_lmdata *data);
|
||||
int add_line_map(t_lmdata *data, char *line);
|
||||
void print_map(t_lmdata *data);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/24 09:44:41 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/24 18:23:42 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -58,16 +58,13 @@ static int lem_in(t_syntax *synt, t_holder *holder,
|
||||
{
|
||||
if (!(lm_parser(synt, lmdata, holder)))
|
||||
return (0);
|
||||
ft_printf("start verify\n");
|
||||
if (!(lm_verify_cmd(synt, holder, lmdata)))
|
||||
return (0);
|
||||
ft_printf("Number of nodes %d\n", lmdata->nb_nodes);
|
||||
print_map(lmdata);
|
||||
if (!lst_indinit(lmdata))
|
||||
return (0);
|
||||
ft_printf("plap\n");
|
||||
if (!(lm_adj_parser(lmdata, holder)))
|
||||
return (0);
|
||||
ft_printf("plop\n");
|
||||
lm_clear_unv(holder);
|
||||
get_nb_paths_max(lmdata, get_node_role(lmdata, 's')->ind
|
||||
, get_node_role(lmdata, 'e')->ind);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/24 09:51:14 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/24 18:03:58 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,6 +33,7 @@ void lm_init_data(t_syntax *synt, t_holder *holder, t_lmdata *ldata)
|
||||
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)
|
||||
|
61
srcs/print_map.c
Normal file
61
srcs/print_map.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* print_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/24 17:35:29 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/26 11:29:53 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void del_map(t_lmdata *data)
|
||||
{
|
||||
t_rdata *tmp;
|
||||
|
||||
while (data->map)
|
||||
{
|
||||
ft_strdel(&(data->map->line));
|
||||
tmp = data->map;
|
||||
data->map = data->map->next;
|
||||
ft_memdel((void**)&tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void print_map(t_lmdata *data)
|
||||
{
|
||||
t_rdata *it;
|
||||
|
||||
it = data->map;
|
||||
while (it)
|
||||
{
|
||||
ft_printf("%s\n", it->line);
|
||||
it = it->next;
|
||||
}
|
||||
del_map(data);
|
||||
}
|
||||
|
||||
int add_line_map(t_lmdata *data, char *line)
|
||||
{
|
||||
t_rdata *it;
|
||||
t_rdata *new;
|
||||
|
||||
if ((new = (t_rdata*)ft_memalloc(sizeof(t_rdata))) == NULL)
|
||||
return (1);
|
||||
new->line = line;
|
||||
new->next = NULL;
|
||||
if (data->map == NULL)
|
||||
data->map = new;
|
||||
else
|
||||
{
|
||||
it = data->map;
|
||||
while (it->next)
|
||||
it = it->next;
|
||||
it->next = new;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user