<file_sep>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   get_info.c                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: tclarita <<EMAIL>>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/01/31 01:00:13 by tclarita          #+#    #+#             */
/*   Updated: 2020/02/04 10:03:58 by tclarita         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "lem_in.h"

void	get_ants_num(t_lem *data)
{
	char *line;

	get_next_line(0, &line);
	if (ft_atoi(line) > 0)
	{
		data->ants = ft_atoi(line);
		ft_printf("%s\n", line);
	}
	else
	{
		ft_strdel(&line);
		ft_exit(data);
	}
	ft_strdel(&line);
}

void	init_connections(t_lem *data)
{
	int		i;
	int		l;

	data->edge = (int **)malloc(sizeof(int *) * (data->room_num));
	i = 0;
	while (data->room_num > i)
	{
		l = 0;
		data->edge[i] = (int *)malloc(sizeof(int) * (data->room_num));
		while (data->room_num > l)
		{
			data->edge[i][l] = 0;
			l++;
		}
		i++;
	}
	data->started = 1;
}

void	get_connections(t_lem *data, char *line)
{
	char	**tmp;
	int		first;
	int		second;

	if (data->started == 0)
		init_connections(data);
	first = 0;
	second = 0;
	tmp = ft_strsplit(line, '-');
	while (ft_strcmp(data->rooms[first], tmp[0]) != 0)
		first++;
	while (ft_strcmp(data->rooms[second], tmp[1]) != 0)
		second++;
	data->edge[first][second] = 1;
	data->edge[second][first] = 1;
	free(tmp[0]);
	free(tmp[1]);
	free(tmp);
}

void	find_path(t_lem *data)
{
	
}

void	get_info(t_lem *data)
{
	get_ants_num(data);
	get_rooms(data);
	//? write(1, "\n", 1);
	//? ft_printf("Start is: %s\nEnd is: %s\n", data->rooms[0], data->rooms[1]);
	//? int i;
	//? i = 0;
	//? while (i < data->room_num)
	//? {
	//? 	ft_printf("%s\n", data->rooms[i]);
	//? 	i++;
	//? }
	//? i = 0;
	//? int l;
	//? l = 0;
	//? while (data->room_num > i)
	//? {
	//? 	while (data->room_num > l)
	//? 	{
	//? 		ft_printf("%3d", data->edge[i][l]);
	//? 		l++;
	//? 	}
	//? 	l = 0;
	//? 	write(1, "\n", 1);
	//? 	i++;
	//? }
	find_path(data);
}
<file_sep># **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    Makefile                                           :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: tclarita <<EMAIL>>          +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2019/12/16 16:06:30 by tclarita          #+#    #+#              #
#    Updated: 2020/02/04 10:03:19 by tclarita         ###   ########.fr        #
#                                                                              #
# **************************************************************************** #

NAME = lem_in

SRC = main.c get_info.c tools.c get_rooms.c

OBJ = $(SRC:.c=.o)

HEADER = lem_in.h

FLAGS = -Wall -Werror -Wextra -I $(HEADER)
PRINTF_LIBFT = ft_printf
COLOR = \033[2;14m

.PHONY: clean fclean re all

all: $(NAME)

$(NAME): $(OBJ) $(SRC)
		@make -C $(PRINTF_LIBFT)
		@gcc -c $(SRC)
		@gcc -o $(NAME) $(FLAGS) $(OBJ) ft_printf/libftprintf.a
		@make clean -silent
		@echo "$(COLOR)Lem_in successfully compiled"

%.o : %.c
		@echo "$(NAME) >>> Add/Update $^"

clean:
		@rm -rf $(OBJ)
		@make clean -C $(PRINTF_LIBFT)

fclean: clean
		@rm -rf $(NAME)
		@make fclean -C $(PRINTF_LIBFT)

re: fclean all
<file_sep>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   get_rooms.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: tclarita <<EMAIL>>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/04 10:01:30 by tclarita          #+#    #+#             */
/*   Updated: 2020/02/04 10:02:41 by tclarita         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "lem_in.h"

char	**get_start_room(t_lem *data, char **tmp, char *line)
{
	get_next_line(0, &line);
	free(tmp[0]);
	free(tmp);
	tmp = ft_strsplit(line, ' ');
	ft_printf("%s\n", line);
	data->rooms[0] = ft_strnew(ft_strlen(tmp[0] + 1));
	data->rooms[0] = ft_strcpy(data->rooms[0], tmp[0]);
	ft_strdel(&line);
	return (tmp);
}

char	**get_end_room(t_lem *data, char **tmp, char *line)
{
	get_next_line(0, &line);
	free(tmp[0]);
	free(tmp);
	tmp = ft_strsplit(line, ' ');
	ft_printf("%s\n", line);
	data->rooms[1] = ft_strnew(ft_strlen(tmp[0] + 1));
	data->rooms[1] = ft_strcpy(data->rooms[1], tmp[0]);
	ft_strdel(&line);
	return (tmp);
}

int		get_middle_room(int i, t_lem *data, char **tmp)
{
	data->rooms[i] = ft_strnew(ft_strlen(tmp[0] + 1));
	data->rooms[i] = ft_strcpy(data->rooms[i], tmp[0]);
	i++;
	data->room_num++;
	return (i);
}

void	free_tmp(char **tmp)
{
	free(tmp[0]);
	free(tmp[1]);
	free(tmp[2]);
	free(tmp);
}

void	get_rooms(t_lem *data)
{
	char	*line;
	char	**tmp;
	int		i;

	i = 2;
	while (get_next_line(0, &line) > 0)
	{
		ft_printf("%s\n", line);
        if (ft_strchr(line, '-'))
			get_connections(data, line);
		else
		{
			tmp = ft_strsplit(line, ' ');
			if (ft_strcmp(tmp[0], "##start") == 0)
				tmp = get_start_room(data, tmp, line);
			else if (ft_strcmp(tmp[0], "##end") == 0)
				tmp = get_end_room(data, tmp, line);
			else if (tmp[0][0] != '#' && tmp[0][0] != 'L')
				i = get_middle_room(i, data, tmp);
			free_tmp(tmp);
		}
		ft_strdel(&line);
	}
	ft_strdel(&line);
}
<file_sep># Lem_In
Lem_In
Still working on it
