first commit
This commit is contained in:
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.
Reference in New Issue
Block a user