semi-final parser

This commit is contained in:
Mthandazo Ndhlovu 2019-05-02 12:58:28 +02:00
commit 8552cf8a32
10 changed files with 150 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
/* Updated: 2019/04/30 08:23:04 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 11:18:03 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -109,10 +109,15 @@ int lm_ext_conn(t_holder *holder, t_lmdata *data
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
, char *raw);
int lm_find_index(t_lmdata *data, char *str);
void lm_get_cmd_vertices(int count, t_syntax *synt
, t_lmdata *ldata, char *line);
int lm_get_value(char *line);
void lm_get_cmd_vert(int count, t_syntax *synt
, t_lmdata *ldata, char *line);
void lm_check_start_vert(int count, t_syntax *synt
, t_lmdata *ldata, char *line);
void lm_check_end_vert(int count, t_syntax *synt
, t_lmdata *ldata, char *line);
void lm_get_vert_link(int count, t_lmdata *ldata
, t_syntax *synt, t_holder *holder, char *line);
int lm_validate_rooms(char *name, char *x, char *y);

View File

@ -1,13 +1,63 @@
3
1 0 2
##start
#dd
#ddddd
##sjdjdjssjds
##djsjddjs
#sddsds
##start
#dsdsdsdsd
0 2 0
##end
##sjsjsjjds
#sjdsjdsjs
#sjsjdsjsaj
#sjsjss
##start
##end
#sjsjdsjsdh
#sksksdksdsk
#skdkskdsjds
4 2 6
2 4 2
#comment
#comment
#comment
#comment
#comment
3 4 4
#comment
#comment
##nothing
#comming
#asazii
0-1
#hellow
##42 ecole
##good
0-2
#comment
#comment
#comment
#comment
#comment
#comment
#comment
#comment
2-3
##kkkk
#kkklkk
#sdedfdds
#cdkskvkfdkndfvnds
#cbdjvbdj
#wofokdkfsdsd
3-4
#cooment
#comment
#comment
##starrtt
4-1
1-2
0-2

BIN
srcs/.lem_in.c.swp Normal file

Binary file not shown.

BIN
srcs/.lm_utils_parser.c.swp Normal file

Binary file not shown.

View File

@ -6,12 +6,27 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
/* Updated: 2019/04/30 07:21:10 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 12:56:48 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void lm_test_print(t_lmdata *data)
{
t_node *node;
if (data != NULL)
{
node = data->nodes_data;
while (node)
{
ft_printf("name: %s | x: %d | y: %d | role: %c \n", node->name, node->x, node->y, node->role);
node = node->next;
}
}
}
static int lem_in(t_syntax *synt, t_holder *holder,
t_lmdata *lmdata, t_ind ***ret)
{
@ -22,7 +37,8 @@ static int lem_in(t_syntax *synt, t_holder *holder,
return (0);
if ((lm_adj_parser(lmdata, holder) == 0))
return (0);
//print_map(lmdata);
print_map(lmdata);
lm_test_print(lmdata);
lm_clear_unv(holder);
get_nb_paths_max(lmdata, get_node_role(lmdata, 's')->ind
, get_node_role(lmdata, 'e')->ind);

View File

@ -6,7 +6,7 @@
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
/* Updated: 2019/04/29 12:06:41 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 12:58:05 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,7 +39,7 @@ int lm_check_forbiden_chars(char *line, int flag)
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);

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/23 17:43:34 by tmaze #+# #+# */
/* Updated: 2019/04/30 07:06:35 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 12:52:26 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,56 @@ void lm_initdata(t_lmdata *data)
data->adj = NULL;
}
void lm_check_start_vert(int count, t_syntax *synt, t_lmdata *ldata, char *line)
{
if ((synt->s_pos < synt->e_pos) && lm_check_forbiden_chars(line, 0))
{
if ((count > synt->s_pos && count < synt->e_pos)
&& (!synt->s_vert))
{
if ((lm_add_vertex(ldata, line, 's', synt)))
synt->s_vert = count;
else
synt->s_error = 1;
}
}
if ((synt->s_pos > synt->e_pos) && lm_check_forbiden_chars(line, 0))
{
if (!synt->s_vert)
{
if ((lm_add_vertex(ldata, line, 's', synt)))
synt->s_vert = count;
else
synt->s_error = 1;
}
}
}
void lm_check_end_vert(int count, t_syntax *synt, t_lmdata *ldata, char *line)
{
if((synt->e_pos < synt->s_pos) && lm_check_forbiden_chars(line, 0))
{
if ((count > synt->e_pos && count < synt->s_pos)
&& (!synt->e_vert))
{
if ((lm_add_vertex(ldata, line, 'e', synt)))
synt->e_vert = count;
else
synt->e_error = 1;
}
}
if ((synt->e_pos > synt->s_pos) && lm_check_forbiden_chars(line, 0))
{
if (!synt->e_vert)
{
if ((lm_add_vertex(ldata, line, 'e', synt)))
synt->e_vert = count;
else
synt->e_error = 1;
}
}
}
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
, char *raw)
{

View File

@ -6,7 +6,7 @@
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */
/* Updated: 2019/04/30 12:06:22 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 11:18:42 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,7 +62,7 @@ static int lm_get_ant_(int counter, t_lmdata *ldata
static int lm_get_vertices(int count, t_lmdata *data
, t_syntax *syntax, t_holder *holder, char *line)
{
lm_get_cmd_vert(count, syntax, data, line);
lm_get_cmd_vertices(count, syntax, data, line);
if (!syntax->s_error && !syntax->e_error)
{
lm_get_vert_link(count, data, syntax, holder, line);

View File

@ -6,7 +6,7 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
/* Updated: 2019/04/30 08:16:49 by mndhlovu ### ########.fr */
/* Updated: 2019/05/02 11:18:12 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,12 +34,24 @@ int lm_get_value(char *line)
return (0);
}
void lm_get_cmd_vertices(int count, t_syntax *synt
, t_lmdata *ldata, char *line)
{
if (count > 0 && line != NULL)
{
lm_check_start_vert(count, synt, ldata, line);
lm_check_end_vert(count, synt, ldata, line);
}
}
void lm_get_cmd_vert(int count, t_syntax *synt
, t_lmdata *ldata, char *line)
{
char *tmp;
if (synt->s_pos == count - 1)
if ((synt->s_pos == count - 1 && lm_check_forbiden_chars(line, 0))
|| ((synt->s_pos <= count && !synt->s_vert)
&& lm_check_forbiden_chars(line, 0)))
{
tmp = ft_strchr(line, '#');
if (tmp == NULL && count != synt->e_vert)
@ -49,7 +61,9 @@ void lm_get_cmd_vert(int count, t_syntax *synt
synt->s_error = 1;
}
}
if (synt->e_pos == count - 1)
if ((synt->e_pos == count - 1 && lm_check_forbiden_chars(line, 0))
|| ((synt->e_pos <= count && !synt->e_vert)
&& lm_check_forbiden_chars(line, 0)))
{
tmp = ft_strchr(line, '#');
if (tmp == NULL && count != synt->s_vert)

View File

@ -6,11 +6,12 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/24 17:35:29 by tmaze #+# #+# */
/* Updated: 2019/04/29 12:40:25 by mndhlovu ### ########.fr */
/* Updated: 2019/04/29 13:05:56 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
#include <stdio.h>
void del_map(t_lmdata *data)
{
@ -18,9 +19,9 @@ void del_map(t_lmdata *data)
while (data->map)
{
ft_strdel(&(data->map->line));
tmp = data->map;
data->map = data->map->next;
ft_strdel(&(tmp->line));
ft_memdel((void**)&tmp);
}
}