commit 9e4d93b53b1d29a48cd06653bc87787e626a5c87
parent 0391badc787ad74ae3b4295f13b9a3a3faa6d357
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Tue, 5 Jan 2021 22:16:49 -0800
Refactor gawk()
Move the `fatal` and `done` checks to the loop and define a the
size in gawk.h.
Diffstat:
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/gawk.h b/gawk.h
@@ -12,6 +12,7 @@
#define MY_LINE_MAX 256
#define MY_PATH_MAX 128
#define MY_PIPE_MAX 12
+#define MY_PROMPT_MAX 64
#define MY_URL_MAX 72
/* NOTE: don't change address order, see itemtoaddr() */
diff --git a/main.c b/main.c
@@ -384,7 +384,7 @@ gawk(char const **addr)
static int depth;
char cache[MY_PATH_MAX];
char inbuf[MY_INPUT_MAX];
- char prompt[64];
+ char prompt[MY_PROMPT_MAX];
int done;
int mycache;
@@ -407,12 +407,10 @@ gawk(char const **addr)
strlcpy(inbuf, cache_command, sizeof(inbuf));
goto execute;
}
- while (!done &&
+ while (!fatal && done <= 0 &&
input(inbuf, sizeof(inbuf), separators[0], prompt, stdin) == 0) {
execute:
done = execute(cache, inbuf, depth, addr);
- if (done < 0 && !fatal)
- done = 0;
}
if (mycache)