diff --git a/.gitignore b/.gitignore index d9c4f04..e525c97 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ objs/ + +*.o + +a\.out\.dSYM/ + +a\.out diff --git a/Makefile b/Makefile index ac53509..e6b9426 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/14 22:01:39 by vmanzoni ### ########.fr # +# Updated: 2019/04/15 20:17:47 by vmanzoni ### ########.fr # # # # **************************************************************************** # diff --git a/README.md b/README.md index 9104141..92de26a 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ - [x] Check if we have a file - [x] Read file -- [ ] Check if there are errors in file +- [x] Check if there are errors in file - At least 1 tetrimino or less than 26 -- [ ] Check if every tetrimino is valid +- [x] Check if every tetrimino is valid - 4 char * 4 lines - 4 blocks in 1 tetrimino - No solo block -- [ ] Transform file into tetriminos +- [x] Transform file into tetriminos - [ ] Backtracking for smallest square - [ ] Transform tetriminos to letters - [ ] Print result diff --git a/a.out b/a.out deleted file mode 100755 index 7345a48..0000000 Binary files a/a.out and /dev/null differ diff --git a/a.out.dSYM/Contents/Info.plist b/a.out.dSYM/Contents/Info.plist deleted file mode 100644 index 3679a65..0000000 --- a/a.out.dSYM/Contents/Info.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIdentifier - com.apple.xcode.dsym.a.out - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - dSYM - CFBundleSignature - ???? - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/a.out.dSYM/Contents/Resources/DWARF/a.out b/a.out.dSYM/Contents/Resources/DWARF/a.out deleted file mode 100644 index 5c9f559..0000000 Binary files a/a.out.dSYM/Contents/Resources/DWARF/a.out and /dev/null differ diff --git a/add_to_list.c b/add_to_list.c index 936492b..4fda9a6 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -3,16 +3,21 @@ /* ::: :::::::: */ /* add_to_list.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ +/* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 17:07:34 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 20:49:33 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" #include +/* +** Function that fills the char **tetraminos section of the structure +** with the most little rectangle that fit the tetraminos +*/ + char **fill_tetraminos(char **square, int *tab) { char **result; @@ -40,6 +45,13 @@ char **fill_tetraminos(char **square, int *tab) return (result); } +/* +** This function calculate the line and columns where the tetraminos +** start and end, by skipping the empty lines +** +** ! it has a little bug so far, i need to fix it +*/ + void find_start_and_end(char **square, int **x) { int i; @@ -66,6 +78,19 @@ void find_start_and_end(char **square, int **x) i--; } +/* +** this function first call find_start_and_end to find the coordinates +** of start en end of the most little rectangle that fit the tetraminos +** +** it allows it to fill the structure with the size information +** (for instance : +** "##" ".#" ".#" +** is a tatraminos of 2 by 3) +** then it fills also the area information (2 * 3 = 6) +** +** and finally it calls fill_tetraminos to fill the char **tetraminos +*/ + int fill_list(char **square, t_fillist *list) { int *tab; @@ -79,6 +104,14 @@ int fill_list(char **square, t_fillist *list) return (1); } +/* +** this function first checks if the structure has been created +** if not, it creates the first element, else it adds an element +** and modifies the initial pointer to link to the new first element +** +** then it calls fill_list to fill the data of the structure +*/ + int add_to_list(char **square, t_fillist **list) { t_fillist *tmp; @@ -94,12 +127,13 @@ int add_to_list(char **square, t_fillist **list) return (1); } +/* 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 > 4) + if (ac > 1) { add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste if (ac == 9) @@ -115,3 +149,4 @@ int main(int ac, char **av) return (0); } +*/ diff --git a/fillit.h b/fillit.h index f4e6a06..6eb65b5 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/15 15:51:03 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 20:53:57 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,21 +23,9 @@ # define BUFF_SIZE 1024 /* -** DELETE BEFORE EVALUATION +** STRUCTURE */ -void print_test(char *test); - -/* -** FUNCTIONS -*/ - -char *read_file(char *file); -void print_error(char *s); -int check_file_errors(char *file); -int check_tetri_errors(char *tetri); -int check_tetri_errors2(char *tetri); - typedef struct s_fillist { int id; @@ -48,6 +36,17 @@ typedef struct s_fillist struct s_fillist *next; } t_fillist; +/* +** FUNCTIONS +*/ + +void print_test(char *test); //DELETE BEFORE EVALUATION +char *read_file(char *file); +void print_error(char *s); +void parse_input(char *input); +int check_file_errors(char *file); +int check_tetri_errors(char *tetri); +int check_tetri_errors2(char *tetri); int add_to_list(char **square, t_fillist **list); #endif diff --git a/handle_errors.c b/handle_errors.c index f553bb9..2f5a907 100644 --- a/handle_errors.c +++ b/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/15 00:13:18 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 14:41:19 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,8 +42,9 @@ int check_file_errors(char *file) return (1); if (file[i] == '\n') line_nbr++; -// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#') -// return (1); + if (file[i] == '\n' && file[i+1] != '\0' && \ + file[i+2] != '.' && file[i+2] != '#') + return (1); i++; } if (line_nbr < 4 || line_nbr > 129) @@ -51,6 +52,12 @@ int check_file_errors(char *file) return (0); } +/* +** Function that check if tetrimino square contains: +** - 4 '#' +** - 12 '.' +*/ + int check_tetri_errors(char *tetri) { int i; @@ -73,6 +80,9 @@ int check_tetri_errors(char *tetri) return (0); } +/* +** Function that check if tetrimino parts are linked +*/ int check_tetri_errors2(char *tetri) { diff --git a/main.c b/main.c index b3bd85c..c87f7f1 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/15 00:12:25 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 20:54:24 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,16 +22,14 @@ 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"); - if (check_tetri_errors(input)) - print_error("Error: Tetrimino not valid.\n"); + parse_input(input); /* - Check if every tetrimino is valid Transform input to tetriminos Backtracking for smallest square Transform tetriminos with letters Print result */ - print_test(input); + //print_test(input); } else print_error("Usage: Please submit a file.\n"); diff --git a/parse_input.c b/parse_input.c new file mode 100644 index 0000000..fcddb12 --- /dev/null +++ b/parse_input.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_input.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ +/* Updated: 2019/04/16 11:50:45 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "fillit.h" + +/* +** Function that parse a file and put each tetrimino in a linked list +*/ + +char **create_square(char *tetri) +{ + char **square = NULL; + int i; + int k; + + i = 0; + while (tetri[i]) + { + k = 0; + *square = malloc((sizeof(char)*4) + 1); + while (k < 4) + { + *square[k] = tetri[i]; + k++; + i++; + } + i++; + //printf("print:\n%s\n", *square); + while (tetri[i] == '\n') + i++; + } + return (square); +} + +void parse_input(char *input) +{ + static t_fillist *list = NULL; + char tetri[20]; + int i; + int j; + + i = 0; + while (input[i]) + { + j = 0; + while (j < 19) + tetri[j++] = input[i++]; + tetri[19] = '\0'; + //printf("PRINT:\n%s\n", tetri); + if (check_tetri_errors(tetri)) + print_error("Error: Tetrimino not valid."); + add_to_list(create_square(tetri), &list); + while (input[i] == '\n') + i++; + } +} diff --git a/read_file.c b/read_file.c index 345e91f..a53e571 100644 --- a/read_file.c +++ b/read_file.c @@ -6,14 +6,14 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 23:01:31 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/15 14:48:36 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" /* -** Function that read and return a ptr to file +** Function that read and return a ptr to file content */ char *read_file(char *file) @@ -39,35 +39,3 @@ char *read_file(char *file) close(fd); return (result); } - -/* -** Function that parse a file and return each tetrimino -*/ - -int parse_input(char *input) -{ - char tetri; - int c; - int i; - int j; - - c = 0; - while (input[c]) - { - i = 0; - while (i < 4) - { - j = 0; - while (j < 4) - { - tetri[j] = input[c++]; - j++; - } - if (check_tetri_errors(tetri)) - print_error("Error: Tetrimino not valid.\n"); - c++; - i++; - } - c++; - } -}