feat: added maps, added readfile to parsing

This commit is contained in:
Baptiste GOULARD 2024-11-12 11:30:30 +01:00
parent 4db733648e
commit e4d2dfda21
19 changed files with 282 additions and 41 deletions

View file

@ -24,11 +24,11 @@
void parse_args(char *arg, t_info *inf)
{
if (arg == NULL && inf->cli_ctx.file == NULL)
return (inf->last_error = MISSING_FILE_ERROR, (void)0);
return (inf->last_error = ERROR_MISSING_FILE, (void)0);
if (arg && ft_strlen(arg) < 5)
return (inf->last_error = NAME_FILE_ERROR, (void)0);
return (inf->last_error = ERROR_NAME_FILE, (void)0);
if (arg && ft_strend_with(arg, FILE_EXTENSION) == false)
return (inf->last_error = EXTENSION_FILE_ERROR, (void)0);
return (inf->last_error = ERROR_EXTENSION_FILE, (void)0);
if (arg && inf->cli_ctx.file == NULL)
inf->cli_ctx.file = ft_strdup(arg);
inf->last_error = NO_ERROR;

58
parsing/map.c Normal file
View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 08:31:06 by bgoulard #+# #+# */
/* Updated: 2024/11/12 11:29:13 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "ft_string.h"
#include "ft_optional.h"
#include "ft_optional_types.h"
#include <stdio.h>
#include <sys/types.h>
// steps:
// 1. load_map into a buffer
// 2. store the map while deleting trailing newlines
void *load_map(void *data)
{
t_info *info = (t_info *)data;
char *file = NULL;
file = ft_fd_to_buff(info->map.fd);
info->map.fraw = ft_split(file, '\n');
ft_free((void **)&file);
return (info->last_error = ERROR_IMPLEM, NULL);
}
void *traverse_map(void *data)
{
t_info *info = (t_info *)data;
info->last_error = ERROR_IMPLEM;
return (NULL);
}
void parse_map(t_info *info)
{
t_optional opt = {OPT_NONE, NULL};
const t_data_tr_i function_list[] = {
load_map,
traverse_map,
NULL,
};
opt.val = info;
opt.pres = OPT_SOME;
info->map.path = info->cli_ctx.file;
if (ft_optional_chain(&opt, function_list) == false)
return (c3_perror(info), (void)0);
}