Makefile && more

This commit is contained in:
Timo Schmidt 2023-04-05 01:44:14 +02:00
parent 7f9b89a691
commit c83d0865e9
8 changed files with 161 additions and 6 deletions

81
Makefile Normal file
View File

@ -0,0 +1,81 @@
SRC = main.c \
io.c \
parsing.c \
parsing_simple.c \
solution.c \
mem.c \
HEADERS = parsing.h \
OBJDIR = obj
SRCDIR = srcs
INCDIR = includes
CC = cc
CFLAGS = \
-Wall \
-Wextra \
-Werror \
-I$(INCDIR) \
-fcolor-diagnostics \
LDFLAGS =
_OBJ = $(SRC:.c=.o)
OBJ = $(addprefix $(OBJDIR)/,$(_OBJ))
DEPS = $(addprefix $(INCDIR)/,$(HEADERS))
RM = /bin/rm -f
RMDIR = /bin/rmdir
.DEFAULT_GOAL = test
NAME ?= bsq
.PHONY: re fclean clean all
all: $(NAME)
clean:
@$(RM) $(OBJ)
fclean: clean
@$(RM) $(NAME)
@$(RMDIR) $(OBJDIR) 2>/dev/null || true
re: fclean all
$(NAME): $(OBJ)
@$(CC) $(LDFLAGS) $^ -o $@
$(OBJ): | $(OBJDIR)
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(DEPS)
@norminette $< >/dev/null || { printf '\033[101;37m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;37m%s\033[m\n' "<<<Norminette Failed!"; exit 1; }
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR):
@mkdir -p $@
tests: test
test: re run fclean
SUCCESS_MSG = printf '\n\033[102;30m --- %s --- \033[m\n\n' "Test passed!"
FAIL_MSG = printf '\n\033[101;37m --- %s --- \033[m\n\n' "Test failed!"
SUCCESS_MSG_VALG = printf '\n\033[102;30m --- %s --- \033[m\n\n' "Valgrind ran without errors!"
FAIL_MSG_VALG = printf '\n\033[101;37m --- %s --- \033[m\n\n' "Valgrind Failed!"
SUCCESS = && $(SUCCESS_MSG) || $(FAIL_MSG)
SUCCESS_VALG = && $(SUCCESS_MSG_VALG) || $(FAIL_MSG_VALG)
FAIL = && $(FAIL_MSG) || $(SUCCESS_MSG)
VALGRIND = valgrind --leak-check=full --error-exitcode=1
YLW = : ;
CYN = : ;
CLR_RST = && : 
run:
@clear
$(YLW) ./$(NAME) $(CLR_RST) $(SUCCESS)
valgrind: re
$(CYN) $(VALGRIND) ./$(NAME) $(CLR_RST) $(SUCCESS_VALG)

BIN
obj/io.o Normal file

Binary file not shown.

BIN
obj/main.o Normal file

Binary file not shown.

32
srcs/main.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
/* Updated: 2023/04/04 22:57:12 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "parsing.h"
int main(int argc, char **argv)
{
t_map map;
int ret;
(void)argc;
(void)argv;
ret = read_fname("./assets/map2", &map);
printf("Reading file ret val: %d\n", ret);
printf("Empty: '%c'\n", map.meta.empty);
printf("Obstacle: '%c'\n", map.meta.obstacle);
printf("Full: '%c'\n", map.meta.full);
printf("Height: %d\n", map.meta.height);
printf("Width: %d\n", map.meta.width);
printf("Map:\n%s\n", map.data);
return (0);
}

25
srcs/mem.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/05 00:03:33 by tischmid #+# #+# */
/* Updated: 2023/04/05 00:05:22 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *char_calloc(size_t size)
{
char *ptr;
ptr = malloc(size);
if (!ptr)
return (ptr);
while (size--)
ptr[size] = 0;
return (ptr);
}

View File

@ -6,12 +6,14 @@
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 16:19:27 by apago #+# #+# */
/* Updated: 2023/04/04 18:26:39 by apago ### ########.fr */
/* Updated: 2023/04/05 00:06:36 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
void *char_calloc(size_t size);
int parse_meta(char *str, t_meta *meta)
{
int read_bytes;
@ -40,6 +42,8 @@ size_t parse_line(char *line, char *dst, t_meta *meta)
{
int i;
while (*dst++)
;
i = 0;
while (i < meta->width)
{
@ -58,15 +62,15 @@ size_t parse_line(char *line, char *dst, t_meta *meta)
return (meta->width + 1);
}
// size_t offset; // unused
char *parse_data(char *data, t_meta *meta)
{
char *res;
size_t offset;
size_t read_bytes;
int i;
i = 0;
res = malloc(meta->width * meta->height * sizeof(char));
res = char_calloc(meta->width * meta->height * sizeof(char));
if (!res)
return (0);
while (i < meta->height)

View File

@ -6,7 +6,7 @@
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 18:25:47 by apago #+# #+# */
/* Updated: 2023/04/04 18:28:51 by apago ### ########.fr */
/* Updated: 2023/04/04 21:56:56 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,8 +27,8 @@ size_t read_uint(char *str)
int parse_valid_uint(char *str, size_t len)
{
int res;
int i;
int res;
size_t i;
res = 0;
i = 0;

13
srcs/solution.c Normal file
View File

@ -0,0 +1,13 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 21:46:57 by tischmid #+# #+# */
/* Updated: 2023/04/04 21:50:48 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>