cgmnlm

gemini line mode browser - colorful & extended fork of https://git.sr.ht/~sircmpwn/gmni
git clone git://git.clttr.info/cgmnlm.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 7e3f6b7fac896d9be72b65e337a5fdb321036920
parent b262fa7c52973a1f626f54e553be49de73706638
Author: René Wagner <rwa@clttr.info>
Date:   Thu, 18 Aug 2022 20:10:25 +0200

fix usage of vars in do_prompts

Diffstat:
Msrc/gmnlm.c | 49++++++++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -648,7 +648,7 @@ do_prompts(const char *prompt, struct browser *browser) size_t l = 0; - char url[1024] = {0}; + char curr_url[1024] = {0}; char save_url[1024] = {0}; char *in = NULL; @@ -717,8 +717,8 @@ do_prompts(const char *prompt, struct browser *browser) result = PROMPT_AGAIN; goto exit; case 'l': - snprintf(url, sizeof(url), "gemini://geminispace.info/backlinks?%s", browser->plain_url); - set_url(browser, url, &browser->history); + snprintf(curr_url, sizeof(curr_url), "gemini://geminispace.info/backlinks?%s", browser->plain_url); + set_url(browser, curr_url, &browser->history); result = PROMPT_ANSWERED; goto exit; case 'f': @@ -752,8 +752,8 @@ do_prompts(const char *prompt, struct browser *browser) } } if (keep > 9) { - strncpy(url , browser->plain_url, keep+1); - set_url(browser, url, &browser->history); + strncpy(curr_url , browser->plain_url, keep+1); + set_url(browser, curr_url, &browser->history); } result = PROMPT_ANSWERED; goto exit; @@ -802,9 +802,9 @@ do_prompts(const char *prompt, struct browser *browser) goto exit; case 'e': case 't': - strncpy(&save_url[0], browser->plain_url, sizeof(url)-1); + strncpy(&save_url[0], browser->plain_url, sizeof(save_url)-1); if (!in[1]) { - strncpy(&url[0], browser->plain_url, sizeof(url)-1); + strncpy(&curr_url[0], browser->plain_url, sizeof(curr_url)-1); } else { struct link *link = browser->links; int linksel = (int)strtol(in+1, &endptr, 10); @@ -816,30 +816,30 @@ do_prompts(const char *prompt, struct browser *browser) if (!link) { fprintf(stderr, "Error: no such link.\n"); } else { - strncpy(&url[0], link->url, sizeof(url)-1); + strncpy(&curr_url[0], link->url, sizeof(curr_url)-1); } } } - if (url[0]) { - fprintf(browser->tty, "=> %s\n", url); + if (curr_url[0]) { + fprintf(browser->tty, "=> %s\n", curr_url); char *tempfile; tempfile = tmpnam(NULL); if (in[0] == 't') { struct gemini_response resp; - set_url(browser, url, NULL); + set_url(browser, curr_url, NULL); enum gemini_result res = do_requests(browser, &resp); if (res != GEMINI_OK) { fprintf(stderr, "Error: %s\n", gemini_strerr(res, &resp)); } else { - download_resp(browser->tty, resp, tempfile, url); + download_resp(browser->tty, resp, tempfile, curr_url); } gemini_response_finish(&resp); set_url(browser, save_url, NULL); } if (in[0] == 'e' || browser->autoopen) { char target[1050]; - snprintf(target, sizeof(target), "xdg-open %s >/dev/null 2>&1", in[0] == 't' ? tempfile : url); + snprintf(target, sizeof(target), "xdg-open %s >/dev/null 2>&1", in[0] == 't' ? tempfile : curr_url); if ( !system(target) ) fprintf(browser->tty, "Link send to xdg-open\n"); } fprintf(browser->tty, "\n"); @@ -930,24 +930,23 @@ do_prompts(const char *prompt, struct browser *browser) } } struct gemini_response resp; - char url[1024] = {0}, old_url[1024] = {0}; - strncpy(&old_url[0], browser->plain_url, sizeof(url)-1); - strncpy(&url[0], d_url, sizeof(url)-1); + strncpy(&save_url[0], browser->plain_url, sizeof(url)-1); + strncpy(&curr_url[0], d_url, sizeof(url)-1); // XXX: may affect history, do we care? - set_url(browser, url, NULL); + set_url(browser, curr_url, NULL); enum gemini_result res = do_requests(browser, &resp); if (res != GEMINI_OK) { fprintf(stderr, "Error: %s\n", gemini_strerr(res, &resp)); - set_url(browser, old_url, NULL); + set_url(browser, save_url, NULL); goto exit; } - download_resp(browser->tty, resp, trim_ws(endptr), url); + download_resp(browser->tty, resp, trim_ws(endptr), curr_url); gemini_response_finish(&resp); - set_url(browser, old_url, NULL); + set_url(browser, save_url, NULL); goto exit; case '|': - strncpy(&url[0], browser->plain_url, sizeof(url)-1); + strncpy(&curr_url[0], browser->plain_url, sizeof(url)-1); res = do_requests(browser, &resp); if (res != GEMINI_OK) { fprintf(stderr, "Error: %s\n", @@ -956,7 +955,7 @@ do_prompts(const char *prompt, struct browser *browser) } pipe_resp(browser->tty, resp, &in[1]); gemini_response_finish(&resp); - set_url(browser, url, NULL); + set_url(browser, curr_url, NULL); goto exit; case '?': if (in[1]) { @@ -989,18 +988,18 @@ do_prompts(const char *prompt, struct browser *browser) goto exit; } else if (endptr[0] == '|') { struct gemini_response resp; - strncpy(url, browser->plain_url, sizeof(url) - 1); + strncpy(curr_url, browser->plain_url, sizeof(curr_url) - 1); set_url(browser, link->url, &browser->history); enum gemini_result res = do_requests(browser, &resp); if (res != GEMINI_OK) { fprintf(stderr, "Error: %s\n", gemini_strerr(res, &resp)); - set_url(browser, url, NULL); + set_url(browser, curr_url, NULL); goto exit; } pipe_resp(browser->tty, resp, &endptr[1]); gemini_response_finish(&resp); - set_url(browser, url, NULL); + set_url(browser, curr_url, NULL); goto exit; } else { assert(endptr[0] == '\0');