tExit when cmdline url isn't a directory item - sacc - sacc(omys), simple console gopher client (mirror) HTML git clone https://git.parazyd.org/sacc DIR Log DIR Files DIR Refs DIR LICENSE --- DIR commit b8badd7aa651af9ba23714f12c8fc68c2c4bdcdf DIR parent 32250e601c63ec2a1f0a1bab6c523b6372fc4f05 HTML Author: Quentin Rameau <quinq@fifth.space> Date: Thu, 13 Jul 2017 13:30:26 +0200 Exit when cmdline url isn't a directory item Diffstat: M sacc.c | 10 +++++++--- M ui_ti.c | 11 +++++++---- M ui_txt.c | 10 +++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) --- DIR diff --git a/sacc.c b/sacc.c t@@ -436,7 +436,7 @@ dig(Item *entry, Item *item) return item->type; if (!item->entry) - item->entry = entry; + item->entry = entry ? entry : item; switch (item->type) { case 'h': /* fallthrough */ t@@ -476,7 +476,7 @@ dig(Item *entry, Item *item) static void delve(Item *hole) { - Item *entry = hole; + Item *entry = NULL; char *selector; while (hole) { t@@ -512,9 +512,13 @@ delve(Item *hole) hole->port, hole->type, hole->selector); } + if (!entry) + return; + do { display(entry); - } while ((hole = selectitem(entry)) == entry); + hole = selectitem(entry); + } while (hole == entry); } } DIR diff --git a/ui_ti.c b/ui_ti.c t@@ -116,16 +116,16 @@ void display(Item *entry) { Item **items; - Dir *dir = entry->dat; + Dir *dir; size_t i, curln, lastln, nitems, printoff; - if (!(entry->type == '1' || entry->type == '7')) + if (!entry || !(entry->type == '1' || entry->type == '7')) return; putp(tparm(clear_screen)); displaystatus(entry); - if (!dir) + if (!(dir = entry->dat)) return; putp(tparm(save_cursor)); t@@ -250,9 +250,12 @@ jumptoline(Item *entry, ssize_t offset) Item * selectitem(Item *entry) { - Dir *dir = entry->dat; + Dir *dir; int plines = lines-2; + if (!entry || !(dir = entry->dat)) + return NULL; + for (;;) { switch (getchar()) { case 0x1b: /* ESC */ DIR diff --git a/ui_txt.c b/ui_txt.c t@@ -88,11 +88,12 @@ void display(Item *entry) { Item **items; - Dir *dir = entry->dat; + Dir *dir; size_t i, lines, nitems; int nd; - if (!(entry->type == '1' || entry->type == '7') || !dir) + if (!entry || !(entry->type == '1' || entry->type == '7') || + !(dir = entry->dat)) return; items = dir->items; t@@ -111,11 +112,14 @@ display(Item *entry) Item * selectitem(Item *entry) { - Dir *dir = entry->dat; + Dir *dir; static char c; char buf[BUFSIZ], nl; int item, nitems, lines; + if (!entry || !(dir = entry->dat)) + return NULL; + nitems = dir ? dir->nitems : 0; if (!c) c = 'h';