From 16f98e1a1d03185b4ca2b5b86b744ae83b9d88f7 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sat, 27 Apr 2019 14:55:50 +0200 Subject: [PATCH] .h, main, Makefile and add_to_list edit for Testing --- ' | 105 -------------------------------------------------- Makefile | 6 +-- add_to_list.c | 18 ++------- fillit.h | 11 +++--- main.c | 10 +---- 5 files changed, 15 insertions(+), 135 deletions(-) delete mode 100644 ' diff --git a/' b/' deleted file mode 100644 index 1963f8f..0000000 --- a/' +++ /dev/null @@ -1,105 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* add_to_list.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/24 13:36:26 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "fillit.h" -#include - -/* -** DELETE BEFORE EVAL - TEST FUNCTION -** Function that prints a 16 bites short -*/ - -//void print_bits(short line) -//{ -// int mask; -// -// mask = 1 << 16; -// while (mask >>= 1) -// (line & mask) ? write(1, "1", 1) : write(1, "0", 1); -// write(1, "\n", 1); -//} - -/* -** Function that transforme a tetrminos char* into a short of 16 bites -** then it fills it and its reverse into the list -*/ - -int 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; - } - return (0); -} - -/* -** Function that create 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); -} - -/* -** DELETE BEFORE EVAL - MAIN FOR TEST -*/ - -//int main(int ac, char **av) -//{ -// static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure -// int i; -// -// if (ac > 1) -// { -// add_to_list(*(++av), &list); -// while (list && (i = -1)) -// { -// printf("%d\n", list->tetribit); -// print_bits(list->tetribit); -// print_bits(list->tibirtet); -// list = list->next; -// } -// } -// return (0); -//} - diff --git a/Makefile b/Makefile index acf29e3..d29c807 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/24 13:49:48 by hulamy ### ########.fr # +# Updated: 2019/04/27 14:50:31 by vmanzoni ### ########.fr # # # # **************************************************************************** # @@ -25,7 +25,7 @@ SRCS = main.c \ OBJS = $(SRCS:.c=.o) -LIB = libft/ +LIB = ../42-libft/ CC = gcc CFLAGS = -Wall -Werror -Wextra @@ -42,7 +42,7 @@ $(NAME): mv $(OBJS) $(OBJ_DIR) clean: - make -C libft/ clean + make -C $(LIB) clean $(RM) $(OBJ_DIR) fclean: clean diff --git a/add_to_list.c b/add_to_list.c index 92d6405..178aaf4 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/25 13:06:01 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 14:54:11 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ ** DELETE BEFORE EVAL - TEST FUNCTION ** Function that prints a 16 bites short */ - +/* void print_bits(short line) { int mask; @@ -27,6 +27,7 @@ void print_bits(short line) (line & mask) ? write(1, "1", 1) : write(1, "0", 1); write(1, "\n", 1); } +*/ /* ** Function that transforme a tetrminos char* into a short of 16 bites @@ -35,7 +36,6 @@ void print_bits(short line) void fill_list(char line[], t_fillist *list) { - unsigned short tmp; int i; i = 0; @@ -46,18 +46,9 @@ void fill_list(char line[], t_fillist *list) i++; if (line[i++] == '#') list->tetribit |= 1; - print_bits(list->tetribit); + print_bits(list->tetribit, 16); } -// tmp = list->tetribit; -// while (tmp) -// { -// if (tmp & 1) -// list->tibirtet |= 1; -// list->tibirtet <<= 1; -// tmp >>= 1; -// } // print_bits(list->tetribit); - return (0); } /* @@ -102,4 +93,3 @@ int add_to_list(char *line, t_fillist **list) // } // return (0); //} - diff --git a/fillit.h b/fillit.h index a0e1348..ffb34a0 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/27 02:03:20 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 14:52:54 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ #include // for system call open #include // for printf (DELETE BEFORE EVAL) -#include "libft/includes/libft.h" +#include "../42-libft/includes/libft.h" # define BUFF_SIZE 1024 /* @@ -40,12 +40,13 @@ typedef struct s_fillist char *read_file(char *file); void print_error(char *s); -void parse_input(char *input, t_fillist *list); +void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors_proxy(char *tetri); int add_to_list(char *square, t_fillist **list); -int fill_list(char *line, t_fillist *list); -void print_bits(short line); //TO DELETE BEFORE EVAL +void fill_list(char line[], t_fillist *list); + +void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL #endif diff --git a/main.c b/main.c index 38b6ab4..725ea18 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/24 21:42:45 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/27 14:47:35 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ int main(int argc, char **argv) { char *input; - static t_fillist *list; if (argc == 2) { @@ -23,12 +22,7 @@ int main(int argc, char **argv) print_error("Error: Could not read file.\n"); if (check_file_errors(input)) print_error("Error: Invalid file.\n"); - parse_input(input, list); - while (list) - { - printf("%i\n", list->tetribit); - list = list->next; - } + parse_input(input); /* Backtracking for smallest square Transform tetriminos with letters & Print result