commit 5f125c4f75c25a0bd4aeecc9625307c52f6a8c41
parent da486e90d17187e1fe8d8ed26982840059aaf968
Author: Quentin Rameau <quinq@fifth.space>
Date: Wed, 12 Jul 2017 23:54:23 +0200
Replace Dir pointer with a void pointer in Item struct
Diffstat:
4 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/common.h b/common.h
@@ -13,7 +13,7 @@ struct item {
size_t printoff;
size_t curline;
Item *entry;
- Dir *dir;
+ void *dat;
};
struct dir {
diff --git a/sacc.c b/sacc.c
@@ -94,7 +94,7 @@ usage(void)
static void
clearitem(Item *item)
{
- Dir *dir = item->dir;
+ Dir *dir = item->dat;
Item **items;
size_t i;
@@ -105,7 +105,7 @@ clearitem(Item *item)
free(items[i]);
}
free(items);
- clear(&item->dir);
+ clear(&item->dat);
}
clear(&item->raw);
@@ -444,7 +444,7 @@ dig(Item *entry, Item *item)
break;
case '1':
case '7':
- if (!fetchitem(item) || !(item->dir = molddiritem(item->raw))) {
+ if (!fetchitem(item) || !(item->dat = molddiritem(item->raw))) {
fputs("Couldn't parse dir item\n", stderr);
return 0;
}
@@ -480,7 +480,7 @@ delve(Item *hole)
displaytextitem(hole);
break;
case '1':
- if (dig(entry, hole) && hole->dir)
+ if (dig(entry, hole) && hole->dat)
entry = hole;
break;
case '7':
@@ -488,7 +488,7 @@ delve(Item *hole)
free(hole->raw);
hole->raw = NULL;
hole->printoff = 0;
- if (dig(entry, hole) && hole->dir)
+ if (dig(entry, hole) && hole->dat)
entry = hole;
free(hole->selector);
hole->selector = selector;
@@ -571,7 +571,7 @@ moldentry(char *url)
entry->printoff = 0;
entry->curline = 0;
entry->raw = NULL;
- entry->dir = NULL;
+ entry->dat = NULL;
return entry;
}
diff --git a/ui_ti.c b/ui_ti.c
@@ -94,7 +94,7 @@ help(void)
static void
displaystatus(Item *item)
{
- size_t nitems = item->dir ? item->dir->nitems : 0;
+ size_t nitems = item->dat ? ((Dir*)item->dat)->nitems : 0;
putp(tparm(save_cursor));
@@ -114,6 +114,7 @@ void
display(Item *entry)
{
Item **items;
+ Dir *dir = entry->dat;
size_t i, curln, lastln, nitems, printoff;
if (!(entry->type == '1' || entry->type == '7'))
@@ -122,13 +123,13 @@ display(Item *entry)
putp(tparm(clear_screen));
displaystatus(entry);
- if (!entry->dir)
+ if (!dir)
return;
putp(tparm(save_cursor));
- items = entry->dir->items;
- nitems = entry->dir->nitems;
+ items = dir->items;
+ nitems = dir->nitems;
printoff = entry->printoff;
curln = entry->curline;
lastln = printoff + lines-1; /* one off for status bar */
@@ -153,19 +154,20 @@ display(Item *entry)
static void
movecurline(Item *item, int l)
{
+ Dir *dir = item->dat;
size_t nitems;
ssize_t curline, offline;
int plines = lines-2;
- if (item->dir == NULL)
+ if (dir == NULL)
return;
curline = item->curline + l;
- nitems = item->dir->nitems;
+ nitems = dir->nitems;
if (curline < 0 || curline >= nitems)
return;
- printitem(item->dir->items[item->curline]);
+ printitem(dir->items[item->curline]);
item->curline = curline;
if (l > 0) {
@@ -175,7 +177,7 @@ movecurline(Item *item, int l)
putp(tparm(cursor_address, plines, 0));
putp(tparm(scroll_forward));
- printitem(item->dir->items[offline]);
+ printitem(dir->items[offline]);
putp(tparm(restore_cursor));
item->printoff += l;
@@ -187,7 +189,7 @@ movecurline(Item *item, int l)
putp(tparm(cursor_address, 0, 0));
putp(tparm(scroll_reverse));
- printitem(item->dir->items[offline]);
+ printitem(dir->items[offline]);
putchar('\n');
putp(tparm(restore_cursor));
@@ -197,7 +199,7 @@ movecurline(Item *item, int l)
putp(tparm(cursor_address, curline - item->printoff, 0));
putp(tparm(enter_standout_mode));
- printitem(item->dir->items[curline]);
+ printitem(dir->items[curline]);
putp(tparm(exit_standout_mode));
displaystatus(item);
fflush(stdout);
@@ -206,13 +208,14 @@ movecurline(Item *item, int l)
static void
jumptoline(Item *entry, ssize_t offset)
{
+ Dir *dir = entry->dat;
size_t nitems;
int plines = lines-2;
- if (!entry->dir)
+ if (!dir)
return;
- nitems = entry->dir->nitems;
+ nitems = dir->nitems;
if (offset <= 0) {
if (!entry->curline)
@@ -245,7 +248,7 @@ jumptoline(Item *entry, ssize_t offset)
Item *
selectitem(Item *entry)
{
- Dir *dir = entry->dir;
+ Dir *dir = entry->dat;
int plines = lines-2;
for (;;) {
@@ -305,7 +308,7 @@ selectitem(Item *entry)
continue;
case _key_end:
end:
- jumptoline(entry, entry->dir->nitems);
+ jumptoline(entry, dir->nitems);
continue;
case _key_lnup:
lnup:
diff --git a/ui_txt.c b/ui_txt.c
@@ -58,7 +58,7 @@ ndigits(size_t n)
static void
printstatus(Item *item, char c)
{
- size_t nitems = item->dir ? item->dir->nitems : 0;
+ size_t nitems = item->dat ? ((Dir*)item->dat)->nitems : 0;
printf("%3lld%%%*c %s:%s%s [%c]: ",
(item->printoff + lines >= nitems) ? 100 :
@@ -87,14 +87,15 @@ void
display(Item *entry)
{
Item **items;
+ Dir *dir = entry->dat;
size_t i, lines, nitems;
int nd;
- if (!(entry->type == '1' || entry->type == '7') || !entry->dir)
+ if (!(entry->type == '1' || entry->type == '7') || !dir)
return;
- items = entry->dir->items;
- nitems = entry->dir->nitems;
+ items = dir->items;
+ nitems = dir->nitems;
lines = entry->printoff + termlines();
nd = ndigits(nitems);
@@ -109,11 +110,12 @@ display(Item *entry)
Item *
selectitem(Item *entry)
{
+ Dir *dir = entry->dat;
static char c;
char buf[BUFSIZ], nl;
int item, nitems, lines;
- nitems = entry->dir ? entry->dir->nitems : 0;
+ nitems = dir ? dir->nitems : 0;
if (!c)
c = 'h';
@@ -181,7 +183,7 @@ selectitem(Item *entry)
} while (item < 0 || item > nitems);
if (item > 0)
- return entry->dir->items[item-1];
+ return dir->items[item-1];
return entry->entry;
}