From 8da1c5bec65cc748bca3382a8f7ad320dfc81082 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 24 Apr 2019 15:47:42 +0200 Subject: [PATCH] rangement des fichiers tests et makefile --- Makefile | 58 +++++----- README.md | 20 ---- parse_input.c | 103 +++++++++--------- add_to_list.c => test_add_to_list.c | 4 +- ...est_square.c => test_get_smallest_square.c | 0 print_fillit.c => test_print_fillit.c | 0 6 files changed, 77 insertions(+), 108 deletions(-) delete mode 100644 README.md rename add_to_list.c => test_add_to_list.c (95%) rename get_smallest_square.c => test_get_smallest_square.c (100%) rename print_fillit.c => test_print_fillit.c (100%) diff --git a/Makefile b/Makefile index acf29e3..8e8e8d3 100644 --- a/Makefile +++ b/Makefile @@ -6,49 +6,43 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/24 13:49:48 by hulamy ### ########.fr # +# Updated: 2019/04/24 15:44:55 by hulamy ### ########.fr # # # # **************************************************************************** # -NAME = fillit +# - - - - - - - - - - - - - - - # +# VARIABLES # +# - - - - - - - - - - - - - - - # -OBJ_DIR = ./objs -HEADER = fillit.h +NAME = fillit +CC = gcc -SRCS = main.c \ - read_file.c \ - handle_errors.c \ - parse_input.c \ - add_to_list.c \ -# get_smallest_square.c \ - print_fillit.c +CFLAGS = -I. +CFLAGS += -Wall -Wextra -Werror + +LDFLAGS = -L./libft/ +LDLIBS = -lft + +SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') -OBJS = $(SRCS:.c=.o) -LIB = libft/ +# - - - - - - - - - - - - - - - # +# RULES # +# - - - - - - - - - - - - - - - # -CC = gcc -CFLAGS = -Wall -Werror -Wextra +all: $(NAME) -RM = rm -rf +$(NAME): $(SRCS) + $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) -all: $(NAME) +debug: + $(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) -$(NAME): - make -C $(LIB) - $(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS) - $(CC) -o $(NAME) $(OBJS) -L $(LIB) -lft - mkdir $(OBJ_DIR) - mv $(OBJS) $(OBJ_DIR) +lib: + make -C ./libft/ clean: - make -C libft/ clean - $(RM) $(OBJ_DIR) + /bin/rm -rf $(NAME) + /bin/rm -rf $(NAME).dSYM -fclean: clean - make -C libft/ fclean - $(RM) $(NAME) - -re: fclean all - -.PHONY: all clean fclean re +re: clean all diff --git a/README.md b/README.md deleted file mode 100644 index 92de26a..0000000 --- a/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Fillit - -**hulamy** and **vmanzoni** - -## To do - -- [x] Check if we have a file -- [x] Read file -- [x] Check if there are errors in file - - At least 1 tetrimino or less than 26 -- [x] Check if every tetrimino is valid - - 4 char * 4 lines - - 4 blocks in 1 tetrimino - - No solo block -- [x] Transform file into tetriminos -- [ ] Backtracking for smallest square -- [ ] Transform tetriminos to letters -- [ ] Print result - -- [ ] Optimisation diff --git a/parse_input.c b/parse_input.c index c98c57b..3b75b63 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,28 +6,63 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/24 13:48:21 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 15:12:32 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" /* -** DELETE BEFORE EVAL -** Function that print a short in bites +** Function that transforme a tetrminos char* into a short of 16 bites +** and then fills it and its reversed into the list */ -//void print_short(short octet) -//{ -// unsigned int i; -// -// i = 1 << 15; -// while (i) -// { -// (octet & i) ? printf("1") : printf("0"); -// i >>= 1; -// } -//} +void fill_list(char line[], t_fillist *list) +{ + unsigned short tmp; + int i; + + i = 0; + while (line[i]) + { + list->tetribit <<= 1; + if (line[i] == '\n') + i++; + if (line[i++] == '#') + list->tetribit |= 1; + } + while (!(list->tetribit & (1 << 15))) + list->tetribit <<= 1; + tmp = list->tetribit; + while (tmp) + { + list->tibirtet <<= 1; + if (tmp & 1) + list->tibirtet |= 1; + tmp >>= 1; + } +} + +/* +** Function that creates the linked list and add a new structure +** linked each time needed +*/ + +int add_to_list(char *line, t_fillist **list) +{ + t_fillist *tmp; + + if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) + return (0); + if (!(*list)) + tmp->next = NULL; + else + tmp->next = *list; + *list = tmp; + fill_list(line, *list); + return (1); +} + /* ** Function that parse a file and put each tetrimino in a linked list @@ -41,7 +76,6 @@ void parse_input(char *input) int j; i = 0; -// printf("%s", input); while (input[i]) { j = 0; @@ -51,47 +85,8 @@ void parse_input(char *input) if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); add_to_list(tetri, &list); -// printf("added to list !!\n"); while (input[i] && input[i] != '.' && input[i] != '#') i++; } -/* DEBUG PART - Print each tetribit*/ -// while (list != NULL) -// { -// printf("%i\n", list->tetribit); -// print_short(list->tetribit); -// printf("\n"); -// print_short(list->tibirtet); -// printf("\n"); -// list = list->next; -// } } -/* -** DELETE BEFORE EVAL - NOT USED ANYMORE -** Function that parse a file and put each tetrimino in a linked list -*/ - -// char **create_square(char *tetri) -// { -// char **square; -// int i; -// int k; -// -// i = 0; -// if (!(square = (char**)malloc(sizeof(*square) * (4 + 1)))) -// return (NULL); -// square[4] = NULL; -// while (*tetri && (k = -1)) -// { -// if (!(square[i] = (char*)malloc(sizeof(**square) * (4 + 1)))) -// return (NULL); -// square[i][4] = '\0'; -// while (++k < 4) -// square[i][k] = *(tetri++); -// while (*tetri == '\n') -// tetri++; -// i++; -// } -// return (square); -// } diff --git a/add_to_list.c b/test_add_to_list.c similarity index 95% rename from add_to_list.c rename to test_add_to_list.c index add0b91..d90ca8f 100644 --- a/add_to_list.c +++ b/test_add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/24 13:45:53 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 15:12:48 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ /* ** Function that transforme a tetrminos char* into a short of 16 bites -** then it fills it and its reverse into the list +** and then fills it and its reversed into the list */ void fill_list(char line[], t_fillist *list) diff --git a/get_smallest_square.c b/test_get_smallest_square.c similarity index 100% rename from get_smallest_square.c rename to test_get_smallest_square.c diff --git a/print_fillit.c b/test_print_fillit.c similarity index 100% rename from print_fillit.c rename to test_print_fillit.c