first commit
This commit is contained in:
78
BSQ/srcs/Display-c/write.c
Normal file
78
BSQ/srcs/Display-c/write.c
Normal file
@ -0,0 +1,78 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* write.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/31 23:11:14 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 20:34:57 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Display-h/write.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
#include "../../includes/algo-h/algo.h"
|
||||
#include "../../includes/utils-h/charobj.h"
|
||||
#include "../../includes/utils-h/fst_line.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void ft_print(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_print_linesq(int side,char x)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while(i < side)
|
||||
{
|
||||
ft_putchar(x);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_print_result(t_square sq,t_charobj c,t_coords *listobj,int file)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int ysq;
|
||||
|
||||
y = 1;
|
||||
ysq = 0;
|
||||
while (y < ft_len_colum(file))
|
||||
{
|
||||
x = 0;
|
||||
while (x < ft_len_line(file, y))
|
||||
{
|
||||
if ((listobj[x].x == x) && (listobj[y].y == y))
|
||||
ft_putchar(c.o);
|
||||
else if ((sq.x == x) && (ysq < sq.side))
|
||||
{
|
||||
ft_print_linesq(sq.side,c.x);
|
||||
x += sq.side -1;
|
||||
ysq++;
|
||||
}
|
||||
else
|
||||
ft_putchar(c.n);
|
||||
x++;
|
||||
}
|
||||
ft_putchar('\n');
|
||||
y++;
|
||||
}
|
||||
}
|
BIN
BSQ/srcs/Display-c/write.o
Normal file
BIN
BSQ/srcs/Display-c/write.o
Normal file
Binary file not shown.
55
BSQ/srcs/algo/algo.c
Normal file
55
BSQ/srcs/algo/algo.c
Normal file
@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* algo.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/01 22:03:23 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 20:32:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/algo-h/algo.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
|
||||
int ft_is_side_max(int x, int y, int mx, int my)
|
||||
{
|
||||
int l;
|
||||
|
||||
l = (mx - x) - (my - y);
|
||||
if (l > 0)
|
||||
return (mx - x);
|
||||
else if (l < 0)
|
||||
return (my - y);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
t_square ft_comb(t_coords *listobjsx, t_coords *listobjsy)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
t_square square_max;
|
||||
|
||||
square_max.x = 0;
|
||||
square_max.y = 0;
|
||||
square_max.side = 0;
|
||||
i = -1;
|
||||
j = -1;
|
||||
while (listobjsx[++i].x > -1)
|
||||
{
|
||||
while (listobjsy[++j].y > -1)
|
||||
{
|
||||
if ((square_max.x - listobjsx[i].x) < 0
|
||||
&& (square_max.y - listobjsy[j].y) < 0)
|
||||
{
|
||||
square_max.x = listobjsx[i].x;
|
||||
square_max.y = listobjsy[i].y;
|
||||
square_max.side = ft_is_side_max(listobjsx[i].x,
|
||||
listobjsy[j].y, square_max.x, square_max.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (square_max);
|
||||
}
|
BIN
BSQ/srcs/algo/algo.o
Normal file
BIN
BSQ/srcs/algo/algo.o
Normal file
Binary file not shown.
31
BSQ/srcs/algo/controller.c
Normal file
31
BSQ/srcs/algo/controller.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* controller.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/02 14:57:07 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 20:39:52 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Display-h/write.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
#include "../../includes/algo-h/algo.h"
|
||||
#include "../../includes/utils-h/charobj.h"
|
||||
#include "../../includes/utils-h/fst_line.h"
|
||||
|
||||
int ft_controller(int file)
|
||||
{
|
||||
t_charobj charobj;
|
||||
|
||||
charobj = ft_get_charobj(ft_get_first_line(file), ft_len_line(file, 0));
|
||||
ft_print_result(ft_comb(ft_sort_x(ft_get_list_obj(file, charobj.o),
|
||||
ft_get_nobj(file, charobj.o)),
|
||||
ft_sort_y(ft_get_list_obj(file, charobj.o),
|
||||
ft_get_nobj(file, charobj.o))), charobj,
|
||||
ft_get_list_obj(file, charobj.o),
|
||||
file);
|
||||
return (0);
|
||||
}
|
BIN
BSQ/srcs/algo/controller.o
Normal file
BIN
BSQ/srcs/algo/controller.o
Normal file
Binary file not shown.
47
BSQ/srcs/main.c
Normal file
47
BSQ/srcs/main.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/31 23:14:41 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 20:37:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/utils-h/utils.h"
|
||||
|
||||
int ft_while_file(int file, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (argv[i])
|
||||
{
|
||||
if (ft_check_map(file) == 1)
|
||||
return (1);
|
||||
ft_controller(file);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int file;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
if (argc == 1)
|
||||
{
|
||||
file = 0;
|
||||
ft_controller(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
file = open(argv[i], O_RDONLY);
|
||||
ft_while_file(file, argv);
|
||||
}
|
||||
|
||||
}
|
BIN
BSQ/srcs/main.o
Normal file
BIN
BSQ/srcs/main.o
Normal file
Binary file not shown.
23
BSQ/srcs/parsing-c/charobj.c
Normal file
23
BSQ/srcs/parsing-c/charobj.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* charobj.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/02 15:09:36 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 19:39:22 by axdubois ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/utils-h/charobj.h"
|
||||
|
||||
t_charobj ft_get_charobj(char *ftline,int sizeline)
|
||||
{
|
||||
t_charobj charobj;
|
||||
|
||||
charobj.n = ftline[sizeline -3];
|
||||
charobj.o = ftline[sizeline -2];
|
||||
charobj.x = ftline[sizeline -1];
|
||||
return (charobj);
|
||||
}
|
BIN
BSQ/srcs/parsing-c/charobj.o
Normal file
BIN
BSQ/srcs/parsing-c/charobj.o
Normal file
Binary file not shown.
77
BSQ/srcs/parsing-c/fst_line.c
Normal file
77
BSQ/srcs/parsing-c/fst_line.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fst_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/01 18:23:55 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 11:28:35 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
|
||||
int ft_len_line(int file, int n)
|
||||
{
|
||||
int count;
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
i++;
|
||||
}
|
||||
count = 0;
|
||||
buf = malloc(1);
|
||||
while (*buf != '\n' && read(file, &buf, 1) > 0)
|
||||
count++;
|
||||
free(buf);
|
||||
close(file);
|
||||
return (count);
|
||||
}
|
||||
|
||||
int ft_len_colum(int file)
|
||||
{
|
||||
int count;
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
buf = malloc(1);
|
||||
while (read(file, &buf, 1) > 0)
|
||||
{
|
||||
if (*buf == '\n')
|
||||
count++;
|
||||
}
|
||||
free(buf);
|
||||
close(file);
|
||||
return (count);
|
||||
}
|
||||
|
||||
char *ft_get_first_line(int file)
|
||||
{
|
||||
char *buf;
|
||||
int i;
|
||||
char *fst_line;
|
||||
int len_line;
|
||||
|
||||
//if (file == -1) main
|
||||
//return (-1);
|
||||
len_line = ft_len_line(file, 0);
|
||||
fst_line = malloc(len_line + 1);
|
||||
if (fst_line == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < len_line)
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
fst_line[i] = *buf;
|
||||
i++;
|
||||
}
|
||||
fst_line[i] = 0;
|
||||
return (fst_line);
|
||||
}
|
BIN
BSQ/srcs/parsing-c/fst_line.o
Normal file
BIN
BSQ/srcs/parsing-c/fst_line.o
Normal file
Binary file not shown.
61
BSQ/srcs/parsing-c/map_error.c
Normal file
61
BSQ/srcs/parsing-c/map_error.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/02 10:06:20 by adjoly #+# #+# */
|
||||
/* Updated: 2023/08/02 19:46:23 by axdubois ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Display-h/write.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
#include "../../includes/algo-h/algo.h"
|
||||
#include "../../includes/utils-h/charobj.h"
|
||||
#include "../../includes/utils-h/fst_line.h"
|
||||
|
||||
int ft_write_error(int file)
|
||||
{
|
||||
write(2, "Map Error", 1);
|
||||
close(file);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int i;
|
||||
int result;
|
||||
|
||||
i = 0;
|
||||
result = 0;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
result = (result * 10) + str[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
int ft_check_map(int file)
|
||||
{
|
||||
char *first_line;
|
||||
int line_nb;
|
||||
int i_line_nb;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
line_nb = ft_len_colum(file);
|
||||
first_line = ft_get_first_line(file);
|
||||
i_line_nb = ft_atoi(first_line);
|
||||
if (i_line_nb != line_nb)
|
||||
return (ft_write_error(file));
|
||||
while (i < line_nb)
|
||||
{
|
||||
if (ft_len_line(file, i) != i_line_nb)
|
||||
return (ft_write_error(file));
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
BIN
BSQ/srcs/parsing-c/map_error.o
Normal file
BIN
BSQ/srcs/parsing-c/map_error.o
Normal file
Binary file not shown.
116
BSQ/srcs/parsing-c/parsing.c
Normal file
116
BSQ/srcs/parsing-c/parsing.c
Normal file
@ -0,0 +1,116 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/31 23:10:14 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 19:39:26 by axdubois ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
#include "../../includes/utils-h/fst_line.h"
|
||||
|
||||
int ft_get_nobj(int file, char o)
|
||||
{
|
||||
int count;
|
||||
char *buf;
|
||||
|
||||
count = 0;
|
||||
buf = malloc(1);
|
||||
while (read(file, &buf, 1) > 0)
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
if (*buf == o)
|
||||
count++;
|
||||
}
|
||||
free(buf);
|
||||
close(file);
|
||||
return (count);
|
||||
}
|
||||
|
||||
int ft_get_y(int file, int obj_c, char o)
|
||||
{
|
||||
int count_obj;
|
||||
int y_obj;
|
||||
char *buf;
|
||||
|
||||
y_obj = 0;
|
||||
count_obj = 0;
|
||||
buf = malloc(1);
|
||||
while (*buf)
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
if (*buf == '\n')
|
||||
y_obj++;
|
||||
if (*buf == o)
|
||||
{
|
||||
count_obj++;
|
||||
if (obj_c == count_obj)
|
||||
return (y_obj);
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int ft_get_x(int file, int obj_c, char o)
|
||||
{
|
||||
int count_obj;
|
||||
int x_obj;
|
||||
char *buf;
|
||||
|
||||
x_obj = 0;
|
||||
count_obj = 0;
|
||||
buf = malloc(1);
|
||||
while (*buf)
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
if (*buf == '\n')
|
||||
x_obj = 0;
|
||||
if (*buf == o)
|
||||
{
|
||||
count_obj++;
|
||||
if (obj_c == count_obj)
|
||||
return (x_obj);
|
||||
}
|
||||
x_obj++;
|
||||
}
|
||||
free(buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
t_coords *ft_get_list_obj(int file, char o)
|
||||
{
|
||||
t_coords *list_obj;
|
||||
int i;
|
||||
int *buf;
|
||||
int obj_c;
|
||||
|
||||
list_obj = malloc(sizeof(t_coords) * ft_get_nobj(file, o));
|
||||
if (list_obj == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
obj_c = 0;
|
||||
buf = malloc(1);
|
||||
while (i < ft_get_nobj(file, o))
|
||||
{
|
||||
read(file, &buf, 1);
|
||||
if (*buf == o)
|
||||
{
|
||||
obj_c++;
|
||||
list_obj[i].x = ft_get_x(file, obj_c, o);
|
||||
list_obj[i].y = ft_get_y(file, obj_c, o);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
list_obj[i].x = ft_len_line(file, 1);
|
||||
list_obj[i].y = ft_len_colum(file);
|
||||
i++;
|
||||
list_obj[i].x = -1;
|
||||
list_obj[i].y = -1;
|
||||
free(buf);
|
||||
return (list_obj);
|
||||
}
|
BIN
BSQ/srcs/parsing-c/parsing.o
Normal file
BIN
BSQ/srcs/parsing-c/parsing.o
Normal file
Binary file not shown.
37
BSQ/srcs/utils-c/free.c
Normal file
37
BSQ/srcs/utils-c/free.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/01 17:51:39 by adjoly #+# #+# */
|
||||
/* Updated: 2023/08/01 18:16:58 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Display-h/write.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
|
||||
void ft_free_coords(t_coords *coords)
|
||||
{
|
||||
free(coords);
|
||||
}
|
||||
|
||||
void ft_free_arr(char *arr)
|
||||
{
|
||||
free(arr);
|
||||
}
|
||||
|
||||
void ft_free_d_arr(char **arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (arr[i])
|
||||
{
|
||||
free(arr[i]);
|
||||
i++;
|
||||
}
|
||||
free(*arr);
|
||||
}
|
BIN
BSQ/srcs/utils-c/free.o
Normal file
BIN
BSQ/srcs/utils-c/free.o
Normal file
Binary file not shown.
80
BSQ/srcs/utils-c/utils.c
Normal file
80
BSQ/srcs/utils-c/utils.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/31 23:27:23 by axdubois #+# #+# */
|
||||
/* Updated: 2023/08/02 19:28:42 by axdubois ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Display-h/write.h"
|
||||
#include "../../includes/utils-h/utils.h"
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (*str != 0)
|
||||
{
|
||||
i++;
|
||||
str++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
tmp = *b;
|
||||
*b = *a;
|
||||
*a = tmp;
|
||||
}
|
||||
|
||||
t_coords *ft_sort_x(t_coords *coords, int size)
|
||||
{
|
||||
t_coords *arr;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
arr = coords;
|
||||
while (i != size - 1)
|
||||
{
|
||||
if (arr[i].x > arr[i + 1].x)
|
||||
{
|
||||
ft_swap(&arr[i].x, &arr[i + 1].x);
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (arr);
|
||||
}
|
||||
|
||||
t_coords *ft_sort_y(t_coords *coords, int size)
|
||||
{
|
||||
t_coords *arr;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
arr = coords;
|
||||
while (i != size - 1)
|
||||
{
|
||||
if (arr[i].y > arr[i + 1].y)
|
||||
{
|
||||
ft_swap(&arr[i].y, &arr[i + 1].y);
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (arr);
|
||||
}
|
BIN
BSQ/srcs/utils-c/utils.o
Normal file
BIN
BSQ/srcs/utils-c/utils.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user