Skip to content

Commit

Permalink
[FIX] return KO if i have no room
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-labadie committed Apr 12, 2024
1 parent 90598f1 commit dc33922
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
int error_handling(int argc, char const *const *argv);

int my_putchar(char c);
void my_put_errchar(char c);
int my_put_errchar(char c);
int my_putstr(char const *str);
int my_put_errstr(char const *str);
int my_strlen(char const *str);
Expand Down
3 changes: 2 additions & 1 deletion lib/my/my_put_errchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include <unistd.h>

void my_put_errchar(char c)
int my_put_errchar(char c)
{
write(2, &c, 1);
return 84;
}
2 changes: 1 addition & 1 deletion lib/my/my_put_errstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ int my_put_errstr(char const *str)
my_put_errchar(str[i]);
i += 1;
}
return (i);
return 84;
}
11 changes: 6 additions & 5 deletions src/parsing/tunnels.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ static int get_rooms(matrix_t **matrix, room_t *room)
(*matrix)->end_room = i;
i++;
}
if ((*matrix)->start_room < 0 || (*matrix)->end_room < 0) {
my_put_errstr("Error : no START or no END room found\n");
return KO;
}
if ((*matrix)->start_room < 0 || (*matrix)->end_room < 0)
return my_put_errstr("Error : no START or no END room found\n");
return OK;
}

Expand Down Expand Up @@ -111,8 +109,11 @@ int put_tunnel(amazed_t *amazed, char *line)
{
if (!amazed)
return KO;
if (!amazed->room)
return my_put_errstr("Error : No room\n");
if (!amazed->matrix)
get_rooms(&amazed->matrix, amazed->room);
if (get_rooms(&amazed->matrix, amazed->room) == KO)
return KO;
if (check_tunnel(amazed->matrix->names, line) == KO)
return KO;
add_tunnel(&amazed->tunnels, line);
Expand Down

0 comments on commit dc33922

Please sign in to comment.