tReplace Dir pointer with a void pointer in Item struct - 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 5f125c4f75c25a0bd4aeecc9625307c52f6a8c41 DIR parent da486e90d17187e1fe8d8ed26982840059aaf968 HTML 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: M common.h | 2 +- M sacc.c | 12 ++++++------ M ui_ti.c | 31 +++++++++++++++++-------------- M ui_txt.c | 14 ++++++++------ 4 files changed, 32 insertions(+), 27 deletions(-) --- DIR diff --git a/common.h b/common.h t@@ -13,7 +13,7 @@ struct item { size_t printoff; size_t curline; Item *entry; - Dir *dir; + void *dat; }; struct dir { DIR diff --git a/sacc.c b/sacc.c t@@ -94,7 +94,7 @@ usage(void) static void clearitem(Item *item) { - Dir *dir = item->dir; + Dir *dir = item->dat; Item **items; size_t i; t@@ -105,7 +105,7 @@ clearitem(Item *item) free(items[i]); } free(items); - clear(&item->dir); + clear(&item->dat); } clear(&item->raw); t@@ -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; } t@@ -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': t@@ -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; t@@ -571,7 +571,7 @@ moldentry(char *url) entry->printoff = 0; entry->curline = 0; entry->raw = NULL; - entry->dir = NULL; + entry->dat = NULL; return entry; } DIR diff --git a/ui_ti.c b/ui_ti.c t@@ -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)); t@@ -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')) t@@ -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 */ t@@ -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) { t@@ -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; t@@ -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)); t@@ -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); t@@ -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) t@@ -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 (;;) { t@@ -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: DIR diff --git a/ui_txt.c b/ui_txt.c t@@ -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 : t@@ -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); t@@ -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'; t@@ -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; }