gawk

[old] Sed-like interface to the Gopher protocol
Log | Files | Refs | LICENSE

commit 7c166993c74c4bef19553a20e4206659d159cf30
parent 91209551fd7463eee86284190b0241ec2b037332
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed,  6 Jan 2021 23:59:11 -0800

Standardize and improve error messages

Apart from being more useful in general, if they start with a letter
it is lowercase and they don't end in a period which is now inserted
by `warn'.

Also remove unused function `strtorange'.

Diffstat:
Mcommand.c | 12++++++------
Mmain.c | 12++++++------
Mnet.c | 4++--
Mutil.c | 25+++----------------------
4 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/command.c b/command.c @@ -64,9 +64,9 @@ LOCAL int warg(int min, int max, int argc, char **ap) { if (max > 0 && argc > max) - warn(0, "'%s': '%s'... unused.", *ap, ap[max]); + warn(0, "%s: '%s'... unused", *ap, ap[max]); else if (min > 0 && argc < min) - warn(0, "'%s': Not enough arguments.", *ap); + warn(0, "%s: Not enough arguments", *ap); else return 0; return 1; @@ -104,7 +104,7 @@ timid_gopher(char **addr, char *path, int bin, int timeout) { if (!exists(path)) return gopher(addr, path, bin, timeout); - warn(EEXIST, "'%s'", path); + warn(EEXIST, "not writing to '%s'", path); return 1; } @@ -122,7 +122,7 @@ cfetch(int argc, char **argv, int ino, char **item) else { path = basename(item[GI_PATH]); if (path == NULL) { - warn(errno, "Unable to get basename '%s'", item[GI_PATH]); + warn(errno, "unable to get basename '%s'", item[GI_PATH]); return NEXT; } } @@ -168,7 +168,7 @@ cprint(int argc, char **argv, int ino, char **item) if (**item == 'i') printf(" %s\n", item[GI_INFO] + 1); else if (**item == '3') - warn(0, "'%s': %s\n", item[GI_HOST], item[GI_INFO] + 1); + fprintf(stderr, "%s: %s\n", item[GI_HOST], item[GI_INFO] + 1); else printf("%4d [%c] %s\n", ino, item[GI_INFO][0], item[GI_INFO] + 1); @@ -213,7 +213,7 @@ frange(int argc, char **argv, int ino, char **item) if (warg(3, -1, argc, argv)) return FAIL; if (argc % 2 != 1) { - warn(0, "%s: Unbalenced range.", *argv); + warn(0, "%s: Unbalenced range", *argv); return FAIL; } diff --git a/main.c b/main.c @@ -77,7 +77,7 @@ refill_bufbuf: if (bb[next] == '\0') { if (len >= sizeof(buf) - 1) { too_big: - warn(E2BIG, "input"); + warn(0, "input too large"); return 1; } goto refill_bufbuf; @@ -168,7 +168,7 @@ execute(char const *cache, char *input, int depth, char **addr) nbufs = argsplit(bufs, LEN(bufs), input, separators[1], 0); if (nbufs < 0) { - warn(0, "Pipeline too long."); + warn(0, "pipeline too long"); return ERROR; } @@ -177,9 +177,9 @@ execute(char const *cache, char *input, int depth, char **addr) bufs[i], separators[2], 1); if (cmds[i].argc < 1) { if (cmds[i].argc < 0) - warn(E2BIG, "command %d", i); + warn(0, "command %d: Too many arguments", i); else if (nbufs > 1) - warn(0, "command %d: Empty command.", i); + warn(0, "command %d: Empty command", i); return ERROR; } if (cmds[i].argv[0][0] != negate) { @@ -194,13 +194,13 @@ execute(char const *cache, char *input, int depth, char **addr) cmds[i].f = getcom(cmds[i].argv[0], itembinds, LEN(itembinds)); if (cmds[i].f == NULL) { if (i > 0) { - warn(0, "'%s': Not a pipeline command.", + warn(0, "'%s': Not a pipeline command", cmds[i].argv[0]); return ERROR; } cmds[i].f = getcom(cmds[i].argv[0], binds, LEN(binds)); if (cmds[i].f == NULL) { - warn(0, "'%s': Not a command.", cmds[i].argv[0]); + warn(0, "'%s': Not a command", cmds[i].argv[0]); return ERROR; } return cmds[i].f(cmds[i].argc, cmds[i].argv, depth, addr); diff --git a/net.c b/net.c @@ -38,7 +38,7 @@ resolve(char const *host, char const *port) freeaddrinfo(ai0); if (s == -1) { - warn(0, "unable to connect to '%s' at '%s'", host, port); + warn(errno, "unable to connect '%s' (%s)", host, port); return -1; } return s; @@ -123,7 +123,7 @@ gphto(int sock, char const *path, int bin, int timeout) pfd.fd = sock; pfd.events = POLLRDNORM; if (poll(&pfd, 1, timeout) < 1) { - warn(errno, "Unable to recieve response"); + warn(errno, "unable to recieve response"); return 1; } diff --git a/util.c b/util.c @@ -32,7 +32,7 @@ wfopen(char const *path, char const *mode) fp = fopen(path, mode); if (fp == NULL) - warn(errno, "unable to open '%s' ('%s')", path, mode); + warn(errno, "unable to open '%s' (%s)", path, mode); return fp; } @@ -49,25 +49,6 @@ exists(char const *path) } int -strtorange(unsigned int *r, unsigned int min, unsigned int max, char const *s) -{ - char *ep; - unsigned long n; - - n = strtoul(s, &ep, 10); - if (*s == '\0' || *ep != '\0') - errno = EINVAL; - else if (n < min || n > max) - errno = ERANGE; - else { - *r = n; - return 0; - } - warn(errno, "'%s'", s); - return 1; -} - -int wfclose(FILE *fp) { int error; @@ -97,7 +78,7 @@ wstrtonum(const char *ns, long long min, long long max, const char **err) n = strtonum(ns, min, max, err); if (*err != NULL) - warn(0, "number '%s': %s", ns, *err); + warn(0, "numeric string '%s' is %s", ns, *err); return n; } @@ -124,5 +105,5 @@ warn(int error, char const *format, ...) if (error) fprintf(stderr, ": %s", strerror(error)); - fputc('\n', stderr); + fprintf(stderr, ".\n"); }