Skip to content

Commit

Permalink
RM: major error of parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan-Cordelier committed Apr 11, 2024
1 parent 2ea50d0 commit f2c69cb
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
2 changes: 2 additions & 0 deletions include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void free_graph(void *data);

//init
void init_parsing(parsing_t **lab);
void init_solution(int **matrice, int param[4], void *data);

//Put
int mini_printf(const char *format, ...);
Expand Down Expand Up @@ -54,6 +55,7 @@ int get_start(void *data);
int my_getnbr(char const *str);

//Free
int free_all(parsing_t *lab, char **tab);
void free_tab(char **tab);

#endif /* MYH */
2 changes: 1 addition & 1 deletion include/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct parsing_s {
} parsing_t;

typedef struct solutions_s {
int *path;
char *path;
int len;
struct solutions_s *next;
} solutions_t;
Expand Down
7 changes: 7 additions & 0 deletions src/free.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#include "my.h"

int free_all(parsing_t *lab, char **tab)
{
free_lst(&lab);
free_tab(tab);
return 0;
}

void free_tab(char **tab)
{
for (int i = 0; i < tab_len(tab); i++)
Expand Down
8 changes: 6 additions & 2 deletions src/get_start_end_robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ int get_nb_robot(void *data)
int get_start(void *data)
{
int end = -1;
int is_tunnel = -1;
parsing_t **lab = (parsing_t **) data;

reverse(lab);
for (parsing_t *temp = (*lab)->next; temp != NULL; temp = temp->next) {
if ((temp)->next != NULL && my_strcmp((temp)->str, "##start") == 0) {
if ((temp)->next != NULL && my_strcmp((temp)->str, "##start") == 0)
end = my_getnbr(temp->next->str);
}
if ((temp) != NULL && is_in_str((temp)->str, '-') != 0)
is_tunnel++;
}
reverse(lab);
if (is_tunnel == -1)
return is_tunnel;
return end;
}
10 changes: 6 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ int main(void)
param[END] = get_end(&lab);
param[ROBOT] = get_nb_robot(&lab);
param[LEN] = my_get_biggest_nb(tab);
for (int i = 0; i < 3; i++) {
if (param[i] == -1)
return 84;
}
moove(matrice, param);
free_lst(&lab);
free_tab(tab);
return 0;
return free_all(lab, tab);
}

/*for (int i = 0; i < 3; i++) {
printf("%d\n", param[i]);
mini_printf("%d\n", param[i]);
if (param[i] == -1)
return 84;
}*/
Expand Down
2 changes: 1 addition & 1 deletion src/my_getnbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int my_getnbr(char const *str)
i = nb_0(str, i);
while (str[i + len_nb] >= '0' && str[i + len_nb] <= '9')
len_nb++;
if (len_nb > 15 || len_nb == 0 && str[0] != '0')
if (len_nb > 15 || (len_nb == 0 && str[0] != '0'))
return (-1);
nb = get_nb_provi(puissance, len_nb, str, i);
nb_final = test_max_int(neg, nb);
Expand Down
8 changes: 4 additions & 4 deletions src/str/remoove_tag_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ char *rm_tag_str(char *str)
char *cpy = NULL;
int j = 0;

if (my_strcmp(str, "##start") == 0 || my_strcmp(str, "##end") == 0)
if (my_strcmp(str, "##start") == 0 || my_strcmp(str, "##end") == 0 ||
str[0] == '#')
return str;
cpy = malloc(sizeof(char) * my_strlen(str));
for (int i = j; str[i] != '\0'; i++) {
Expand All @@ -23,9 +24,8 @@ char *rm_tag_str(char *str)
cpy[i] = str[i];
j++;
}
if (j <= 1)
return str;
j--;
if (cpy[j] != '\0')
j--;
cpy[j] = '\0';
return cpy;
}
41 changes: 14 additions & 27 deletions src/struct_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,37 @@

#include "my.h"

int nb_solutions(int **matrice, int start, int len)
char *init_shortest_path(int **matrice, int param[4])
{
int size = 0;

for (int i = 0; i < len; i ++) {
if (matrice[start][i] == 1)
size++;
}
return size;
}

int *init_shortest_path(int **matrice, int start, int end, int len)
{
int *path = NULL;
char *path = NULL;

return path;
}

solutions_t *add_solution(int **matrice, int start, int end, int len)
int add_solution(int **matrice, int param[4], void *data)
{
solutions_t **sol = (solutions_t **) data;
solutions_t *new = NULL;
int size = nb_solutions(matrice, start, len);
int last = 0;

new = malloc(sizeof(solutions_t));
new->path = NULL;
new->len = -1;
new->next = NULL;
return new;
return last;
}

solutions_t *init_solutions(int **matrice, int start, int end, int len)
void init_solution(int **matrice, int param[4], void *data)
{
solutions_t *sol = NULL;
int size = nb_solutions(matrice, start, len);
solutions_t **sol = (solutions_t **) data;
int size = 0;

sol = malloc(sizeof(solutions_t));
sol->path = NULL;
sol->len = -1;
sol->next = NULL;
for (int i = 0; i < size; i++) {
sol->next = add_solution(matrice, start, end, len);
sol = sol->next;
(*sol)->path = NULL;
(*sol)->len = -1;
(*sol)->next = NULL;
while (size == 0) {
size = add_solution(matrice, param, sol);
}
return sol;
}

void init_parsing(parsing_t **lab)
Expand Down

0 comments on commit f2c69cb

Please sign in to comment.