Auto stash before merge of "master" and "origin/master" + CLEANING

This commit is contained in:
Manzovince
2019-05-20 13:48:14 +02:00
parent f4b1da414c
commit 2dbd5b7320
4 changed files with 26 additions and 40 deletions

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/05/17 18:37:47 by hulamy ### ########.fr */
/* Updated: 2019/05/20 13:43:34 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,10 +14,9 @@
# define FILLIT_H
#include <stdlib.h>
#include <unistd.h> // for system call write
#include <fcntl.h> // for system call open
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
#include "libft/includes/libft.h"
@@ -76,8 +75,8 @@ int check_tetri_errors(char *tetri);
int check_tetri_errors_proxy(char *tetri);
int add_to_list(char *square, t_fillist **list, char letter);
void fill_list(char line[], t_fillist *list);
void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL
void print_tetri(unsigned int bits, int size); //TO DELETE BEFORE EVAL
void print_bits(unsigned int bits, int size);
void print_tetri(unsigned int bits, int size);
int search_map(t_fillist *list);
void print_map(unsigned int *tab, int width, int height, char letter);
void print_final_map(t_fillist *list, int size, int flag);

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/05/09 12:45:25 by vmanzoni ### ########.fr */
/* Updated: 2019/05/20 13:42:07 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,27 +23,28 @@ void print_error(char *str)
}
/*
** UPGRADE VERSION
** Function that display error message *s on fd
** with more informations
** and exit program
**
**void print_error_extended(int error)
**{
** if (error == 1)
** ft_putstr("error: File contains char other than '.','#' and '\\n'.\n");
** if (error == 2)
** ft_putstr("error: File contains more than 2 '\\n' in a row.\n");
** if (error == 3)
** ft_putstr("error: File contains less than 1 tetrimino "
** "or more than 26.\n");
** if (error == 4)
** ft_putstr("error: Tetrimino has more or less than 4 #.\n");
** if (error == 5)
** ft_putstr("error: Tetrimino # are not all connected.\n");
** exit(1);
**}
*/
void print_error_extended(int error)
{
if (error == 1)
ft_putstr("error: File contains char other than '.','#' and '\\n'.\n");
if (error == 2)
ft_putstr("error: File contains more than 2 '\\n' in a row.\n");
if (error == 3)
ft_putstr("error: File contains less than 1 tetrimino "
"or more than 26.\n");
if (error == 4)
ft_putstr("error: Tetrimino has more or less than 4 #.\n");
if (error == 5)
ft_putstr("error: Tetrimino # are not all connected.\n");
exit(1);
}
/*
** Function to see if there if an error if the file
** - less than 4 lines

5
main.c
View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
/* Updated: 2019/05/17 18:40:34 by hulamy ### ########.fr */
/* Updated: 2019/05/20 13:41:00 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,11 +23,8 @@ int main(int argc, char **argv)
{
if (!(input = read_file(argv[1])))
print_error("error\n");
// print_error("error: Could not read file.\n");
if (check_file_errors(input))
print_error("error\n");
// print_error("error: Invalid file.\n");
// print_error_extended(check_file_errors(input));
size = parse_input(input, &list);
ft_putnbrendl(size);
print_final_map(list, size, 1); // DEBUG

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/05/17 18:40:30 by hulamy ### ########.fr */
/* Updated: 2019/05/20 13:44:23 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -44,9 +44,7 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
unsigned int mask;
unsigned int tmp;
// cree un mask avec des 1 a gauche sur la largeur du tetriminos
mask = ~0u << (32 - width) >> 16;
// fabrique la ligne pour le tetriminos de la bonne largeur
tmp = tetri;
tmp = (mask & tetri);
tmp |= ((mask & tetri << 4) >> width);
@@ -65,12 +63,9 @@ void fill_list(char line[], t_fillist *list)
unsigned int mask;
int i;
// transforme la ligne de . et # en un short de 0 et 1
list->tetribit = tab_to_bin(line);
list->memory = 0;
// cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
// utilise le mask pour trouver la largeur que prend le tetriminos
i = 0;
while (!(mask & list->tetribit) && i++ < 4)
mask >>= 1;
@@ -78,20 +73,16 @@ void fill_list(char line[], t_fillist *list)
while (mask & list->tetribit && ++i < 4)
mask >>= 1;
list->width = i - list->width;
// deplace le tetriminos tout en haut a gauche
//(i - list->width = le nombre de colonne vide a gauche)
list->tetribit <<= (i - list->width);
while (!(list->tetribit & (~0u << 12)))
list->tetribit <<= 4;
// trouve la hauteur du tetri
i = 0;
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
i++;
list->height = i;
// fabrique la ligne pour le tetriminos de la bonne largeur
list->tetribit = reduce_tetri(list->tetribit, list->width);
list->position = 0;
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
}
/*
@@ -142,8 +133,6 @@ int parse_input(char *input, t_fillist **list)
tetri[19] = '\0';
if (check_tetri_errors(tetri))
print_error("error\n");
// print_error("error: Wrong tetrimino.\n");
// print_error_extended(check_tetri_errors(tetri));
add_to_list(tetri, list, letter++);
while (input[i] && input[i] != '.' && input[i] != '#')
i++;