gawk

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

commit eb0c6118a0a696be48995faa496e1c919252e2cb
parent 97328d55af30493615f5eff43d910462cc46ac8f
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 23 Dec 2020 23:19:25 -0800

Add concatenation flag to argsplit() to fix splitrun()

This fixes empty fields in gopher-items.

Diffstat:
Mmain.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/main.c b/main.c @@ -94,17 +94,17 @@ warg(int min, int max, int argc, const char **ap) } int -argsplit(char **argv, int arg_max, char *s, const char *sep) +argsplit(char **argv, int size, char *s, const char *sep, int concatenate) { int argc; - for (argc = 0; argc < arg_max && + for (argc = 0; argc < size && (argv[argc] = strsep(&s, sep)) != NULL;) { - if (*argv[argc] != '\0') + if (!concatenate || *argv[argc] != '\0') ++argc; } - if (argc == arg_max && + if (argc == size && argv[argc - 1][strcspn(argv[argc - 1], sep)] == '\0') return -1; return argc; @@ -293,10 +293,11 @@ splitrun(filter **filters, int argc, const char **argv, unsigned int index, char int i, n; char *item[GI_NULL + 1]; - /* NOTE: argsplit ignores multiple terminators. */ - n = argsplit(item, LEN(item), s, "\t\r\n"); - if (n != 4 && (n < 4 || n > 5 || strcmp(item[GI_PLUS], "+") != 0)) + n = argsplit(item, LEN(item), s, "\t\r", 0) - 1; + if (n != 4 && (n < 4 || n > 5 || strcmp(item[GI_PLUS], "+") != 0)) { + warnx("%d: Invalid gopher-item.", index); return UNWIND; + } if (filters != NULL) { for (i = 0; filters[i] != NULL; ++i) { @@ -634,7 +635,7 @@ gawk(const char **addr) done = 0; snprintf(prompt, sizeof(prompt), "(%d) [%s] %s ", depth, addr[AR_HOST], addr[AR_PATH]); while (!fatal && !done && input(inbuf, sizeof(inbuf), ISS, prompt, stdin) == 0) { - argc = argsplit(argv, LEN(argv), inbuf, IFS); + argc = argsplit(argv, LEN(argv), inbuf, IFS, 1); if (argc < 0) { warnx("Too many arguments."); } else if (argc > 0) {