commit 300c803bc6c0534c5df6cf30bb895fa6257ab324
parent 2c622122971a43b7929db7cb745ef00066baaae1
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Mon, 4 Jan 2021 22:35:12 -0800
Fix and improve cache command
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -7,6 +7,9 @@ static const char *default_address[] = { "/", "localhost", "70" };
/* how long to wait for response */
static int timeout = 5 * 1000;
+/* command which gets run when a file is cached */
+static const char cache_command[] = "p n";
+
#define IFS0 ";\n" /* statement sep */
#define IFS1 "|" /* command sep */
#define IFS2 " \t," /* argument sep */
diff --git a/main.c b/main.c
@@ -24,6 +24,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "command.h"
@@ -353,8 +354,6 @@ gawk(const char **addr)
mycache = 1;
if (gopher(addr, cache) == 1)
return ERROR;
- /*done = run_command(cache, NULL, 0, NULL, cprintn);
- */
}
++depth;
@@ -362,7 +361,13 @@ gawk(const char **addr)
snprintf(prompt, sizeof(prompt), "(%d) [%s] %s ",
depth, addr[AR_HOST], addr[AR_PATH]);
done = 0;
+
+ if (mycache) {
+ strlcpy(inbuf, cache_command, sizeof(inbuf));
+ goto execute;
+ }
while (!done && input(inbuf, sizeof(inbuf), IFS0, prompt, stdin) == 0) {
+execute:
done = execute(cache, inbuf, depth, addr);
if (done == ERROR && !fatal)
done = 0;