commit b80dbab2aeb720e58eb416912c23850715f516c2
parent 51bf87b71f0b0cc490c80baf0a941ee65d9444b2
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Fri, 1 Jan 2021 21:20:07 -0800
Refactor gawk
Diffstat:
M | main.c | | | 24 | ++++++++++++------------ |
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/main.c b/main.c
@@ -657,21 +657,22 @@ gawk(const char **addr)
else {
mycache = 1;
if (gopher(addr, cache) == 1)
- return 0; /* let the user handle it */
+ return ERROR;
done = run_command(cache, NULL, 0, NULL, cprintn);
}
- /* NOTE: do not return until --depth */
++depth;
+ snprintf(prompt, sizeof(prompt), "(%d) [%s] %s ",
+ depth, addr[AR_HOST], addr[AR_PATH]);
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) {
+ while (!done && input(inbuf, sizeof(inbuf), ISS, prompt, stdin) == 0) {
argc = argsplit(argv, LEN(argv), inbuf, IFS, 1);
- if (argc < 0) {
+ if (argc < 0)
warnx("Too many arguments.");
- } else if (argc > 0) {
- done = execute(argc, (const char **)argv, depth, cache, addr);
+ else if (argc > 0) {
+ done = execute(argc, (const char **)argv,
+ depth, cache, addr);
if (done == ERROR && !fatal)
done = 0;
}
@@ -681,13 +682,12 @@ gawk(const char **addr)
wremove(cache);
if (feof(stdin))
done = depth;
-
- --depth;
-
- if (ferror(stdin) && !fatal) {
- warn("'%s'", "/dev/stdin");
+ else if (ferror(stdin) && !fatal) {
+ warn("stdin");
return fatal = -1;
}
+
+ --depth;
return done - 1;
}