init
This commit is contained in:
36
BSQ/Makefile
Normal file
36
BSQ/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/30 09:24:04 by nlocusso #+# #+# #
|
||||
# Updated: 2022/08/03 14:43:35 by lflandri ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SRCS = ft_mapcmp.c ft_is_printable.c ft_contain_only.c ft_write_map.c file_reader.c ft_putstr.c find_square.c standart_entry_reader.c ft_strstr.c ft_tablen.c ft_strndup.c main.c ft_atou.c ft_strlen.c ft_is_digit.c ft_duplicated.c ft_split.c map_reader.c ft_strcat.c
|
||||
|
||||
|
||||
PO = ${SRCS:.c=.o}
|
||||
|
||||
NAME = bsq
|
||||
|
||||
all : ${NAME}
|
||||
|
||||
${NAME}: ${PO}
|
||||
gcc -o ${NAME} -Wall -Wextra -Werror ${PO}
|
||||
|
||||
.c.o : $(PO)
|
||||
gcc -c -Wall -Wextra -Werror $< -o ${<:.c=.o}
|
||||
|
||||
clean :
|
||||
rm -f ${PO}
|
||||
|
||||
fclean : clean
|
||||
rm -f ${NAME}
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
56
BSQ/bsq.h
Normal file
56
BSQ/bsq.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bsq.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/01 20:56:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/03 12:44:34 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BSQ_H
|
||||
# define BSQ_H
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
struct s_map {
|
||||
char obstacle;
|
||||
char clear;
|
||||
char full;
|
||||
unsigned int v_len;
|
||||
unsigned int h_len;
|
||||
};
|
||||
typedef struct s_map t_map_property;
|
||||
struct s_square
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int size;
|
||||
};
|
||||
typedef struct s_square t_square;
|
||||
int ft_duplicated(char *str);
|
||||
int ft_is_printable(char *str);
|
||||
void starting_crea_map(char *path, char *str_entry);
|
||||
void read_standart_entry(void);
|
||||
void free_map(char **map);
|
||||
unsigned int ft_atou(char *str);
|
||||
unsigned int ft_mapcmp(t_map_property p1, t_map_property p2);
|
||||
int ft_is_digit(char *str);
|
||||
unsigned int ft_contain_only(char **str, char *charset);
|
||||
unsigned int ft_tablen(char **tab);
|
||||
char **ft_atomap(char *str, t_map_property *property);
|
||||
char *ft_strcat(char *dest, char *src);
|
||||
void write_map(char **map, t_map_property map_p);
|
||||
char **ft_split(char *str, char *sep);
|
||||
char *ft_strndup(char *src, unsigned int n);
|
||||
unsigned int ft_strlen(char *str);
|
||||
int ft_strstr(char *str, char *to_find);
|
||||
char *ft_filereader(char *path);
|
||||
void replace_map(char **map, t_square squarre, t_map_property map_p);
|
||||
t_square point_checker(char **map, t_map_property map_p);
|
||||
#endif
|
62
BSQ/file_reader.c
Normal file
62
BSQ/file_reader.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* file_reader.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/01 20:55:35 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 14:22:34 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
int ft_filelen(char *path)
|
||||
{
|
||||
int file_descriptor;
|
||||
int letter_readed_counter;
|
||||
char letters_readed[10];
|
||||
int length;
|
||||
|
||||
file_descriptor = open(path, O_RDONLY);
|
||||
if (file_descriptor == -1)
|
||||
return (-1);
|
||||
length = 0;
|
||||
letter_readed_counter = -1;
|
||||
while (letter_readed_counter != 0)
|
||||
{
|
||||
letter_readed_counter = read(file_descriptor, letters_readed, 10);
|
||||
length = length + letter_readed_counter;
|
||||
}
|
||||
if (close(file_descriptor) == -1)
|
||||
return (-1);
|
||||
return (length);
|
||||
}
|
||||
|
||||
char *ft_filereader(char *path)
|
||||
{
|
||||
char *str;
|
||||
int file_descriptor;
|
||||
int length;
|
||||
|
||||
length = ft_filelen(path);
|
||||
if (length < 1)
|
||||
{
|
||||
str = malloc(sizeof(*str));
|
||||
str[0] = 0;
|
||||
return (str);
|
||||
}
|
||||
str = malloc(sizeof(*str) * (length + 1));
|
||||
file_descriptor = open(path, O_RDONLY);
|
||||
if (file_descriptor == -1)
|
||||
{
|
||||
str[0] = 0;
|
||||
return (str);
|
||||
}
|
||||
read(file_descriptor, str, length);
|
||||
str[length - 1] = 0;
|
||||
if (close(file_descriptor) == -1)
|
||||
str[0] = 0;
|
||||
return (str);
|
||||
}
|
BIN
BSQ/file_reader.o
Normal file
BIN
BSQ/file_reader.o
Normal file
Binary file not shown.
159
BSQ/find_square.c
Normal file
159
BSQ/find_square.c
Normal file
@ -0,0 +1,159 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_square.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/01 21:09:15 by lflandri #+# #+# */
|
||||
/* Updated: 2022/08/02 18:37:53 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
void init_t_squarre(t_square *square, int x, int y, int size)
|
||||
{
|
||||
(*square).size = size;
|
||||
(*square).x = x;
|
||||
(*square).y = y;
|
||||
}
|
||||
|
||||
t_square find_the_biggest_square(t_square square1, t_square square2)
|
||||
{
|
||||
if (square1.size >= square2.size)
|
||||
return (square1);
|
||||
return (square2);
|
||||
}
|
||||
|
||||
int right_bottom_square_checker(t_square square,
|
||||
unsigned int ind, char **map, t_map_property map_p)
|
||||
{
|
||||
unsigned int ind2;
|
||||
|
||||
ind2 = 0;
|
||||
while (ind2 != ind + 1)
|
||||
{
|
||||
if (map[square.y + ind][square.x + ind2] != map_p.obstacle
|
||||
&& map[square.y + ind2][square.x + ind] != map_p.obstacle)
|
||||
ind2++;
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
t_square left_top_square_checker(t_square square, char **map,
|
||||
t_map_property map_p)
|
||||
{
|
||||
unsigned int ind;
|
||||
|
||||
ind = 0;
|
||||
while (square.x + ind != map_p.h_len && square.y + ind != map_p.v_len
|
||||
&& map[square.y + ind][square.x] != map_p.obstacle
|
||||
&& map[square.y][square.x + ind] != map_p.obstacle)
|
||||
{
|
||||
if (right_bottom_square_checker(square, ind, map, map_p))
|
||||
square.size = ind + 1;
|
||||
else
|
||||
return (square);
|
||||
ind++;
|
||||
}
|
||||
return (square);
|
||||
}
|
||||
|
||||
t_square point_checker(char **map, t_map_property map_p)
|
||||
{
|
||||
t_square big_square;
|
||||
t_square new_square;
|
||||
unsigned int ind_w;
|
||||
unsigned int ind_h;
|
||||
|
||||
ind_h = -1;
|
||||
big_square.size = 0;
|
||||
while (++ind_h != map_p.v_len)
|
||||
{
|
||||
ind_w = -1;
|
||||
while (++ind_w != map_p.h_len)
|
||||
{
|
||||
init_t_squarre(&new_square, ind_w, ind_h, 0);
|
||||
new_square = left_top_square_checker(new_square, map, map_p);
|
||||
big_square = find_the_biggest_square(big_square, new_square);
|
||||
}
|
||||
}
|
||||
return (big_square);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_square coucou;
|
||||
|
||||
|
||||
t_map_property map_p;
|
||||
map_p.obstacle = 'o';
|
||||
map_p.clear = '.';
|
||||
map_p.full = 'x';
|
||||
map_p.v_len = 5;
|
||||
map_p.h_len = 5;
|
||||
|
||||
char *map[] =
|
||||
{".o...",
|
||||
"oo..o",
|
||||
"..oo.",
|
||||
".....",
|
||||
"..o.o"};
|
||||
|
||||
|
||||
|
||||
t_map_property map_p;
|
||||
map_p.obstacle = 'o';
|
||||
map_p.clear = '.';
|
||||
map_p.full = 'x';
|
||||
map_p.v_len = 30;
|
||||
map_p.h_len = 30;
|
||||
|
||||
char *map[] =
|
||||
{"o....oo...o.o.o..ooo...o....oo",
|
||||
"...o..oo......oo.o..o......o.o",
|
||||
"ooo........o..o.o..oo......ooo",
|
||||
"o......oo...o....oooo..o....o.",
|
||||
"......oo.........o..o.....o...",
|
||||
".o....o.......o.o.oooo...ooo..",
|
||||
".oo.o.oo.ooo.....oo.ooo.o.o.o.",
|
||||
"oo...o.o...o..o.o..oooo....oo.",
|
||||
"..ooo.oo....o..o.oo..o........",
|
||||
"...o.oooo.....ooo..o........o.",
|
||||
"o............oooo.o.o..oo.o.oo",
|
||||
"o....o...oo....o.o....o.o.....",
|
||||
"..o.o...o...oo..ooo......o....",
|
||||
"o....o.........o...o....oo....",
|
||||
"oo..o.......ooo...o...o.ooo.oo",
|
||||
"o.o.....oo..oo.oo....o.oo.oo.o",
|
||||
".o.o..o.oo.oo..o.oo.oo.o.o.o.o",
|
||||
".o.o.....oo.o.o...o..o.oo....o",
|
||||
"....o..oo..o...oo..o....o.o...",
|
||||
"oo.o............o...o..oo..o..",
|
||||
".........o..o.oo..ooo..o..o..o",
|
||||
"..o.ooooo...o.o...o.oo.o.o.ooo",
|
||||
".o....o...oooo..o......o.o....",
|
||||
"o...ooo.....oo..o....o..ooo..o",
|
||||
".o...oo.o.....o.o.....o......o",
|
||||
"o...oo.........o..o.......o...",
|
||||
"oo.....oo.....o....oo.oo......",
|
||||
".........o......oo.o.oo.o.o.o.",
|
||||
"o.o..o...o.o.....o.oo...oo..o.",
|
||||
"..oo...o.oo.ooo..oo.o.o......o"};
|
||||
|
||||
|
||||
coucou = point_checker(map, map_p);
|
||||
//replace_map(map, coucou, map_p);
|
||||
printf ("%d\n", coucou.x);
|
||||
printf ("%d\n", coucou.y);
|
||||
printf ("%d\n", coucou.size);
|
||||
//write_map(map, map_p);
|
||||
}
|
||||
*/
|
BIN
BSQ/find_square.o
Normal file
BIN
BSQ/find_square.o
Normal file
Binary file not shown.
23
BSQ/ft_atou.c
Normal file
23
BSQ/ft_atou.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atou.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 10:37:25 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 10:37:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
unsigned int ft_atou(char *str)
|
||||
{
|
||||
int i;
|
||||
unsigned int base;
|
||||
|
||||
i = 0;
|
||||
base = 0;
|
||||
while ('0' <= str[i] && str[i] <= '9')
|
||||
base = base * 10 + (str[i++] - '0');
|
||||
return (base);
|
||||
}
|
BIN
BSQ/ft_atou.o
Normal file
BIN
BSQ/ft_atou.o
Normal file
Binary file not shown.
35
BSQ/ft_contain_only.c
Normal file
35
BSQ/ft_contain_only.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_contain_only.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 11:44:05 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/03 17:55:00 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
unsigned int ft_contain_only(char **lines, char *charset)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
while (lines[k][0] != 0)
|
||||
{
|
||||
i = 0;
|
||||
while (lines[k][i] != 0)
|
||||
{
|
||||
j = 0;
|
||||
while (charset[j] != lines[k][i] && charset[j] != 0)
|
||||
j++;
|
||||
if (charset[j] == 0)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
return (1);
|
||||
}
|
BIN
BSQ/ft_contain_only.o
Normal file
BIN
BSQ/ft_contain_only.o
Normal file
Binary file not shown.
33
BSQ/ft_duplicated.c
Normal file
33
BSQ/ft_duplicated.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_duplicated.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/03 11:50:50 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/03 12:38:01 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_duplicated(char *str)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (str[i + 1] != 0)
|
||||
{
|
||||
j = i + 1;
|
||||
while (str[i] != str[j])
|
||||
{
|
||||
if (str[j] == 0)
|
||||
break ;
|
||||
j++;
|
||||
}
|
||||
if (str[j] != 0)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
BIN
BSQ/ft_duplicated.o
Normal file
BIN
BSQ/ft_duplicated.o
Normal file
Binary file not shown.
25
BSQ/ft_is_digit.c
Normal file
25
BSQ/ft_is_digit.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_digit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 10:41:19 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 18:31:40 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_digit(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if (!(str[i] >= '0' && str[i] <= '9'))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
BIN
BSQ/ft_is_digit.o
Normal file
BIN
BSQ/ft_is_digit.o
Normal file
Binary file not shown.
22
BSQ/ft_is_printable.c
Normal file
22
BSQ/ft_is_printable.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/03 12:41:02 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/03 12:44:05 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_printable(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!(*str >= 32 && *str <= 126))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
BIN
BSQ/ft_is_printable.o
Normal file
BIN
BSQ/ft_is_printable.o
Normal file
Binary file not shown.
28
BSQ/ft_mapcmp.c
Normal file
28
BSQ/ft_mapcmp.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_mapcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 14:38:48 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 16:00:11 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
unsigned int ft_mapcmp(t_map_property p1, t_map_property p2)
|
||||
{
|
||||
if (p1.obstacle != p2.obstacle)
|
||||
return (0);
|
||||
if (p1.clear != p2.clear)
|
||||
return (0);
|
||||
if (p1.full != p2.full)
|
||||
return (0);
|
||||
if (p1.v_len != p2.v_len)
|
||||
return (0);
|
||||
if (p1.h_len != p2.h_len)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
BIN
BSQ/ft_mapcmp.o
Normal file
BIN
BSQ/ft_mapcmp.o
Normal file
Binary file not shown.
19
BSQ/ft_putstr.c
Normal file
19
BSQ/ft_putstr.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/31 08:46:44 by nlauvray #+# #+# */
|
||||
/* Updated: 2022/08/02 18:38:07 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
write(1, str++, 1);
|
||||
}
|
BIN
BSQ/ft_putstr.o
Normal file
BIN
BSQ/ft_putstr.o
Normal file
Binary file not shown.
40
BSQ/ft_split.c
Normal file
40
BSQ/ft_split.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/31 08:41:20 by nlauvray #+# #+# */
|
||||
/* Updated: 2022/08/03 17:34:23 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
char **ft_split(char *str, char *sep)
|
||||
{
|
||||
char **tab;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int k;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
tab = malloc(sizeof(str) * ft_strlen(str));
|
||||
while (str[i] != 0 && ft_strlen(str) > i)
|
||||
{
|
||||
k = i;
|
||||
tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1));
|
||||
while (i < k + ft_strstr(&str[k], sep))
|
||||
{
|
||||
tab[j][i - k] = str[i];
|
||||
i++;
|
||||
}
|
||||
tab[j][i - k] = '\0';
|
||||
i = k + ft_strstr(&str[k], sep) + ft_strlen(sep);
|
||||
j++;
|
||||
}
|
||||
tab[j] = "";
|
||||
return (tab);
|
||||
}
|
BIN
BSQ/ft_split.o
Normal file
BIN
BSQ/ft_split.o
Normal file
Binary file not shown.
24
BSQ/ft_strcat.c
Normal file
24
BSQ/ft_strcat.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 12:01:12 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 12:05:15 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
while (*dest != 0)
|
||||
dest++;
|
||||
while (*src != 0)
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
BIN
BSQ/ft_strcat.o
Normal file
BIN
BSQ/ft_strcat.o
Normal file
Binary file not shown.
23
BSQ/ft_strlen.c
Normal file
23
BSQ/ft_strlen.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/31 08:47:30 by nlauvray #+# #+# */
|
||||
/* Updated: 2022/08/02 14:29:35 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
unsigned int ft_strlen(char *str)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
BIN
BSQ/ft_strlen.o
Normal file
BIN
BSQ/ft_strlen.o
Normal file
Binary file not shown.
29
BSQ/ft_strndup.c
Normal file
29
BSQ/ft_strndup.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strndup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 10:19:17 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 14:24:27 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
char *ft_strndup(char *src, unsigned int n)
|
||||
{
|
||||
char *dest;
|
||||
unsigned int i;
|
||||
|
||||
dest = malloc(sizeof(*src) * (ft_strlen(src) + 1));
|
||||
i = 0;
|
||||
while (src[i] != 0 && i < n - 1)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = 0;
|
||||
return (dest);
|
||||
}
|
BIN
BSQ/ft_strndup.o
Normal file
BIN
BSQ/ft_strndup.o
Normal file
Binary file not shown.
31
BSQ/ft_strstr.c
Normal file
31
BSQ/ft_strstr.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nlauvray <nlauvray@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/31 08:35:51 by nlauvray #+# #+# */
|
||||
/* Updated: 2022/07/31 12:37:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strstr(char *str, char *to_find)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
j = 0;
|
||||
while (str[i + j] == to_find[j])
|
||||
{
|
||||
if (to_find[j + 1] == 0)
|
||||
return (i);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
BIN
BSQ/ft_strstr.o
Normal file
BIN
BSQ/ft_strstr.o
Normal file
Binary file not shown.
21
BSQ/ft_tablen.c
Normal file
21
BSQ/ft_tablen.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tablen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 11:04:59 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 14:30:16 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
unsigned int ft_tablen(char **tab)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i][0] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
BIN
BSQ/ft_tablen.o
Normal file
BIN
BSQ/ft_tablen.o
Normal file
Binary file not shown.
44
BSQ/ft_write_map.c
Normal file
44
BSQ/ft_write_map.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_write_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 11:30:49 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/02 18:40:55 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
void write_map(char **map, t_map_property map_p)
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
|
||||
y = -1;
|
||||
while (++y != map_p.v_len)
|
||||
{
|
||||
x = -1;
|
||||
while (++x != map_p.h_len)
|
||||
write(1, map[y] + x, 1);
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
void replace_map(char **map, t_square squarre, t_map_property map_p)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
y = squarre.y - 1;
|
||||
while (++y != squarre.size + squarre.y)
|
||||
{
|
||||
x = squarre.x - 1;
|
||||
while (++x != squarre.size + squarre.x)
|
||||
{
|
||||
map[y][x] = map_p.full;
|
||||
}
|
||||
}
|
||||
}
|
BIN
BSQ/ft_write_map.o
Normal file
BIN
BSQ/ft_write_map.o
Normal file
Binary file not shown.
75
BSQ/main.c
Normal file
75
BSQ/main.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 11:24:01 by lflandri #+# #+# */
|
||||
/* Updated: 2022/08/03 14:29:29 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
void free_map(char **map)
|
||||
{
|
||||
char **map_adress;
|
||||
|
||||
map -= 1;
|
||||
map_adress = map;
|
||||
while (**map != 0)
|
||||
{
|
||||
free(*map);
|
||||
map++;
|
||||
}
|
||||
free(map_adress);
|
||||
}
|
||||
|
||||
void starting_crea_map(char *path, char *str)
|
||||
{
|
||||
char **map;
|
||||
t_map_property map_p_tempo;
|
||||
t_map_property *map_p;
|
||||
t_square square;
|
||||
|
||||
map_p = &map_p_tempo;
|
||||
if (str == NULL)
|
||||
str = ft_filereader(path);
|
||||
if (ft_strlen(str) <= 4)
|
||||
{
|
||||
free(str);
|
||||
write(2, "map error\n", 10);
|
||||
return ;
|
||||
}
|
||||
map = ft_atomap(str, map_p);
|
||||
free(str);
|
||||
if (map != NULL)
|
||||
{
|
||||
square = point_checker(map, *map_p);
|
||||
replace_map(map, square, *map_p);
|
||||
write_map(map, *map_p);
|
||||
free_map(map);
|
||||
}
|
||||
else
|
||||
write(2, "map error\n", 10);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int ind;
|
||||
|
||||
if (ac != 1)
|
||||
{
|
||||
ind = 0;
|
||||
while (++ind != ac)
|
||||
{
|
||||
starting_crea_map(av[ind], NULL);
|
||||
if (ind + 1 != ac)
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
read_standart_entry();
|
||||
return (0);
|
||||
}
|
BIN
BSQ/main.o
Normal file
BIN
BSQ/main.o
Normal file
Binary file not shown.
80
BSQ/map_reader.c
Normal file
80
BSQ/map_reader.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_reader.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/01 21:13:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/08/03 17:57:26 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
t_map_property ft_map_error(void)
|
||||
{
|
||||
t_map_property property;
|
||||
|
||||
property.full = 0;
|
||||
property.obstacle = 0;
|
||||
property.clear = 0;
|
||||
property.h_len = 0;
|
||||
property.v_len = 0;
|
||||
return (property);
|
||||
}
|
||||
|
||||
t_map_property property_return_error(char *lines_counter)
|
||||
{
|
||||
free(lines_counter);
|
||||
return (ft_map_error());
|
||||
}
|
||||
|
||||
t_map_property ft_get_map_property(char **lines)
|
||||
{
|
||||
t_map_property property;
|
||||
char *lines_counter;
|
||||
unsigned int i;
|
||||
|
||||
if (!(ft_strlen(lines[0]) >= 4)
|
||||
|| !ft_is_printable(&lines[0][ft_strlen(lines[0]) - 3])
|
||||
|| ft_duplicated(&lines[0][ft_strlen(lines[0]) - 3]))
|
||||
return (ft_map_error());
|
||||
lines_counter = ft_strndup(lines[0], ft_strlen(lines[0]) - 2);
|
||||
if (!ft_is_digit(lines_counter))
|
||||
return (property_return_error(lines_counter));
|
||||
if (ft_tablen(&lines[1]) != ft_atou(lines_counter))
|
||||
return (property_return_error(lines_counter));
|
||||
i = 2;
|
||||
while (ft_strlen(lines[1]) == ft_strlen(lines[i]))
|
||||
i++;
|
||||
if (i != ft_tablen(lines))
|
||||
return (property_return_error(lines_counter));
|
||||
property.full = lines[0][ft_strlen(lines[0]) - 1];
|
||||
property.obstacle = lines[0][ft_strlen(lines[0]) - 2];
|
||||
property.clear = lines[0][ft_strlen(lines[0]) - 3];
|
||||
property.v_len = ft_atou(lines_counter);
|
||||
property.h_len = ft_strlen(lines[1]);
|
||||
free(lines_counter);
|
||||
return (property);
|
||||
}
|
||||
|
||||
char **ft_atomap(char *str, t_map_property *property)
|
||||
{
|
||||
char **lines;
|
||||
|
||||
lines = ft_split(str, "\n");
|
||||
*property = ft_get_map_property(lines);
|
||||
if (ft_mapcmp(*property, ft_map_error()) != 0)
|
||||
{
|
||||
free_map(&lines[1]);
|
||||
return (NULL);
|
||||
}
|
||||
lines[0][ft_strlen(lines[0]) - 1] = 0;
|
||||
if (ft_contain_only(&lines[1], &lines[0][ft_strlen(lines[0]) - 2]) == 0)
|
||||
{
|
||||
free_map(&lines[1]);
|
||||
return (NULL);
|
||||
}
|
||||
return (&lines[1]);
|
||||
}
|
BIN
BSQ/map_reader.o
Normal file
BIN
BSQ/map_reader.o
Normal file
Binary file not shown.
2
BSQ/maps
Normal file
2
BSQ/maps
Normal file
@ -0,0 +1,2 @@
|
||||
1_dp
|
||||
_d____________________________________________________________________________________
|
105
BSQ/standart_entry_reader.c
Normal file
105
BSQ/standart_entry_reader.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* standart_entry_reader.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lflandri <lflandri@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/03 08:52:24 by lflandri #+# #+# */
|
||||
/* Updated: 2022/08/03 18:08:16 by lflandri ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsq.h"
|
||||
|
||||
char *add_to_malloc(char *mal, char *str)
|
||||
{
|
||||
char *new_mal;
|
||||
int ind;
|
||||
|
||||
ind = 0;
|
||||
while (mal[ind])
|
||||
ind++;
|
||||
new_mal = malloc(sizeof(char) * (ind + 2));
|
||||
ind = -1;
|
||||
while (mal[++ind])
|
||||
new_mal[ind] = mal[ind];
|
||||
new_mal[ind] = *str;
|
||||
new_mal[ind + 1] = 0;
|
||||
free(mal);
|
||||
return (new_mal);
|
||||
}
|
||||
|
||||
void read_map_on_entry(char *mal, unsigned int lines_counter)
|
||||
{
|
||||
char str[1];
|
||||
unsigned int count;
|
||||
|
||||
count = 0;
|
||||
if (!lines_counter)
|
||||
{
|
||||
free(mal);
|
||||
write(2, "map error\n", 10);
|
||||
return ;
|
||||
}
|
||||
mal = add_to_malloc(mal, "\n");
|
||||
while (count != lines_counter)
|
||||
{
|
||||
read(STDIN_FILENO, str, 1);
|
||||
if (*str == '\n')
|
||||
count++;
|
||||
mal = add_to_malloc(mal, str);
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
starting_crea_map(NULL, mal);
|
||||
}
|
||||
|
||||
void check_read_map_on_entry(char *mal)
|
||||
{
|
||||
char *lines_counter;
|
||||
|
||||
if (!(ft_strlen(mal) >= 4))
|
||||
{
|
||||
free(mal);
|
||||
write(2, "map error\n", 10);
|
||||
return ;
|
||||
}
|
||||
lines_counter = ft_strndup(mal, ft_strlen(mal) - 2);
|
||||
if (!ft_is_digit(lines_counter))
|
||||
{
|
||||
free(mal);
|
||||
free(lines_counter);
|
||||
write(2, "map error\n", 10);
|
||||
return ;
|
||||
}
|
||||
read_map_on_entry(mal, ft_atou(lines_counter));
|
||||
free(lines_counter);
|
||||
}
|
||||
|
||||
void read_standart_entry(void)
|
||||
{
|
||||
char str[1];
|
||||
char *mal;
|
||||
int size;
|
||||
int fd;
|
||||
|
||||
mal = malloc(sizeof(char));
|
||||
*mal = '\0';
|
||||
size = 1;
|
||||
while (size == 1)
|
||||
{
|
||||
size = read(STDIN_FILENO, str, 1);
|
||||
if (*str == '\n')
|
||||
break ;
|
||||
mal = add_to_malloc(mal, str);
|
||||
}
|
||||
fd = open(mal, O_RDONLY);
|
||||
if (fd != -1)
|
||||
{
|
||||
close(fd);
|
||||
starting_crea_map(mal, NULL);
|
||||
free(mal);
|
||||
}
|
||||
else
|
||||
check_read_map_on_entry(mal);
|
||||
}
|
BIN
BSQ/standart_entry_reader.o
Normal file
BIN
BSQ/standart_entry_reader.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user