gophra

gopher client for plan9
git clone git://nsmpr.xyz/gophra.git
Log | Files | Refs

commit 6867e70d23442c59c53402ab3f766a7ac6c3bdae
parent 2809473fd3803550b0870dd3ae606a9117c7876d
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Mon, 26 Jul 2021 15:30:08 +0000

hacky download for type 9 links

Diffstat:
Mgophra.c | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/gophra.c b/gophra.c @@ -33,11 +33,13 @@ Text text; char status[256], path[256], addr[256], type; const char *tmpfile = "/tmp/gophra.tmp"; long scroll; +Mousectl *mc; +Keyboardctl *kc; char* getlinep(Text*, ulong); URI extracturi(char *s); int runuri(char*); -int save(char*, char*); +int save(char*, char*, char*); void back(void); void calcrects(void); void drawborder(void); @@ -315,6 +317,7 @@ drawmenu(void) n = strchr(s, '\t') - (s + 1); while (dp.x + stringnwidth(font, s+1, n) > rw.max.x) n--; buf = mallocz(sizeof(char) * (n + 1), 1); + if (buf == nil) break; memcpy(buf, s + 1, n); if (*s == 'i') Ifg = Iwfg; else Ifg = Iwfgl; @@ -375,7 +378,7 @@ handlelink(char *addr, char type, char *path) History *hnew; switch (type) { case '0': - if (save(addr, path) == 0) proccreate(runhold, 0, 1024 * 8); + if (save(addr, path, tmpfile) == 0) proccreate(runhold, 0, 1024 * 8); break; case '1': hnew = malloc(sizeof(History)); @@ -385,8 +388,11 @@ handlelink(char *addr, char type, char *path) strncpy(hp->path, path, 256); loadtext(addr, path); break; + case '9': + save(addr, path, tmpfile); + break; case 'I': - if (save(addr, path) == 0) proccreate(runpage, 0, 1024 * 8); + if (save(addr, path, tmpfile) == 0) proccreate(runpage, 0, 1024 * 8); break; default: snprint(status, 255, "unknown type - %c", type); @@ -422,7 +428,7 @@ runpage(void*) } int -save(char *addr, char *path) +save(char *addr, char *path, char *fname) { int dcfd, wfd; long n; @@ -439,9 +445,10 @@ save(char *addr, char *path) return -1; } - wfd = create(tmpfile, OWRITE, 0666); + wfd = create(fname, OWRITE, 0666); if (wfd <= 0) { - snprint(status, 255, "failed to create tmpfile"); + snprint(status, 255, "failed to create file"); + fprint(2, "%r\n"); drawstatus(); flushimage(display, 1); return -1;