aboutsummaryrefslogtreecommitdiff
path: root/browser.c
diff options
context:
space:
mode:
Diffstat (limited to 'browser.c')
-rw-r--r--browser.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/browser.c b/browser.c
index f5a10cc..22d4b90 100644
--- a/browser.c
+++ b/browser.c
@@ -122,25 +122,31 @@ int main(int argc, char* argv[]) {
*/
page = get_page("127.0.0.1", "8080", address);
-
- free(anchorIndecies);
- anchorCount = 0;
renderPage(page, &md, &anchorIndecies, &anchorCount);
/*
* Handle user input
*/
+
scanf("%d", &gotoIndex);
- sdsfree(address);
- char* newplace = strchr(page + anchorIndecies[gotoIndex], '(') + 1;
- address = sdscatlen(sdsnew(argv[1]), newplace, strchr(newplace, ')') - newplace);
+ if (gotoIndex < anchorCount) {
+ char* newplace = strchr(page + anchorIndecies[gotoIndex], '(') + 1;
+ sdsfree(address);
+ address = sdscatlen(sdsnew(argv[1]), newplace, strchr(newplace, ')') - newplace);
+
+ free(anchorIndecies);
+ anchorCount = 0;
+ }
+ else {
+ printf("error\n");
+ }
+ sdsfree(page);
count++;
}
regfree(&md.anchor);
- sdsfree(page);
- sdsfree(address);
free(anchorIndecies);
+ sdsfree(address);
}