new check for raw string (doesn't work)

This commit is contained in:
Gregory Tertyshny 2016-12-15 19:16:26 +02:00
parent 0f6aaeb611
commit 6be9cc0cbc
6 changed files with 78 additions and 122 deletions

View file

@ -25,7 +25,8 @@ SRC_FILES = main.c \
to_letters.c \ to_letters.c \
test!_check.c \ test!_check.c \
test!_print_one_string.c \ test!_print_one_string.c \
test!_print_table.c test!_print_table.c \
check_raw_string.c
OBJ_FILES = $(SRC_FILES:.c=.o) OBJ_FILES = $(SRC_FILES:.c=.o)

View file

@ -36,7 +36,6 @@ typedef struct s_map
unsigned int figure_amount; unsigned int figure_amount;
} t_map; } t_map;
// obsolete, rewrite for unit16
typedef struct s_tetrominoes_templates typedef struct s_tetrominoes_templates
{ {
char figure[17]; char figure[17];
@ -64,10 +63,13 @@ void move_up_left(char **table);
void print_one_string(char **glued); void print_one_string(char **glued);
// compare 19 templates with each tetromino in *ttr table // compare 19 templates with each tetromino in *ttr table
void test_check(char **ttr, t_tetrominoes_templates *tamplates); void test_check(char **ttr, char **tamplates);
// change hashes ('#') with letters // change hashes ('#') with letters
// obsolete, rewrite for structs array // obsolete, rewrite for structs array
void to_letters(char **ttr); void to_letters(char **ttr);
// проверка считаной строки
int check_raw_string(char *raw_string);
#endif #endif

34
src/check_raw_string.c Normal file
View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_raw_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 18:32:54 by gtertysh #+# #+# */
/* Updated: 2016/12/15 18:32:58 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
int check_raw_string(char *raw_string)
{
int n_count;
n_count = 0;
if (*raw_string == 0 || *raw_string == '\n')
return (1);
while(*raw_string)
{
if (*raw_string == '\n')
n_count++;
if ((n_count + 1) % 4 == 0)
if (*(raw_string + 1) != '\0')
if (*(raw_string + 1) != '\n' && !(*(raw_string + 2) == '.' || *(raw_string + 2) == '#'))
return (1);
raw_string++;
}
if (n_count < 3)
return (1);
return (0);
}

View file

@ -12,103 +12,26 @@
#include "fillit.h" #include "fillit.h"
// bad global variable char *str_templates[19] =
t_tetrominoes_templates templates[19] = { "#...#...#...#...",
{ "####............",
{ "#..." "#...#...##......",
"#..." "..#.###.........",
"#..." "##...#...#......",
"#..." }, "###.#...........",
".#...#..##......",
{ "####" "###...#.........",
"...." "##..#...#.......",
"...." "#...###.........",
"...." }, "###..#..........",
"#...##..#.......",
{ "#..." ".#..###.........",
"#..." ".#..##...#......",
"##.." "##..##..........",
"...." }, "##...##.........",
".#..##..#.......",
{ "..#." ".##.##..........",
"###." "#...##...#......"
"...."
"...." },
{ "##.."
".#.."
".#.."
"...." },
{ "###."
"#..."
"...."
"...." },
{ ".#.."
".#.."
"##.."
"...." },
{ "###."
"..#."
"...."
"...." },
{ "##.."
"#..."
"#..."
"...." },
{ "#..."
"###."
"...."
"...." },
{ "###."
".#.."
"...."
"...." },
{ "#..."
"##.."
"#..."
"...." },
{ ".#.."
"###."
"...."
"...." },
{ ".#.."
"##.."
".#.."
"...." },
{ "##.."
"##.."
"...."
"...." },
{ "##.."
".##."
"...."
"...." },
{ ".#.."
"##.."
"#..."
"...." },
{ ".##."
"##.."
"...."
"...." },
{ "#..."
"##.."
".#.."
"...." }
}; };
int main(int argc, char **argv) int main(int argc, char **argv)
@ -124,31 +47,27 @@ int main(int argc, char **argv)
ft_putstr("error\n"); ft_putstr("error\n");
return (1); return (1);
} }
string = read_file(argv[1]);
if (!(string = read_file(argv[1]))) if (!(string = read_file(argv[1])))
{ {
ft_putstr("error\n"); ft_putstr("error\n");
return (1); return (1);
} }
printf("string:\n\n\n%s\n", string); if (check_raw_string(string))
{
ft_putstr("error\n");
return (1);
}
table = to_table(&string); table = to_table(&string);
printf("print_table:\n\n\n"); // if (check_string_table(table))
print_table(table); // {
// ft_putstr("error\n");
// return (1);
// }
ttr = glue_figure(table); ttr = glue_figure(table);
printf("glued figures:\n\n\n");
print_one_string(ttr);
move_up_left(ttr); move_up_left(ttr);
printf("move to up left:\n\n\n"); //print_one_string(ttr);
print_one_string(ttr); test_check(ttr, str_templates);
//to_letters(ttr);
printf("test check:\n\n"); // print_one_string(ttr);
test_check(ttr, templates);
to_letters(ttr);
printf("to latters:\n\n");
print_one_string(ttr);
return (0); return (0);
} }

View file

@ -32,7 +32,7 @@ char *read_file(char *path)
string = ft_memalloc(sizeof(char) * BUF_S); string = ft_memalloc(sizeof(char) * BUF_S);
while ((readed = read(fd, buf, BUF_S))) while ((readed = read(fd, buf, BUF_S)))
{ {
buf[BUF_S] = '\0'; buf[readed] = '\0';
old_size = ft_strlen(string); old_size = ft_strlen(string);
string = ft_realloc(string, old_size + readed, old_size); string = ft_realloc(string, old_size + readed, old_size);
ft_strcat(string, buf); ft_strcat(string, buf);

View file

@ -14,7 +14,7 @@
// Test func. Compare figures from file // Test func. Compare figures from file
// with templates // with templates
void test_check(char **ttr, t_tetrominoes_templates *tamplates) void test_check(char **ttr, char **tamplates)
{ {
int i; int i;
int j; int j;
@ -28,8 +28,8 @@ void test_check(char **ttr, t_tetrominoes_templates *tamplates)
printf("\n\ninput:\n"); printf("\n\ninput:\n");
printf("%s\n", ttr[i]); printf("%s\n", ttr[i]);
printf("\n\ntemplate:\n"); printf("\n\ntemplate:\n");
printf("%s\n", tamplates[j].figure); printf("%s\n", tamplates[j]);
if ((ft_memcmp(ttr[i], tamplates[j].figure, 17) == 0)) if ((ft_memcmp(ttr[i], tamplates[j], 17) == 0))
printf(" match!\n"); printf(" match!\n");
j++; j++;
} }