commit e0142677f028fa10fe60feb95af7ea06bfb492af
parent 4d3efda82f69bc1ba930ba192d12e59a95c7d05f
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Tue, 5 Jan 2021 14:40:35 -0800
Use constant array for separators in config.h
Much cleaner than using a set of macros and indexes are implicit.
Diffstat:
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -10,9 +10,10 @@ static int timeout = 5 * 1000;
/* command which gets run when a file is cached */
static const char cache_command[] = "p";
-#define IFS0 ";\n" /* statement sep */
-#define IFS1 "|" /* command sep */
-#define IFS2 " \t," /* argument sep */
+/* statement, command, argument */
+static char const *const separators[] = {
+ ";\n", "|", " \t,"
+};
/* arbitrary limits */
#define CHUNK_SIZE 256 /* for slurping data */
diff --git a/main.c b/main.c
@@ -299,13 +299,13 @@ execute(char const *cache, char *input, int depth, char const **addr)
if (*input == '\0')
return ERROR;
- cbufslen = argsplit(cbufs, LEN(cbufs), input, IFS1, 0);
+ cbufslen = argsplit(cbufs, LEN(cbufs), input, separators[1], 0);
for (i = 0; i < cbufslen; ++i) {
if (i >= MY_PIPE_MAX) {
warn(0, "Pipeline too long.");
return ERROR;
}
- acs[i] = argsplit(avs[i], LEN(avs[i]), cbufs[i], IFS2, 1);
+ acs[i] = argsplit(avs[i], LEN(avs[i]), cbufs[i], separators[2], 1);
if (acs[i] == 0) {
warn(0, "Empty pipe (#%d).", ++i);
return ERROR;
@@ -365,7 +365,8 @@ gawk(char const **addr)
strlcpy(inbuf, cache_command, sizeof(inbuf));
goto execute;
}
- while (!done && input(inbuf, sizeof(inbuf), IFS0, prompt, stdin) == 0) {
+ while (!done &&
+ input(inbuf, sizeof(inbuf), separators[0], prompt, stdin) == 0) {
execute:
done = execute(cache, inbuf, depth, addr);
if (done < 0 && !fatal)