tMove fetching item in its own function - 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 b2cd58c614e59b3def93e302717c728b31eea7bd DIR parent 72f22a1a005e90143cff6749fc8022164c2e357a HTML Author: Quentin Rameau <quinq@fifth.space> Date: Wed, 5 Jul 2017 16:58:32 +0200 Move fetching item in its own function Diffstat: M sacc.c | 39 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) --- DIR diff --git a/sacc.c b/sacc.c t@@ -324,21 +324,10 @@ connectto(const char *host, const char *port) } static int -dig(Item *entry, Item *item) +fetchitem(Item *item) { int sock; - if (item->raw) /* already in cache */ - return item->type; - - if (!item->entry) - item->entry = entry; - - if (item->type > '1') { - fprintf(stderr, "Type %c not supported\n", item->type); - return 0; - } - sock = connectto(item->host, item->port); sendselector(sock, item->selector); item->raw = getrawitem(sock); t@@ -351,12 +340,34 @@ dig(Item *entry, Item *item) return 0; } - if (item->type == '1') { - if (!(item->dir = molddiritem(item->raw))) { + return (item->raw != NULL); +} + +static int +dig(Item *entry, Item *item) +{ + if (item->raw) /* already in cache */ + return item->type; + + if (!item->entry) + item->entry = entry; + + switch (item->type) { + case '0': + if (!fetchitem(item)) + return 0; + break; + case '1': + if (!fetchitem(item) || !(item->dir = molddiritem(item->raw))) { fputs("Couldn't parse dir item\n", stderr); return 0; } + break; + default: + fprintf(stderr, "Type %c not supported\n", item->type); + return 0; } + return item->type; }