commit b8badd7aa651af9ba23714f12c8fc68c2c4bdcdf
parent 32250e601c63ec2a1f0a1bab6c523b6372fc4f05
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:
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/sacc.c b/sacc.c
@@ -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 */
@@ -476,7 +476,7 @@ dig(Item *entry, Item *item)
static void
delve(Item *hole)
{
- Item *entry = hole;
+ Item *entry = NULL;
char *selector;
while (hole) {
@@ -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);
}
}
diff --git a/ui_ti.c b/ui_ti.c
@@ -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));
@@ -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 */
diff --git a/ui_txt.c b/ui_txt.c
@@ -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;
@@ -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';