Trying to trace the source of the segfault
I will breakdown the parser for a slight moment then relink it.
This commit is contained in:
parent
a8b2e31701
commit
c35deace58
2
Makefile
2
Makefile
@ -6,7 +6,7 @@
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
|
||||
# Updated: 2019/04/22 09:44:46 by tmaze ### ########.fr #
|
||||
# Updated: 2019/04/22 12:10:47 by mndhlovu ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/22 10:01:33 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 12:48:54 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
|
||||
# Updated: 2019/04/18 09:18:00 by tmaze ### ########.fr #
|
||||
# Updated: 2019/04/22 12:11:07 by mndhlovu ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
CC = gcc
|
||||
CCFLAGS = -Wall -Werror -Wextra
|
||||
CCFLAGS = -Wall -Werror -Wextra -g
|
||||
CCSTD =
|
||||
|
||||
NAME = libft.a
|
||||
|
28
libft/ft_strcmp.c
Normal file
28
libft/ft_strcmp.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/03 15:38:27 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/22 10:46:05 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
int diff;
|
||||
|
||||
i = 1;
|
||||
diff = (unsigned char)s1[0] - (unsigned char)s2[0];
|
||||
while (diff == 0 && s1[i - 1] && s2[i - 1])
|
||||
{
|
||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
i++;
|
||||
}
|
||||
return (diff);
|
||||
}
|
@ -3,26 +3,22 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/03 15:38:27 by tmaze #+# #+# */
|
||||
/* Updated: 2018/04/08 15:30:24 by tmaze ### ########.fr */
|
||||
/* Created: 2018/11/07 17:33:42 by mndhlovu #+# #+# */
|
||||
/* Updated: 2018/11/09 17:56:30 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
int diff;
|
||||
size_t len;
|
||||
|
||||
i = 1;
|
||||
diff = (unsigned char)s1[0] - (unsigned char)s2[0];
|
||||
while (diff == 0 && s1[i - 1] && s2[i - 1])
|
||||
{
|
||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
i++;
|
||||
}
|
||||
return (diff);
|
||||
len = 0;
|
||||
while (s1[len] && s2[len] && s1[len] == s2[len])
|
||||
len++;
|
||||
return ((unsigned char)s1[len] - (unsigned char)s2[len]);
|
||||
}
|
||||
|
@ -1,165 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* edmunds_karp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/28 16:21:19 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/14 14:03:45 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
static void update_weights(t_lmdata *data, t_bfs *tab, int end_ind)
|
||||
{
|
||||
t_ind *it;
|
||||
int i;
|
||||
|
||||
i = end_ind;
|
||||
while (i != -1)
|
||||
{
|
||||
if (tab[i].parent != -1)
|
||||
{
|
||||
it = data->adj[tab[i].parent];
|
||||
while (it && it->index != i)
|
||||
it = it->next;
|
||||
if (it && it->index == i)
|
||||
it->weight--;
|
||||
it = data->adj[i];
|
||||
while (it && it->index != tab[i].parent)
|
||||
it = it->next;
|
||||
if (it && it->index == tab[i].parent)
|
||||
it->weight++;
|
||||
}
|
||||
i = tab[i].parent;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_score(t_lmdata *data, t_ind **ret)
|
||||
{
|
||||
int tot;
|
||||
int score;
|
||||
int nb_paths;
|
||||
int i;
|
||||
t_ind *it;
|
||||
|
||||
i = 0;
|
||||
tot = 0;
|
||||
score = 0;
|
||||
while (ret && ret[i])
|
||||
i++;
|
||||
nb_paths = i;
|
||||
ft_printf("nb_paths: %d\n", nb_paths);
|
||||
i = 0;
|
||||
while (ret && ret[i] && (it = ret[i]))
|
||||
{
|
||||
while (it && ++tot)
|
||||
it = it->next;
|
||||
tot = tot + (data->nbants / nb_paths) - 1;
|
||||
if (score == 0 || tot > score)
|
||||
score = tot;
|
||||
i++;
|
||||
}
|
||||
return (score);
|
||||
}
|
||||
|
||||
/* static int reset_weights(t_lmdata *data, int node) */
|
||||
/* { */
|
||||
/* t_ind *it; */
|
||||
/* t_ind *it2; */
|
||||
|
||||
/* it = data->adj[node]; */
|
||||
/* it2 = NULL; */
|
||||
/* while (it && it->weight != 2) */
|
||||
/* it = it->next; */
|
||||
/* if (it && it->weight == 2) */
|
||||
/* it->weight = 1; */
|
||||
/* if (it && it->index) */
|
||||
/* it2 = data->adj[it->index]; */
|
||||
/* while (it2 && it2->index != node) */
|
||||
/* it2 = it2->next; */
|
||||
/* if (it2 && it2->index == node) */
|
||||
/* it2->weight = 1; */
|
||||
/* return ((it != NULL) ? it->index : -1); */
|
||||
/* } */
|
||||
|
||||
static t_ind **clean_ret(t_ind **ret)
|
||||
{
|
||||
tablst_inddel(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static t_ind **resolve_path(t_lmdata *data, int s_ind, int e_ind, t_bfs *tab)
|
||||
{
|
||||
t_ind **ret;
|
||||
int i;
|
||||
int j;
|
||||
t_ind *it;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if ((ret = (t_ind**)ft_memalloc(sizeof(t_ind*) * (data->nb_paths_max + 1))) != NULL)
|
||||
{
|
||||
it = data->adj[e_ind];
|
||||
while (it && i < data->nb_paths_max && (j = e_ind) == e_ind)
|
||||
{
|
||||
if (it->weight == 2 && (j = it->index))
|
||||
{
|
||||
if (lst_indadd(&(ret[i]), e_ind) == NULL)
|
||||
return (clean_ret(ret));
|
||||
while (j != s_ind)
|
||||
{
|
||||
if (lst_indadd(&(ret[i]), j) == NULL)
|
||||
return (clean_ret(ret));
|
||||
j = tab[j].parent;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_ind **edmunds_karp(t_lmdata *data, int start_ind, int end_ind)
|
||||
{
|
||||
t_bfs tab[data->nb_nodes];
|
||||
t_ind **ret[2];
|
||||
int score[2];
|
||||
|
||||
ret[0] = NULL;
|
||||
ret[1] = NULL;
|
||||
score[0] = 0;
|
||||
score[1] = 0;
|
||||
ft_printf("nb paths max: %d\n", data->nb_paths_max);
|
||||
if (data && data->adj)
|
||||
{
|
||||
bfs(data, tab, start_ind, end_ind);
|
||||
while (tab[end_ind].parent != -1)
|
||||
{
|
||||
update_weights(data, tab, end_ind);
|
||||
if (tab[end_ind].parent != -1)
|
||||
ret[1] = resolve_path(data, start_ind, end_ind, tab);
|
||||
ft_printf("ret 0: %p\n", ret[0]);
|
||||
ft_printf("score 0: %d\nscore 1: %d\n", score[0], get_score(data, ret[1]));
|
||||
score[1] = get_score(data, ret[1]);
|
||||
if (ret[0] == NULL || score[0] > score[1])
|
||||
{
|
||||
score[0] = score[1];
|
||||
if (ret[0] != NULL)
|
||||
clean_ret(ret[0]);
|
||||
ret[0] = ret[1];
|
||||
bfs(data, tab, start_ind, end_ind);
|
||||
}
|
||||
else if (score[0] <= score[1])
|
||||
{
|
||||
clean_ret(ret[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (ret[0]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/22 10:02:05 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 15:37:45 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -60,6 +60,7 @@ static int lem_in(t_syntax *synt, t_holder *holder,
|
||||
return (0);
|
||||
if (!(lm_verify_cmd(synt, holder, lmdata)))
|
||||
return (0);
|
||||
ft_printf("Number of nodes %d\n", lmdata->nb_nodes);
|
||||
if (!lst_indinit(lmdata))
|
||||
return (0);
|
||||
if (!(lm_adj_parser(lmdata, holder)))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/22 09:55:46 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/22 12:43:44 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,16 +30,23 @@ int lm_check_forbiden_chars(char *line, int flag)
|
||||
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 && (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||
if (flag == 2 && dash == NULL
|
||||
&& (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||
return (1);
|
||||
if (flag == 3 && dash != NULL && (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||
if (flag == 3 && dash != NULL
|
||||
&& (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/05 06:35:40 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/11 11:32:32 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 15:31:10 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/29 07:17:06 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/11 20:34:58 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 14:28:24 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/23 17:43:34 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/08 18:26:13 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 12:44:00 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/11 11:39:06 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 12:52:48 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -88,7 +88,7 @@ int lm_find_index(t_lmdata *data, char *str)
|
||||
nodes = data->nodes_data;
|
||||
while (nodes)
|
||||
{
|
||||
if (ft_strcmp(nodes->name, str) == 0)
|
||||
if (ft_strequ(nodes->name, str))
|
||||
return (nodes->ind);
|
||||
nodes = nodes->next;
|
||||
}
|
||||
@ -99,6 +99,8 @@ 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))))
|
||||
@ -106,8 +108,16 @@ int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw)
|
||||
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]);
|
||||
src = lm_find_index(data, tab[0]);
|
||||
dest = lm_find_index(data, tab[1]);
|
||||
if (src == -1 || dest == -1)
|
||||
{
|
||||
ft_printf("Bingo :%s\n", raw);
|
||||
ft_del_words_tables(&tab);
|
||||
return 0;
|
||||
}
|
||||
new->src_ind = src;
|
||||
new->dest_ind = dest;
|
||||
new->next = NULL;
|
||||
if (holder->data == NULL)
|
||||
holder->data = new;
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* lm_parser.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/25 06:30:51 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/20 13:08:01 by mndhlovu ### ########.fr */
|
||||
/* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/22 15:31:03 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,22 +17,25 @@ void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||
char *tmp;
|
||||
|
||||
tmp = ft_strchr(line, '#');
|
||||
ft_printf("Bingo 1\n");
|
||||
if ((!synt->s_cmd || !synt->e_cmd)
|
||||
&& (tmp != NULL && line[1] == '#'
|
||||
&& lm_check_forbiden_chars(line, 1)))
|
||||
{
|
||||
if (!synt->s_cmd)
|
||||
{
|
||||
if (ft_strcmp(tmp, "##start") == 0)
|
||||
if (ft_strcmp(line, "##start") == 0)
|
||||
{
|
||||
ft_printf("Bingo 2\n");
|
||||
synt->s_cmd = 1;
|
||||
synt->s_pos = index;
|
||||
}
|
||||
}
|
||||
if (!synt->e_cmd)
|
||||
{
|
||||
if (ft_strcmp(tmp, "##end") == 0)
|
||||
if (ft_strcmp(line, "##end") == 0)
|
||||
{
|
||||
ft_printf("Bingo 3\n");
|
||||
synt->e_cmd = 1;
|
||||
synt->e_pos = index;
|
||||
}
|
||||
@ -49,6 +52,7 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, ch
|
||||
value = lm_get_value(line);
|
||||
if (value != -1)
|
||||
{
|
||||
ft_printf("Bingo 4 %d\n", value);
|
||||
ldata->nbants = value;
|
||||
synt->nb_state = 1;
|
||||
return (1);
|
||||
@ -61,9 +65,11 @@ int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, ch
|
||||
static int lm_get_vertices(int count, t_syntax *synt,
|
||||
t_lmdata *data, t_holder *holder, char *line)
|
||||
{
|
||||
ft_printf("Bingo 5\n");
|
||||
lm_get_cmd_vert(count, synt, data, line);
|
||||
if (!synt->s_error && !synt->e_error)
|
||||
{
|
||||
ft_printf("Bingo 6 %s\n", line);
|
||||
lm_get_vert_link(count, synt, data, holder, line);
|
||||
if (!synt->v_error && !synt->l_error)
|
||||
return (1);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/20 13:25:57 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/22 15:30:39 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -67,6 +67,7 @@ void lm_get_vert_link(int count, t_syntax *synt, t_lmdata *ldata
|
||||
{
|
||||
if (lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
ft_printf("Bingo 7 %s\n", line);
|
||||
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
||||
{
|
||||
synt->v_error = 1;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/27 14:56:55 by tmaze #+# #+# */
|
||||
/* Updated: 2019/04/09 19:04:33 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/04/22 15:30:24 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user