commit 7413a7e4a50f91b2d7c21b6b249da85065953145
parent a413191f30c58f6d72a696819ee63f94c95c936e
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Mon, 21 Dec 2020 14:47:40 -0800
Make command delimiters a macro
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -36,6 +36,7 @@
#define BUFSIZE 4096
#define ARGV_MAX 16
#define ARG_SEP ":\t "
+#define CMD_SEP ";\n"
enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_NULL };
@@ -187,7 +188,7 @@ resolve(const char *host, const char *port)
}
int
-input(char *buf, int size, const char *prompt, FILE *fp)
+input(char *buf, int size, const char *delims, const char *prompt, FILE *fp)
{
int next;
static int len;
@@ -201,7 +202,7 @@ refill_bufbuf:
len = strlen(bb);
}
- next = strcspn(bb, ";\n");
+ next = strcspn(bb, delims);
if (bb[next] == '\0') {
if (len >= sizeof(buf) - 1) {
too_big:
@@ -548,7 +549,7 @@ gawk(int depth, const char *tmpdir, const char *host, const char *path, const ch
done = 0;
snprintf(prompt, sizeof(prompt), "[%s] %s ", host, path);
- while (!done && input(inbuf, sizeof(inbuf), prompt, stdin) == 0) {
+ while (!done && input(inbuf, sizeof(inbuf), CMD_SEP, prompt, stdin) == 0) {
start = inbuf + strspn(inbuf, " \t");
if (*start != '\0') {
argc = argsplit(argv, LEN(argv), start + 1, ARG_SEP);