sacc

sacc (saccomys): simple gopher client.
Log | Files | Refs | LICENSE

commit 50d40c927e6bfb06eea4e94865e2d5a9ee9978ca
parent 0ba0de905d001b69aac78f2629cf31039bb74d67
Author: Quentin Rameau <quinq@fifth.space>
Date:   Thu, 22 Jun 2017 14:30:53 +0200

Copy cmdline in main rather than in moldentry

We would lose raw when fetching the item, and the logic of having
connection data inside the parent is preserved

Diffstat:
sacc.c | 31++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -380,17 +380,15 @@ delve(Item *hole) } Item * -parseurl(const char *URL) +moldentry(char *url) { - Item *hole; - char *p, *url, *host, *port = "gopher", *gopherpath = "1"; + Item *entry; + char *p, *host = url, *port = "gopher", *gopherpath = "1"; int parsed, ipv6; - host = url = xstrdup(URL); - if (p = strstr(url, "://")) { if (strncmp(url, "gopher", p - url)) - die("Protocol not supported: %.*s (%s)", p - url, url, URL); + die("Protocol not supported: %.*s", p - url, url); host = p + 3; } @@ -424,20 +422,19 @@ parseurl(const char *URL) } if (*host == '\0' || *port == '\0' || ipv6) - die("Can't parse url: %s", URL); + die("Can't parse url"); if (gopherpath[0] > '1') - die("Gopher type not supported: %s (%s)", - typedisplay(gopherpath[0]), URL); - + die("Gopher type not supported: %s", + typedisplay(gopherpath[0])); entry = xmalloc(sizeof(Item)); - entry->raw = url; entry->type = gopherpath[0]; entry->username = entry->selector = ++gopherpath; entry->host = host; entry->port = port; entry->entry = entry; + entry->raw = NULL; entry->dir = NULL; return entry; @@ -446,15 +443,19 @@ parseurl(const char *URL) int main(int argc, char *argv[]) { - Item *hole; + Item *entry; + char *url; if (argc != 2) usage(); - hole = parseurl(argv[1]); + url = xstrdup(argv[1]); + + entry = moldentry(url); + delve(entry); - delve(hole); - free(hole); /* TODO free all tree recursively */ + free(entry); /* TODO free all tree recursively */ + free(url); return 0; }