gawk

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

commit 8ba258493b5f1c1d390301d74b59fa7f3923f875
parent 7413a7e4a50f91b2d7c21b6b249da85065953145
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Mon, 21 Dec 2020 15:00:03 -0800

Only print prompt when on a tty and fix bug

Fix EOF causing an error when at the first level.

Diffstat:
Mmain.c | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c @@ -187,6 +187,17 @@ resolve(const char *host, const char *port) return s; } +void +putprompt(const char *prompt) +{ + if (isatty(STDIN_FILENO)) + fputs(prompt, stderr); + else if (errno == ENOTTY) + errno = 0; + else + warn("isatty %d", STDIN_FILENO); +} + int input(char *buf, int size, const char *delims, const char *prompt, FILE *fp) { @@ -195,7 +206,7 @@ input(char *buf, int size, const char *delims, const char *prompt, FILE *fp) static char bb[ARG_MAX]; if (len <= 0) { - fputs(prompt, stderr); + putprompt(prompt); refill_bufbuf: if (fgets(bb + len, sizeof(bb) - len, fp) == NULL) return 1; @@ -570,6 +581,9 @@ gawk(int depth, const char *tmpdir, const char *host, const char *path, const ch warn("'stdin'"); return -1; } + + if (feof(stdin)) + done = depth; return done - 1; }