Makefile and some structuring work

This commit is contained in:
Gregory Tertyshny 2016-12-14 20:00:58 +02:00
parent 1f4a66128f
commit 2ead8d88f5
19 changed files with 709 additions and 407 deletions

3
.gitignore vendored
View file

@ -31,3 +31,6 @@
# Debug files
*.dSYM/
*.su
# Vim temp
*.swp

71
Makefile Normal file
View file

@ -0,0 +1,71 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
# Updated: 2016/12/14 18:41:33 by gtertysh ### ########.fr #
# #
# **************************************************************************** #
NAME = fillit
SRCDIR = ./src/
OBJDIR = ./obj/
SRC_FILES = main.c \
fillit.c \
glue_figure.c \
move_up_left.c \
read_file.c \
string_to_table.c \
to_letters.c \
test!_check.c \
test!_print_one_string.c \
test!_print_table.c
OBJ_FILES = $(SRC_FILES:.c=.o)
SRC = $(addprefix $(SRCDIR), $(SRC_FILES))
OBJ = $(addprefix $(OBJDIR), $(OBJ_FILES))
INC = -I ./inc
LIB = libft.a
LIBFLAGS = -lft -L $(LIBFOLDER)
LIBFOLDER = ./libft/
FLAGS = -Werror -Wextra -Wall
CC = clang
all: $(NAME)
$(NAME): $(OBJ) $(LIBFOLDER)$(LIB)
$(CC) $(FLAGS) $(OBJ) $(LIBFLAGS) -o $(NAME)
$(OBJDIR)%.o : $(SRCDIR)%.c
$(CC) $(FLAGS) $(INC) -c $< -o $@
$(LIBFOLDER)$(LIB):
make -C $(LIBFOLDER)
clean:
rm -rf $(OBJ)
fclean: clean
rm -rf $(NAME)
libclean:
make clean -C $(LIBFOLDER)
libfclean:
make fclean -C $(LIBFOLDER)
re: fclean libfclean all

View file

@ -1,17 +0,0 @@
typedef struct s_tetraminos
{
uint16_t line[16];
int offset_y;
} t_tetraminos;
typedef struct s_map
{
uint16_t line[16];
unsigned int size;
t_tetraminos *figure[26];
unsigned int figure_amount;
} t_map;
t_tetraminos *convert_tetramino(char *s);
t_map *map_initialization(char **tetramino_table);

72
inc/fillit.h Normal file
View file

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 16:42:06 by gtertysh #+# #+# */
/* Updated: 2016/12/14 16:45:34 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
#include "libft.h"
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h> // warning!
# define BUF_S 8192
typedef struct s_tetrominoes
{
uint16_t line[16];
int offset_y;
} t_tetrominoes;
typedef struct s_map
{
uint16_t line[16];
unsigned int size;
t_tetrominoes *figure[26];
unsigned int figure_amount;
} t_map;
// obsolete, rewrite for unit16
typedef struct s_tetrominoes_templates
{
char figure[17];
} t_tetrominoes_templates;
t_tetrominoes *convert_tetramino(char *s);
t_map *map_initialization(char **tetramino_table);
// reads from file
char *read_file(char *path);
// convert string to table by spliting by '\n'
char **to_table(char **string);
// print table returned by to_table()
void print_table(char **table);
// creates new table where each string represent whole figrure
char **glue_figure(char **table);
// move tetromino in top left corner
void move_up_left(char **table);
// print table returned by glue_figure()
void print_one_string(char **glued);
// compare 19 templates with each tetromino in *ttr table
void test_check(char **ttr, t_tetrominoes_templates *tamplates);
// change hashes ('#') with letters
// obsolete, rewrite for structs array
void to_letters(char **ttr);
#endif

97
inc/libft.h Normal file
View file

@ -0,0 +1,97 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
/* Updated: 2016/12/06 20:08:35 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <string.h>
# include <stdlib.h>
# include <unistd.h>
typedef struct s_list
{
void *content;
size_t content_size;
struct s_list *next;
} t_list;
void *ft_memset(void *b, int c, size_t len);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t len);
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
void *ft_memmove(void *dst, const void *src, size_t len);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
size_t ft_strlen(const char *s);
char *ft_strdup(const char *s1);
char *ft_strcpy(char *dst, const char *src);
char *ft_strncpy(char *dst, const char *src, size_t len);
char *ft_strcat(char *s1, const char *s2);
char *ft_strncat(char *s1, const char *s2, size_t n);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
char *ft_strstr(const char *big, const char *little);
char *ft_strnstr(const char *big, const char *little,
size_t len);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_atoi(const char *str);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalpha(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
int ft_tolower(int c);
int ft_toupper(int c);
void *ft_memalloc(size_t size);
void ft_memdel(void **ap);
char *ft_strnew(size_t size);
void ft_strdel(char **as);
void ft_strclr(char *s);
void ft_striter(char *s, void (*f)(char *));
void ft_striteri(char *s, void (*f)(unsigned int, char *));
char *ft_strmap(char const *s, char (*f)(char));
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
int ft_strequ(char const *s1, char const *s2);
int ft_strnequ(char const *s1, char const *s2, size_t n);
char *ft_strsub(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s);
char **ft_strsplit(char const *s, char c);
char *ft_itoa(int c);
void ft_putchar(char c);
void ft_putstr(char const *s);
void ft_putendl(char const *s);
void ft_putnbr(int n);
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char const *s, int fd);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr_fd(int n, int fd);
t_list *ft_lstnew(void const *content, size_t content_size);
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
void ft_lstadd(t_list **alst, t_list *new);
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
t_list *ft_lststrsplit(const char *s, char c);
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
t_list *ft_lst_at(t_list *l, unsigned int at);
void ft_lstadd_back(t_list **l, void *data, size_t size);
void *ft_realloc(void *old, unsigned int new_size,
unsigned int old_size);
#endif

379
main.c
View file

@ -1,379 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
/* Updated: 2016/12/10 21:35:59 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#define BUF_S 8192
typedef struct s_tetrominoes
{
char figure[17];
} t_ttr;
t_ttr ttr_tamplates[19] =
{
{ "#..."
"#..."
"#..."
"#..." },
{ "####"
"...."
"...."
"...." },
{ "#..."
"#..."
"##.."
"...." },
{ "..#."
"###."
"...."
"...." },
{ "##.."
".#.."
".#.."
"...." },
{ "###."
"#..."
"...."
"...." },
{ ".#.."
".#.."
"##.."
"...." },
{ "###."
"..#."
"...."
"...." },
{ "##.."
"#..."
"#..."
"...." },
{ "#..."
"###."
"...."
"...." },
{ "###."
".#.."
"...."
"...." },
{ "#..."
"##.."
"#..."
"...." },
{ ".#.."
"###."
"...."
"...." },
{ ".#.."
"##.."
".#.."
"...." },
{ "##.."
"##.."
"...."
"...." },
{ "##.."
".##."
"...."
"...." },
{ ".#.."
"##.."
"#..."
"...." },
{ ".##."
"##.."
"...."
"...." },
{ "#..."
"##.."
".#.."
"...." }
};
// read from file. Returns string.
char *read_file(char *path)
{
int fd;
int readed;
int old_size;
char buf[BUF_S + 1];
char *string;
readed = 0;
string = 0;
old_size = 0;
if (!(fd = open(path, O_RDONLY)))
{
ft_putstr("error\n");
return (0);
}
string = ft_memalloc(sizeof(char) * BUF_S);
while ((readed = read(fd, buf, BUF_S)))
{
buf[BUF_S] = '\0';
old_size = ft_strlen(string);
string = ft_realloc(string, old_size + readed, old_size);
ft_strcat(string, buf);
}
return (string);
}
// Split string to table by newline character. Each string contain one line of the file
char **to_table(char *string)
{
char **table;
table = ft_strsplit(string, '\n');
free(string);
string = NULL;
return (table);
}
// Test func. Print string table.
void print_table(char **table)
{
int i;
i = 0;
while (table[i])
{
ft_putstr(table[i]);
ft_putstr("\n");
if ((i + 1) % 4 == 0)
ft_putchar('\n');
i++;
}
}
// Test func. Print table but one string contain whole figure.
void print_one_string(char **glued)
{
int i;
int j;
i = 0;
while (glued[i])
{
j = 0;
while (glued[i][j])
{
ft_putchar(glued[i][j]);
if ((j + 1) % 4 == 0)
ft_putchar('\n');
j++;
}
ft_putstr("\n");
i++;
}
}
// This function creates string table in which one line represent one figure
// by "glueing" evry 4 strings from table
char **glue_figure(char **table)
{
int i;
int j;
int size;
char **ttr_table;
size = 0;
i = 0;
j = 0;
while(table[size])
size++;
ttr_table = ft_memalloc(sizeof(char *) * (size / 4 + 1));
while (i < size / 4)
ttr_table[i++] = ft_memalloc(sizeof(char) * 17);
ttr_table[i] = 0;
i = 0;
while (i < size / 4)
{
ft_strcat(ttr_table[i], table[j]);
j++;
if (j % 4 == 0)
i++;
}
i = 0;
while(table[i])
free(table[i++]);
free(table);
return (ttr_table);
}
// Moves figures to top left corner.
// table contains strings each represent one figure
void move_up_left(char **table)
{
int i;
int j;
int k;
char tmp[17];
i = 0;
while (table[i])
{
ft_memcpy(tmp, table[i], 17);
j = 0;
while(table[i][j] != '#')
j++;
ft_memmove(tmp, table[i] + j, 17 - j);
k = 0;
while ( (tmp[3] == '#' && tmp[4] == '#') ||
(tmp[7] == '#' && tmp[8] == '#') ||
(tmp[11] == '#' && tmp[12] == '#'))
{
ft_memmove((tmp + k + 1), (tmp + k), 17 - j);
*(tmp + k) = '.';
j--;
k++;
}
k = 15;
while (j--)
{
*(tmp + k--) = '.';
}
ft_memcpy(table[i], tmp, 17);
i++;
}
}
// convert "#" symbols to letters
void to_letters(char **ttr)
{
char ch;
int i;
int j;
i = 0;
ch = 'A';
while(ttr[i])
{
j = 0;
while(ttr[i][j])
{
if(ttr[i][j] == '#')
ttr[i][j] = ch;
j++;
}
i++;
ch++;
}
}
// Test func. Compare figures from file
// with templates
void test_check(char **ttr, t_ttr *tamplates)
{
int i;
int j;
i = 0;
while (ttr[i])
{
j = 0;
while(j < 19)
{
printf("\n\ninput:\n");
printf("%s\n", ttr[i]);
printf("\n\ntemplate:\n");
printf("%s\n", tamplates[j].figure);
if ((ft_memcmp(ttr[i], tamplates[j].figure, 17) == 0))
printf(" match!\n");
j++;
}
i++;
}
}
// Forgot for what this func was added:)
int ft_dumb_sqrt(int nb)
{
int i;
i = 0;
while (i * i < nb)
i++;
return (i);
}
int main(int argc, char **argv)
{
char *string;
char **table;
char **ttr;
int i;
i = 0;
if (argc != 2)
{
ft_putstr("error\n");
return (1);
}
string = read_file(argv[1]);
if (!(string = read_file(argv[1])))
{
ft_putstr("error\n");
return (1);
}
printf("string:\n\n\n%s\n", string);
table = to_table(string);
// set null to free :)
printf("print_table:\n\n\n");
print_table(table);
ttr = glue_figure(table);
printf("glued figures:\n\n\n");
print_one_string(ttr);
move_up_left(ttr);
printf("move to up left:\n\n\n");
print_one_string(ttr);
//printf("test check:\n\n");
//test_check(ttr, ttr_tamplates);
to_letters(ttr);
printf("to latters:\n\n");
print_one_string(ttr);
printf("%d\n", ft_dumb_sqrt(4));
//while (i < 19)
//{
// ft_putstr(ttr[i++].figure);
// ft_putstr("\n");
//}
//if (check(string))
//{
// ft_putstr("error\n");
// return (1);
//}
return (0);
}

View file

@ -1,12 +1,11 @@
#include "fillit.h"
#include <stdlib.h>
#include <stdio.h>
unsigned int ft_sqrt_ceil(unsigned int num)
{
int i;
unsigned int i;
i = 1;
// int and unsigned int comparsion
while (i * i < num)
i++;
return (i);
@ -21,14 +20,14 @@ void clear_map(t_map *map)
map->line[i++] = 0;
}
t_tetraminos *convert_tetramino(char *s)
t_tetrominoes *convert_tetramino(char *s)
{
t_tetraminos *res;
t_tetrominoes *res;
uint16_t temp;
int i;
int y;
res = (t_tetraminos*)malloc(sizeof(t_tetraminos));
res = (t_tetrominoes*)malloc(sizeof(t_tetrominoes));
res->offset_y = 0;
i = 0;
y = 1;
@ -68,7 +67,7 @@ void insert_tetramino(t_map *map, int index)
{
int i;
int k;
t_tetraminos *temp;
t_tetrominoes *temp;
temp = map->figure[index];
i = temp->offset_y;
@ -85,7 +84,7 @@ void erase_tetramino(t_map *map, int index)
{
int i;
int k;
t_tetraminos *temp;
t_tetrominoes *temp;
temp = map->figure[index];
i = temp->offset_y;
@ -97,6 +96,6 @@ void erase_tetramino(t_map *map, int index)
}
}
void algorithm(t_map *map)
{
}
//void algorithm(t_map *map)
//{
//}

46
src/glue_figure.c Normal file
View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* glue_figure.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:12:30 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:12:32 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// This function creates string table in which one line represent one figure
// by "glueing" evry 4 strings from table
char **glue_figure(char **table)
{
int i;
int j;
int size;
char **ttr_table;
size = 0;
i = 0;
j = 0;
while(table[size])
size++;
ttr_table = ft_memalloc(sizeof(char *) * (size / 4 + 1));
while (i < size / 4)
ttr_table[i++] = ft_memalloc(sizeof(char) * 17);
ttr_table[i] = 0;
i = 0;
while (i < size / 4)
{
ft_strcat(ttr_table[i], table[j]);
j++;
if (j % 4 == 0)
i++;
}
i = 0;
while(table[i])
free(table[i++]);
free(table);
return (ttr_table);
}

154
src/main.c Normal file
View file

@ -0,0 +1,154 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
/* Updated: 2016/12/14 16:45:31 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// bad global variable
t_tetrominoes_templates templates[19] =
{
{ "#..."
"#..."
"#..."
"#..." },
{ "####"
"...."
"...."
"...." },
{ "#..."
"#..."
"##.."
"...." },
{ "..#."
"###."
"...."
"...." },
{ "##.."
".#.."
".#.."
"...." },
{ "###."
"#..."
"...."
"...." },
{ ".#.."
".#.."
"##.."
"...." },
{ "###."
"..#."
"...."
"...." },
{ "##.."
"#..."
"#..."
"...." },
{ "#..."
"###."
"...."
"...." },
{ "###."
".#.."
"...."
"...." },
{ "#..."
"##.."
"#..."
"...." },
{ ".#.."
"###."
"...."
"...." },
{ ".#.."
"##.."
".#.."
"...." },
{ "##.."
"##.."
"...."
"...." },
{ "##.."
".##."
"...."
"...." },
{ ".#.."
"##.."
"#..."
"...." },
{ ".##."
"##.."
"...."
"...." },
{ "#..."
"##.."
".#.."
"...." }
};
int main(int argc, char **argv)
{
char *string;
char **table;
char **ttr;
int i;
i = 0;
if (argc != 2)
{
ft_putstr("error\n");
return (1);
}
string = read_file(argv[1]);
if (!(string = read_file(argv[1])))
{
ft_putstr("error\n");
return (1);
}
printf("string:\n\n\n%s\n", string);
table = to_table(&string);
printf("print_table:\n\n\n");
print_table(table);
ttr = glue_figure(table);
printf("glued figures:\n\n\n");
print_one_string(ttr);
move_up_left(ttr);
printf("move to up left:\n\n\n");
print_one_string(ttr);
printf("test check:\n\n");
test_check(ttr, templates);
to_letters(ttr);
printf("to latters:\n\n");
print_one_string(ttr);
return (0);
}

50
src/move_up_left.c Normal file
View file

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_up_left.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:13:59 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:14:07 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// Moves figures to top left corner.
// table contains strings each represent one figure
void move_up_left(char **ttr)
{
int i;
int j;
int k;
char tmp[17];
i = 0;
while (ttr[i])
{
ft_memcpy(tmp, ttr[i], 17);
j = 0;
while(ttr[i][j] != '#')
j++;
ft_memmove(tmp, ttr[i] + j, 17 - j);
k = 0;
while ( (tmp[3] == '#' && tmp[4] == '#') ||
(tmp[7] == '#' && tmp[8] == '#') ||
(tmp[11] == '#' && tmp[12] == '#'))
{
ft_memmove((tmp + k + 1), (tmp + k), 17 - j);
*(tmp + k) = '.';
j--;
k++;
}
k = 15;
while (j--)
{
*(tmp + k--) = '.';
}
ft_memcpy(ttr[i], tmp, 17);
i++;
}
}

41
src/read_file.c Normal file
View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 16:55:43 by gtertysh #+# #+# */
/* Updated: 2016/12/14 16:55:45 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// read from file. Returns string.
char *read_file(char *path)
{
int fd;
int readed;
int old_size;
char buf[BUF_S + 1];
char *string;
readed = 0;
string = 0;
old_size = 0;
if (!(fd = open(path, O_RDONLY)))
{
ft_putstr("error\n");
return (0);
}
string = ft_memalloc(sizeof(char) * BUF_S);
while ((readed = read(fd, buf, BUF_S)))
{
buf[BUF_S] = '\0';
old_size = ft_strlen(string);
string = ft_realloc(string, old_size + readed, old_size);
ft_strcat(string, buf);
}
return (string);
}

25
src/string_to_table.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* string_to_table.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 16:56:56 by gtertysh #+# #+# */
/* Updated: 2016/12/14 16:56:57 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// Split string to table by newline character.
// Each string contain one line of the file
char **to_table(char **string)
{
char **table;
table = ft_strsplit(*string, '\n');
free(*string);
*string = NULL;
return (table);
}

38
src/test!_check.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:26:13 by gtertysh #+# #+# */
/* Updated: 2016/12/14 18:47:16 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// Test func. Compare figures from file
// with templates
void test_check(char **ttr, t_tetrominoes_templates *tamplates)
{
int i;
int j;
i = 0;
while (ttr[i])
{
j = 0;
while(j < 19)
{
printf("\n\ninput:\n");
printf("%s\n", ttr[i]);
printf("\n\ntemplate:\n");
printf("%s\n", tamplates[j].figure);
if ((ft_memcmp(ttr[i], tamplates[j].figure, 17) == 0))
printf(" match!\n");
j++;
}
i++;
}
}

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_print_one_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:09:23 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:09:24 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// Test func. Print table but one string contain whole figure.
void print_one_string(char **glued)
{
int i;
int j;
i = 0;
while (glued[i])
{
j = 0;
while (glued[i][j])
{
ft_putchar(glued[i][j]);
if ((j + 1) % 4 == 0)
ft_putchar('\n');
j++;
}
ft_putstr("\n");
i++;
}
}

30
src/test!_print_table.c Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_print_table.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:07:19 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:07:22 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// Test func. Print string table,
// each line - line of tetromino figure.
void print_table(char **table)
{
int i;
i = 0;
while (table[i])
{
ft_putstr(table[i]);
ft_putstr("\n");
if ((i + 1) % 4 == 0)
ft_putchar('\n');
i++;
}
}

37
src/to_letters.c Normal file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* to_letters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:21:37 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:21:39 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
// convert "#" symbols to letters
// rewrite for new method with structures
void to_letters(char **ttr)
{
char ch;
int i;
int j;
i = 0;
ch = 'A';
while(ttr[i])
{
j = 0;
while(ttr[i][j])
{
if(ttr[i][j] == '#')
ttr[i][j] = ch;
j++;
}
i++;
ch++;
}
}