Skip to content

Commit

Permalink
Merge pull request #6 from Haliris/parser_beta
Browse files Browse the repository at this point in the history
Beta version of parser
  • Loading branch information
Tsunghao-C authored Aug 26, 2024
2 parents f144e04 + d847b1e commit 5ca4d6b
Show file tree
Hide file tree
Showing 16 changed files with 569 additions and 228 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
# By: jteissie <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/15 12:02:08 by tsuchen #+# #+# #
# Updated: 2024/08/15 14:40:12 by jteissie ### ########.fr #
# Updated: 2024/08/16 19:28:50 by jteissie ### ########.fr #
# #
# **************************************************************************** #

NAME = cub3d

SRCS_M = main.c

SRCS_PS = parser.c
SRCS_PS = parser.c \
build_map.c \
parser_utils.c

SRCS_MAP = map.c

Expand All @@ -36,7 +38,7 @@ OBJS = $(SRCS:.c=.o)

HEAD = includes/

CFLAGS = -Wall -Wextra -Werror # -g
CFLAGS = -Wall -Wextra -Werror -g3

CC = cc

Expand All @@ -57,7 +59,11 @@ $(NAME): $(OBJS) $(H_DEPS)
$(CC) $(CFLAGS) $(OBJS) $(MLXFLAGS) $(LIBFT) -o $(NAME)

minilibx-linux:
git clone https://github.com/42Paris/minilibx-linux.git $@
@if [ ! -d "$@" ]; then \
git clone https://github.com/42Paris/minilibx-linux.git $@; \
else \
echo "mlx already present in the working directory, aborting clone."; \
fi

bonus: $(NAME)

Expand Down
33 changes: 31 additions & 2 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */
/* Updated: 2024/08/15 00:34:12 by tsuchen ### ########.fr */
/* Updated: 2024/08/16 19:18:23 by jteissie ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,6 +15,7 @@

# include <stdlib.h>
# include <stdio.h>
# include <stdint.h>
# include <unistd.h>
# include <string.h>
# include <errno.h>
Expand All @@ -30,6 +31,11 @@
# include "ft_printf.h"
# include "get_next_line_bonus.h"

# include "parser.h"

# define SUCCESS 0
# define PANIC 1

# define OUT STDOUT_FILENO
# define IN STDIN_FILENO
# define ER STDERR_FILENO
Expand All @@ -39,5 +45,28 @@
# define MOUSE_PRESS 4
# define MOUSE_MOVE 6
# define CLOSE_BUTTON 17
# define FILE_EXTENSION ".cub"

typedef enum e_bool
{
FALSE,
TRUE,
} t_bool;

typedef enum e_p_dir
{
NORTH = 'N',
SOUTH = 'S',
WEST = 'W',
EAST = 'E',
} t_p_dir;
typedef struct s_data
{
char *map_path;
int map_fd;
size_t map_bound;
char **map;
t_p_dir p_dir;
} t_data;

#endif
33 changes: 33 additions & 0 deletions includes/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 15:00:57 by jteissie #+# #+# */
/* Updated: 2024/08/16 18:58:41 by jteissie ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PARSER_H
# define PARSER_H
# include "cub3d.h"

typedef enum e_bool t_bool;
typedef struct s_data t_data;

typedef enum e_parse_status
{
MAP_OK,
MAP_ERR,
PANIC_ERR,
} t_parse_status;

int parse_map(t_data *data);
char **build_map(t_data *data);
t_bool is_invalid_char(char c);
t_parse_status check_invalid_chars(char **map);
void fill_whitespaces(char **map);
t_parse_status find_start(uint32_t coordinates[], char **map);
#endif
40 changes: 13 additions & 27 deletions libft/includes/get_next_line_bonus.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@
/* ::: :::::::: */
/* get_next_line_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 17:54:22 by tsuchen #+# #+# */
/* Updated: 2024/06/15 13:59:19 by tsuchen ### ########.fr */
/* Created: 2024/05/25 14:11:27 by jteissie #+# #+# */
/* Updated: 2024/08/16 18:20:02 by jteissie ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef GET_NEXT_LINE_BONUS_H
# define GET_NEXT_LINE_BONUS_H

# include "libft.h"
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <limits.h>
# include <stdint.h>
# include <errno.h>
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 42
# define BUFFER_SIZE 1
# endif
# define MAX_FD 1024
# define ER STDERR_FILENO
# include <unistd.h>
# include "libft.h"
# include <stdlib.h>

typedef struct s_list_gnl
{
char *str;
struct s_list_gnl *next;
} t_list_gnl;
void ft_lst_append(t_list_gnl **lst, char *str);
void ft_update_list(t_list_gnl **lst);
void ft_delone(t_list_gnl *lst);
int ft_have_nl_lst(t_list_gnl *bgn_lst);
int ft_line_size(t_list_gnl *lst);
char *get_next_line(int fd);
char *ft_gen_nl(t_list_gnl *lst);
void ft_fetch_nl(int fd, t_list_gnl **bgn_lst);

char *fetch_line(char *line_stash, int fd, int *status);
char *trim_buff(char *read_buff);
void get_stash(char *stash, char *line);
char *ft_str_rejoin(char *stash, char *append);
int find_eol(char *str);
void copy_and_cat(char *out, char *cpy_src, char *cat_src);
#endif
Loading

0 comments on commit 5ca4d6b

Please sign in to comment.