conflict merge
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,10 +1 @@
|
||||
|
||||
includes/fillit\.h\.gch
|
||||
|
||||
a\.out
|
||||
|
||||
*.out
|
||||
|
||||
objs/
|
||||
|
||||
fillit
|
||||
|
||||
21
Makefile
21
Makefile
@@ -6,26 +6,20 @@
|
||||
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
|
||||
# Updated: 2019/04/14 14:21:26 by vmanzoni ### ########.fr #
|
||||
# Updated: 2019/04/14 22:01:39 by vmanzoni ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = fillit
|
||||
|
||||
SRC_DIR = srcs/
|
||||
|
||||
SRCS = *.c
|
||||
|
||||
OBJ_DIR = objs/
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
HEADER = includes/
|
||||
|
||||
SRCS = *.c
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
LIB = fillit.h
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
RM = rm -rf
|
||||
@@ -33,15 +27,20 @@ RM = rm -rf
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME):
|
||||
$(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR), $(SRCS))
|
||||
$(CC) $(OBJS) -o $(NAME)
|
||||
make -C libft/
|
||||
$(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS)
|
||||
$(CC) -o $(NAME) $(OBJS) -L libft/ -lft
|
||||
#$(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR), $(SRCS))
|
||||
#$(CC) $(OBJS) -o $(NAME)
|
||||
mkdir $(OBJ_DIR)
|
||||
mv $(OBJS) $(OBJ_DIR)
|
||||
|
||||
clean:
|
||||
make -C libft/ clean
|
||||
$(RM) $(OBJ_DIR)
|
||||
|
||||
fclean: clean
|
||||
make -C libft/ fclean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 22:24:29 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/04/15 00:14:19 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h> // for debug printf
|
||||
#include <stdbool.h> // to use bool type
|
||||
|
||||
# define BUFFER_SIZE 1024
|
||||
# define BUFF_SIZE 1024
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVALUATION
|
||||
@@ -33,8 +33,10 @@ void print_test(char *test);
|
||||
*/
|
||||
|
||||
char *read_file(char *file);
|
||||
void print_error(char *s, int fd);
|
||||
int ft_file_errors(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
|
||||
{
|
||||
@@ -6,11 +6,11 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 14:17:47 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 21:37:19 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/fillit.h"
|
||||
#include "fillit.h"
|
||||
|
||||
/*
|
||||
char *get_smallest_square()
|
||||
@@ -6,19 +6,20 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 14:39:12 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/15 00:13:18 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/fillit.h"
|
||||
#include "fillit.h"
|
||||
|
||||
/*
|
||||
** Function that display error message *s on fd
|
||||
** Function that display error message *s on fd and exit program
|
||||
*/
|
||||
|
||||
void print_error(char *s)
|
||||
{
|
||||
write(2, s, strlen(s));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -28,27 +29,65 @@ void print_error(char *s)
|
||||
** - two \n in a row
|
||||
*/
|
||||
|
||||
int ft_file_errors(char *file)
|
||||
int check_file_errors(char *file)
|
||||
{
|
||||
int i;
|
||||
int line_nbr;
|
||||
|
||||
i = 0;
|
||||
line_nbr = 0;
|
||||
while (*file)
|
||||
while (file[i])
|
||||
{
|
||||
if (*file == '\n')
|
||||
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
|
||||
return (1);
|
||||
if (file[i] == '\n')
|
||||
line_nbr++;
|
||||
file++;
|
||||
//if (*file == '\n')
|
||||
//return (1);
|
||||
// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#')
|
||||
// return (1);
|
||||
i++;
|
||||
}
|
||||
if (line_nbr < 4 || line_nbr > 129)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
int ft_tetri_errors()
|
||||
int check_tetri_errors(char *tetri)
|
||||
{
|
||||
int i;
|
||||
int htg;
|
||||
int dot;
|
||||
|
||||
i = 0;
|
||||
htg = 0;
|
||||
dot = 0;
|
||||
while (tetri[i])
|
||||
{
|
||||
if (tetri[i] == '#')
|
||||
htg++;
|
||||
else if (tetri[i] == '.')
|
||||
dot++;
|
||||
i++;
|
||||
}
|
||||
if (htg != 4 || dot != 12 || check_tetri_errors2(tetri))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int check_tetri_errors2(char *tetri)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tetri[i])
|
||||
{
|
||||
if (tetri[i] == '.' || tetri[i] == '\n')
|
||||
i++;
|
||||
else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#'
|
||||
|| tetri[i + 5] == '#' || tetri[i - 5] == '#'))
|
||||
i++;
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
1
libft
Submodule
1
libft
Submodule
Submodule libft added at dad20d5d96
@@ -6,11 +6,11 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 15:18:46 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/04/15 00:12:25 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/fillit.h"
|
||||
#include "fillit.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -20,8 +20,10 @@ int main(int argc, char **argv)
|
||||
{
|
||||
if (!(input = read_file(argv[1])))
|
||||
print_error("Error: Could not read file.\n");
|
||||
else if (ft_file_errors(input))
|
||||
if (check_file_errors(input))
|
||||
print_error("Error: Invalid file.\n");
|
||||
if (check_tetri_errors(input))
|
||||
print_error("Error: Tetrimino not valid.\n");
|
||||
/*
|
||||
Check if every tetrimino is valid
|
||||
Transform input to tetriminos
|
||||
@@ -32,6 +34,6 @@ int main(int argc, char **argv)
|
||||
print_test(input);
|
||||
}
|
||||
else
|
||||
print_error("Error: Please submit a file.\n");
|
||||
print_error("Usage: Please submit a file.\n");
|
||||
return (0);
|
||||
}
|
||||
@@ -6,11 +6,11 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:35:48 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 14:32:02 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/15 00:11:22 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/fillit.h"
|
||||
#include "fillit.h"
|
||||
|
||||
/*
|
||||
void ft_print_fillit()
|
||||
@@ -6,31 +6,68 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 14:23:24 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 23:01:31 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/fillit.h"
|
||||
#include "fillit.h"
|
||||
|
||||
/*
|
||||
** Function that read and return a ptr to file
|
||||
*/
|
||||
|
||||
char *read_file(char *file)
|
||||
{
|
||||
char buf[BUFFER_SIZE];
|
||||
char buf[BUFF_SIZE];
|
||||
int fd;
|
||||
int rv;
|
||||
int i;
|
||||
char *result;
|
||||
|
||||
if (((fd = open(file, O_RDONLY)) < 0) \
|
||||
|| ((rv = read(fd, &buf, BUFFER_SIZE)) < 0) \
|
||||
|| !(result = malloc(sizeof(char))))
|
||||
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|
||||
|| !(result = malloc(sizeof(char) * rv)))
|
||||
return (NULL);
|
||||
buf[rv] = '\0';
|
||||
i = 0;
|
||||
while (rv--)
|
||||
while (buf[i])
|
||||
{
|
||||
result[i] = buf[i];
|
||||
i++;
|
||||
}
|
||||
result[i] = '\0';
|
||||
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++;
|
||||
}
|
||||
}
|
||||
4
samples/test
Normal file
4
samples/test
Normal file
@@ -0,0 +1,4 @@
|
||||
..#.
|
||||
..#.
|
||||
..#.
|
||||
..
|
||||
BIN
srcs/a.out
Executable file
BIN
srcs/a.out
Executable file
Binary file not shown.
Reference in New Issue
Block a user