sacc

sacc(omys), simple console gopher client (mirror)
git clone https://git.parazyd.org/sacc
Log | Files | Refs | LICENSE

commit 5bf8439ba81e8d9235923dc3f8effa4a105ab8ba
parent a3ee498a2796928b86bdb2b6fd73c56af68dc0eb
Author: Christoph Lohmann <20h@r-36.net>
Date:   Tue, 25 Jul 2017 19:49:30 +0200

Add a status to failed connectto() requests.

Diffstat:
Mcommon.h | 1+
Msacc.c | 24++++++++++++++++--------
Mui_ti.c | 23+++++++++++++++++++++++
Mui_txt.c | 15+++++++++++++++
4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/common.h b/common.h @@ -25,6 +25,7 @@ struct dir { void die(const char *fmt, ...); void display(Item *item); Item *selectitem(Item *entry); +void status(char *fmt, ...); const char *typedisplay(char t); void uicleanup(void); char *uiprompt(char *fmt, ...); diff --git a/sacc.c b/sacc.c @@ -341,8 +341,10 @@ connectto(const char *host, const char *port) struct addrinfo *addrs, *addr; int sock, r; - if (r = getaddrinfo(host, port, &hints, &addrs)) - die("Can't resolve hostname ā€œ%sā€: %s", host, gai_strerror(r)); + if (r = getaddrinfo(host, port, &hints, &addrs)) { + status("Can't resolve hostname ā€œ%sā€: %s", host, gai_strerror(r)); + return -1; + } for (addr = addrs; addr; addr = addr->ai_next) { if ((sock = socket(addr->ai_family, addr->ai_socktype, @@ -354,10 +356,14 @@ connectto(const char *host, const char *port) } break; } - if (sock < 0) - die("Can't open socket: %s", strerror(errno)); - if (r < 0) - die("Can't connect to: %s:%s: %s", host, port, strerror(errno)); + if (sock < 0) { + status("Can't open socket: %s", strerror(errno)); + return -1; + } + if (r < 0) { + status("Can't connect to: %s:%s: %s", host, port, strerror(errno)); + return -1; + } freeaddrinfo(addrs); @@ -372,7 +378,8 @@ download(Item *item, int dest) int src; if (!item->tag) { - src = connectto(item->host, item->port); + if ((src = connectto(item->host, item->port)) < 0) + return 0; sendselector(src, item->selector); } else if ((src = open(item->tag, O_RDONLY)) < 0) { printf("Can't open source file %s: %s\n", @@ -446,7 +453,8 @@ fetchitem(Item *item) { int sock; - sock = connectto(item->host, item->port); + if ((sock = connectto(item->host, item->port)) < 0) + return 0; sendselector(sock, item->selector); item->raw = getrawitem(sock); close(sock); diff --git a/ui_ti.c b/ui_ti.c @@ -118,6 +118,29 @@ help(Item *entry) return &item; } +void +status(char *fmt, ...) +{ + va_list ap; + + putp(tparm(save_cursor)); + + putp(tparm(cursor_address, lines-1, 0)); + putp(tparm(enter_standout_mode)); + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + + printf(" <Press Key to continue>"); + getchar(); + + putp(tparm(exit_standout_mode)); + + putp(tparm(restore_cursor)); + fflush(stdout); +} + static void displaystatus(Item *item) { diff --git a/ui_txt.c b/ui_txt.c @@ -56,6 +56,21 @@ ndigits(size_t n) return (n < 10) ? 1 : (n < 100) ? 2 : 3; } +void +status(char *fmt, ...) +{ + va_list arg; + + va_start(arg, fmt); + vprintf(fmt, arg); + va_end(arg); + + printf(" <Press Key to continue>"); + fflush(stdout); + + getchar(); +} + static void printstatus(Item *item, char c) {