fix paths
This commit is contained in:
parent
060963039c
commit
053b04133a
1 changed files with 40 additions and 22 deletions
|
@ -239,18 +239,23 @@ int polls_command(char *command, hashmap *polls, hashmap *cmd) {
|
|||
|
||||
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||
int top) {
|
||||
char *page;
|
||||
char *page2;
|
||||
if (top) {
|
||||
page = handle_pages(command, "/path ");
|
||||
if (page == 0)
|
||||
page2 = handle_pages(command, "/path ");
|
||||
if (page2 == 0)
|
||||
return 0;
|
||||
} else {
|
||||
page = command;
|
||||
page2 = command;
|
||||
}
|
||||
|
||||
page[strlen(page) - 1] = '\0';
|
||||
if (strlen(page) == 0)
|
||||
char *page = malloc(strlen(page2) + 1);
|
||||
strcpy(page, page2);
|
||||
if (page[strlen(page) - 1] == '\n') {
|
||||
page[strlen(page) - 1] = '\0';
|
||||
}
|
||||
if (strlen(page) == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (top) {
|
||||
printf("Path of %s:\n", page);
|
||||
|
@ -260,41 +265,54 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
|||
|
||||
uintptr_t result;
|
||||
hashmap_get(already_done, page, strlen(page), &result);
|
||||
|
||||
if (result != 0)
|
||||
|
||||
if (result != 0) {
|
||||
return 1;
|
||||
}
|
||||
hashmap_set(already_done, page, strlen(page), (uintptr_t)1, 0);
|
||||
|
||||
hashmap_get(elements_rev, page, strlen(page) - 1, &result);
|
||||
|
||||
if (result == 0 || strlen((char *)result) < 1)
|
||||
if (result == 0 || strlen((char *)result) < 1) {
|
||||
return 1;
|
||||
|
||||
printf("%s: %s", command, (char *)result);
|
||||
}
|
||||
|
||||
// todo: refactor;
|
||||
char *tmp = (char *)result, *tmp2 = 0;
|
||||
if (tmp[strlen(tmp)-1] == '\n') {
|
||||
tmp[strlen(tmp) - 1] = '\0';
|
||||
}
|
||||
|
||||
int combos = 0;
|
||||
for (int i = 1; i < MAX_COMBO_LENGTH; i++) {
|
||||
combos = i;
|
||||
tmp2 = tmp;
|
||||
tmp = strstr(tmp, ";");
|
||||
if (tmp == 0 || tmp2 == tmp)
|
||||
break;
|
||||
if (strlen(tmp) < 2) {
|
||||
break;
|
||||
if (tmp2[0] == ';') {
|
||||
tmp2++;
|
||||
}
|
||||
tmp[0] = '\0';
|
||||
tmp++;
|
||||
|
||||
if (i == 1) {
|
||||
path_command(tmp2, elements_rev, already_done, 0);
|
||||
tmp = strstr(tmp2, ";");
|
||||
if (tmp == 0) {
|
||||
tmp = &tmp2[strlen(tmp2)];
|
||||
}
|
||||
|
||||
path_command(tmp, elements_rev, already_done, 0);
|
||||
char *tmp23 = malloc(strlen(tmp2) - strlen(tmp) + 2);
|
||||
memcpy(tmp23, &tmp2[0], strlen(tmp2) - strlen(tmp) + 2);
|
||||
tmp23[strlen(tmp2) - strlen(tmp) + 1] = '\0';
|
||||
char *strstrd = strstr(tmp23, ";");
|
||||
if (strstrd != 0) {
|
||||
strstrd[0] = '\0';
|
||||
}
|
||||
|
||||
path_command(tmp23, elements_rev, already_done, 0);
|
||||
|
||||
if (strlen(tmp23) < 1) {
|
||||
break;
|
||||
}
|
||||
free(tmp23);
|
||||
}
|
||||
|
||||
printf("<- %s\n-> %s\n", (char*) result, (char *)page);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue