.h, main, Makefile and add_to_list edit for Testing
This commit is contained in:
105
'
105
'
@@ -1,105 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* add_to_list.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
|
||||||
/* Updated: 2019/04/24 13:36:26 by hulamy ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "fillit.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
** 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);
|
|
||||||
//}
|
|
||||||
|
|
||||||
6
Makefile
6
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2019/03/01 13:24:35 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)
|
OBJS = $(SRCS:.c=.o)
|
||||||
LIB = libft/
|
LIB = ../42-libft/
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Werror -Wextra
|
CFLAGS = -Wall -Werror -Wextra
|
||||||
@@ -42,7 +42,7 @@ $(NAME):
|
|||||||
mv $(OBJS) $(OBJ_DIR)
|
mv $(OBJS) $(OBJ_DIR)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
make -C libft/ clean
|
make -C $(LIB) clean
|
||||||
$(RM) $(OBJ_DIR)
|
$(RM) $(OBJ_DIR)
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/14 15:20:53 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
|
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||||
** Function that prints a 16 bites short
|
** Function that prints a 16 bites short
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
void print_bits(short line)
|
void print_bits(short line)
|
||||||
{
|
{
|
||||||
int mask;
|
int mask;
|
||||||
@@ -27,6 +27,7 @@ void print_bits(short line)
|
|||||||
(line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
(line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
||||||
write(1, "\n", 1);
|
write(1, "\n", 1);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function that transforme a tetrminos char* into a short of 16 bites
|
** 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)
|
void fill_list(char line[], t_fillist *list)
|
||||||
{
|
{
|
||||||
unsigned short tmp;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -46,18 +46,9 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
i++;
|
i++;
|
||||||
if (line[i++] == '#')
|
if (line[i++] == '#')
|
||||||
list->tetribit |= 1;
|
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);
|
// print_bits(list->tetribit);
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -102,4 +93,3 @@ int add_to_list(char *line, t_fillist **list)
|
|||||||
// }
|
// }
|
||||||
// return (0);
|
// return (0);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|||||||
11
fillit.h
11
fillit.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:34:46 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 <fcntl.h> // for system call open
|
#include <fcntl.h> // for system call open
|
||||||
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
||||||
|
|
||||||
#include "libft/includes/libft.h"
|
#include "../42-libft/includes/libft.h"
|
||||||
# define BUFF_SIZE 1024
|
# define BUFF_SIZE 1024
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -40,12 +40,13 @@ typedef struct s_fillist
|
|||||||
|
|
||||||
char *read_file(char *file);
|
char *read_file(char *file);
|
||||||
void print_error(char *s);
|
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_file_errors(char *file);
|
||||||
int check_tetri_errors(char *tetri);
|
int check_tetri_errors(char *tetri);
|
||||||
int check_tetri_errors_proxy(char *tetri);
|
int check_tetri_errors_proxy(char *tetri);
|
||||||
int add_to_list(char *square, t_fillist **list);
|
int add_to_list(char *square, t_fillist **list);
|
||||||
int fill_list(char *line, t_fillist *list);
|
void fill_list(char line[], t_fillist *list);
|
||||||
void print_bits(short line); //TO DELETE BEFORE EVAL
|
|
||||||
|
void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
10
main.c
10
main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *input;
|
char *input;
|
||||||
static t_fillist *list;
|
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
@@ -23,12 +22,7 @@ int main(int argc, char **argv)
|
|||||||
print_error("Error: Could not read file.\n");
|
print_error("Error: Could not read file.\n");
|
||||||
if (check_file_errors(input))
|
if (check_file_errors(input))
|
||||||
print_error("Error: Invalid file.\n");
|
print_error("Error: Invalid file.\n");
|
||||||
parse_input(input, list);
|
parse_input(input);
|
||||||
while (list)
|
|
||||||
{
|
|
||||||
printf("%i\n", list->tetribit);
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Backtracking for smallest square
|
Backtracking for smallest square
|
||||||
Transform tetriminos with letters & Print result
|
Transform tetriminos with letters & Print result
|
||||||
|
|||||||
Reference in New Issue
Block a user