check_tetri_error WORKING + Parser
This commit is contained in:
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
|
||||
|
||||
4
fillit.h
4
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 17:43:41 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 22:32:32 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -35,5 +35,7 @@ void print_test(char *test);
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,19 +6,20 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 21:37:23 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 22:57:14 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -41,8 +42,8 @@ int check_file_errors(char *file)
|
||||
return (1);
|
||||
if (file[i] == '\n')
|
||||
line_nbr++;
|
||||
if (file[i] == '\n' && file[i+1] == '\n')
|
||||
return (1);
|
||||
// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#')
|
||||
// return (1);
|
||||
i++;
|
||||
}
|
||||
if (line_nbr < 4 || line_nbr > 129)
|
||||
@@ -61,17 +62,18 @@ int check_tetri_errors(char *tetri)
|
||||
dot = 0;
|
||||
while (tetri[i])
|
||||
{
|
||||
if (tetri[i] = '#')
|
||||
if (tetri[i] == '#')
|
||||
htg++;
|
||||
else if (tetri[i] = '.')
|
||||
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;
|
||||
@@ -79,11 +81,13 @@ int check_tetri_errors2(char *tetri)
|
||||
i = 0;
|
||||
while (tetri[i])
|
||||
{
|
||||
if (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
7
main.c
7
main.c
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 21:37:27 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 22:58:47 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,6 +22,8 @@ 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");
|
||||
/*
|
||||
Check if every tetrimino is valid
|
||||
Transform input to tetriminos
|
||||
@@ -31,7 +33,6 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
}
|
||||
else
|
||||
print_error("Error: Please submit a file.\n");
|
||||
print_error("Usage: Please submit a file.\n");
|
||||
return (0);
|
||||
print_test(input);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/14 21:37:37 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/14 23:01:31 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -46,7 +46,7 @@ char *read_file(char *file)
|
||||
|
||||
int parse_input(char *input)
|
||||
{
|
||||
char /*NOM DE LA VARIABLE*/;
|
||||
char tetri;
|
||||
int c;
|
||||
int i;
|
||||
int j;
|
||||
@@ -60,9 +60,11 @@ int parse_input(char *input)
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
{
|
||||
/*NOM DE LA VARIABLE[j]*/ = input[c++];
|
||||
tetri[j] = input[c++];
|
||||
j++;
|
||||
}
|
||||
if (check_tetri_errors(tetri))
|
||||
print_error("Error: Tetrimino not valid.\n");
|
||||
c++;
|
||||
i++;
|
||||
}
|
||||
|
||||
4
samples/test
Normal file
4
samples/test
Normal file
@@ -0,0 +1,4 @@
|
||||
..#.
|
||||
..#.
|
||||
..#.
|
||||
..
|
||||
Reference in New Issue
Block a user