Skip to content

Commit a576e56

Browse files
committed
[ERROR] Uploading all files, computer stops
1 parent fa6c700 commit a576e56

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

lib/my/my_putstr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ int my_strlen(char const *str);
1212
int my_putstr(char const *str, int len)
1313
{
1414
write(1, str, len);
15-
return (0);
15+
return (len);
1616
}

main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ int fs_open_file(char const *file_path);
99

1010
int main(int argc, char **argv)
1111
{
12-
fs_open_file(argv[1]);
12+
if (fs_open_file(argv[1]))
13+
return (84);
1314
return (0);
1415
}

src/bsq.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ void buff_to_str(char *str)
4444
j = 0;
4545
i++;
4646
}
47-
file[k][j] = str[i];
48-
j++;
47+
file[k][j++] = str[i];
4948
}
50-
k++;
51-
file[k] = NULL;
49+
file[++k] = NULL;
5250
free(str);
5351
find_the_square(file);
5452
}
5553

56-
void error_handler(char *str)
54+
int error_handler(char *str)
5755
{
5856
int i = 0;
5957
int j = 0;
@@ -62,13 +60,14 @@ void error_handler(char *str)
6260

6361
for (i; str[i] != '\n'; i++)
6462
if (str[i] > 57 || str[i] < 48)
65-
exit(84);
63+
return (84);
6664
if (i == 0)
67-
exit(84);
65+
return (84);
6866
i++;
6967
for (j = i; str[j] != '\0'; j++)
7068
if (str[j] != '.' && str[j] != 'o' && str[j] != '\n')
71-
exit(84);
69+
return (84);
70+
return (0);
7271
}
7372

7473
int fs_open_file(char const *file_path)
@@ -89,7 +88,8 @@ int fs_open_file(char const *file_path)
8988
read(fd, buffer, sd.st_size);
9089
close(fd);
9190
buffer[sd.st_size - 1] = '\0';
92-
error_handler(buffer);
91+
if (error_handler(buffer))
92+
return (84);
9393
buff_to_str(buffer);
9494
return (0);
9595
}

src/find_the_square.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77

88
#include "my.h"
99

10-
void squaring_map(square_t square, char **tab, int x, int y)
10+
void squaring_map(char **tab, int x, int y)
1111
{
12-
if (tab[y - 1][x] <= tab[y - 1][x - 1]
13-
&& tab[y - 1][x] <= tab[y][x - 1])
14-
tab[y][x] = tab[y - 1][x] + 1;
15-
if (tab[y - 1][x - 1] <= tab[y - 1][x]
16-
&& tab[y - 1][x - 1] <= tab[y][x - 1])
17-
tab[y][x] = tab[y - 1][x - 1] + 1;
18-
if (tab[y][x - 1] <= tab[y - 1][x - 1]
19-
&& tab[y][x - 1] <= tab[y - 1][x])
20-
tab[y][x] = tab[y][x - 1] + 1;
12+
int up = tab[y - 1][x];
13+
int up_left = tab[y - 1][x - 1];
14+
int left = tab[y][x - 1];
15+
16+
if (up <= up_left && up <= left)
17+
tab[y][x] = up + 1;
18+
if (up_left <= up && up_left <= left)
19+
tab[y][x] = up_left + 1;
20+
if (left <= up_left && left <= up)
21+
tab[y][x] = left + 1;
2122
}
2223

23-
void first_lines(square_t square, char **tab)
24+
void first_lines(char **tab)
2425
{
2526
int x = 0;
2627
int y = 0;
@@ -83,13 +84,13 @@ void find_the_square(char **tab)
8384
int x = 1;
8485
square_t square = {1, 0, 0};
8586

86-
first_lines(square, tab);
87+
first_lines(tab);
8788
for (y = 1; tab[y] != 0; y++)
8889
for (x = 1; tab[y][x] != '\0'; x++)
8990
if (tab[y][x] == 'o')
9091
tab[y][x] = 1;
9192
else
92-
squaring_map(square, tab, x, y);
93+
squaring_map(tab, x, y);
9394
find_biggest(square, tab);
9495
for (y = 0; tab[y] != 0; y++)
9596
free(tab[y]);

tests/test_out.c

+43-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,48 @@ Test(fs_open_file, test01, .init = redirect_all_std)
2121
cr_assert_stdout_eq_str("xxxx.o\nxxxx.o\nxxxxo.\nxxxx.o\no...o.\n");
2222
}
2323

24-
Test(fs_open_file, test02, .init = redirect_all_std)
24+
Test(fs_open_file, test_a_simple_box, .init = redirect_all_std)
2525
{
26-
fs_open_file("map3.txt");
26+
fs_open_file("mouli_maps/intermediate_map_one_empty_box");
27+
cr_assert_stdout_eq_str("x\n");
28+
}
29+
30+
Test(error_handler, test_unexisting_map, .init = redirect_all_std)
31+
{
32+
int ret;
33+
34+
ret = fs_open_file("map3.txt");
35+
cr_assert_eq(84, ret);
36+
}
37+
38+
Test(error_handler, test_without_line_number, .init = redirect_all_std)
39+
{
40+
int ret;
41+
42+
ret = fs_open_file("mouli_maps/maps_without_line_number");
43+
cr_assert_eq(84, ret);
44+
}
45+
46+
Test(error_handler, test_wihtout_number_in_line_number, .init = redirect_all_std)
47+
{
48+
int ret;
49+
50+
ret = fs_open_file("mouli_maps/maps_without_number_in_first_line");
51+
cr_assert_eq(84, ret);
52+
}
53+
54+
Test(error_handler, test_with_a_letter_in_number_field, .init = redirect_all_std)
55+
{
56+
int ret;
57+
58+
ret = fs_open_file("mouli_maps/maps_with_letter_in_number_field");
59+
cr_assert_eq(84, ret);
60+
}
61+
62+
Test(error_handler, test_a_letter_in_map, .init = redirect_all_std)
63+
{
64+
int ret;
65+
66+
ret = fs_open_file("mouli_maps/map_with_other_character");
67+
cr_assert_eq(84, ret);
2768
}

0 commit comments

Comments
 (0)